package thyyxxk.webserver.controller.lc.project;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.lc.company.LcCompany;
import thyyxxk.webserver.entity.lc.company.LcCompanyParam;
import thyyxxk.webserver.entity.lc.project.LcProject;
import thyyxxk.webserver.entity.lc.project.LcProjectParam;
import thyyxxk.webserver.entity.lc.project.LcProjectType;
import thyyxxk.webserver.service.lc.project.LcProjectService;
import thyyxxk.webserver.service.lc.project.LcProjectTypeService;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;


@RestController
@RequestMapping("/LcProject")
public class LcProjectController {

    @Autowired
    private LcProjectService lcProjectService;

    /**
     * 通过id获取项目信息
     * @param id
     * @return
     */
    @GetMapping("/getLcProjectById")
    public ResultVo<LcProjectParam> getLcProjectById(@RequestParam("id") String id) {
        if (StringUtil.isBlank(id)) {
            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "id不能为空！");
        }
        return ResultVoUtil.success(lcProjectService.getLcProjectById(id));
    }

    /**
     * 模糊分页查询项目列表
     * @param lcProjectParam
     * @return
     */
    @PostMapping("/getLcProjectList")
    public ResultVo<Page<LcProject>> getLcCompanyById(@RequestBody LcProjectParam lcProjectParam) {
        return ResultVoUtil.success(lcProjectService.getLcProjectList(lcProjectParam));
    }

    /**
     * 新增项目
     * @param lcProjectParam
     * @return
     */
    @PostMapping("/insertLcProject")
    public ResultVo<String> insertLcCompany(@RequestBody LcProjectParam lcProjectParam) {
        int i = lcProjectService.insertLcProject(lcProjectParam);
        if(i > 0) {
            return ResultVoUtil.success();
        } else {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "新增失败");
        }
    }
}
