| | |
| | | package com.zy.crm.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSON; |
| | | 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; |
| | |
| | | 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; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.ClassUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | private ContractSalesService contractSalesService; |
| | | @Autowired |
| | | private OssService ossService; |
| | | @Autowired |
| | | private UserService userService; |
| | | @Autowired |
| | | private ProcessPermissionsService processPermissionsService; |
| | | |
| | | @RequestMapping(value = "/contract/{id}/auth") |
| | | @RequestMapping(value = "/contract/{id}/auth2") |
| | | @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") |
| | |
| | | } |
| | | |
| | | 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){ |
| | | if (getRole().getId()==1){ |
| | | wrapper.or().eq("host_id",1); |
| | | }else if (getRole().getId()==2){ |
| | | wrapper.eq("dept_id",getDeptId()); |
| | | }else { |
| | | 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(1); |
| | | |
| | | User manager = new User(); |
| | | try{ |
| | | manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | }catch (Exception e){ |
| | | manager = getUser(); |
| | | } |
| | | contract.setDirector(manager.getId()); |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/contract/delete/auth") |
| | | @ManagerAuth |
| | | @ManagerAuth(memo = "删除合同") |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | contractService.deleteById(id); |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/contract/generate/auth") |
| | | @ManagerAuth |
| | | @ManagerAuth(memo = "生成合同") |
| | | public ResponseEntity<InputStreamResource> generate(@RequestParam Integer id, |
| | | @RequestParam String contractTemplate){ |
| | | try { |
| | |
| | | /////////////////////////生成Tab表格数据///////////////////////// |
| | | |
| | | String fileName = this.getClass().getClassLoader().getResource("contractTemplate/" + contractTemplate + ".docx").getPath();//获取文件路径 |
| | | return WordUtils.generate(fileName, map, tabParam); |
| | | |
| | | // String outPdfPath = fileName.split("\\.")[0]+".pdf"; |
| | | ResponseEntity<InputStreamResource> generate = WordUtils.generate(fileName, map, tabParam); |
| | | // WordUtils.documents4jWordToPdf(fileName,outPdfPath); |
| | | return generate; |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/contract/download/auth") |
| | | @ManagerAuth |
| | | @ManagerAuth(memo = "下载合同") |
| | | public ResponseEntity<InputStreamResource> download(@RequestParam("id") Integer id) { |
| | | Contract contract = contractService.selectById(id); |
| | | if (contract == null) { |
| | |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PostMapping(value = "/contract/approval/auth") |
| | | @ManagerAuth |
| | | public R approvalBusinessTrip(@RequestParam Long contractId, |
| | | @RequestParam(required = false) Long plannerId){ |
| | | Contract contract = contractService.selectById(contractId); |
| | | assert contract != null; |
| | | Date now = new Date(); |
| | | switch (contract.getSettle()) { |
| | | case 0: |
| | | 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; |
| | | case 2: |
| | | contract.setDirector(dto.getUserId()); |
| | | 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 manager = userService.selectById(contract.getDirector()); |
| | | |
| | | 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; |
| | | case 3: |
| | | contract.setDirector(dto.getUserId()); |
| | | 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: |
| | | User planLeader = userService.selectById(contract.getDirector()); |
| | | |
| | | 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; |
| | | case 4: |
| | | contract.setDirector(dto.getUserId()); |
| | | 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("审批成功"); |
| | | } |
| | | |
| | | } |