package com.project.zcustom.controller.logistics;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.zcustom.domain.addional.LargeHousingLand;
import com.project.zcustom.service.logistics.ILargeHousingLandService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

@RestController
@RequestMapping("/zcustom/housing")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LargeHousingLandController extends BaseController{

    @Autowired
    private ILargeHousingLandService largeHousingLandService;
    @GetMapping("/list")
    public AjaxResult list(LargeHousingLand entity) {
        return AjaxResult.success("查询成功", largeHousingLandService.pagingLargePlatHousingLandList(entity));
    }


    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", largeHousingLandService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platHousingLand:add')")
    @Log(title = "房产土地", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody LargeHousingLand entity) {
        return toAjax(largeHousingLandService.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platHousingLand:edit')")
    @Log(title = "房产土地", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody LargeHousingLand entity) {
        return toAjax(largeHousingLandService.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platHousingLand:remove')")
    @Log(title = "房产土地", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(largeHousingLandService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }

    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file) {
        return toAjax(largeHousingLandService.upload(file));
    }
}
