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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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.xmgl.modules.basicdata.entity.Company;
import com.zhgd.xmgl.modules.basicdata.service.ICompanyService;
import com.zhgd.xmgl.modules.basicdata.service.IEngineeringService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Title: Controller
 * @Description: 参建单位
 * @author： pengj
 * @date： 2023-03-13
 * @version： V1.0
 */
@RestController
@RequestMapping("/gov/company")
@Slf4j
@Api(tags = "参建单位管理")
public class GovCompanyController {
    @Autowired
    private ICompanyService companyService;

    @Autowired
    private IEngineeringService engineeringService;

    /**
     * 分页列表查询
     *
     * @return
     */
    @OperLog(operModul = "参建单位管理", operType = "分页查询", operDesc = "分页列表查询参建单位信息")
    @ApiOperation(value = " 分页列表查询参建单位信息", notes = "分页列表查询参建单位信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "参建单位类型", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "engineeringSn", value = "工程sn   ", paramType = "query", dataType = "String")
    })
    @PostMapping(value = "/page")
    public Result<IPage<Company>> queryPageList(Page page, @RequestBody Company company) {
        LambdaQueryWrapper<Company> wrapper = Wrappers.<Company>lambdaQuery();
        if (StringUtils.isNotBlank(company.getType())) {
            wrapper.like(Company::getType, company.getType());
        }
        if (StringUtils.isNotBlank(company.getEngineeringSn())) {
            wrapper.eq(Company::getEngineeringSn, company.getEngineeringSn());
        }
        IPage<Company> pageList = companyService.page(page, wrapper);
        return Result.success(pageList);
    }
}
