Search in sources :

Example 1 with SignContentItem

use of com.eservice.api.model.contract_sign.SignContentItem in project sinsim by WilsonHu.

the class OrderSignController method update.

@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(Integer contractId, String orderSign) {
    if (orderSign == null || "".equals(orderSign)) {
        ResultGenerator.genFailResult("签核信息为空!");
    }
    if (contractId == null || contractId <= 0) {
        ResultGenerator.genFailResult("合同ID不存在或者无效!");
    }
    OrderSign orderSignObj = JSONObject.parseObject(orderSign, OrderSign.class);
    if (orderSignObj == null) {
        ResultGenerator.genFailResult("签核信息JSON解析失败!");
    } else {
        // 更新需求单签核记录
        orderSignObj.setUpdateTime(new Date());
        orderSignService.update(orderSignObj);
        // 更新需求单状态
        List<SignContentItem> orderSignContentList = JSON.parseArray(orderSignObj.getSignContent(), SignContentItem.class);
        boolean haveReject = false;
        for (SignContentItem item : orderSignContentList) {
            // 如果签核内容中有“拒绝”状态的签核信息,需要将该
            if (item.getResult().equals(Constant.SIGN_REJECT)) {
                haveReject = true;
                break;
            }
        }
        MachineOrder machineOrder = machineOrderService.findById(orderSignObj.getOrderId());
        if (haveReject) {
            machineOrder.setStatus(Constant.ORDER_REJECTED);
            // 需要把之前的签核状态result设置为初始状态“SIGN_INITIAL”,但是签核内容不变(contract & machineOrder)
            // 合同相关
            ContractSign contractSignObj = contractSignService.detailByContractId(String.valueOf(contractId));
            List<SignContentItem> contractSignList = JSON.parseArray(contractSignObj.getSignContent(), SignContentItem.class);
            for (SignContentItem item : contractSignList) {
                item.setResult(Constant.SIGN_INITIAL);
            }
            contractSignObj.setSignContent(JSONObject.toJSONString(contractSignList));
            // 当前审核步骤变成空
            contractSignObj.setCurrentStep("");
            contractSignService.update(contractSignObj);
            // 需求单相关,当前需求单审核变为初始化“SIGN_INITIAL”
            for (SignContentItem item : orderSignContentList) {
                item.setResult(Constant.SIGN_INITIAL);
            }
            orderSignObj.setSignContent(JSONObject.toJSONString(orderSignContentList));
            orderSignService.update(orderSignObj);
        } else {
            if (!machineOrder.getStatus().equals(Constant.ORDER_CHECKING)) {
                machineOrder.setStatus(Constant.ORDER_CHECKING);
            }
        }
        machineOrderService.update(machineOrder);
        // 更新合同签核记录
        String step = commonService.getCurrentSignStep(contractId);
        ContractSign contractSign = contractSignService.detailByContractId(String.valueOf(contractId));
        if (step == null || contractSign == null) {
            throw new RuntimeException();
        } else {
            Contract contract = contractService.findById(contractId);
            if (step.equals(Constant.SIGN_FINISHED)) {
                // 表示签核已经完成,合同设置“CONTRACT_CHECKING_FINISHED”
                contract.setStatus(Constant.CONTRACT_CHECKING_FINISHED);
                // 需求单也需要设置为签核完成状态“ORDER_CHECKING_FINISHED”
                Condition tempCondition = new Condition(ContractSign.class);
                tempCondition.createCriteria().andCondition("contract_id = ", contractId);
                List<MachineOrder> machineOrderList = machineOrderService.findByCondition(tempCondition);
                for (MachineOrder item : machineOrderList) {
                    if (item.getStatus().equals(Constant.ORDER_CHECKING)) {
                        item.setStatus(Constant.ORDER_CHECKING_FINISHED);
                    }
                    machineOrderService.update(item);
                }
                // 根据合同中的需求单进行机器添加, 在需求单签核、合同签核都加上是因为最后一步审核可能是需求单,也可能是合同
                commonService.createMachineByContractId(contractId);
            } else {
                if (haveReject) {
                    contract.setStatus(Constant.CONTRACT_REJECTED);
                } else if (contract.getStatus().equals(Constant.CONTRACT_REJECTED)) {
                    contract.setStatus(Constant.CONTRACT_CHECKING);
                }
            }
            contract.setUpdateTime(new Date());
            contractService.update(contract);
        }
        contractSign.setCurrentStep(step);
        contractSignService.update(contractSign);
    }
    return ResultGenerator.genSuccessResult();
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) OrderSign(com.eservice.api.model.order_sign.OrderSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) ContractSign(com.eservice.api.model.contract_sign.ContractSign) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Contract(com.eservice.api.model.contract.Contract) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SignContentItem

use of com.eservice.api.model.contract_sign.SignContentItem in project sinsim by WilsonHu.

the class CommonService method getCurrentSignStep.

/**
 * 用于返回对应合同的所有签核记录,每一次提交审核以后,都需要通过该API获取所有审核内容,再设置审核状态
 *
 * @param contractId
 * @return result, 如果签核流程不存在返回null, 未结束则返回正在签核中的名称,结束则返回“FINISHED”
 */
public String getCurrentSignStep(Integer contractId) {
    String result = null;
    // 通过合同号找到有效的订单签核记录
    List<OrderSign> orderSignList = orderSignService.getValidOrderSigns(contractId);
    // 找到有效的合同签核记录,其实就是最新的合同簽和記錄
    ContractSign contractSign1 = contractSignService.detailByContractId(String.valueOf(contractId));
    HashMap<Integer, List<SignContentItem>> signContentSortByNumberMap = new HashMap<>();
    for (OrderSign os : orderSignList) {
        String contentStr = os.getSignContent();
        List<SignContentItem> orderSignContentList = JSON.parseArray(contentStr, SignContentItem.class);
        for (SignContentItem item : orderSignContentList) {
            if (signContentSortByNumberMap.get(item.getNumber()) != null) {
                signContentSortByNumberMap.get(item.getNumber()).add(item);
            } else {
                List<SignContentItem> list = new ArrayList<>();
                list.add(item);
                signContentSortByNumberMap.put(item.getNumber(), list);
            }
        }
    }
    List<SignContentItem> contractSignContentList = JSONObject.parseArray(contractSign1.getSignContent(), SignContentItem.class);
    for (SignContentItem item : contractSignContentList) {
        if (signContentSortByNumberMap.get(item.getNumber()) != null) {
            signContentSortByNumberMap.get(item.getNumber()).add(item);
        } else {
            List<SignContentItem> list = new ArrayList<>();
            list.add(item);
            signContentSortByNumberMap.put(item.getNumber(), list);
        }
    }
    // 签核流程不存在
    if (signContentSortByNumberMap.size() == 0) {
        return result;
    }
    // 将map.entrySet()转换成list
    List<Map.Entry<Integer, List<SignContentItem>>> list = new ArrayList<>(signContentSortByNumberMap.entrySet());
    // 通过比较器来实现排序
    Collections.sort(list, new Comparator<Map.Entry<Integer, List<SignContentItem>>>() {

        @Override
        public int compare(Map.Entry<Integer, List<SignContentItem>> o1, Map.Entry<Integer, List<SignContentItem>> o2) {
            // 升序排序
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    Iterator<Map.Entry<Integer, List<SignContentItem>>> entries = signContentSortByNumberMap.entrySet().iterator();
    boolean currentStepFound = false;
    while (entries.hasNext() && !currentStepFound) {
        Map.Entry<Integer, List<SignContentItem>> entry = entries.next();
        Integer key = entry.getKey();
        List<SignContentItem> value = entry.getValue();
        for (SignContentItem item : value) {
            // 根據簽和順序,找到最先的被拒絕或者未簽合的流程
            if (item.getResult().equals(Constant.SIGN_REJECT) || item.getResult().equals(Constant.SIGN_INITIAL)) {
                List<Role> roleList = roleService.findAll();
                for (Role role : roleList) {
                    if (role.getId().equals(item.getRoleId())) {
                        result = role.getRoleName();
                    }
                }
                currentStepFound = true;
            }
        }
    }
    // 如果没有找到,表示该签核流程已经完成,此时返回一个特殊的String给调用者
    if (!currentStepFound) {
        result = Constant.SIGN_FINISHED;
    }
    return result;
}
Also used : Role(com.eservice.api.model.role.Role) OrderSign(com.eservice.api.model.order_sign.OrderSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) ContractSign(com.eservice.api.model.contract_sign.ContractSign)

Example 3 with SignContentItem

use of com.eservice.api.model.contract_sign.SignContentItem in project sinsim by WilsonHu.

the class ContractController method buildContractExcel.

/**
 * 根据 contract_id,创建EXCEL表格,“合同评审单”+“客户需求单” 等sheet。
 * 具体内容来自 contract, contract_sign,machine_order,order_detail
 * Update: 总经理,销售,财务之外的用户,生成的excel里不显示金额信息.
 *
 * @param contractId
 * @return
 */
@PostMapping("/buildContractExcel")
public Result buildContractExcel(@RequestParam Integer contractId, @RequestParam String account) {
    InputStream fs = null;
    POIFSFileSystem pfs = null;
    HSSFWorkbook wb = null;
    FileOutputStream out = null;
    String downloadPath = "";
    /*
        返回给docker外部下载
         */
    String downloadPathForNginx = "";
    // 只有总经理,销售,财务等用户,生成的excel里才显示金额信息. '6','7','9','14','15'
    Boolean displayPrice = false;
    User user = userService.selectByAccount(account);
    if (user != null) {
        Integer roleId = user.getRoleId();
        if ((6 == roleId) || (7 == roleId) || (9 == roleId) || (14 == roleId) || (15 == roleId)) {
            displayPrice = true;
        }
    }
    try {
        ClassPathResource resource = new ClassPathResource("empty_contract.xls");
        fs = resource.getInputStream();
        pfs = new POIFSFileSystem(fs);
        wb = new HSSFWorkbook(pfs);
        Contract contract = contractService.findById(contractId);
        if (contract == null) {
            return ResultGenerator.genFailResult("contractID not exist!");
        }
        // 一个合同可能对应多个需求单
        List<Integer> machineOrderIdList = new ArrayList<Integer>();
        MachineOrder mo;
        for (int i = 0; i < machineOrderService.findAll().size(); i++) {
            mo = machineOrderService.findAll().get(i);
            if (mo.getContractId().equals(contractId)) {
                machineOrderIdList.add(mo.getId());
            }
        }
        MachineOrder machineOrder;
        MachineOrderDetail machineOrderDetail;
        // 需求单签核,一个需求单对应0个或多个签核
        List<OrderSign> orderSignList;
        // 读取了模板内所有sheet1内容
        HSSFSheet sheet1 = wb.getSheetAt(0);
        // 在相应的单元格进行赋值(A2)
        HSSFCell cell = sheet1.getRow(1).getCell((short) 0);
        cell.setCellValue(new HSSFRichTextString("合 同 号:" + contract.getContractNum()));
        // D2
        cell = sheet1.getRow(1).getCell((short) 3);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy/MM/dd");
        String dateString = formatter.format(contract.getCreateTime());
        HSSFCellStyle style = cell.getCellStyle();
        style.setWrapText(true);
        cell.setCellStyle(style);
        cell.setCellValue(new HSSFRichTextString(dateString));
        // B3
        cell = sheet1.getRow(2).getCell((short) 1);
        cell.setCellValue(new HSSFRichTextString(contract.getCustomerName()));
        // N个需求单,插入N行
        Integer machineOrderCount = machineOrderIdList.size();
        insertRow(wb, sheet1, 5, machineOrderCount);
        System.out.println("======== machineOrderCount: " + machineOrderCount);
        Integer allSum = 0;
        for (int i = 0; i < machineOrderCount; i++) {
            machineOrder = machineOrderService.findById(contractId);
            machineOrderDetail = machineOrderService.getOrderAllDetail(machineOrderIdList.get(i));
            // A5,A6,A7,...品牌
            cell = sheet1.getRow(5 + i).getCell((short) 0);
            cell.setCellValue(new HSSFRichTextString(machineOrderService.findAll().get(i).getBrand()));
            // B5,B6,B7,...机型
            cell = sheet1.getRow(5 + i).getCell((short) 1);
            cell.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachineType().getName()));
            // C5,C6,C7,...数量
            cell = sheet1.getRow(5 + i).getCell((short) 2);
            cell.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachineNum().toString()));
            // D5,D6,D7,...单价
            cell = sheet1.getRow(5 + i).getCell((short) 3);
            if (displayPrice) {
                cell.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachinePrice()));
            } else {
                cell.setCellValue(new HSSFRichTextString("/"));
            }
            // E5,E6,E7...总价
            cell = sheet1.getRow(5 + i).getCell((short) 4);
            if (displayPrice) {
                Integer sum = Integer.parseInt(machineOrderDetail.getMachinePrice()) * machineOrderDetail.getMachineNum();
                allSum = allSum + sum;
                cell.setCellValue(new HSSFRichTextString(sum.toString()));
            } else {
                cell.setCellValue(new HSSFRichTextString("/"));
            }
        }
        Integer locationRow = 6 + machineOrderCount;
        // 总计
        cell = sheet1.getRow(locationRow++).getCell((short) 4);
        if (displayPrice) {
            cell.setCellValue(new HSSFRichTextString(allSum.toString()));
        } else {
            cell.setCellValue(new HSSFRichTextString("/"));
        }
        // 付款方式
        cell = sheet1.getRow(locationRow++).getCell((short) 1);
        cell.setCellValue(new HSSFRichTextString(contract.getPayMethod()));
        // 合同交货日期
        String dateTimeString = formatter.format(contract.getContractShipDate());
        cell = sheet1.getRow(locationRow++).getCell((short) 1);
        cell.setCellValue(new HSSFRichTextString(dateTimeString));
        // 备注
        cell = sheet1.getRow(locationRow++).getCell((short) 0);
        cell.setCellValue(new HSSFRichTextString(contract.getMark()));
        // 销售员
        locationRow = locationRow + 6;
        cell = sheet1.getRow(locationRow++).getCell((short) 1);
        cell.setCellValue(new HSSFRichTextString(contract.getSellman()));
        // 一个合同对应多个签核 TODO:多个签核时如何选择,contractSignService.detailByContractId 可能要改。
        ContractSign contractSign;
        // 合同审核信息,来自 contract_sign
        contractSign = contractSignService.detailByContractId(contractId.toString());
        SignContentItem signContentItem;
        List<SignContentItem> signContentItemList = JSON.parseArray(contractSign.getSignContent(), SignContentItem.class);
        OrderSign orderSign = null;
        /**
         *  根据签核内容 signContentItemList,动态填入表格。
         *  signType为 “合同签核”的,都按顺序填入表格
         */
        // 合同的N个签核,插入N行
        Integer contractSignCount = signContentItemList.size();
        insertRow(wb, sheet1, locationRow, contractSignCount);
        for (int k = 0; k < contractSignCount; k++) {
            /**
             * 合同签核的: 角色(部门)/人/时间/意见
             */
            // 1.签核角色(部门)
            int roleId = signContentItemList.get(k).getRoleId();
            // 根据roleId返回角色(部门)
            String roleName = roleService.findById(roleId).getRoleName();
            cell = sheet1.getRow(locationRow).getCell((short) 0);
            cell.setCellValue(new HSSFRichTextString(roleName));
            // 2.签核人
            cell = sheet1.getRow(locationRow).getCell((short) 1);
            cell.setCellValue(new HSSFRichTextString(signContentItemList.get(k).getUser()));
            // 3.签核时间
            cell = sheet1.getRow(locationRow).getCell((short) 2);
            if (null != signContentItemList.get(k).getDate()) {
                cell.setCellValue(new HSSFRichTextString(formatter2.format(signContentItemList.get(k).getDate())));
            }
            cell = sheet1.getRow(locationRow).getCell((short) 3);
            cell.setCellValue(new HSSFRichTextString("意见"));
            // 4.签核意见
            cell = sheet1.getRow(locationRow++).getCell((short) 4);
            cell.setCellValue(new HSSFRichTextString(signContentItemList.get(k).getComment()));
        }
        // 最后删除多余一行
        sheet1.shiftRows(locationRow + 1, sheet1.getLastRowNum(), -1);
        // 根据实际需求单数量,动态复制生成新的sheet;
        for (int i = 0; i < machineOrderCount - 1; i++) {
            // clone已经包含copy+paste
            wb.cloneSheet(1);
        }
        // 调整sheet位置
        Integer sheetCount = wb.getNumberOfSheets();
        wb.setSheetOrder("Sheet3", sheetCount - 1);
        // sheet2,sheet3...,第1,2,...个需求单
        for (int i = 0; i < machineOrderCount; i++) {
            machineOrderDetail = machineOrderService.getOrderAllDetail(machineOrderIdList.get(i));
            HSSFSheet sheetX = wb.getSheetAt(1 + i);
            // 在相应的单元格进行赋值
            // B2
            HSSFCell cell2 = sheetX.getRow(1).getCell((short) 1);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getSellman()));
            // D2
            cell2 = sheetX.getRow(1).getCell((short) 3);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getMaintainType()));
            // F2
            cell2 = sheetX.getRow(1).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderNum()));
            // I2
            cell2 = sheetX.getRow(1).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(contract.getContractNum()));
            // C3
            cell2 = sheetX.getRow(2).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getCustomer()));
            // E3
            cell2 = sheetX.getRow(2).getCell((short) 4);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getBrand()));
            // H3
            cell2 = sheetX.getRow(2).getCell((short) 7);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachineType().getName()));
            // C4
            cell2 = sheetX.getRow(3).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getHeadNum().toString()));
            // E4
            cell2 = sheetX.getRow(3).getCell((short) 4);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getHeadDistance().toString()));
            // H4
            cell2 = sheetX.getRow(3).getCell((short) 7);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getxDistance()));
            // H5
            cell2 = sheetX.getRow(4).getCell((short) 7);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getyDistance()));
            // D6
            cell2 = sheetX.getRow(5).getCell((short) 3);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTowelColor()));
            // F6
            cell2 = sheetX.getRow(5).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTowelDaxle()));
            // H6
            cell2 = sheetX.getRow(5).getCell((short) 7);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTowelHaxle()));
            // K6
            cell2 = sheetX.getRow(5).getCell((short) 10);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTowelMotor()));
            // D7
            cell2 = sheetX.getRow(6).getCell((short) 3);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTapingHead()));
            // H7
            cell2 = sheetX.getRow(6).getCell((short) 7);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getSpecialTowelNeedle()));
            // C8
            cell2 = sheetX.getRow(7).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricPc()));
            // D8
            cell2 = sheetX.getRow(7).getCell((short) 3);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getCountry()));
            // F8
            cell2 = sheetX.getRow(7).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricMotor()));
            // I8
            cell2 = sheetX.getRow(7).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricMotorXy()));
            // C9
            cell2 = sheetX.getRow(8).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricTrim()));
            // F9
            cell2 = sheetX.getRow(8).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricPower()));
            // I9
            cell2 = sheetX.getRow(8).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricSwitch()));
            // C10
            cell2 = sheetX.getRow(9).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getElectricOil()));
            // C11
            cell2 = sheetX.getRow(10).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleSplit()));
            // F11
            cell2 = sheetX.getRow(10).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxlePanel()));
            // i11
            cell2 = sheetX.getRow(10).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleNeedle()));
            // C12
            cell2 = sheetX.getRow(11).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleRail()));
            // f12
            cell2 = sheetX.getRow(11).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleDownCheck()));
            // i12
            cell2 = sheetX.getRow(11).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleHook()));
            // C13
            cell2 = sheetX.getRow(12).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleJump()));
            // F13
            cell2 = sheetX.getRow(12).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleUpperThread()));
            // C14
            cell2 = sheetX.getRow(13).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getAxleAddition()));
            // C15
            cell2 = sheetX.getRow(14).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkColor()));
            // f15
            cell2 = sheetX.getRow(14).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkPlaten()));
            // G15
            cell2 = sheetX.getRow(14).getCell((short) 6);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkPlatenColor()));
            // i15
            cell2 = sheetX.getRow(14).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkRing()));
            // C16
            cell2 = sheetX.getRow(15).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkBracket()));
            // f16
            cell2 = sheetX.getRow(15).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkStop()));
            // i16
            cell2 = sheetX.getRow(15).getCell((short) 8);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getFrameworkLight()));
            // C17
            cell2 = sheetX.getRow(16).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getDriverType()));
            // f17
            cell2 = sheetX.getRow(16).getCell((short) 5);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getDriverMethod()));
            // C18
            cell2 = sheetX.getRow(17).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getDriverHorizonNum().toString()));
            // C19
            cell2 = sheetX.getRow(18).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getOrderDetail().getDriverVerticalNum().toString()));
            // C20
            cell2 = sheetX.getRow(19).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getPackageMethod()));
            // C22,23 ... N 装置名称
            String str = machineOrderDetail.getEquipment();
            JSONArray jsonArray = JSON.parseArray(str);
            Integer equipmentCount = 0;
            Integer totalPriceOfOrder = 0;
            if (null != jsonArray) {
                // 该需求单的N个装置,插入N行
                equipmentCount = jsonArray.size();
                insertRow2(wb, sheetX, 21, equipmentCount - 1);
                System.out.println("========order: " + machineOrderDetail.getOrderNum() + " inserted " + equipmentCount + " line");
                for (int j = 0; j < equipmentCount; j++) {
                    Equipment eq = JSON.parseObject((String) jsonArray.get(j).toString(), Equipment.class);
                    cell2 = sheetX.getRow(21 + j).getCell((short) 0);
                    cell2.setCellValue(new HSSFRichTextString(Integer.toString(j + 1)));
                    cell2 = sheetX.getRow(21 + j).getCell((short) 1);
                    cell2.setCellValue(new HSSFRichTextString(eq.getName()));
                    cell2 = sheetX.getRow(21 + j).getCell((short) 2);
                    cell2.setCellValue(new HSSFRichTextString(eq.getNumber().toString()));
                    cell2 = sheetX.getRow(21 + j).getCell((short) 3);
                    if (displayPrice) {
                        cell2.setCellValue(new HSSFRichTextString(eq.getPrice().toString()));
                    } else {
                        cell2.setCellValue(new HSSFRichTextString("/"));
                    }
                    cell2 = sheetX.getRow(21 + j).getCell((short) 4);
                    int eqSum = eq.getNumber() * eq.getPrice();
                    totalPriceOfOrder += eqSum;
                    if (displayPrice) {
                        cell2.setCellValue(new HSSFRichTextString((Integer.toString(eqSum))));
                    } else {
                        cell2.setCellValue(new HSSFRichTextString("/"));
                    }
                }
            } else {
                System.out.println("========order: " + machineOrderDetail.getOrderNum() + " inserted 000 line");
            }
            // 装置end
            // 订机数量
            cell2 = sheetX.getRow(21 + equipmentCount).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachineNum().toString()));
            // 机器单价
            cell2 = sheetX.getRow(21 + equipmentCount).getCell((short) 3);
            if (displayPrice) {
                cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getMachinePrice()));
            } else {
                cell2.setCellValue(new HSSFRichTextString("/"));
            }
            // 机器总价
            Integer machineOrderSum = Integer.parseInt(machineOrderDetail.getMachinePrice()) * machineOrderDetail.getMachineNum();
            cell2 = sheetX.getRow(21 + equipmentCount).getCell((short) 4);
            if (displayPrice) {
                cell2.setCellValue(new HSSFRichTextString(machineOrderSum.toString()));
            } else {
                cell2.setCellValue(new HSSFRichTextString("/"));
            }
            // 需求单总价
            totalPriceOfOrder += machineOrderSum;
            cell2 = sheetX.getRow(22 + equipmentCount).getCell((short) 4);
            if (displayPrice) {
                cell2.setCellValue(new HSSFRichTextString(totalPriceOfOrder.toString()));
            } else {
                cell2.setCellValue(new HSSFRichTextString("/"));
            }
            // 合同的交货日期
            cell2 = sheetX.getRow(23 + equipmentCount).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(formatter2.format(contract.getContractShipDate())));
            // 计划发货日期
            cell2 = sheetX.getRow(24 + equipmentCount).getCell((short) 2);
            cell2.setCellValue(new HSSFRichTextString(formatter2.format(machineOrderDetail.getPlanShipDate())));
            // 备注
            cell2 = sheetX.getRow(25 + equipmentCount).getCell((short) 0);
            cell2.setCellValue(new HSSFRichTextString(machineOrderDetail.getMark()));
            /**
             *  需求单审核信息,来自 order_sign, 具体有几个签核步骤,可以动态填入表格
             */
            orderSignList = orderSignService.getOrderSignListByOrderId(machineOrderIdList.get(i));
            if (orderSignList.size() > 0) {
                // 取最后一次的签核,后续看是否需要根据时间来取最新
                orderSign = orderSignList.get(orderSignList.size() - 1);
                signContentItemList = JSON.parseArray(orderSign.getSignContent(), SignContentItem.class);
                // 需求单的N个签核,插入N行
                Integer orderSignCount = signContentItemList.size();
                insertRow2(wb, sheetX, 33 + equipmentCount, orderSignCount);
                for (int k = 0; k < orderSignCount; k++) {
                    /**
                     * 需求单签核的: 角色(部门)/人/时间/意见
                     */
                    // 1.签核角色(部门)
                    int roleId = signContentItemList.get(k).getRoleId();
                    // 根据roleId返回角色(部门)
                    String roleName = roleService.findById(roleId).getRoleName();
                    cell = sheetX.getRow(33 + equipmentCount + k).getCell((short) 0);
                    cell.setCellValue(new HSSFRichTextString(roleName));
                    // 2.签核人
                    cell = sheetX.getRow(33 + equipmentCount + k).getCell((short) 1);
                    cell.setCellValue(new HSSFRichTextString(signContentItemList.get(k).getUser()));
                    // 3.签核时间
                    cell = sheetX.getRow(33 + equipmentCount + k).getCell((short) 2);
                    if (null != signContentItemList.get(k).getDate()) {
                        cell.setCellValue(new HSSFRichTextString(formatter2.format(signContentItemList.get(k).getDate())));
                    }
                    cell = sheetX.getRow(33 + equipmentCount + k).getCell((short) 3);
                    cell.setCellValue(new HSSFRichTextString("意见"));
                    // 4.签核意见
                    cell = sheetX.getRow(33 + equipmentCount + k).getCell((short) 4);
                    cell.setCellValue(new HSSFRichTextString(signContentItemList.get(k).getComment()));
                    // 合并单元格
                    sheetX.addMergedRegion(new CellRangeAddress(33 + equipmentCount + k, 33 + equipmentCount + k, 4, 10));
                }
                // 最后删除多余一行
                sheetX.shiftRows(33 + equipmentCount + orderSignCount + 1, sheetX.getLastRowNum(), -1);
            }
        }
        // 修改模板内容导出新模板,生成路径供前端下载
        downloadPath = contractOutputDir + contract.getContractNum() + ".xls";
        downloadPathForNginx = "/excel/" + contract.getContractNum() + ".xls";
        out = new FileOutputStream(downloadPath);
        wb.write(out);
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            fs.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if ("".equals(downloadPath)) {
        return ResultGenerator.genFailResult("生成合同文件失败!");
    } else {
        return ResultGenerator.genSuccessResult(downloadPathForNginx);
    }
}
Also used : User(com.eservice.api.model.user.User) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) OrderSign(com.eservice.api.model.order_sign.OrderSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) InputStream(java.io.InputStream) JSONArray(com.alibaba.fastjson.JSONArray) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Equipment(com.eservice.api.model.contract.Equipment) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileOutputStream(java.io.FileOutputStream) ContractSign(com.eservice.api.model.contract_sign.ContractSign) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Contract(com.eservice.api.model.contract.Contract) SimpleDateFormat(java.text.SimpleDateFormat) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with SignContentItem

use of com.eservice.api.model.contract_sign.SignContentItem in project sinsim by WilsonHu.

the class ContractSignController method update.

@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String contractSign) {
    ContractSign contractSignObj = JSON.parseObject(contractSign, ContractSign.class);
    contractSignObj.setUpdateTime(new Date());
    contractSignService.update(contractSignObj);
    String step = commonService.getCurrentSignStep(contractSignObj.getContractId());
    if (step == null) {
        throw new RuntimeException();
    } else {
        Contract contract = contractService.findById(contractSignObj.getContractId());
        if (step.equals(Constant.SIGN_FINISHED)) {
            // 表示签核已经完成
            contract.setStatus(Constant.CONTRACT_CHECKING_FINISHED);
            // 需求单也需要设置为签核完成状态“ORDER_CHECKING_FINISHED”
            Condition tempCondition = new Condition(ContractSign.class);
            tempCondition.createCriteria().andCondition("contract_id = ", contract.getId());
            List<MachineOrder> machineOrderList = machineOrderService.findByCondition(tempCondition);
            for (MachineOrder item : machineOrderList) {
                if (item.getStatus().equals(Constant.ORDER_CHECKING)) {
                    item.setStatus(Constant.ORDER_CHECKING_FINISHED);
                }
                machineOrderService.update(item);
            }
            // 根据合同中的需求单进行机器添加
            commonService.createMachineByContractId(contractSignObj.getContractId());
        } else {
            // 更新合同状态
            List<SignContentItem> contractSignContentList = JSON.parseArray(contractSignObj.getSignContent(), SignContentItem.class);
            boolean haveReject = false;
            for (SignContentItem item : contractSignContentList) {
                // 如果签核内容中有“拒绝”状态的签核信息,需要将该
                if (item.getResult().equals(Constant.SIGN_REJECT)) {
                    haveReject = true;
                    break;
                }
            }
            if (haveReject) {
                contract.setStatus(Constant.CONTRACT_REJECTED);
                // 合同相关
                for (SignContentItem item : contractSignContentList) {
                    item.setResult(Constant.SIGN_INITIAL);
                }
                contractSignObj.setSignContent(JSONObject.toJSONString(contractSignContentList));
                // 当前审核步骤变成空
                step = "";
                // 需求单相关
                List<OrderSign> orderSignList = orderSignService.getValidOrderSigns(contractSignObj.getContractId());
                for (OrderSign item : orderSignList) {
                    // 之前把正在签核中,或者驳回状态的需求单的签核状态设置为“SIGN_INITIAL”
                    MachineOrder machineOrder = machineOrderService.findById(item.getOrderId());
                    Byte status = machineOrder.getStatus();
                    if (Constant.ORDER_CHECKING.equals(status) || Constant.ORDER_REJECTED.equals(status)) {
                        List<SignContentItem> signContentItemList = JSONObject.parseArray(item.getSignContent(), SignContentItem.class);
                        for (SignContentItem signContentItem : signContentItemList) {
                            signContentItem.setResult(Constant.SIGN_INITIAL);
                        }
                        item.setSignContent(JSONObject.toJSONString(signContentItemList));
                        orderSignService.update(item);
                        // 需求单状态设置为“ORDER_REJECTED”
                        machineOrder.setStatus(Constant.ORDER_REJECTED);
                        machineOrderService.update(machineOrder);
                    }
                }
            } else {
                // 已驳回的重新审核后,更改合同状态为审核中.
                if (contract.getStatus() == Constant.CONTRACT_REJECTED) {
                    contract.setStatus(Constant.CONTRACT_CHECKING);
                    // 需求单也需要重新设置为审核中
                    Condition tempCondition = new Condition(ContractSign.class);
                    tempCondition.createCriteria().andCondition("contract_id = ", contract.getId());
                    List<MachineOrder> machineOrderList = machineOrderService.findByCondition(tempCondition);
                    for (MachineOrder item : machineOrderList) {
                        if (item.getStatus() == Constant.ORDER_REJECTED) {
                            item.setStatus(Constant.ORDER_CHECKING);
                        }
                        machineOrderService.update(item);
                    }
                }
            }
        }
        contract.setUpdateTime(new Date());
        contractService.update(contract);
    }
    contractSignObj.setCurrentStep(step);
    contractSignService.update(contractSignObj);
    return ResultGenerator.genSuccessResult();
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Date(java.util.Date) OrderSign(com.eservice.api.model.order_sign.OrderSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) ContractSign(com.eservice.api.model.contract_sign.ContractSign) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ContractSign (com.eservice.api.model.contract_sign.ContractSign)4 SignContentItem (com.eservice.api.model.contract_sign.SignContentItem)4 OrderSign (com.eservice.api.model.order_sign.OrderSign)4 Contract (com.eservice.api.model.contract.Contract)3 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Condition (tk.mybatis.mapper.entity.Condition)2 JSONArray (com.alibaba.fastjson.JSONArray)1 Equipment (com.eservice.api.model.contract.Equipment)1 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)1 Role (com.eservice.api.model.role.Role)1 User (com.eservice.api.model.user.User)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1