package com.enterprise.manage.modules.asset.controller;

import com.enterprise.manage.common.base.BaseController;
import com.enterprise.manage.common.web.request.PageDomain;
import com.enterprise.manage.common.web.response.Result;
import com.enterprise.manage.common.web.response.module.ResultTable;
import com.enterprise.manage.modules.asset.domain.Land;
import com.enterprise.manage.modules.asset.service.ILandService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 土地信息 Controller
 *
 * @author QingLi Wang
 * @version 1.0.0
 * 2023-11-28 09:51
 */
@RestController
@RequestMapping("/asset/land/v1")
public class LandController extends BaseController {

    private ILandService landService;

    @Autowired
    public LandController(ILandService landService) {
        this.landService = landService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','asset:land:list')")
    public ResultTable list(PageDomain pageDomain, Land param) {
        PageInfo<Land> landPage = landService.page(pageDomain, param);
        return pageTable(landPage.getList(), landPage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','asset:land:list')")
    public Result get(@PathVariable Long id) {
        return success(landService.queryById(id));
    }

    @PostMapping
    @PreAuthorize("hasPermission('','asset:land:add')")
    public Result add(Land land) {
        return decide(landService.save(land));
    }

    @PutMapping
    @PreAuthorize("hasPermission('','asset:land:edit')")
    public Result edit(Land land) {
        return decide(landService.update(land));
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasPermission('','asset:land:del')")
    public Result remove(@PathVariable Integer id) {
        return decide(landService.removeById(id));
    }

}
