中扬CRM客户关系管理系统
LSH
2023-10-06 efbc8993d6545d7ab898f5349a89915729fe5cb7
src/main/java/com/zy/crm/manager/controller/PriOnline2Controller.java
@@ -1,5 +1,6 @@
package com.zy.crm.manager.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -10,13 +11,13 @@
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.Plan;
import com.zy.crm.manager.entity.Pri;
import com.zy.crm.manager.entity.PriOnline2;
import com.zy.crm.manager.service.PlanService;
import com.zy.crm.manager.service.PriOnline2Service;
import com.zy.crm.manager.service.PriService;
import com.zy.crm.manager.entity.*;
import com.zy.crm.manager.service.*;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils;
@@ -40,14 +41,28 @@
    @Autowired
    private PlanService planService;
    @Autowired
    private PriSalesService priSalesService;
    @Autowired
    private CstmrService cstmrService;
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/priOnline2/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(priOnline2Service.selectById(String.valueOf(id)));
        PriOnline2 priOnline2 = priOnline2Service.selectById(String.valueOf(id));
        assert priOnline2 != null;
        JSONObject resultObj = JSON.parseObject(JSON.toJSONString(priOnline2));
        // 步骤条相关
        resultObj.put("step", priOnline2.getSettle() == 4 ? 0 : priOnline2.getSettle() + 1);
        return R.ok().add(resultObj);
    }
    @RequestMapping(value = "/priOnline2/viewCheck/{id}/auth")
    @ManagerAuth
    @ManagerAuth(memo = "查看询价")
    public R viewCheck(@PathVariable("id") String id) {
        PriOnline2 priOnline = priOnline2Service.selectById(String.valueOf(id));
        if (Cools.isEmpty(priOnline.getCheckData())) {
@@ -65,11 +80,12 @@
                  @RequestParam(required = false)String condition,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<PriOnline2> 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,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId");
        wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
        wrapper.setSqlSelect("id,title,create_time as createTime,filepath,settle,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId");
//        wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
        excludeTrash(param);
        convert(param, wrapper);
        allLike(PriOnline2.class, param.keySet(), wrapper, condition);
        wrapper.or().eq("member_id",getUserId());
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(priOnline2Service.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -106,12 +122,12 @@
    }
    @RequestMapping(value = "/priOnline2/add/auth")
    @ManagerAuth
    @ManagerAuth(memo = "添加核价管理")
    public R add(@RequestBody Map<String,Object> map) {
        PriOnline2 priOnline2 = new PriOnline2();
        priOnline2.setCreateTime(new Date());
        priOnline2.setTitle(map.get("title").toString());
        priOnline2.setTemplateName(map.get("title").toString());
//        priOnline2.setTemplateName(map.get("title").toString());
        priOnline2.setSheetData(map.get("sheetData").toString());
        priOnline2.setItemId(Long.parseLong(map.get("itemId").toString()));
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
@@ -126,11 +142,24 @@
        priOnline2.setUpdateUserId(getUserId());
        //状态,未完成
        priOnline2.setStatus(0);
        //业务员
//        Item item = itemService.selectById(priOnline.getItemId());
        Plan plan = planService.selectById(priOnline2.getItemId());
        priOnline2.setMemberId(plan.getUserId());
        Cstmr cstmr = cstmrService.selectById(plan.getCstmrId());
        priOnline2.setTemplateName(cstmr.getName());  //甲方单位名称
        priOnline2.setSettle(0);
        User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        List<String> initNames = new ArrayList<>();
        initNames.add("创建核价单模板");
        initNames.add("提交核价");
        initNames.add("部门经理审核");
        initNames.add("业务员确认");
        priOnline2.setSettleMsg(JSON.toJSONString(SettleDto.initSalesPricing(manager,getUser(),initNames,3)));
        //设置项目流程
        plan.setStep(2);
@@ -141,7 +170,7 @@
    }
    @RequestMapping(value = "/priOnline2/addOther/auth")
    @ManagerAuth
    @ManagerAuth(memo = "另存核价管理")
    public R addOther(@RequestBody Map<String,Object> map) {
        PriOnline2 online = priOnline2Service.selectById(Long.parseLong(map.get("id").toString()));
@@ -173,7 +202,7 @@
    }
   @RequestMapping(value = "/priOnline2/update/auth")
   @ManagerAuth
   @ManagerAuth(memo = "更新核价管理")
    public R update(@RequestBody Map<String,Object> map){
        PriOnline2 priOnline2 = priOnline2Service.selectById(Long.parseLong(map.get("id").toString()));
        if (priOnline2.getStatus() == 1) {
@@ -191,7 +220,7 @@
    //更新状态
    @RequestMapping(value = "/priOnline2/updateForm/auth")
    @ManagerAuth
    @ManagerAuth(memo = "更新核价管理状态")
    public R updateForm(Long id,Integer status,String title,String templateName){
        PriOnline2 priOnline2 = priOnline2Service.selectById(id);
        priOnline2.setStatus(status);
@@ -203,7 +232,7 @@
    }
    @RequestMapping(value = "/priOnline2/uploadCheck/auth")
    @ManagerAuth
    @ManagerAuth(memo = "上传询价文件")
    public R uploadCheck(@RequestParam("id") Integer id,
                         @RequestParam("checkData") String checkData,
                         @RequestParam("file") MultipartFile[] files){
@@ -272,10 +301,16 @@
    }
    @RequestMapping(value = "/priOnline2/delete/auth")
    @ManagerAuth
    @ManagerAuth(memo = "删除核价管理")
    public R delete(Long[] ids){
        if (Cools.isEmpty(ids)){
            return R.error();
        }
        for (Long id : ids){
            int priSales = priSalesService.selectCount(new EntityWrapper<PriSales>().eq("pri_online2_id", id));
            if (priSales!=0){
                return R.error("存在关联的产品费用明细,禁止删除!!!");
            }
        }
        priOnline2Service.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
@@ -297,13 +332,14 @@
    public R query(String condition) {
        EntityWrapper<PriOnline2> wrapper = new EntityWrapper<>();
        wrapper.like("order_num", condition);
        wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
        wrapper.in("user_id", getUserRoleBelongsToUserId("allopen"));
        Page<PriOnline2> page = priOnline2Service.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (PriOnline2 priOnline2 : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", priOnline2.getId());
            map.put("value", priOnline2.getOrderNum() + "/" + priOnline2.getPlanId$() + "/" + priOnline2.getMemberId$());
//            map.put("value", priOnline2.getOrderNum() + "/" + priOnline2.getPlanId$() + "/" + priOnline2.getMemberId$());
            map.put("value", priOnline2.getOrderNum() + "/" + priOnline2.getTemplateName());
            result.add(map);
        }
        return R.ok(result);
@@ -328,4 +364,120 @@
        return R.ok().add(vos);
    }
    @PostMapping(value = "/priOnline2/approval/auth")
    @ManagerAuth
    public R approvalBusinessTrip(@RequestParam Long priOnlineId,
                                  @RequestParam(required = false) Long plannerId){
        PriOnline2 priOnline2 = priOnline2Service.selectById(priOnlineId);
        assert priOnline2 != null;
        Date now = new Date();
        switch (priOnline2.getSettle()) {
            case 0:
                User user2 = userService.selectById(priOnline2.getUserId());
                User manager1 = userService.getDeptManager(getHostId(), user2.getDeptId());
                if (Cools.isEmpty(getUser())) {
                    return R.error("抱歉,您没有提交的权限");
                }
                if (!getUserId().equals(getUser().getId())) {
                    return R.error("抱歉,您没有提交的权限");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list1 = JSON.parseArray(priOnline2.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list1) {
                    switch (dto.getStep()) {
                        case 0:
                            dto.setCurr(Boolean.FALSE);
                            break;
                        case 1:
                            dto.setCurr(Boolean.TRUE);
                            dto.setMsg(getUser().getNickname() + "提交完成");
                            dto.setTime(DateUtils.convert(now));
                            break;
                        default:
                            break;
                    }
                }
                priOnline2.setSettleMsg(JSON.toJSONString(list1));
                // 修改规划单状态
                priOnline2.setSettle(1);
                priOnline2.setUpdateUserId(getUserId());
                priOnline2.setUpdateTime(now);
                priOnline2.setMemberId(manager1.getId());
                if (!priOnline2Service.updateById(priOnline2)) {
                    throw new CoolException("提交失败,请联系管理员");
                }
                break;
            case 1:
                // 本部门经理审核
                User user = userService.selectById(priOnline2.getUserId());
                User manager = userService.getDeptManager(getHostId(), user.getDeptId());
                if (manager.getId().equals(getUserId())) {
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(priOnline2.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(now));
                                break;
                            default:
                                break;
                        }
                    }
                    priOnline2.setSettleMsg(JSON.toJSONString(list));
                    // 修改规划单状态
                    priOnline2.setSettle(2);  // 申请通过
                    priOnline2.setUpdateTime(now);
                    if (!priOnline2Service.updateById(priOnline2)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有审核的权限!!!");
                }
                break;
            case 2:
                // 业务员
                User salesman0 = userService.selectById(priOnline2.getUserId());
                if (!getUserId().equals(salesman0.getId())) {
                    return R.error("抱歉,您无需确认!!!");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list2 = JSON.parseArray(priOnline2.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list2) {
                    switch (dto.getStep()) {
                        case 2:
                            dto.setCurr(Boolean.TRUE);
                            break;
                        case 3:
                            dto.setCurr(Boolean.TRUE);
                            dto.setMsg("业务员" + salesman0.getNickname() + "以确认");
                            dto.setTime(DateUtils.convert(new Date()));
                            break;
                        default:
                            break;
                    }
                }
                priOnline2.setSettleMsg(JSON.toJSONString(list2));
                // 修改规划单状态
                priOnline2.setSettle(3);  // 审批通过
                priOnline2.setUpdateTime(new Date());
                if (!priOnline2Service.updateById(priOnline2)) {
                    throw new CoolException("确认失败,请联系管理员");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
}