Search in sources :

Example 6 with UserDetail

use of com.eservice.api.model.user.UserDetail in project sinsim by WilsonHu.

the class CommonService method pushMachineOrderMsgToAftersale.

/**
 * 推送公众号消息给轮到 订单签核的人(通过售后系统)
 * @param orderSignObj
 * @param contract
 * @param machineOrder
 * @param haveReject 是否驳回 ( 虽然这个信息可以从cs中提取,但是调用该函数的地方前面已经提前过了,方便用)
 */
public void pushMachineOrderMsgToAftersale(OrderSign orderSignObj, Contract contract, MachineOrder machineOrder, boolean haveReject, String msgInfo) {
    // 指定格式,因为售后解析要用到
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // 指定北京时间
    formatter.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    String createDateStr = formatter.format(machineOrder.getCreateTime());
    /**
     * 签核结束,推送给订单录单人;
     */
    if (orderSignObj.getCurrentStep().equals(Constant.SIGN_FINISHED)) {
        List<UserDetail> userList = userService.selectUsers(contract.getRecordUser(), null, null, null, null, 1);
        if (userList.isEmpty() || userList == null) {
            logger.error("根据 " + contract.getRecordUser() + "找不到User");
        } else {
            // 找到录单人
            UserDetail toUser = userList.get(0);
            logger.info("订单签核结束,推送给订单录单人");
            commonService.sendSignInfoViWxMsg(toUser.getAccount(), machineOrder.getOrderNum(), "", createDateStr, contract.getMarketGroupName(), contract.getRecordUser(), msgInfo);
        }
    } else {
        /**
         * 签核没有结束:
         *      驳回:推送给所有参与签核的人;
         *      非驳回:推送给轮到签核的角色
         */
        Role role = roleService.findBy("roleName", orderSignObj.getCurrentStep());
        if (role == null) {
            logger.error("根据该 role_name " + orderSignObj.getCurrentStep() + "找不到Role");
            return;
        }
        if (haveReject) {
            // 驳回,发给所有参与签核的人。+ 录单人
            List<User> userList = null;
            userList = commonService.getUsersInMachineOrderSign(orderSignObj);
            if (userList != null && userList.size() != 0) {
                for (User toUser : userList) {
                    logger.info("订单拒绝,发给参与签核的人 " + toUser.getAccount());
                    commonService.sendSignInfoViWxMsg(toUser.getAccount(), machineOrder.getOrderNum(), "", createDateStr, contract.getMarketGroupName(), contract.getRecordUser(), msgInfo);
                }
            } else {
                logger.warn(machineOrder.getOrderNum() + ", 订单在此次拒绝前,没有参与过签核的人, 异常不可能");
            }
            // 考虑录单人和签核人可能是相同的,这种情况只需要发一次
            boolean isRecorderInUserList = false;
            for (User toUser : userList) {
                if (toUser.getAccount().equals(contract.getRecordUser())) {
                    isRecorderInUserList = true;
                    break;
                }
            }
            if (!isRecorderInUserList) {
                logger.info("订单驳回,发给录单人 " + contract.getRecordUser());
                commonService.sendSignInfoViWxMsg(contract.getRecordUser(), machineOrder.getOrderNum(), "", createDateStr, contract.getMarketGroupName(), contract.getRecordUser(), msgInfo);
            }
        } else {
            // 如果是销售部经理还要细分发给哪个部门的销售经理,
            if (role.getRoleName().equals(Constant.SING_STEP_SALES_MANAGER)) {
                logger.info("推送签核给销售部经理");
                List<UserDetail> toSalesManagerList = null;
                // 旧的签核记录里,没有SalesDepartment
                if (orderSignObj.getSalesDepartment() != null) {
                    /**
                     * 外贸总监,user.market_group_name 不再是外贸一部、
                     * 外贸经理,user.market_group_name 还是外贸二部。
                     * 内贸部的订单:发给内贸经理
                     * 外贸1部的订单(外贸一部的销售员+外贸总监所录入):发给外贸经理
                     * 外贸2部的订单(外贸二部的销售员+外贸经理所录入):发给外贸经理
                     */
                    if (orderSignObj.getSalesDepartment().equals(Constant.STR_DEPARTMENT_DOMESTIC)) {
                        toSalesManagerList = userService.selectUsers(null, null, Constant.ROLE_ID_SALES_MANAGER, null, Constant.STR_DEPARTMENT_DOMESTIC, 1);
                    } else if (orderSignObj.getSalesDepartment().equals(Constant.STR_DEPARTMENT_FOREIGN_1)) {
                        toSalesManagerList = userService.selectUsers(null, null, Constant.ROLE_ID_SALES_MANAGER, null, Constant.STR_DEPARTMENT_FOREIGN_FUZZY, 1);
                    } else if (orderSignObj.getSalesDepartment().equals(Constant.STR_DEPARTMENT_FOREIGN_2)) {
                        // 同上,即外贸一部二部,都是由外贸经理来审核
                        toSalesManagerList = userService.selectUsers(null, null, Constant.ROLE_ID_SALES_MANAGER, null, Constant.STR_DEPARTMENT_FOREIGN_FUZZY, 1);
                    }
                    if (toSalesManagerList != null) {
                        for (UserDetail toUser : toSalesManagerList) {
                            logger.info("订单继续签核,发给下销售经理  " + toUser.getAccount());
                            commonService.sendSignInfoViWxMsg(toUser.getAccount(), machineOrder.getOrderNum(), "", createDateStr, contract.getMarketGroupName(), contract.getRecordUser(), msgInfo);
                        }
                    } else {
                        logger.info("推送消息,找不到销售部经理");
                    }
                } else {
                    /**
                     * 外贸总监,角色即要有外贸经理的权限,又,,,目前特殊化的东西有点多。
                     * 外贸总监的销售部门是空的,不是一部也不是二部
                     */
                    logger.info("odersign 销售部门为空");
                }
            } else {
                List<UserDetail> userList = userService.selectUsers(null, null, role.getId(), null, null, 1);
                if (userList.isEmpty() || userList == null) {
                    logger.error("根据该roleId " + role.getId() + "找不到User");
                } else {
                    // 可能有多个负责人,比如研发部现在就两个经理,都通知
                    for (UserDetail toUser : userList) {
                        logger.info("订单继续签核,发给下1个签核人 " + toUser.getAccount());
                        commonService.sendSignInfoViWxMsg(toUser.getAccount(), machineOrder.getOrderNum(), "", createDateStr, contract.getMarketGroupName(), contract.getRecordUser(), msgInfo);
                    }
                }
            }
        }
    }
}
Also used : UserDetail(com.eservice.api.model.user.UserDetail) Role(com.eservice.api.model.role.Role) User(com.eservice.api.model.user.User) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

UserDetail (com.eservice.api.model.user.UserDetail)6 User (com.eservice.api.model.user.User)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 Role (com.eservice.api.model.role.Role)2 PageInfo (com.github.pagehelper.PageInfo)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Condition (tk.mybatis.mapper.entity.Condition)2 ContactForm (com.eservice.api.model.contact_form.ContactForm)1 IotMachine (com.eservice.api.model.iot_machine.IotMachine)1 Date (java.util.Date)1