package com.zhgd.xmgl.modules.basicdata.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.util.PageUtil;
import com.zhgd.xmgl.modules.basicdata.entity.Engineering;
import com.zhgd.xmgl.modules.basicdata.service.IEngineeringService;
import com.zhgd.xmgl.modules.basicdata.vo.EngineeringVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @Title: Controller
 * @Description: 项目工程表
 * @author： pds
 * @date： 2023-02-22
 * @version： V1.0
 */
@RestController
@RequestMapping("/project/engineering")
@Slf4j
@Api(tags = "工程信息")
public class EngineeringController {
    @Autowired
    private IEngineeringService engineeringService;

    /**
     * 分页列表查询
     * @return
     */
    @OperLog(operModul = "工程管理", operType = "分页查询", operDesc = "分页列表查询报监记录")
    @ApiOperation(value = " 分页列表查询报监记录", notes = "分页列表查询报监记录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
    })
    @PostMapping(value = "/page")
    public Result<IPage<Engineering>> queryPageList(@RequestBody Map<String, Object> map) {
        Result<IPage<Engineering>> result = new Result<IPage<Engineering>>();
        LambdaQueryWrapper<Engineering> wrapper = Wrappers.<Engineering>lambdaQuery();
        Page<Engineering> page = PageUtil.getPage(map);
        IPage<Engineering> pageList = engineeringService.getPageList(page, wrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 项目报监
     *
     * @param engineeringVo
     * @return
     */
    @OperLog(operModul = "工程管理", operType = "新增", operDesc = "项目报监")
    @ApiOperation(value = " 项目报监", notes = "项目报监", httpMethod = "POST")
    @PostMapping(value = "/add")
    public Result<Engineering> add(@RequestBody EngineeringVo engineeringVo) {
        Result<Engineering> result = new Result<Engineering>();
        engineeringService.saveInfo(engineeringVo);
        result.success("添加成功！");
        return result;
    }

    /**
     * 再次申请
     *
     * @param engineering
     * @return
     */
    @OperLog(operModul = "工程管理", operType = "修改", operDesc = "再次申请")
    @ApiOperation(value = " 再次申请", notes = "再次申请", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "工程ID", paramType = "query", required = true, dataType = "Integer")
    @PostMapping(value = "/edit")
    public Result<Engineering> edit(@RequestBody Engineering engineering) {
        Result<Engineering> result = new Result<Engineering>();
        engineeringService.updateInfo(engineering);
        result.success("添加成功！");
        return result;
    }

    /**
     * 通过id查询
     *
     * @return
     */
    @OperLog(operModul = "工程管理", operType = "查询", operDesc = "通过id查询项目工程信息")
    @ApiOperation(value = "通过id查询项目工程信息", notes = "通过id查询项目工程信息", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "项目工程表ID", paramType = "query", required = true, dataType = "Integer")
    @PostMapping(value = "/queryById")
    public Result<Engineering> queryById(@RequestBody Engineering engineeringEntity) {
        Result<Engineering> result = new Result<Engineering>();
        Engineering engineering = engineeringService.getById(engineeringEntity.getId());
        if (engineering == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(engineering);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 查询项目下的工程信息
     *
     * @return
     */
    @OperLog(operModul = "工程管理", operType = "查询", operDesc = "查询项目下的工程列表")
    @ApiOperation(value = "查询工程列表", notes = "查询项目下的工程列表", httpMethod = "GET")
    @GetMapping(value = "/queryByProject")
    public Result<List<Engineering>> queryByProject() {
        List<Engineering> engineeringList = engineeringService.list();
        return Result.success(engineeringList);
    }
}
