瀏覽代碼

测试修改

yusm 4 月之前
父節點
當前提交
b96384dbb7

+ 12 - 1
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/ContractPaymentController.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -43,7 +44,17 @@ public class ContractPaymentController {
         String token = request.getHeader("token");
         String token = request.getHeader("token");
         User user = userService.getById(token);
         User user = userService.getById(token);
         if (user.getCompanyId()!=4215){
         if (user.getCompanyId()!=4215){
-            msg.data = contractPaymentService.list(new QueryWrapper<ContractPayment>().eq("contract_id", contractId));
+            List<ContractPayment> paymentList = contractPaymentService.list(new QueryWrapper<ContractPayment>().eq("contract_id", contractId));
+            for (ContractPayment contractPayment : paymentList) {
+                if (contractPayment!=null&&contractPayment.getInvoiceType()!=null){
+                    if (contractPayment.getInvoiceType()==0){
+                        contractPayment.setInvoiceTypeName("增值税专用发票");
+                    }else {
+                        contractPayment.setInvoiceTypeName("增值税普通发票");
+                    }
+                }
+            }
+            msg.data = paymentList;
         }else {
         }else {
             msg.data = payCustomizedService.list(new QueryWrapper<ContractPayCustomized>().eq("contract_id", contractId));
             msg.data = payCustomizedService.list(new QueryWrapper<ContractPayCustomized>().eq("contract_id", contractId));
         }
         }

+ 3 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/ContractPayment.java

@@ -77,6 +77,9 @@ public class ContractPayment extends Model<ContractPayment> {
     @TableField("invoice_type")
     @TableField("invoice_type")
     private Integer invoiceType;
     private Integer invoiceType;
 
 
+    @TableField(exist = false)
+    private String  invoiceTypeName;
+
     /**
     /**
      * 税额
      * 税额
      */
      */

+ 3 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/mapper/ContractMapper.java

@@ -23,4 +23,7 @@ public interface ContractMapper extends BaseMapper<Contract> {
 
 
     Long selectContractCntWithType(Integer companyId, String number, String name, String typeName, Integer status, String startDate, String endDate, String paymentStartDate, String paymentEndDate, Integer secTypeId, String customerOrg, Integer finishStatus, int type, Integer dept, String userId);
     Long selectContractCntWithType(Integer companyId, String number, String name, String typeName, Integer status, String startDate, String endDate, String paymentStartDate, String paymentEndDate, Integer secTypeId, String customerOrg, Integer finishStatus, int type, Integer dept, String userId);
 
 
+    List<Contract> selectContractByPinWithType(Integer companyId, Integer pageStart, Integer pageSize, String number, String name, String typeName, Integer status, String startDate, String endDate, String paymentStartDate, String paymentEndDate, Integer secTypeId, String customerOrg, Integer finishStatus, int type, Integer dept, String userId);
+
+    Long selectContractContByPinWithType(Integer companyId, String number, String name, String typeName, Integer status, String startDate, String endDate, String paymentStartDate, String paymentEndDate, Integer secTypeId, String customerOrg, Integer finishStatus, int type, Integer dept, String userId);
 }
 }

+ 37 - 22
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/ContractServiceImpl.java

@@ -125,11 +125,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
         try {
         try {
 
 
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
-            List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
+            /*List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
             if(functionContractList.size() <= 0){
             if(functionContractList.size() <= 0){
                 httpRespMsg.setError(MessageUtils.message("access.viewError"));
                 httpRespMsg.setError(MessageUtils.message("access.viewError"));
                 return httpRespMsg;
                 return httpRespMsg;
-            }
+            }*/
             List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
             List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
             if (types.size() == 0){
             if (types.size() == 0){
                 //String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
                 //String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
@@ -163,7 +163,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
 
 
 
 
             //首先获取所有合同的Id
             //首先获取所有合同的Id
-            List<Integer> contractCollect = contracts.stream().map(c -> c.getId()).collect(Collectors.toList());
+            List<Integer> contractCollect = contracts.stream().map(Contract::getId).collect(Collectors.toList());
+            contractCollect.add(-1);
             List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().in("contract_id", contractCollect));
             List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().in("contract_id", contractCollect));
             for (Contract contract : contracts) {
             for (Contract contract : contracts) {
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
@@ -173,8 +174,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                 BigDecimal decimal = contractPaymentList.stream().filter(c -> c.getContractId().equals(contract.getId()) && c.getIsBilled() == 1).map(ContractPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                 BigDecimal decimal = contractPaymentList.stream().filter(c -> c.getContractId().equals(contract.getId()) && c.getIsBilled() == 1).map(ContractPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                 contract.setInvoicedAmount(decimal);
                 contract.setInvoicedAmount(decimal);
             }
             }
-
-            contractCollect.add(-1);
             //查询所有合同的所有附件
             //查询所有合同的所有附件
             List<ContractDocument> fileList = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().in("contract_id", contractCollect).eq("is_deleted",0));
             List<ContractDocument> fileList = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().in("contract_id", contractCollect).eq("is_deleted",0));
             //获取所有附件的上传者id
             //获取所有附件的上传者id
@@ -304,6 +303,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
 //        headList.add("创建时间");
 //        headList.add("创建时间");
 //        headList.add("备注");
 //        headList.add("备注");
         headList.add(MessageUtils.message("entry.contractNo"));
         headList.add(MessageUtils.message("entry.contractNo"));
+        headList.add("部门");
         headList.add(MessageUtils.message("contract.name"));
         headList.add(MessageUtils.message("contract.name"));
         headList.add(MessageUtils.message("Contract.startDate"));
         headList.add(MessageUtils.message("Contract.startDate"));
         headList.add(MessageUtils.message("Contract.endDate"));
         headList.add(MessageUtils.message("Contract.endDate"));
@@ -318,6 +318,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
         for (ContractPageVO contract : data) {
         for (ContractPageVO contract : data) {
             ArrayList<String> item = new ArrayList<>();
             ArrayList<String> item = new ArrayList<>();
             item.add(contract.getNumber()==null?"":contract.getNumber());
             item.add(contract.getNumber()==null?"":contract.getNumber());
+            item.add(StringUtils.isEmpty(contract.getDepartmentName())?"":contract.getDepartmentName());
             item.add(null == contract.getName()?"":contract.getName());
             item.add(null == contract.getName()?"":contract.getName());
             item.add(contract.getStartDate()==null?"":contract.getStartDate()+"");
             item.add(contract.getStartDate()==null?"":contract.getStartDate()+"");
             item.add(contract.getEndDate()==null?"":contract.getEndDate()+"");
             item.add(contract.getEndDate()==null?"":contract.getEndDate()+"");
@@ -366,6 +367,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
      * @return
      * @return
      */
      */
     @Override
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public HttpRespMsg addContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
     public HttpRespMsg addContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("token"));
         User user = userMapper.selectById(request.getHeader("token"));
@@ -426,7 +428,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                 for (ContractPayment contractPayment:contractPaymentList) {
                 for (ContractPayment contractPayment:contractPaymentList) {
                     contractPayment.setContractId(contract.getId());
                     contractPayment.setContractId(contract.getId());
                     contractPaymentMapper.insert(contractPayment);
                     contractPaymentMapper.insert(contractPayment);
-                    if (contractPayment.getIsPayed()) {
+                    if (contractPayment.getIsPayed()!=null&&contractPayment.getIsPayed()) {
                         bg = bg.add(contractPayment.getAmount());
                         bg = bg.add(contractPayment.getAmount());
                     }
                     }
                 }
                 }
@@ -463,11 +465,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
     public HttpRespMsg editContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
     public HttpRespMsg editContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("token"));
         User user = userMapper.selectById(request.getHeader("token"));
-        List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
+        /*List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
         if(functionContractList.size() <= 0){
         if(functionContractList.size() <= 0){
             httpRespMsg.setError(MessageUtils.message("access.operationError"));
             httpRespMsg.setError(MessageUtils.message("access.operationError"));
             return httpRespMsg;
             return httpRespMsg;
-        }
+        }*/
         try {
         try {
             if (contract.getId() == null) {
             if (contract.getId() == null) {
                 httpRespMsg.setError(MessageUtils.message("name.idNullError"));
                 httpRespMsg.setError(MessageUtils.message("name.idNullError"));
@@ -1574,6 +1576,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
         try {
         try {
             String token = request.getHeader("token");
             String token = request.getHeader("token");
             User user = userMapper.selectById(token);
             User user = userMapper.selectById(token);
+            boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部合同");
+            boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门合同数据");
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
             List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
             List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
 //            CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, user.getCompanyId()));
 //            CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, user.getCompanyId()));
@@ -1583,10 +1587,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
 //                companyUserMap  = companyUserList.stream().collect(Collectors.toMap(User::getId, t -> t));
 //                companyUserMap  = companyUserList.stream().collect(Collectors.toMap(User::getId, t -> t));
 //            }
 //            }
 
 
-            if(functionContractList.size() <= 0){
-                httpRespMsg.setError(MessageUtils.message("access.viewError"));
-                return httpRespMsg;
-            }
             List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
             List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
             if (types.size() == 0){
             if (types.size() == 0){
                 //String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
                 //String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
@@ -1602,14 +1602,18 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
             if (pageIndex!=null){
             if (pageIndex!=null){
                 pageStart = (pageIndex -1) * pageSize;
                 pageStart = (pageIndex -1) * pageSize;
             }
             }
-//            if (StringUtils.isNotBlank(number)){
-//                number = "%" + number + "%";
-//            }
-//            if (StringUtils.isNotBlank(name)){
-//                name = "%" + name + "%";
-//            }
-            List<Contract> contracts = contractMapper.selectContractByPin(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
-            Long totalCnt = contractMapper.selectContractCnt(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
+            int type=0;
+            Integer dept=user.getDepartmentId();
+            String userId=user.getId();
+            if (isAll){
+                type=1;//查看全部
+            }else if (isNotAll) {
+                type=2;//查看对应部门
+            }else {
+                type=3;//查看个人
+            }
+            List<Contract> contracts = contractMapper.selectContractByPinWithType(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
+            Long totalCnt = contractMapper.selectContractContByPinWithType(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
             for (Contract contract : contracts) {
             for (Contract contract : contracts) {
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                     contract.setCreatorName(contract.getCreatorWxCorpId());
                     contract.setCreatorName(contract.getCreatorWxCorpId());
@@ -1749,6 +1753,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
     public HttpRespMsg getContractDetail(HttpServletRequest request, Integer id) {
     public HttpRespMsg getContractDetail(HttpServletRequest request, Integer id) {
         HttpRespMsg respMsg = new HttpRespMsg();
         HttpRespMsg respMsg = new HttpRespMsg();
         Contract contract = contractMapper.selectById(id);
         Contract contract = contractMapper.selectById(id);
+        if(contract.getDepartmentId()!=null){
+            contract.setDepartmentName(departmentService.getById(contract.getDepartmentId()).getDepartmentName());
+        }
         if (contract.getTypeId()!=null){
         if (contract.getTypeId()!=null){
             SysDict dict = sysDictService.getById(contract.getTypeId());
             SysDict dict = sysDictService.getById(contract.getTypeId());
             if (dict!=null){
             if (dict!=null){
@@ -1764,6 +1771,10 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                 contract.setNextPaymentAmount(contractPayment.getAmount());
                 contract.setNextPaymentAmount(contractPayment.getAmount());
             }
             }
         }
         }
+        List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().eq("is_billed", 1).eq("contract_id",contract.getId()));
+        //已开票金额
+        BigDecimal decimal = contractPaymentList.stream().map(ContractPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+        contract.setInvoicedAmount(decimal);
         List<ContractCustom> selectedList = contractCustomMapper.selectList(new QueryWrapper<ContractCustom>().eq("contract_id", contract.getId()));
         List<ContractCustom> selectedList = contractCustomMapper.selectList(new QueryWrapper<ContractCustom>().eq("contract_id", contract.getId()));
         if (selectedList != null && !selectedList.isEmpty()) {
         if (selectedList != null && !selectedList.isEmpty()) {
             contract.setCustomData(selectedList.get(0));
             contract.setCustomData(selectedList.get(0));
@@ -2046,7 +2057,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
 
 
                         paymentArrayList.add(payment);
                         paymentArrayList.add(payment);
                         BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
                         BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
-                        contract.setPayment(paymented.add(BigDecimal.valueOf(vo.getReturnMoney())));
+                        if(vo.getIsreturn().equals("是")) {
+                            contract.setPayment(paymented.add(BigDecimal.valueOf(vo.getReturnMoney())));
+                        }
                     }
                     }
                     contractPaymentService.saveBatch(paymentArrayList);
                     contractPaymentService.saveBatch(paymentArrayList);
                     contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
                     contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
@@ -2124,7 +2137,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                     contractPaymentService.save(payment);
                     contractPaymentService.save(payment);
 
 
                     BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
                     BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
-                    contract.setPayment(paymented.add(BigDecimal.valueOf(contractVo.getReturnMoney())));
+                    if(contractVo.getIsreturn().equals("是")) {
+                        contract.setPayment(paymented.add(BigDecimal.valueOf(contractVo.getReturnMoney())));
+                    }
                     contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
                     contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
                 }
                 }
             }
             }

+ 1 - 1
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/SysFormServiceImpl.java

@@ -99,7 +99,7 @@ public class SysFormServiceImpl extends ServiceImpl<SysFormMapper, SysForm> impl
                 }
                 }
             }
             }
         }else {
         }else {
-            Collections.addAll(heads,"合同编号","合同名称","合同金额","合同类型","计划开始时间","计划结束时间","自定义字段","备注","是否已回款","回款日期","金额","是否已开票","开票日期","发票种类","税率","税额");
+            Collections.addAll(heads,"合同编号","合同名称","合同金额","合同类型","计划开始时间","计划结束时间","部门","自定义字段","备注","是否已回款","回款日期","金额","是否已开票","开票日期","发票种类","税率","税额");
         }
         }
         List<List<String>> allList = new ArrayList<>();
         List<List<String>> allList = new ArrayList<>();
         allList.add(heads);
         allList.add(heads);

+ 102 - 3
fhKeeper/formulahousekeeper/management-crm/src/main/resources/mapper/ContractMapper.xml

@@ -114,7 +114,7 @@
         select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
         select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
         contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
         contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
         user.name as creatorName,user.corpwx_userid as creatorWxCorpId, contract.project_id, contract.payment, cp.pay_date AS next_payment_date, cp.amount AS next_payment_amount,
         user.name as creatorName,user.corpwx_userid as creatorWxCorpId, contract.project_id, contract.payment, cp.pay_date AS next_payment_date, cp.amount AS next_payment_amount,
-        contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time
+        contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time,contract.department_id,d.department_name as departmentName
         from contract
         from contract
         left join sys_dict on contract.type_id = sys_dict.id
         left join sys_dict on contract.type_id = sys_dict.id
         left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
         left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
@@ -122,6 +122,7 @@
         left join user
         left join user
         on contract.creator_id = user.id
         on contract.creator_id = user.id
         left join contract_custom cc on cc.contract_id=contract.id
         left join contract_custom cc on cc.contract_id=contract.id
+        left join department d on  d.department_id=contract.department_id
         where contract.company_id = #{companyId}
         where contract.company_id = #{companyId}
         <if test="number!=null">
         <if test="number!=null">
             and number like CONCAT('%', #{number}, '%')
             and number like CONCAT('%', #{number}, '%')
@@ -176,7 +177,7 @@
             and contract.name like CONCAT('%', #{name}, '%')
             and contract.name like CONCAT('%', #{name}, '%')
         </if>
         </if>
         <if test="typeName!=null">
         <if test="typeName!=null">
-            and sys_dict.name = #{typeName}
+            and sys_dict.id = #{typeName}
         </if>
         </if>
         <if test="secTypeId!=null">
         <if test="secTypeId!=null">
             and contract.sec_type_id = #{secTypeId}
             and contract.sec_type_id = #{secTypeId}
@@ -214,6 +215,7 @@
         LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
         LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
         left join user
         left join user
         on contract.creator_id = user.id
         on contract.creator_id = user.id
+        left join sys_dict on contract.type_id = sys_dict.id
         left join contract_custom cc on cc.contract_id=contract.id
         left join contract_custom cc on cc.contract_id=contract.id
         left join department d on d.department_id=contract.department_id
         left join department d on d.department_id=contract.department_id
         where contract.company_id = #{companyId}
         where contract.company_id = #{companyId}
@@ -224,7 +226,52 @@
             and contract.name like CONCAT('%', #{name}, '%')
             and contract.name like CONCAT('%', #{name}, '%')
         </if>
         </if>
         <if test="typeName!=null">
         <if test="typeName!=null">
-            and contract_type.id = #{typeName}
+            and  sys_dict.id = #{typeName}
+        </if>
+        <if test="secTypeId!=null">
+            and contract.sec_type_id = #{secTypeId}
+        </if>
+        <if test="status!=null">
+            and status = #{status}
+        </if>
+        <if test="startDate!=null and endDate !=null">
+            and indate between #{startDate} and #{endDate}
+        </if>
+        <if test="paymentStartDate != null and paymentEndDate != null">
+            and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
+        </if>
+        <if test="finishStatus!=null">
+            and cc.finish_status = #{finishStatus}
+        </if>
+        <if test="customerOrg!=null">
+            and cc.customer_org like  CONCAT('%', #{customerOrg}, '%')
+        </if>
+        <if test="type == 2 and dept!=null">
+            and contract.department_id=#{dept}
+        </if>
+        <if test="type == 3 and userId!=null">
+            and contract.creator_id=#{userId}
+        </if>
+    </select>
+    <select id="selectContractContByPinWithType" resultType="java.lang.Long">
+        select count(1)
+        from contract
+        left join sys_dict on contract.type_id = sys_dict.id
+        left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
+        LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
+        left join user
+        on contract.creator_id = user.id
+        left join contract_custom cc on cc.contract_id=contract.id
+        left join department d on  d.department_id=contract.department_id
+        where contract.company_id = #{companyId}
+        <if test="number!=null">
+            and number like CONCAT('%', #{number}, '%')
+        </if>
+        <if test="name!=null">
+            and contract.name like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="typeName!=null">
+            and sys_dict.name = #{typeName}
         </if>
         </if>
         <if test="secTypeId!=null">
         <if test="secTypeId!=null">
             and contract.sec_type_id = #{secTypeId}
             and contract.sec_type_id = #{secTypeId}
@@ -251,4 +298,56 @@
             and contract.creator_id=#{userId}
             and contract.creator_id=#{userId}
         </if>
         </if>
     </select>
     </select>
+    <select id="selectContractByPinWithType" resultType="com.management.platform.entity.Contract">
+        select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
+        contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
+        user.name as creatorName,user.corpwx_userid as creatorWxCorpId, contract.project_id, contract.payment, cp.pay_date AS next_payment_date, cp.amount AS next_payment_amount,
+        contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time,contract.department_id,d.department_name as departmentName
+        from contract
+        left join sys_dict on contract.type_id = sys_dict.id
+        left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
+        LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
+        left join user
+        on contract.creator_id = user.id
+        left join contract_custom cc on cc.contract_id=contract.id
+        left join department d on  d.department_id=contract.department_id
+        where contract.company_id = #{companyId}
+        <if test="number!=null">
+            and number like CONCAT('%', #{number}, '%')
+        </if>
+        <if test="name!=null">
+            and contract.name like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="typeName!=null">
+            and sys_dict.name = #{typeName}
+        </if>
+        <if test="secTypeId!=null">
+            and contract.sec_type_id = #{secTypeId}
+        </if>
+        <if test="status!=null">
+            and status = #{status}
+        </if>
+        <if test="startDate!=null and endDate !=null">
+            and indate between #{startDate} and #{endDate}
+        </if>
+        <if test="paymentStartDate != null and paymentEndDate != null">
+            and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
+        </if>
+        <if test="finishStatus!=null">
+            and cc.finish_status = #{finishStatus}
+        </if>
+        <if test="customerOrg!=null">
+            and cc.customer_org like  CONCAT('%', #{customerOrg}, '%')
+        </if>
+        <if test="type == 2 and dept!=null">
+            and contract.department_id=#{dept}
+        </if>
+        <if test="type == 3 and userId!=null">
+            and contract.creator_id=#{userId}
+        </if>
+        order by contract.need_pin desc,contract.pin_time desc,contract.id desc
+        <if test="pageStart!=null and pageSize!=null">
+            limit #{pageStart},#{pageSize}
+        </if>
+    </select>
 </mapper>
 </mapper>