Search in sources :

Example 6 with Contract

use of com.eservice.api.model.contract.Contract 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());
        // 更新需求单状态
        List<SignContentItem> orderSignContentList = JSON.parseArray(orderSignObj.getSignContent(), SignContentItem.class);
        boolean haveReject = false;
        boolean needMakeUpOrderSignForForeignDirector = false;
        String currentStep = "";
        MachineOrder machineOrder = machineOrderService.findById(orderSignObj.getOrderId());
        User machineOrderCreator = userService.findById(machineOrder.getCreateUserId());
        for (SignContentItem item : orderSignContentList) {
            // 如果签核内容中有“拒绝”状态的签核信息,需要将该
            if (item.getResult().equals(Constant.SIGN_REJECT)) {
                haveReject = true;
            }
            if (item.getResult() == Constant.SIGN_INITIAL) {
                currentStep = roleService.findById(item.getRoleId()).getRoleName();
                break;
            }
            /**
             * 订单审核完成时,创建设计单 2020-1207改了:
             * 如果是技术部经理签核且通过,则要生成对应的设计单
             * 并且没有生成过联系单
             */
            if (item.getRoleId() == Constant.ROLE_ID_TECH_MANAGER && item.getResult().equals(Constant.SIGN_APPROVE)) {
                logger.info("技术部经理签核,且通过");
                // 查找订单对应的设计单
                List<DesignDepInfoDetail> designDepInfoDetailList = designDepInfoService.selectDesignDepInfo(machineOrder.getOrderNum(), null, null, // 审核中
                Integer.valueOf(Constant.ORDER_CHECKING), null, null, null, null, null, null);
                if (designDepInfoDetailList == null || designDepInfoDetailList.size() == 0) {
                    commonService.createDesignDepInfo(machineOrder);
                }
            }
            /**
             * 技术部签核,更新相关内容:
             * 1. 机架长度 来自于技术部经理的签核内容,从“长度”字符开始截取。
             */
            if (item.getRoleId() == Constant.ROLE_ID_TECH_MANAGER) {
                String commentOfTechManager = item.getComment();
                int start = 0;
                start = commentOfTechManager.indexOf("机架长度");
                if (start == -1) {
                    start = commentOfTechManager.indexOf("【长度】");
                }
                if (start == -1) {
                    start = commentOfTechManager.indexOf("[长度]");
                }
                if (start == -1) {
                    start = commentOfTechManager.indexOf("长度");
                }
                if (start != -1) {
                    machineOrder.setMachineFrameLength(commentOfTechManager.substring(start));
                    machineOrderService.update(machineOrder);
                    logger.info("更新了机架长度为: " + commentOfTechManager.substring(start));
                }
            }
            /**
             * 成本核算员签核,更新相关内容:
             * 1. 毛利率
             */
            if (item.getRoleId() == Constant.ROLE_ID_COST_ACCOUNTANT) {
                String grossProfitString = "";
                int start = 0;
                start = item.getComment().indexOf("【毛利率】");
                if (start == -1) {
                    start = item.getComment().indexOf("[毛利率]");
                }
                if (start == -1) {
                    start = item.getComment().indexOf("毛利率");
                }
                if (start != -1) {
                    grossProfitString = item.getComment().substring(start);
                    machineOrder.setGrossProfit(grossProfitString);
                    machineOrderService.update(machineOrder);
                    logger.info("更新了毛利率为: " + grossProfitString);
                }
            }
            /**
             * 外贸部特殊情况,【外贸部销售经理】审核之后,再由【外贸部总监】审核
             * 非外贸部,不需要经过【外贸部总监】审核
             */
            if (orderSignObj.getCurrentStep().equals(Constant.SING_STEP_SALES_MANAGER) && item.getRoleId() == Constant.ROLE_ID_SALES_MANAGER && item.getResult().equals(Constant.SIGN_APPROVE)) {
                User userSalesManager = userService.selectByAccount(item.getUser());
                if (userSalesManager.getMarketGroupName().equals("外贸一部") || userSalesManager.getMarketGroupName().equals("外贸二部")) {
                    logger.info("外贸部经理签核,且通过,需要【外贸部总监】审核");
                } else {
                    /**
                     * 内贸部的订单不需要外贸总监审核
                     * 外贸总监已经在流程中,把数据补充填上,流程往后走
                     */
                    needMakeUpOrderSignForForeignDirector = true;
                }
            }
        }
        // 都已经签核
        if (!haveReject) {
            if (currentStep.equals("")) {
                currentStep = Constant.SIGN_FINISHED;
            }
            orderSignObj.setCurrentStep(currentStep);
            orderSignService.update(orderSignObj);
            if (needMakeUpOrderSignForForeignDirector) {
                makeUpSignContent(orderSignObj);
            }
        }
        /**
         * 推送公众号消息给轮到的人(通过售后系统)
         */
        Contract contract = contractService.findById(contractId);
        String msgInfo = null;
        if (haveReject) {
            machineOrder.setStatus(Constant.ORDER_REJECTED);
            // /需求单相关,当前需求单审核变为初始化“SIGN_INITIAL”
            for (SignContentItem item : orderSignContentList) {
                item.setResult(Constant.SIGN_INITIAL);
            }
            orderSignObj.setSignContent(JSONObject.toJSONString(orderSignContentList));
            orderSignService.update(orderSignObj);
            // 如果有订单驳回,则设置合同为initial状态
            contract.setStatus(Constant.CONTRACT_INITIAL);
            msgInfo = Constant.STR_MSG_PUSH_SIGN_REFUESED;
        } else {
            if (machineOrder.getStatus().equals(Constant.ORDER_INITIAL)) {
                machineOrder.setStatus(Constant.ORDER_CHECKING);
            }
            // 需求单签核完成
            if (currentStep.equals(Constant.SIGN_FINISHED)) {
                machineOrder.setStatus(Constant.ORDER_CHECKING_FINISHED);
                commonService.createMachineByOrderId(machineOrder);
                msgInfo = Constant.STR_MSG_PUSH_SIGN_DONE;
            } else {
                msgInfo = Constant.STR_MSG_PUSH_IS_TURN_TO_SIGN;
            }
        }
        machineOrderService.update(machineOrder);
        commonService.syncMachineOrderStatusInDesignDepInfo(machineOrder);
        // 推送消息
        commonService.pushMachineOrderMsgToAftersale(orderSignObj, contract, machineOrder, haveReject, msgInfo);
        // 更新合同签核记录
        String step = commonService.getCurrentSignStep(contractId);
        ContractSign contractSign = contractSignService.detailByContractId(String.valueOf(contractId));
        if (step == null || contractSign == null) {
            throw new RuntimeException();
        } else {
            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 : User(com.eservice.api.model.user.User) 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) DesignDepInfoDetail(com.eservice.api.model.design_dep_info.DesignDepInfoDetail) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Contract

use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.

the class CommonService method createDesignDepInfo.

/**
 *  在生成订单、改单、拆单 时,自动生成设计单 ---签核完成时--再改:技术部签核完成就生成设计单。
 *
 * @param machineOrder
 */
public void createDesignDepInfo(MachineOrder machineOrder) {
    DesignDepInfo designDepInfo = new DesignDepInfo();
    designDepInfo.setDesignStatus(Constant.STR_DESIGN_STATUS_UNPLANNED);
    designDepInfo.setOrderNum(machineOrder.getOrderNum());
    if (machineOrder.getOrderNum() == null) {
        logger.error(machineOrder.getId() + "订单号为null");
    }
    designDepInfo.setSaleman(machineOrder.getSellman());
    try {
        List<Contract> list = contractService.getContractByOrderNumber(machineOrder.getOrderNum());
        if (list.size() > 1) {
            logger.error(machineOrder.getOrderNum() + ":该编号存在多个合同" + "自动创建设计单 失败");
            return;
        }
        Contract contract1 = list.get(0);
        if (contract1 != null) {
            designDepInfo.setGuestName(contract1.getCustomerName());
        }
        designDepInfo.setCountry(machineOrder.getCountry());
        designDepInfo.setMachineNum(machineOrder.getMachineNum());
        /**
         * 不仅仅是初始化状态,因为还有改单,拆单对应的状态
         */
        // designDepInfo.setOrderSignStatus(Constant.ORDER_INITIAL);
        // 注意这里是订单状态,不是订单签核状态
        designDepInfo.setOrderSignStatus(machineOrder.getStatus());
        designDepInfo.setOrderId(machineOrder.getId());
        designDepInfo.setCreatedDate(new Date());
        designDepInfo.setUpdatedDate(new Date());
        designDepInfoService.save(designDepInfo);
        logger.info("根据订单" + machineOrder.getOrderNum() + " 自动创建设计单");
    } catch (Exception e) {
        logger.error("自动创建设计单 失败 " + e.getMessage());
    }
}
Also used : DesignDepInfo(com.eservice.api.model.design_dep_info.DesignDepInfo) Contract(com.eservice.api.model.contract.Contract)

Example 8 with Contract

use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.

the class ContractController method isContractExist.

@PostMapping("/isContractExist")
public Result isContractExist(@RequestParam String contractNum) {
    if (contractNum == null) {
        return ResultGenerator.genFailResult("请输入合同编号!");
    } else {
        Condition condition = new Condition(Contract.class);
        condition.createCriteria().andCondition("contract_num = ", contractNum);
        List<Contract> list = contractService.findByCondition(condition);
        if (list.size() == 0) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator.genFailResult("合同编号已存在!");
        }
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with Contract

use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.

the class ContractController method list.

@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
    PageHelper.startPage(page, size);
    List<Contract> list = contractService.findAll();
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 10 with Contract

use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.

the class ContractController method startSign.

@PostMapping("/startSign")
@Transactional(rollbackFor = Exception.class)
public Result startSign(@RequestParam Integer contractId) {
    if (contractId == null) {
        ResultGenerator.genFailResult("合同ID为空!");
    } else {
        ContractSign contractSign = contractSignService.detailByContractId(String.valueOf(contractId));
        if (contractSign == null) {
            return ResultGenerator.genFailResult("根据合同号获取合同签核信息失败!");
        } else {
            // 更新合同状态为“CONTRACT_CHECKING”
            Contract contract = contractService.findById(contractId);
            if (contract == null) {
                return ResultGenerator.genFailResult("合同编号ID无效");
            } else {
                contract.setStatus(Constant.CONTRACT_CHECKING);
                contract.setUpdateTime(new Date());
                contractService.update(contract);
            }
            // 设置该合同下的需求单状态,如果处于“ORDER_INITIAL”状态,则设置为“ORDER_CHECKING”
            Condition tempCondition = new Condition(MachineOrder.class);
            tempCondition.createCriteria().andCondition("contract_id = ", contractId).andCondition("status = ", Constant.ORDER_INITIAL).andCondition("valid = ", 1);
            List<MachineOrder> orderList = machineOrderService.findByCondition(tempCondition);
            for (MachineOrder orderItem : orderList) {
                if (orderItem.getStatus().equals(Constant.ORDER_INITIAL)) {
                    orderItem.setStatus(Constant.ORDER_CHECKING);
                    machineOrderService.update(orderItem);
                    commonService.syncMachineOrderStatusInDesignDepInfo(orderItem);
                    Condition signCondition = new Condition(OrderSign.class);
                    signCondition.createCriteria().andCondition("order_id = ", orderItem.getId());
                    List<OrderSign> orderSignList = orderSignService.findByCondition(signCondition);
                    // 无签核记录
                    if (orderSignList.size() == 0) {
                        throw new RuntimeException();
                    } else {
                        OrderSign sign = orderSignList.get(orderSignList.size() - 1);
                        List<SignContentItem> orderSignContentList = JSON.parseArray(sign.getSignContent(), SignContentItem.class);
                        sign.setCurrentStep(roleService.findById(orderSignContentList.get(0).getRoleId()).getRoleName());
                        orderSignService.update(sign);
                        /**
                         * 发起签核时 也给第一个签核人推送
                         */
                        commonService.pushMachineOrderMsgToAftersale(sign, contract, orderItem, false, Constant.STR_MSG_PUSH_IS_TURN_TO_SIGN);
                    }
                }
            }
        // 更新签核记录
        // contractSign.setUpdateTime(new Date());
        // String currentStep = commonService.getCurrentSignStep(contractId);
        // if (currentStep == null) {
        // return ResultGenerator.genFailResult("获取当前签核steps失败!");
        // }
        // contractSign.setCurrentStep(currentStep);
        // //设置完状态后更新签核记录
        // 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)

Aggregations

Contract (com.eservice.api.model.contract.Contract)13 PostMapping (org.springframework.web.bind.annotation.PostMapping)12 OrderSign (com.eservice.api.model.order_sign.OrderSign)9 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)8 Date (java.util.Date)8 ContractSign (com.eservice.api.model.contract_sign.ContractSign)7 Transactional (org.springframework.transaction.annotation.Transactional)7 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)6 Condition (tk.mybatis.mapper.entity.Condition)6 SignContentItem (com.eservice.api.model.contract_sign.SignContentItem)5 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)4 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)4 OrderChangeRecord (com.eservice.api.model.order_change_record.OrderChangeRecord)3 User (com.eservice.api.model.user.User)3 Equipment (com.eservice.api.model.contract.Equipment)2 Machine (com.eservice.api.model.machine.Machine)2 OrderSplitRecord (com.eservice.api.model.order_split_record.OrderSplitRecord)2 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2