中扬CRM客户关系管理系统
LSH
2023-08-22 564bf7ab6a639c2c4557d35b8fd9b51dca60a738
src/main/java/com/zy/crm/manager/controller/PriQuoteController.java
@@ -12,13 +12,11 @@
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.domain.KeyValueVo;
import com.core.exception.CoolException;
import com.zy.crm.common.model.SettleDto;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.*;
import com.zy.crm.manager.service.ItemService;
import com.zy.crm.manager.service.PlanService;
import com.zy.crm.manager.service.PriQuoteBudgetService;
import com.zy.crm.manager.service.PriQuoteService;
import com.zy.crm.manager.service.*;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.UserService;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -48,6 +46,9 @@
    @Autowired
    private PriQuoteBudgetService priQuoteBudgetService;
    @Autowired
    private PlanTypeService planTypeService;
    @RequestMapping(value = "/priQuote/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
@@ -75,7 +76,7 @@
                  @RequestParam(required = false)String condition,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<PriQuote> wrapper = new EntityWrapper<>();
        wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,update_user_id as updateUserId,update_time as updateTime,in_order_num as inOrderNum,member_id as memberId");
        wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,sheet_data as sheetData,user_id as userId,dept_id as deptId,settle,settle_msg as settleMsg,form,update_user_id as updateUserId,update_time as updateTime,in_order_num as inOrderNum,member_id as memberId");
        wrapper.in("member_id", getUserRoleBelongsToUserId());
        excludeTrash(param);
        convert(param, wrapper);
@@ -134,6 +135,8 @@
        priQuote.setUserId(getUserId());
        //更新人员
        priQuote.setUpdateUserId(getUserId());
        //所属部门
        priQuote.setDeptId(getDeptId());
        //更新时间
        priQuote.setUpdateTime(new Date());
@@ -147,7 +150,8 @@
        priQuote.setForm(JSON.toJSONString(map));     // 自定义表单内容
        priQuote.setSettle(1);  // 1.开始
        User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        priQuote.setSettleMsg(JSON.toJSONString(SettleDto.init(plan, manager)));
        User president = userService.selectOne(new EntityWrapper<User>().eq("role_id",1).eq("username","王开杰"));        // 获取总裁办确认人
        priQuote.setSettleMsg(JSON.toJSONString(SettleDto.initPriQuote(plan, manager,president,getUser())));
        planService.updateById(plan);
@@ -416,4 +420,242 @@
        }
    }
    @PostMapping(value = "/priQuote/approval/auth")
    @ManagerAuth
    public R approvalPriQuote(@RequestParam Long planId,
                      @RequestParam(required = false) Long plannerId){
        PriQuote priQuote = priQuoteService.selectById(planId);
        assert priQuote != null;
        switch (priQuote.getSettle()) {
            case 1:
                // 本部门经理审核
                User user = userService.selectById(priQuote.getUserId());
                User manager = userService.getDeptManager(getHostId(), user.getDeptId());
                if (manager.getId().equals(getUserId())) {
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
                    for (SettleDto dto : list) {
                        switch (dto.getStep()) {
                            case 1:
                                dto.setCurr(Boolean.FALSE);
                                break;
                            case 2:
                                dto.setCurr(Boolean.TRUE);
                                dto.setMsg("部门经理" + manager.getNickname() + "审批通过");
                                dto.setTime(DateUtils.convert(new Date()));
                                break;
                            default:
                                break;
                        }
                    }
                    priQuote.setSettleMsg(JSON.toJSONString(list));
                    // 修改规划单状态
                    priQuote.setSettle(2);  // 总裁办待审
                    priQuote.setUpdateUserId(getUserId());
                    priQuote.setUpdateTime(new Date());
                    if (!priQuoteService.updateById(priQuote)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有审核的权限");
                }
                break;
            case 2:
                // 查找规划组长
                User planLeader = userService.selectOne(new EntityWrapper<User>().eq("username","王开杰"));
                if (Cools.isEmpty(planLeader)) {
                    throw new CoolException("未查找总裁办,请联系管理员");
                }
                if (!getUserId().equals(planLeader.getId())) {
                    return R.error("抱歉,您没有审核的权限");
                }
                User planner = userService.selectById(plannerId);
                // 修改 settle 步骤数据
                List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list) {
                    switch (dto.getStep()) {
                        case 2:
                            dto.setCurr(Boolean.FALSE);
                            break;
                        case 3:
                            dto.setCurr(Boolean.TRUE);
                            dto.setMsg("总裁办" + planLeader.getNickname() + "审批通过");
                            dto.setTime(DateUtils.convert(new Date()));
                            break;
                        default:
                            break;
                    }
                }
                priQuote.setSettleMsg(JSON.toJSONString(list));
                // 修改规划单状态
                priQuote.setSettle(3);  // 规划员待审
                priQuote.setUpdateUserId(getUserId());
                priQuote.setUpdateTime(new Date());
                if (!priQuoteService.updateById(priQuote)) {
                    throw new CoolException("审核失败,请联系管理员");
                }
                break;
            case 3:
                // 业务员
                User salesman0 = userService.selectById(priQuote.getUserId());
                if (!getUserId().equals(salesman0.getId())) {
                    return R.error("抱歉,您没有审核的权限");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list1 = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list1) {
                    switch (dto.getStep()) {
                        case 3:
                            dto.setCurr(Boolean.TRUE);
                            break;
                        case 4:
                            dto.setCurr(Boolean.TRUE);
                            dto.setMsg("业务员" + salesman0.getNickname() + "审批通过");
                            dto.setTime(DateUtils.convert(new Date()));
                            break;
                        default:
                            break;
                    }
                }
                priQuote.setSettleMsg(JSON.toJSONString(list1));
                // 修改规划单状态
                priQuote.setSettle(4);  // 审批通过
                priQuote.setUpdateUserId(getUserId());
                priQuote.setUpdateTime(new Date());
                if (!priQuoteService.updateById(priQuote)) {
                    throw new CoolException("审核失败,请联系管理员");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
    @PostMapping(value = "/priQuote/refuse/auth")
    @ManagerAuth
    public R refusePriQuote(@RequestParam Long planId,
                              @RequestParam(required = false) Long plannerId){
//        PriQuote priQuote = priQuoteService.selectById(planId);
//        assert priQuote != null;
//
//        switch (priQuote.getSettle()) {
//            case 1:
//                // 本部门经理审核
//                User user = userService.selectById(priQuote.getUserId());
//                User manager = userService.getDeptManager(getHostId(), user.getDeptId());
//                if (manager.getId().equals(getUserId())) {
//
//                    // 修改 settle 步骤数据
//                    List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
//                    for (SettleDto dto : list) {
//                        switch (dto.getStep()) {
//                            case 1:
//                                dto.setCurr(Boolean.FALSE);
//                                break;
//                            case 2:
//                                dto.setCurr(Boolean.TRUE);
//                                dto.setMsg("部门经理" + manager.getNickname() + "审批通过");
//                                dto.setTime(DateUtils.convert(new Date()));
//                                break;
//                            default:
//                                break;
//                        }
//                    }
//                    priQuote.setSettleMsg(JSON.toJSONString(list));
//
//                    // 修改规划单状态
//                    priQuote.setSettle(2);  // 总裁办待审
//                    priQuote.setUpdateUserId(getUserId());
//                    priQuote.setUpdateTime(new Date());
//
//                    if (!priQuoteService.updateById(priQuote)) {
//                        throw new CoolException("审核失败,请联系管理员");
//                    }
//
//                } else {
//                    return R.error("抱歉,您没有审核的权限");
//                }
//                break;
//            case 2:
//                // 查找规划组长
//                User planLeader = userService.selectOne(new EntityWrapper<User>().eq("username","王开杰"));
//                if (Cools.isEmpty(planLeader)) {
//                    throw new CoolException("未查找总裁办,请联系管理员");
//                }
//                if (!getUserId().equals(planLeader.getId())) {
//                    return R.error("抱歉,您没有审核的权限");
//                }
//                User planner = userService.selectById(plannerId);
//                // 修改 settle 步骤数据
//                List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
//                for (SettleDto dto : list) {
//                    switch (dto.getStep()) {
//                        case 2:
//                            dto.setCurr(Boolean.FALSE);
//                            break;
//                        case 3:
//                            dto.setCurr(Boolean.TRUE);
//                            dto.setMsg("总裁办" + planLeader.getNickname() + "审批通过");
//                            dto.setTime(DateUtils.convert(new Date()));
//                            break;
//                        default:
//                            break;
//                    }
//                }
//                priQuote.setSettleMsg(JSON.toJSONString(list));
//                // 修改规划单状态
//                priQuote.setSettle(3);  // 规划员待审
//                priQuote.setUpdateUserId(getUserId());
//                priQuote.setUpdateTime(new Date());
//
//                if (!priQuoteService.updateById(priQuote)) {
//                    throw new CoolException("审核失败,请联系管理员");
//                }
//                break;
//            case 3:
//                // 业务员
//                User salesman0 = userService.selectById(priQuote.getUserId());
//                if (!getUserId().equals(salesman0.getId())) {
//                    return R.error("抱歉,您没有审核的权限");
//                }
//                // 修改 settle 步骤数据
//                List<SettleDto> list1 = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class);
//                for (SettleDto dto : list1) {
//                    switch (dto.getStep()) {
//                        case 3:
//                            dto.setCurr(Boolean.TRUE);
//                            break;
//                        case 4:
//                            dto.setCurr(Boolean.TRUE);
//                            dto.setMsg("业务员" + salesman0.getNickname() + "审批通过");
//                            dto.setTime(DateUtils.convert(new Date()));
//                            break;
//                        default:
//                            break;
//                    }
//                }
//                priQuote.setSettleMsg(JSON.toJSONString(list1));
//                // 修改规划单状态
//                priQuote.setSettle(4);  // 审批通过
//                priQuote.setUpdateUserId(getUserId());
//                priQuote.setUpdateTime(new Date());
//
//                if (!priQuoteService.updateById(priQuote)) {
//                    throw new CoolException("审核失败,请联系管理员");
//                }
//                break;
//            default:
//                return R.error();
//        }
        return R.ok("审批成功");
    }
}