中扬CRM客户关系管理系统
LSH
2023-10-09 caac62f1f080ee8db3aba698f7f67ce105ad9ffe
src/main/java/com/zy/crm/manager/controller/ContractController.java
@@ -1,15 +1,16 @@
package com.zy.crm.manager.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.crm.common.model.SettleDto;
import com.zy.crm.common.service.OssService;
import com.zy.crm.manager.entity.Contract;
import com.zy.crm.manager.entity.ContractSales;
import com.zy.crm.manager.entity.PriOnline;
import com.zy.crm.manager.entity.*;
import com.zy.crm.manager.service.ContractSalesService;
import com.zy.crm.manager.service.ContractService;
import com.core.annotations.ManagerAuth;
@@ -18,8 +19,11 @@
import com.core.common.R;
import com.core.domain.KeyValueVo;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.service.ProcessPermissionsService;
import com.zy.crm.manager.utils.ChineseNumberUtils;
import com.zy.crm.manager.utils.WordUtils;
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.InputStreamResource;
import org.springframework.http.HttpHeaders;
@@ -44,11 +48,20 @@
    private ContractSalesService contractSalesService;
    @Autowired
    private OssService ossService;
    @Autowired
    private UserService userService;
    @Autowired
    private ProcessPermissionsService processPermissionsService;
    @RequestMapping(value = "/contract/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(contractService.selectById(String.valueOf(id)));
        Contract contract = contractService.selectById(String.valueOf(id));
        assert contract != null;
        JSONObject resultObj = JSON.parseObject(JSON.toJSONString(contract));
        // 步骤条相关
        resultObj.put("step", contract.getSettle() == 5 ? 0 : contract.getSettle() + 1);
        return R.ok().add(resultObj);
    }
    @RequestMapping(value = "/contract/list/auth")
@@ -68,29 +81,72 @@
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        boolean signUserId = false;
        boolean signDeptId = false;
        boolean signHostId = false;
        for (Map.Entry<String, Object> entry : map.entrySet()){
            if (entry.getKey().equals("dept_id")){
                signDeptId = true;
                if (String.valueOf(entry.getValue()).equals("19")){
                    signHostId = true;
                }
            }
        }
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else if (entry.getKey().equals("dept_id")){
                if (!val.equals("19")){
                    wrapper.eq(entry.getKey(), val);
                }
            } else if (entry.getKey().equals("user_id") && !signDeptId){
                signUserId = true;
                wrapper.eq(entry.getKey(), val);
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
        if (!signUserId && !signDeptId){
            wrapper.eq("user_id", getUserId());
        }
        if (signHostId){
            wrapper.or().eq("host_id",1);
        }
    }
    @RequestMapping(value = "/contract/add/auth")
    @ManagerAuth
    @ManagerAuth(memo = "添加合同")
    public R add(Contract contract) {
        contract.setCreateBy(getUserId());
        contract.setCreateTime(new Date());
        Date now = new Date();
        contract.setUserId(getUserId());
        //创建人员部门
        contract.setDeptId(getDeptId());
        contract.setCreateTime(now);
        contract.setSettle(0);
        User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        List<String> initNames = new ArrayList<>();
        initNames.add("创建产品费用明细模板");
        initNames.add("提交产品费用明细");
        initNames.add("部门经理审核");
        ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 7).eq("process",  "3-1" ));//7:合同管理
        User president = userService.selectById(processPermissions.getUserId());
        initNames.add("总裁办"+president.getNickname()+"审核");
        initNames.add("业务员确认");
        contract.setSettleMsg(JSON.toJSONString(SettleDto.initContract(manager,getUser(),president,initNames,4)));
        contract.setUpdateTime(now);
        contract.setUpdateBy(getUserId());
        contractService.insert(contract);
        return R.ok();
    }
   @RequestMapping(value = "/contract/update/auth")
   @ManagerAuth
   @ManagerAuth(memo = "更新合同")
    public R update(Contract contract){
        if (Cools.isEmpty(contract) || null==contract.getId()){
            return R.error();
@@ -102,7 +158,7 @@
    }
    @RequestMapping(value = "/contract/delete/auth")
    @ManagerAuth
    @ManagerAuth(memo = "删除合同")
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
            contractService.deleteById(id);
@@ -111,7 +167,7 @@
    }
    @RequestMapping(value = "/contract/generate/auth")
    @ManagerAuth
    @ManagerAuth(memo = "生成合同")
    public ResponseEntity<InputStreamResource> generate(@RequestParam Integer id,
                                                        @RequestParam String contractTemplate){
        try {
@@ -121,6 +177,7 @@
                return null;
            }
            HashMap<String, Object> map = new HashMap<>();
            map.put("{{serial}}", contract.getSerial());
            map.put("{{customer}}", contract.getCustomer());
            map.put("{{address}}", contract.getAddress());
            map.put("{{company}}", contract.getCompany());
@@ -189,7 +246,7 @@
    }
    @RequestMapping(value = "/contract/upload/auth")
    @ManagerAuth
    @ManagerAuth(memo = "上传合同")
    public R upload(@RequestParam("id") Integer id,
                         @RequestParam("file") MultipartFile[] files) throws IOException {
        Contract contract = contractService.selectById(id);
@@ -230,7 +287,7 @@
    }
    @RequestMapping(value = "/contract/download/auth")
    @ManagerAuth
    @ManagerAuth(memo = "下载合同")
    public ResponseEntity<InputStreamResource> download(@RequestParam("id") Integer id) {
        Contract contract = contractService.selectById(id);
        if (contract == null) {
@@ -293,4 +350,152 @@
        return R.ok().add(vos);
    }
    @PostMapping(value = "/contracr/approval/auth")
    @ManagerAuth
    public R approvalBusinessTrip(@RequestParam Long contracrId,
                                  @RequestParam(required = false) Long plannerId){
        Contract contract = contractService.selectById(contracrId);
        assert contract != null;
        Date now = new Date();
        switch (contract.getSettle()) {
            case 0:
                User user2 = userService.selectById(contract.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(contract.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;
                    }
                }
                contract.setSettleMsg(JSON.toJSONString(list1));
                // 修改规划单状态
                contract.setSettle(1);
                contract.setUpdateTime(now);
                if (!contractService.updateById(contract)) {
                    throw new CoolException("提交失败,请联系管理员");
                }
                break;
            case 1:
                // 本部门经理审核
                User user = userService.selectById(contract.getUserId());
                User manager = userService.getDeptManager(getHostId(), user.getDeptId());
                if (manager.getId().equals(getUserId())) {
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(contract.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;
                        }
                    }
                    contract.setSettleMsg(JSON.toJSONString(list));
                    // 修改规划单状态
                    contract.setSettle(2);  // 申请通过
                    contract.setUpdateTime(now);
                    if (!contractService.updateById(contract)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有审核的权限!!!");
                }
                break;
            case 2:
                ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 7).eq("process", "3-1"));//3:报销流程
                User planLeader = userService.selectById(processPermissions.getUserId());       // 获取合同管理流程节点确认人
                if (planLeader.getId().equals(getUserId())) {
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(contract.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(now));
                                break;
                            default:
                                break;
                        }
                    }
                    contract.setSettleMsg(JSON.toJSONString(list));
                    // 修改规划单状态
                    contract.setSettle(3);  // 申请通过
                    contract.setUpdateTime(now);
                    if (!contractService.updateById(contract)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有审核的权限!!!");
                }
                break;
            case 3:
                // 业务员
                User salesman0 = userService.selectById(contract.getUserId());
                if (!getUserId().equals(salesman0.getId())) {
                    return R.error("抱歉,您无需确认!!!");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list2 = JSON.parseArray(contract.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list2) {
                    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;
                    }
                }
                contract.setSettleMsg(JSON.toJSONString(list2));
                // 修改规划单状态
                contract.setSettle(4);  // 审批通过
                contract.setUpdateTime(new Date());
                if (!contractService.updateById(contract)) {
                    throw new CoolException("确认失败,请联系管理员");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
}