Search in sources :

Example 6 with OrderSign

use of com.eservice.api.model.order_sign.OrderSign 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 OrderSign

use of com.eservice.api.model.order_sign.OrderSign in project sinsim by WilsonHu.

the class OrderSignController method add.

@PostMapping("/add")
public Result add(String orderSign) {
    OrderSign orderSign1 = JSON.parseObject(orderSign, OrderSign.class);
    orderSignService.save(orderSign1);
    return ResultGenerator.genSuccessResult();
}
Also used : OrderSign(com.eservice.api.model.order_sign.OrderSign) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with OrderSign

use of com.eservice.api.model.order_sign.OrderSign in project sinsim by WilsonHu.

the class OrderSignController method getOrderSignListByOrderId.

/**
 * 根据orderId获取签核信息
 *
 * @param orderId
 * @return  订单的签核记录只有在新增合同-订单时,才创建订单的签核记录,所以这里其实只返回一个签核记录,先保留这样用list
 *          (之前考虑过比如驳回造成的多次签核的分别放在不同的签核记录里,最后其实是放在同个签核记录里)
 */
@PostMapping("/getOrderSignListByOrderId")
public Result getOrderSignListByOrderId(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, @RequestParam Integer orderId) {
    PageHelper.startPage(page, size);
    List<OrderSign> list = orderSignService.getOrderSignListByOrderId(orderId);
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : OrderSign(com.eservice.api.model.order_sign.OrderSign) PageInfo(com.github.pagehelper.PageInfo) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with OrderSign

use of com.eservice.api.model.order_sign.OrderSign in project sinsim by WilsonHu.

the class CommonService method getCurrentSignStep.

// public String gatewayIpFromDockerFile ="aaa"; //main是静态域,所以不方便从main参数里获取值,已改为从文件里读取。
/**
 * 用于返回对应合同的所有签核记录,每一次提交审核以后,都需要通过该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 10 with OrderSign

use of com.eservice.api.model.order_sign.OrderSign in project sinsim by WilsonHu.

the class OrderSignController method list.

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

Aggregations

OrderSign (com.eservice.api.model.order_sign.OrderSign)14 PostMapping (org.springframework.web.bind.annotation.PostMapping)13 Contract (com.eservice.api.model.contract.Contract)9 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)9 ContractSign (com.eservice.api.model.contract_sign.ContractSign)8 Date (java.util.Date)7 Transactional (org.springframework.transaction.annotation.Transactional)7 SignContentItem (com.eservice.api.model.contract_sign.SignContentItem)6 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)6 Condition (tk.mybatis.mapper.entity.Condition)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 PageInfo (com.github.pagehelper.PageInfo)2 FileNotFoundException (java.io.FileNotFoundException)2