package com.huyi.service.common.contract.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huyi.service.common.contract.service.IContractService;
import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
import com.tianhu.common.core.utils.CommonUtil;
import com.tianhu.common.core.web.controller.BaseController;
import com.tianhu.common.core.web.domain.AjaxResult;
import com.tianhu.common.security.service.TokenService;
import com.tianhu.system.api.domain.SysUser;
import com.tianhu.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 合同controller
 *
 * @author ch
 * @date 2021-8-20
 */

@RestController
@RequestMapping("/contractCommon")
public class ContractController extends BaseController {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IContractService contractService;

    @GetMapping("/list")
    public AjaxResult list(String zfcManagementId , String zfcName, String zfcSubject , QueryRequest request) {
        //查询当前操作员
        LoginUser userInfo = tokenService.getLoginUser();
        SysUser use = userInfo.getSysUser();
        //获取企业
//        String companyId = use.getCompanyId();
        Map map = new HashMap(16);
//        if(CommonUtil.isNotEmpty(companyId)){
//            map.put("companyId",companyId);
//        }
        //合同模板名称
        if(CommonUtil.isNotEmpty(zfcName)){
            map.put("zfcName",zfcName);
        }
//        //资方
//        if(CommonUtil.isNotEmpty(scyName)){
//            map.put("scyName",scyName);
//        }
//        //合同状态
//        if(CommonUtil.isNotEmpty(zfcStatus)){
//            map.put("zfcStatus",zfcStatus);
//        }
        //签署主体
        if(CommonUtil.isNotEmpty(zfcSubject)){
            map.put("zfcSubject",zfcSubject);
        }
        //资金方
        if(CommonUtil.isEmpty(zfcManagementId)){
           return AjaxResult.error("请选择资金方");
        }
        map.put("zfcManagementId",zfcManagementId);
        IPage<Map> list = contractService.selectContractList(map,request);
        return AjaxResult.success(list);
    }
}
