Sfoglia il codice sorgente

合同管理代码修改

yusm 2 mesi fa
parent
commit
756274570a

+ 1 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/constant/Constant.java

@@ -58,4 +58,5 @@ public class Constant {
     public static final String[] LEAVE_WAIT_CHECK= {"请假人","请假类型","请假时间","备注"};
     //请假审核通知
     public static final String[] LEAVE_CHECK= {"审核结果","审核人","请假时间","备注"};
+    public static final int JUN_TIAN_COMPANY_ID= 6666;
 }

+ 4 - 2
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/ContractController.java

@@ -92,11 +92,13 @@ public class ContractController {
     public HttpRespMsg importContract (HttpServletRequest request, MultipartFile file){
         String token = request.getHeader("TOKEN");
         User user = userMapper.selectById(token);
-        if (user.getCompanyId() == 10 || user.getCompanyId() == 4215) {
+        /*if (user.getCompanyId() == 10 || user.getCompanyId() == 4215) {
             return contractService.importContractCustom(request,file);
         } else {
             return contractService.importContract(request,file);
-        }
+        }*/
+
+        return  contractService.importContractNew(request, file);
     }
 
     /**

+ 8 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/Contract.java

@@ -219,6 +219,14 @@ public class Contract extends Model<Contract> {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
     private Date pinTime;
 
+    @TableField("department_id")
+    private Integer departmentId;
+
+    @TableField(exist = false)
+    private Integer departmentName;
+
+    @TableField(exist = false)
+    private BigDecimal invoicedAmount;
 
     @Override
     protected Serializable pkVal() {

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

@@ -57,6 +57,39 @@ public class ContractPayment extends Model<ContractPayment> {
     private Boolean isPayed;
 
 
+    /**
+     * 是否开票 1是 0否
+     */
+    @TableField("is_billed")
+    private Integer isBilled;
+
+    /**
+     * 开票日期
+     */
+    @TableField("bill_date")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate billDate;
+
+    /**
+     * 发票类型 0专票 1普票
+     */
+    @TableField("invoice_type")
+    private Integer invoiceType;
+
+    /**
+     * 税额
+     */
+    @TableField("tax_amount")
+    private BigDecimal taxAmount;
+
+    /**
+     * 税率
+     */
+    @TableField("tax_rate")
+    private BigDecimal taxRate;
+
+
     @Override
     protected Serializable pkVal() {
         return this.id;

+ 42 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/vo/ContractVo.java

@@ -0,0 +1,42 @@
+package com.management.platform.entity.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.management.platform.entity.ContractCustom;
+import com.management.platform.entity.ContractPayCustomized;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Date;
+
+
+@Data
+@Accessors(chain = true)
+public class ContractVo {
+
+    private String number;
+    private String name;
+    private double contractAmount;
+    private String contractType;
+    private LocalDate startDate;
+    private LocalDate endDate;
+    private String departmentName;
+    private String design;
+    private String remark;
+    private String isreturn;
+    private LocalDate returnDate;
+    private double returnMoney;
+    private String isBill;
+    private LocalDate billDate;
+    private String billType;
+    private double taxRate;
+    private double tax;
+
+
+}

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

@@ -18,4 +18,9 @@ public interface ContractMapper extends BaseMapper<Contract> {
     Long selectContractCnt(Integer companyId, String number, String name, String typeName, Integer status, String startDate,String endDate, String paymentStartDate, String paymentEndDate, Integer secTypeId,String customerOrg,Integer finishStatus);
 
     List<Contract> selectContractByPin(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);
+
+    List<Contract> selectContractWithType(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 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);
+
 }

+ 2 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/ContractService.java

@@ -46,4 +46,6 @@ public interface ContractService extends IService<Contract> {
     HttpRespMsg undoPin(Contract contract, HttpServletRequest request);
 
     HttpRespMsg getContractDetail(HttpServletRequest request, Integer id);
+
+    HttpRespMsg importContractNew(HttpServletRequest request, MultipartFile file);
 }

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

@@ -6,13 +6,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.management.platform.constant.Constant;
 import com.management.platform.entity.*;
 import com.management.platform.entity.vo.ContractPageVO;
+import com.management.platform.entity.vo.ContractVo;
 import com.management.platform.entity.vo.SysRichFunction;
 import com.management.platform.mapper.*;
-import com.management.platform.service.ContractService;
-import com.management.platform.service.ExcelExportService;
-import com.management.platform.service.SysDictService;
+import com.management.platform.service.*;
 import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
@@ -86,9 +86,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
     private ContractPayCustomizedMapper contractPayCustomizedMapper;
     @Resource
     private SysDictService sysDictService;
+    @Resource
+    private DepartmentService departmentService;
+    @Resource
+    private ContractPaymentService contractPaymentService;
 
     @Resource
     private CompanyDingdingMapper companyDingdingMapper;
+    @Autowired
+    private SysFunctionService sysFunctionService;
+
+
 
 
 
@@ -110,9 +118,12 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                                        String typeName, Integer status, String startDate, String endDate,
                                        String paymentStartDate, String paymentEndDate, Integer secTypeId,String customerOrg,Integer finishStatus) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
+        String token = request.getHeader("token");
+        User user = userMapper.selectById(token);
+        boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部合同");
+        boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门合同数据");
         try {
-            String token = request.getHeader("token");
-            User user = userMapper.selectById(token);
+
             WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
             List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
             if(functionContractList.size() <= 0){
@@ -134,21 +145,39 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
             if (pageIndex!=null){
                 pageStart = (pageIndex -1) * pageSize;
             }
-//            if (StringUtils.isNotBlank(number)){
-//                number = "%" + number + "%";
-//            }
-//            if (StringUtils.isNotBlank(name)){
-//                name = "%" + name + "%";
-//            }
-            List<Contract> contracts = contractMapper.selectContract(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);
+            List<Contract> contracts = new ArrayList<>();
+            Long totalCnt=0L;
+            if (user.getCompanyId()== Constant.JUN_TIAN_COMPANY_ID){
+                int type=0;
+                Integer dept=user.getDepartmentId();
+                String userId=user.getId();
+                if (isAll){
+                    type=1;//查看全部
+                }else if (isNotAll) {
+                    type=2;//查看对应部门
+                }else {
+                    type=3;//查看个人
+                }
+                contracts = contractMapper.selectContractWithType(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
+                totalCnt = contractMapper.selectContractCntWithType(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
+
+            }else {
+                contracts = contractMapper.selectContract(user.getCompanyId(), pageStart, pageSize, number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId, customerOrg, finishStatus);
+                totalCnt = contractMapper.selectContractCnt(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId, customerOrg, finishStatus);
+
+            }
+            //首先获取所有合同的Id
+            List<Integer> contractCollect = contracts.stream().map(c -> c.getId()).collect(Collectors.toList());
+            List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().in("contract_id", contractCollect));
             for (Contract contract : contracts) {
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                     contract.setCreatorName(contract.getCreatorWxCorpId());
                 }
+                //已开票金额
+                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);
             }
-            //首先获取所有合同的Id
-            List<Integer> contractCollect = contracts.stream().map(c -> c.getId()).collect(Collectors.toList());
+
             contractCollect.add(-1);
             //查询所有合同的所有附件
             List<ContractDocument> fileList = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().in("contract_id", contractCollect).eq("is_deleted",0));
@@ -200,6 +229,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
                 contractPageVO.setPlate3(contract.getPlate3());
                 contractPageVO.setPlate4(contract.getPlate4());
                 contractPageVO.setPlate5(contract.getPlate5());
+                contractPageVO.setInvoicedAmount(contract.getInvoicedAmount());
+                contractPageVO.setDepartmentId(contract.getDepartmentId());
+                contractPageVO.setDepartmentName(contract.getDepartmentName());
                 if (contract.getStatus().equals(2)){
                     for (Map<String, Object> contractLog : contractLogs) {
                         if (contractLog.get("contractId").toString().equals(contract.getId().toString())){
@@ -1748,4 +1780,395 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
         return respMsg;
 
     }
+
+    @Override
+    public HttpRespMsg importContractNew(HttpServletRequest request, MultipartFile multipartFile) {
+        HttpRespMsg msg = new HttpRespMsg();
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "导入合同");
+        if(functionContractList.size() <= 0){
+            msg.setError(MessageUtils.message("access.operationError"));
+            return msg;
+        }
+        Integer companyId = user.getCompanyId();
+        //然后处理文件
+        String fileName = multipartFile.getOriginalFilename();
+        File file = new File(fileName == null ? "file" : fileName);
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            inputStream = multipartFile.getInputStream();
+            outputStream = new FileOutputStream(file);
+            byte[] buffer = new byte[4096];
+            int temp = 0;
+            while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
+                outputStream.write(buffer, 0, temp);
+            }
+            inputStream.close();
+            outputStream.close();
+            //然后解析表格
+            Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
+            Sheet sheet = workbook.getSheetAt(0);
+            int rowNum = sheet.getLastRowNum();
+            if (rowNum == 0) {
+                msg.setError(MessageUtils.message("Contract.dataNull"));
+                return msg;
+            }
+            List<Contract> contractList = contractMapper.selectList(new QueryWrapper<Contract>().eq("company_id", companyId));
+            List<SysDict> sysDictList = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ContractType").orderByAsc(SysDict::getSeq));
+            List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().eq("company_id", companyId));
+
+            int dataIndex = 1;
+            HashMap<String, String> map = new HashMap<>();
+            for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
+
+                Row row = sheet.getRow(rowIndex);
+
+                for (int i = 0; i < 17; i++) {
+                    if (row.getCell(i) != null) {
+                        if (i ==2  || i == 11|| i == 15|| i == 16) {
+                            //日期类型的
+                            row.getCell(i).setCellType(CellType.NUMERIC);
+                        } else {
+                            row.getCell(i).setCellType(CellType.STRING);
+                        }
+                    }
+                }
+                if (row!=null){
+                    if (row.getCell(0)==null||row.getCell(1)==null||StringUtils.isEmpty(row.getCell(0).getStringCellValue())||StringUtils.isEmpty(row.getCell(1).getStringCellValue())){
+                        msg.setError("请填写合同编号或合同名称");
+                        return msg;
+                    }
+                    String number = row.getCell(0).getStringCellValue();
+                    String name = row.getCell(1).getStringCellValue();
+                    if (map.containsKey(number)){
+                        if (!map.get(number).equals(name)){
+                            msg.setError("文档中存在合同编号相同但是合同名称不同的数据");
+                            return msg;
+                        }
+                    }
+                    map.put(number,name);
+                }
+            }
+            List<ContractVo> contractVos = new ArrayList<>();
+            for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
+
+                Row row = sheet.getRow(rowIndex);
+                for (int i = 0; i < 17; i++) {
+                    if (row.getCell(i) != null) {
+                        if (i ==2  || i == 11|| i == 15|| i == 16) {
+                            //日期类型的
+                            row.getCell(i).setCellType(CellType.NUMERIC);
+                        } else {
+                            row.getCell(i).setCellType(CellType.STRING);
+                        }
+                    }
+                }
+                if (row!=null){
+                    String number = row.getCell(0).getStringCellValue();
+                    String name = row.getCell(1).getStringCellValue();
+                    double contractAmount = row.getCell(2)==null?0:row.getCell(2).getNumericCellValue();
+                    String contractTypeName =row.getCell(3)==null?"": row.getCell(3).getStringCellValue();
+                    LocalDate startDate = null;
+                    LocalDate endDate = null;
+                    if(row.getCell(4) != null && row.getCell(4).getCellTypeEnum() != CellType.BLANK){
+                        if(!StringUtils.isEmpty(row.getCell(4).getStringCellValue())){
+                            try {
+                                int count = Integer.parseInt(row.getCell(4).getStringCellValue());
+                                // Excel中的日期序列号的基准日期是1900年1月1日
+                                LocalDate baseDate = LocalDate.of(1900, 1, 1);
+                                LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
+                                startDate = date;
+
+                            } catch (Exception e) {
+                                System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
+                                msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
+                                return msg;
+                            }
+                        }
+                    }
+                    if(row.getCell(5) != null && row.getCell(5).getCellTypeEnum() != CellType.BLANK){
+                        if(!StringUtils.isEmpty(row.getCell(5).getStringCellValue())){
+                            try {
+                                int count = Integer.parseInt(row.getCell(5).getStringCellValue());
+                                // Excel中的日期序列号的基准日期是1900年1月1日
+                                LocalDate baseDate = LocalDate.of(1900, 1, 1);
+                                LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
+                                endDate = date;
+
+                            } catch (Exception e) {
+                                System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
+                                msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
+                                return msg;
+                            }
+                        }
+                    }
+                    String dept =row.getCell(6)==null?"":  row.getCell(6).getStringCellValue();
+                    String design =row.getCell(7)==null?"":  row.getCell(7).getStringCellValue();
+                    String remarks =row.getCell(8)==null?"":  row.getCell(8).getStringCellValue();
+                    String isReturn = row.getCell(9)==null?"": row.getCell(9).getStringCellValue();
+                    LocalDate returnDate = null;
+                    if(row.getCell(10) != null && row.getCell(10).getCellTypeEnum() != CellType.BLANK){
+                        if(!StringUtils.isEmpty(row.getCell(10).getStringCellValue())){
+                            try {
+                                int count = Integer.parseInt(row.getCell(10).getStringCellValue());
+                                // Excel中的日期序列号的基准日期是1900年1月1日
+                                LocalDate baseDate = LocalDate.of(1900, 1, 1);
+                                LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
+                                returnDate = date;
+
+                            } catch (Exception e) {
+                                System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
+                                msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
+                                return msg;
+                            }
+                        }
+                    }
+                    double returnAmount = row.getCell(11)==null?0:row.getCell(11).getNumericCellValue();
+                    String isBilled =row.getCell(12)==null?"":  row.getCell(12).getStringCellValue();
+
+                    LocalDate billDate = null;
+                    if(row.getCell(13) != null && row.getCell(13).getCellTypeEnum() != CellType.BLANK){
+                        if(!StringUtils.isEmpty(row.getCell(13).getStringCellValue())){
+                            try {
+                                int count = Integer.parseInt(row.getCell(13).getStringCellValue());
+                                // Excel中的日期序列号的基准日期是1900年1月1日
+                                LocalDate baseDate = LocalDate.of(1900, 1, 1);
+                                LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
+                                billDate = date;
+
+                            } catch (Exception e) {
+                                System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
+                                msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
+                                return msg;
+                            }
+                        }
+                    }
+                    String billType =row.getCell(14)==null?"":  row.getCell(14).getStringCellValue();
+                    double taxRate = row.getCell(15)==null?0:row.getCell(15).getNumericCellValue();
+                    double taxAmount = row.getCell(16)==null?0:row.getCell(16).getNumericCellValue();
+
+                    ContractVo contractVo = new ContractVo();
+                    contractVo.setNumber(number)
+                            .setName(name)
+                            .setContractAmount(contractAmount)
+                            .setContractType(contractTypeName)
+                            .setStartDate(startDate)
+                            .setEndDate(endDate)
+                            .setDepartmentName(dept)
+                            .setDesign(design)
+                            .setRemark(remarks)
+                            .setIsreturn(isReturn)
+                            .setReturnDate(returnDate)
+                            .setReturnMoney(returnAmount)
+                            .setIsBill(isBilled)
+                            .setBillDate(billDate)
+                            .setBillType(billType)
+                            .setTax(taxAmount)
+                            .setTaxRate(taxRate);
+                    contractVos.add(contractVo);
+                }
+            }
+
+
+            Set<Map.Entry<String, String>> entries = map.entrySet();
+            for (Map.Entry<String, String> entry : entries) {
+                List<ContractVo> voList = contractVos.stream().filter(c -> c.getNumber().equals(entry.getKey())).collect(Collectors.toList());
+                if (voList.size() > 1) {
+                    ContractVo contractVo = voList.get(0);
+                    Contract contract = new Contract();
+                    long count = contractList.stream().filter(c -> c.getNumber().equals(contractVo.getNumber())).count();
+                    if (count >0) {
+                        msg.setError("合同编号:"+contractVo.getNumber()+"已存在");
+                        return msg;
+                    }
+                    contract.setNumber(contractVo.getNumber())
+                            .setName(contractVo.getName())
+                            .setAmounts(BigDecimal.valueOf(contractVo.getContractAmount()))
+                            .setStartDate(contractVo.getStartDate())
+                            .setEndDate(contractVo.getEndDate())
+                            .setPlate1(contractVo.getDesign())
+                            .setRemarks(contractVo.getRemark())
+                            .setCompanyId(user.getCompanyId())
+                            .setCreatorId(user.getId())
+                            .setIndate(LocalDate.now());
+                    if (StringUtils.isNotEmpty(contractVo.getContractType())){
+                        Optional<SysDict> first = sysDictList.stream().filter(s -> s.getName().equals(contractVo.getContractType())).findFirst();
+                        if (first.isPresent()) {
+                            contract.setTypeId(first.get().getId());
+                        }else {
+                            msg.setError("合同不已存在");
+                            return msg;
+                        }
+                    }
+                    if (StringUtils.isNotEmpty(contractVo.getDepartmentName())){
+                        Optional<Department> first = departmentList.stream().filter(d -> d.getDepartmentName().equals(contractVo.getDepartmentName())).findFirst();
+                        if (first.isPresent()) {
+                            contract.setDepartmentId(first.get().getDepartmentId());
+                        }else {
+                            msg.setError("部门名称不已存在");
+                            return msg;
+                        }
+                    }
+                    contractMapper.insert(contract);
+
+                    ArrayList<ContractPayment> paymentArrayList = new ArrayList<>();
+                    for (ContractVo vo : voList) {
+                        ContractPayment payment = new ContractPayment();
+                        if (StringUtils.isNotEmpty(vo.getIsreturn())){
+                            if (vo.getIsreturn().equals("是")){
+                                payment.setIsPayed(true);
+                            }else {
+                                payment.setIsPayed(false);
+                            }
+                        }else {
+                            payment.setIsPayed(false);
+                        }
+                        if (StringUtils.isNotEmpty(vo.getIsBill())){
+                            if (vo.getIsBill().equals("是")){
+                                payment.setIsBilled(1);
+                            }else {
+                                payment.setIsBilled(0);
+                            }
+                        }else {
+                            payment.setIsBilled(0);
+                        }
+                        if (StringUtils.isNotEmpty(vo.getBillType())){
+                            if (vo.getBillType().equals("专票")){
+                                payment.setInvoiceType(0);
+                            }else if (vo.getBillType().equals("普票")){
+                                payment.setInvoiceType(1);
+                            }
+                        }
+                        payment.setContractId(contract.getId())
+                                .setPayDate(vo.getReturnDate())
+                                .setAmount(BigDecimal.valueOf(vo.getReturnMoney()))
+                                .setBillDate(vo.getBillDate())
+                                .setTaxAmount(BigDecimal.valueOf(vo.getTax()))
+                                .setTaxRate(BigDecimal.valueOf(vo.getTaxRate()));
+
+                        paymentArrayList.add(payment);
+                        BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
+                        contract.setPayment(paymented.add(BigDecimal.valueOf(vo.getReturnMoney())));
+                    }
+                    contractPaymentService.saveBatch(paymentArrayList);
+                    contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
+                }
+                else {
+                    ContractVo contractVo = voList.get(0);
+                    Contract contract = new Contract();
+                    long count = contractList.stream().filter(c -> c.getNumber()!=null&&c.getNumber().equals(contractVo.getNumber())).count();
+                    if (count >0) {
+                        msg.setError("合同编号:"+contractVo.getNumber()+"已存在");
+                        return msg;
+                    }
+                    contract.setNumber(contractVo.getNumber())
+                            .setName(contractVo.getName())
+                            .setAmounts(BigDecimal.valueOf(contractVo.getContractAmount()))
+                            .setStartDate(contractVo.getStartDate())
+                            .setEndDate(contractVo.getEndDate())
+                            .setPlate1(contractVo.getDesign())
+                            .setRemarks(contractVo.getRemark())
+                            .setCompanyId(user.getCompanyId())
+                            .setCreatorId(user.getId())
+                            .setIndate(LocalDate.now());
+                    if (StringUtils.isNotEmpty(contractVo.getContractType())){
+                        Optional<SysDict> first = sysDictList.stream().filter(s -> s.getName().equals(contractVo.getContractType())).findFirst();
+                        if (first.isPresent()) {
+                            contract.setTypeId(first.get().getId());
+                        }else {
+                            msg.setError("合同不已存在");
+                            return msg;
+                        }
+                    }
+                    if (StringUtils.isNotEmpty(contractVo.getDepartmentName())){
+                        Optional<Department> first = departmentList.stream().filter(d -> d.getDepartmentName().equals(contractVo.getDepartmentName())).findFirst();
+                        if (first.isPresent()) {
+                            contract.setDepartmentId(first.get().getDepartmentId());
+                        }else {
+                            msg.setError("部门名称不已存在");
+                            return msg;
+                        }
+                    }
+                    contractMapper.insert(contract);
+
+                    ContractPayment payment = new ContractPayment();
+                    if (StringUtils.isNotEmpty(contractVo.getIsreturn())){
+                        if (contractVo.getIsreturn().equals("是")){
+                            payment.setIsPayed(true);
+                        }else {
+                            payment.setIsPayed(false);
+                        }
+                    }else {
+                        payment.setIsPayed(false);
+                    }
+                    if (StringUtils.isNotEmpty(contractVo.getIsBill())){
+                        if (contractVo.getIsBill().equals("是")){
+                            payment.setIsBilled(1);
+                        }else {
+                            payment.setIsBilled(0);
+                        }
+                    }else {
+                        payment.setIsBilled(0);
+                    }
+                    if (StringUtils.isNotEmpty(contractVo.getBillType())){
+                        if (contractVo.getBillType().equals("专票")){
+                            payment.setInvoiceType(0);
+                        }else if (contractVo.getBillType().equals("普票")){
+                            payment.setInvoiceType(1);
+                        }
+                    }
+                    payment.setContractId(contract.getId())
+                            .setPayDate(contractVo.getReturnDate())
+                            .setAmount(BigDecimal.valueOf(contractVo.getReturnMoney()))
+                            .setBillDate(contractVo.getBillDate())
+                            .setTaxAmount(BigDecimal.valueOf(contractVo.getTax()))
+                            .setTaxRate(BigDecimal.valueOf(contractVo.getTaxRate()));
+                    contractPaymentService.save(payment);
+
+                    BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
+                    contract.setPayment(paymented.add(BigDecimal.valueOf(contractVo.getReturnMoney())));
+                    contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            //msg.setError("文件处理出错");
+            msg.setError(MessageUtils.message("file.error"));
+            return msg;
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+            //msg.setError("数据格式有误或存在空数据 导入失败");
+            msg.setError(MessageUtils.message("file.dataFormatError"));
+            return msg;
+        }catch (InvalidFormatException e) {
+            e.printStackTrace();
+            //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
+            msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
+            return msg;
+        }catch (EncryptedDocumentException e) {
+            e.printStackTrace();
+            //msg.setError("文件加密状态,需要先解除加密状态再上传");
+            msg.setError(MessageUtils.message("file.encryption"));
+            return msg;
+        } catch (Exception e) {
+            e.printStackTrace();
+            //msg.setError("发生其他错误:"+e.getMessage());
+            msg.setError(MessageUtils.message("other.errorByParameter",e.getMessage()));
+            return msg;
+        } finally {
+            //关闭流
+            try {
+                if (outputStream != null && inputStream != null) {
+                    outputStream.close();
+                    inputStream.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            file.delete();
+        }
+        return msg;
+    }
 }

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

@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -67,25 +68,28 @@ public class SysFormServiceImpl extends ServiceImpl<SysFormMapper, SysForm> impl
             msg.setError("当前表单未配置模板,请先完成模板配置");
             return msg;
         }
-        String config = sysForm.getConfig();
-        JSONObject configOb = JSON.parseObject(config);
-        JSONArray configObJSONArray = configOb.getJSONArray("list");
-        for (int i = 0; i < configObJSONArray.size(); i++) {
-            JSONObject item = configObJSONArray.getJSONObject(i);
-            if(item.getString("type").equals("grid")){
-                JSONArray columns = item.getJSONArray("columns");
-                for (int i1 = 0; i1 < columns.size(); i1++) {
-                    JSONObject columnsJSONObject = columns.getJSONObject(i1);
-                    JSONArray list = columnsJSONObject.getJSONArray("list");
-                    for (int i2 = 0; i2 < list.size(); i2++) {
-                        JSONObject object = list.getJSONObject(i2);
-                        heads.add(object.getString("label"));
+        if (!code.equals("Contract")) {
+            String config = sysForm.getConfig();
+            JSONObject configOb = JSON.parseObject(config);
+            JSONArray configObJSONArray = configOb.getJSONArray("list");
+            for (int i = 0; i < configObJSONArray.size(); i++) {
+                JSONObject item = configObJSONArray.getJSONObject(i);
+                if (item.getString("type").equals("grid")) {
+                    JSONArray columns = item.getJSONArray("columns");
+                    for (int i1 = 0; i1 < columns.size(); i1++) {
+                        JSONObject columnsJSONObject = columns.getJSONObject(i1);
+                        JSONArray list = columnsJSONObject.getJSONArray("list");
+                        for (int i2 = 0; i2 < list.size(); i2++) {
+                            JSONObject object = list.getJSONObject(i2);
+                            heads.add(object.getString("label"));
+                        }
                     }
+                } else {
+                    heads.add(item.getString("label"));
                 }
-            }else {
-                heads.add(item.getString("label"));
             }
-
+        }else {
+            Collections.addAll(heads,"合同编号","合同名称","合同金额","合同类型","计划开始时间","计划结束时间","自定义字段","备注","是否已回款","回款日期","金额","是否已开票","开票日期","发票种类","税率","税额");
         }
         List<List<String>> allList = new ArrayList<>();
         allList.add(heads);

+ 99 - 1
fhKeeper/formulahousekeeper/management-crm/src/main/resources/mapper/ContractMapper.xml

@@ -20,6 +20,7 @@
         <result column="remarks" property="remarks" />
         <result column="payment" property="payment" />
         <result column="sec_type_id" property="secTypeId" />
+        <result column="department_id" property="departmentId" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
@@ -30,7 +31,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,
         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.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
@@ -38,6 +39,7 @@
         left join user
         on contract.creator_id = user.id
         left join contract_custom cc on cc.contract_id=contract.id
+        left join department d.department_id=contract.department_id
         where contract.company_id = #{companyId}
         <if test="number!=null">
             and number like CONCAT('%', #{number}, '%')
@@ -154,4 +156,100 @@
             limit #{pageStart},#{pageSize}
         </if>
     </select>
+    <select id="selectContractWithType" 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.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.id desc
+        <if test="pageStart!=null and pageSize!=null">
+            limit #{pageStart},#{pageSize}
+        </if>
+    </select>
+    <select id="selectContractCntWithType" resultType="java.lang.Long">
+        select count(1) from contract
+        left join contract_type
+        on contract.type_id = contract_type.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.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 contract_type.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>
 </mapper>

+ 6 - 1
fhKeeper/formulahousekeeper/management-crm/src/main/resources/mapper/ContractPaymentMapper.xml

@@ -9,11 +9,16 @@
         <result column="pay_date" property="payDate" />
         <result column="amount" property="amount" />
         <result column="is_payed" property="isPayed" />
+        <result column="is_billed" property="isBilled" />
+        <result column="bill_date" property="billDate" />
+        <result column="invoice_type" property="invoiceType" />
+        <result column="tax_amount" property="taxAmount" />
+        <result column="tax_rate" property="taxRate" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, contract_id, pay_date, amount, is_payed
+        id, contract_id, pay_date, amount, is_payed, is_billed, bill_date, invoice_type, tax_amount, tax_rate
     </sql>
 
 </mapper>