From 66f2e574ff5e98486a8e7ac69fc7138b9210ef27 Mon Sep 17 00:00:00 2001 From: yujintao Date: Mon, 16 Dec 2019 19:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=B1=BB=E5=88=AB=E6=97=B6?= =?UTF-8?q?=E9=99=90=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/epdc/form/UserSysDeptInfoFormDTO.java | 4 - .../result/CategoryInfoResultDTO.java | 2 +- .../service/impl/CategoryServiceImpl.java | 1200 +++++++++-------- .../esua/epdc/dto/KpiTimeLimitItemDTO.java | 4 +- .../esua/epdc/dao/KpiTimeLimitItemDao.java | 16 +- .../epdc/entity/KpiTimeLimitItemEntity.java | 2 +- .../esua/epdc/feign/EventFeignClient.java | 20 +- .../impl/KpiTimeLimitItemServiceImpl.java | 114 +- .../resources/mapper/KpiTimeLimitItemDao.xml | 20 +- 9 files changed, 718 insertions(+), 664 deletions(-) diff --git a/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/UserSysDeptInfoFormDTO.java b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/UserSysDeptInfoFormDTO.java index 238a6ea6b..3f530eec5 100644 --- a/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/UserSysDeptInfoFormDTO.java +++ b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/UserSysDeptInfoFormDTO.java @@ -16,14 +16,10 @@ public class UserSysDeptInfoFormDTO implements Serializable { /** * 主键集合 */ -// @NotEmpty(message = "deptIdList不能为空") -// @Valid private List deptIdList; /** * 部门类型键值 */ -// @NotEmpty(message = "部门类型不能为空") -// @Valid private List typeKeyList; } diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-client/src/main/java/com/elink/esua/epdc/dto/category/result/CategoryInfoResultDTO.java b/esua-epdc/epdc-module/epdc-events/epdc-events-client/src/main/java/com/elink/esua/epdc/dto/category/result/CategoryInfoResultDTO.java index dc7cdd7df..201204679 100644 --- a/esua-epdc/epdc-module/epdc-events/epdc-events-client/src/main/java/com/elink/esua/epdc/dto/category/result/CategoryInfoResultDTO.java +++ b/esua-epdc/epdc-module/epdc-events/epdc-events-client/src/main/java/com/elink/esua/epdc/dto/category/result/CategoryInfoResultDTO.java @@ -34,5 +34,5 @@ public class CategoryInfoResultDTO implements Serializable { /** * 所有上级分类名称,用逗号分开 */ - private List parentNames; + private String parentNames; } diff --git a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/impl/CategoryServiceImpl.java b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/impl/CategoryServiceImpl.java index 30e49d2cf..79e957632 100644 --- a/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/impl/CategoryServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-events/epdc-events-server/src/main/java/com/elink/esua/epdc/modules/category/service/impl/CategoryServiceImpl.java @@ -17,12 +17,14 @@ package com.elink.esua.epdc.modules.category.service.impl; +import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; import com.elink.esua.epdc.commons.tools.constant.Constant; import com.elink.esua.epdc.commons.tools.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.constant.StrConstant; import com.elink.esua.epdc.commons.tools.exception.ErrorCode; import com.elink.esua.epdc.commons.tools.exception.RenException; import com.elink.esua.epdc.commons.tools.redis.RedisKeys; @@ -69,599 +71,617 @@ import java.util.*; @Service public class CategoryServiceImpl extends BaseServiceImpl implements CategoryService { - @Autowired - private CategoryRedis categoryRedis; - @Autowired - private RedisUtils redisUtils; - - private int totalRows = 0; // 总行数 - - private int totalCells = 0;// 总条数 - - public static int Guid=100;//id自增值 - - - - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - public List list(Map params) { - List entityList = baseDao.getList(params); - - List dtoList = ConvertUtils.sourceToTarget(entityList, CategoryDTO.class); - - return TreeUtils.build(dtoList); - } - - @Override - public CategoryDTO get(Long id) { - if (id == null) { - return null; - } - CategoryEntity entity = baseDao.getById(id); - - return ConvertUtils.sourceToTarget(entity, CategoryDTO.class); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void save(CategoryDTO dto) { - String categoryCode = dto.getCategoryCode(); - if (StringUtils.isNotBlank(categoryCode)) { - if (getCodeCount(dto) > 0) { - throw new RenException("您输入的编码已存在"); - } - } - CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); - List list = getPidListByPid(entity.getPid()); - if (list.size() == 0) { - entity.setPids("0"); - } else { - String pids = ""; - for (int i = 0; i < list.size(); i++) { - if (i == list.size() - 1) { - pids = pids + list.get(i).getId().toString(); - } else { - pids = pids + list.get(i).getId().toString() + ","; - } - } - entity.setPids(pids); - } - insert(entity); - this.packageCategoryOption(); - } - - /** - * 获取所有上级分类 - * - * @param pid 上级ID - */ - private List getPidListByPid(Long pid) { - //顶级部门,无上级部门 - if (Constant.CATEGORY_ROOT.equals(pid)) { - return new ArrayList<>(); - } - - //所有的分类列表 - QueryWrapper wrapper = new QueryWrapper<>(); - List categoryEntityList = baseDao.selectList(wrapper); - - //list转map - Map map = new HashMap<>(categoryEntityList.size()); - for (CategoryEntity entity : categoryEntityList) { - map.put(entity.getId(), entity); - } - - //递归查询所有上级分类列表 - List pCategoryEntityList = new ArrayList<>(); - - getPidTree(pid, map, pCategoryEntityList); - - return pCategoryEntityList; - } - - @Override - public List getPidListById(Long id) { - //所有的分类列表 - CategoryEntity categoryEntity = baseDao.selectById(id); - return getPidListByPid(categoryEntity.getPid()); - } - - private void getPidTree(Long pid, Map map, List pCategoryEntityList) { - //顶级,无上级 - if (Constant.CATEGORY_ROOT.equals(pid)) { - return; - } - //上级存在 - CategoryEntity parent = map.get(pid); - if (parent != null) { - getPidTree(parent.getPid(), map, pCategoryEntityList); - } - - pCategoryEntityList.add(parent); - } - - @Override - public Integer getCodeCount(CategoryDTO dto) { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("category_code", dto.getCategoryCode()); - Long id = dto.getId(); - wrapper.ne(id != null, "id", dto.getId()); - wrapper.eq("del_flag", "0"); - return baseDao.selectCount(wrapper); - } - - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(CategoryDTO dto) { - String categoryCode = dto.getCategoryCode(); - if (StringUtils.isNotBlank(categoryCode)) { - if (getCodeCount(dto) > 0) { - throw new RenException("您输入的编码已存在"); - } - } - CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); - //上级部门不能为自身 - if (entity.getId().equals(entity.getPid())) { - throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); - } - List list = getPidListByPid(entity.getPid()); - if (list.size() == 0) { - entity.setPids("0"); - } else { - String pids = ""; - for (int i = 0; i < list.size(); i++) { - if (i == list.size() - 1) { - pids = pids + list.get(i).getId().toString(); - } else { - pids = pids + list.get(i).getId().toString() + ","; - } - } - entity.setPids(pids); - } - updateById(entity); - this.packageCategoryOption(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long id) { - //判断是否有子部门 - List subList = getSubCategoryIdList(id); - if (subList.size() > 1) { - throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); - } - baseDao.deleteBatchIds(Arrays.asList(new Long[]{id})); - - // 逻辑删除(@TableLogic 注解) - //logicDelete(new Long[]{id}, CategoryEntity.class); - this.packageCategoryOption(); - } - - @Override - public List getSubCategoryIdList(Long id) { - List subCategoryIdList = baseDao.getSubCategoryIdList("%" + id + "%"); - subCategoryIdList.add(id); - return subCategoryIdList; - } - - @Override - public Result insertPartyList(MultipartFile file) { - //获取excle版本 - String isExcel2003 = getExcelInfo(file); - Result result = new Result(); - //需存储的实体 - List list = new ArrayList(); - try{ - Workbook wb = null; - InputStream is = file.getInputStream(); - if ("true".equals(isExcel2003)) { - // 当excel是2003时,创建excel2003 - wb = new HSSFWorkbook(is); - }else if("false".equals(isExcel2003)){ - // 当excel是2007时,创建excel2007 - wb = new XSSFWorkbook(is); - } else { - result.setMsg("defeat"); - result.setCode(1); - result.setData("excle格式错误!"); - return result; - } - // 得到第一个shell - Sheet sheet = wb.getSheetAt(0); - // 得到Excel的行数 - this.totalRows = sheet.getPhysicalNumberOfRows(); - // 得到Excel的列数(前提是有行数) - if (totalRows > 1 && sheet.getRow(0) != null) { - this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells(); - } - //查询根分类开始序号 - CategoryEntity categoryEntity = new CategoryEntity(); - categoryEntity.setPid(0L); - QueryWrapper wrapper = new QueryWrapper(categoryEntity); - List categoryEntityList = baseDao.selectList(wrapper); - int numm = categoryEntityList.size(); - if(numm >= 0){ - numm -= 1; - } - //一级分类 - String firstClassName = ""; - Long firstClassId = 0L; - Integer firstClassSort = Integer.parseInt(numm+""); - //二级分类 - String secondClassName = ""; - Long secondClassId = 0L; - Integer secondClassSort = -1; - //三级分类 - String thirdClassName = ""; - Long thirdClassId = 0L; - Integer thirdClassSort = -1; - //四级分类 - String fourthClassName = ""; - Long fourthClassId = 0L; - Integer fourthClassSort = -1; - // 循环Excel行数(不要表头,从2开始) ;0是excle表头、1是列名 - for (int r = 2; r < totalRows; r++) { - Row row = sheet.getRow(r); - if (row == null) { - continue; - } - // 循环Excel的列 只需要读取2-5列 - String firstClassNameCurrent = "";//本行一级分类 - String secondClassNameCurrent = "";//本行二级分类 - String thirdClassNameCurrent = "";//本行三级分类 - String fourthClassNameCurrent = "";//本行四级分类 - for (int c = 1; c < 5; c++) { - Cell cell = row.getCell(c); - if (null != cell) { - if (c == 1) { - //领域列 - firstClassNameCurrent = ""; - String value = getCellContent(cell); - if(!"".equals(value)){ - firstClassName = value; - firstClassNameCurrent = value; - firstClassId = getLongRandom(); - firstClassSort++; - secondClassSort = -1; - thirdClassSort = -1; - fourthClassSort = -1; - } - } else if (c == 2) { - //大类列 - secondClassNameCurrent = ""; - String value = getCellContent(cell); - if(!"".equals(value)){ - secondClassName = value; - secondClassNameCurrent = value; - secondClassId = getLongRandom(); - secondClassSort++; - thirdClassSort = -1; - fourthClassSort = -1; - } - } else if (c == 3) { - //小类列 - thirdClassNameCurrent = ""; - String value = getCellContent(cell); - if(!"".equals(value)){ - thirdClassName = value; - thirdClassNameCurrent = value; - thirdClassId = getLongRandom(); - thirdClassSort++; - fourthClassSort = -1; - } - } else if (c == 4) { - //细类名称列 - fourthClassNameCurrent = ""; - String value = getCellContent(cell); - if(!"".equals(value)){ - fourthClassName = value; - fourthClassNameCurrent = value; - fourthClassId = getLongRandom(); - fourthClassSort++; - } - } - } - } - if(!"".equals(firstClassNameCurrent)){ - //领域 - CategoryEntity insertEntity = getCategoryEntity(firstClassId,0L,"0",firstClassName, - firstClassId+"","0",firstClassSort,0,""); - list.add(insertEntity); - } - if(!"".equals(secondClassNameCurrent)){ - //大类 - CategoryEntity insertEntity = getCategoryEntity(secondClassId,firstClassId,firstClassId+"",secondClassName, - secondClassId+"","1",secondClassSort,0,firstClassName); - list.add(insertEntity); - } - if(!"".equals(thirdClassNameCurrent)){ - //小类 - String pids = firstClassId + "," + secondClassId + ""; - CategoryEntity insertEntity = getCategoryEntity(thirdClassId,secondClassId,pids,thirdClassName, - thirdClassId+"","2",thirdClassSort,0,secondClassName); - list.add(insertEntity); - } - if(!"".equals(fourthClassNameCurrent)){ - //细分类 - String pids = firstClassId + "," + secondClassId + "," + thirdClassId + ""; - CategoryEntity insertEntity = getCategoryEntity(fourthClassId,thirdClassId,pids,fourthClassName, - fourthClassId+"","3",fourthClassSort,0,thirdClassName); - list.add(insertEntity); - } - } - if(list.size() > 0){ - CategoryEntity[] categoryEntities = new CategoryEntity[list.size()]; - for(int k = 0 ; k < list.size() ; k++){ - categoryEntities[k] = list.get(k); - } - baseDao.insertList(categoryEntities); - } - result.setMsg("success"); - result.setCode(0); - result.setData("数据导入成功!"); - return result; - }catch(Exception e){ - - } - result.setMsg("defeat"); - result.setCode(1); - result.setData("数据导入失败!"); - return result; - } - - /** - * 获取单元格内容 - * @param cell - * @return - */ - public String getCellContent(Cell cell){ - String value = ""; - if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { - value = String.valueOf(cell.getNumericCellValue()); - } else { - value = cell.getStringCellValue(); - } - //内容超过25个字进行长度限制,否则数据库会超限 - if(value.length() > 25){ - value = value.substring(0,25) + "..."; - } - return value; - } - - /** - * 获取19位随机数 - * @return - */ - public Long getLongRandom(){ - Guid+=1; - long now = System.currentTimeMillis(); - SimpleDateFormat dateFormat=new SimpleDateFormat("MMdd"); - String time=dateFormat.format(now); - String currentTimeMillis=now+""; - int ran=0; - if(Guid>999){ - Guid=100; - } - ran=Guid; - String str = time+currentTimeMillis.substring(1, currentTimeMillis.length())+ran; - return Long.parseLong(str); - } - - /** - * 拼接entity - * @param id ID - * @param pid 上级分类ID - * @param categoryName 分类名称 - * @param categoryCode 分类编码 - * @param categoryType 分类类别 - * @param sort 排序 - * @param delFlag 删除标识 0:未删除 1:删除 - * @param parentName 上级部门名称 - */ - public CategoryEntity getCategoryEntity(Long id,Long pid,String pids,String categoryName,String categoryCode, - String categoryType,Integer sort,Integer delFlag,String parentName) { - CategoryEntity entity = new CategoryEntity(); - Long userId = SecurityUser.getUserId(); - entity.setId(id); - entity.setPid(pid); - entity.setPids(pids); - entity.setCategoryName(categoryName);//分类名称 - entity.setCategoryCode(categoryCode);//分类编码(暂时使用ID) - entity.setCategoryType(categoryType);//分类类别(默认1) - entity.setSort(sort);//排序 - entity.setDelFlag(delFlag);//删除标识 0:未删除 1:删除 - entity.setParentName(parentName);//上级部门名称 - entity.setCreator(userId); - entity.setUpdater(userId); - entity.setCreateDate(new Date()); - entity.setUpdateDate(new Date()); - return entity; - } - - /** - * 获取excle版本 - * @param mFile - * @return - */ - public String getExcelInfo(MultipartFile mFile) { - String fileName = mFile.getOriginalFilename();// 获取文件名 - String isExcel2003 = "true";// 根据文件名判断文件是2003版本还是2007版本 - try { - if (!validateExcel(fileName)) {// 验证文件名是否合格 - return ""; - } - if (isExcel2007(fileName)) { - isExcel2003 = "false"; - } - return isExcel2003; - } catch (Exception e) { - e.printStackTrace(); - } - return ""; - } - - /** - * 验证EXCEL文件 - * @param filePath - * @return - */ - public boolean validateExcel(String filePath) { - if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))) { - return false; - } - return true; - } - - // @描述:是否是2003的excel,返回true是2003 - public static boolean isExcel2003(String filePath) { - return filePath.matches("^.+\\.(?i)(xls)$"); - } - // @描述:是否是2007的excel,返回true是2007 - public static boolean isExcel2007(String filePath) { - return filePath.matches("^.+\\.(?i)(xlsx)$"); - } - - /** - * @param - * @return com.elink.esua.epdc.commons.tools.utils.Result - * @Author yinzuomei - * @Description 查询事件类别树, 供下拉框调用 - * @Date 2019/12/3 18:07 - **/ - @Override - public Result getCategoryTree() { - String eventsCategoryKey = RedisKeys.getEventsCategoryKey(); - Object obj = redisUtils.get(eventsCategoryKey); - if (null == obj) { - this.packageCategoryOption(); - obj = redisUtils.get(eventsCategoryKey); - } - return new Result().ok((CategoryOption) obj); - } - - /** - * @param formDTO - * @return java.util.List - * @Author yinzuomei - * @Description 根据id查询事件分类基本信息 - * @Date 2019/12/4 9:43 - **/ - @Override - public List listCategoryInfo(CategoryInfoFormDTO formDTO) { - List categoryInfoResultDTOList = new ArrayList<>(); - for (Long id : formDTO.getIds()) { - CategoryEntity entity = baseDao.getById(id); - if (null != entity) { - List parentNameList = new ArrayList<>(); - if (StringUtils.isNotBlank(entity.getPids())) { - String[] pidList = entity.getPids().split(","); - for (String pid : pidList) { - CategoryEntity parentEntity = baseDao.getById(Long.valueOf(pid)); - parentNameList.add(parentEntity.getCategoryName()); - } - } - CategoryInfoResultDTO categoryInfoResultDTO = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); - categoryInfoResultDTO.setParentNames(parentNameList); - categoryInfoResultDTOList.add(categoryInfoResultDTO); - } - } - return categoryInfoResultDTOList; - } - - /** - * @param - * @return void - * @Author yinzuomei - * @Description 组装事件类别 - * @Date 2019/12/3 18:18 - **/ - @Override - public void packageCategoryOption() { - List dtoList = baseDao.selectListCategoryTreeDTO(); - JSONObject node; - JSONArray headNodes = new JSONArray(); - for (CategoryTreeDTO categoryTreeDto : dtoList) { - - if (categoryTreeDto.getPid().longValue() == NumConstant.ZERO_L) { - node = new JSONObject(); - node.put("value", categoryTreeDto.getId()); - node.put("label", categoryTreeDto.getCategoryName()); - headNodes.add(node); - } - } - - // 用于存放所有父级节点 - JSONArray parent; - // 用于存放所有子级节点 - JSONArray allChildren = new JSONArray(); - JSONArray children; - // 用于存放单个子级节点 - JSONObject childNode; - - parent = headNodes; - // 存放其余未处理的类别(节点) - List others = this.getOtherCategory(dtoList, parent); - - while (!others.isEmpty()) { - for (int i = 0; i < parent.size(); i++) { - node = parent.getJSONObject(i); - children = new JSONArray(); - for (CategoryTreeDTO categoryTreeDto : others) { - if (categoryTreeDto.getPid().equals(node.get("value"))) { - childNode = new JSONObject(); - childNode.put("value", categoryTreeDto.getId()); - childNode.put("label", categoryTreeDto.getCategoryName()); - - children.add(childNode); - allChildren.add(childNode); - } - } - if (!children.isEmpty()) { - node.put("children", children); - } - } - parent = allChildren; - - others = this.getOtherCategory(others, parent); - - } + @Autowired + private CategoryRedis categoryRedis; + @Autowired + private RedisUtils redisUtils; + + private int totalRows = 0; // 总行数 + + private int totalCells = 0;// 总条数 + + public static int Guid = 100;//id自增值 + + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public List list(Map params) { + List entityList = baseDao.getList(params); + + List dtoList = ConvertUtils.sourceToTarget(entityList, CategoryDTO.class); + + return TreeUtils.build(dtoList); + } + + @Override + public CategoryDTO get(Long id) { + if (id == null) { + return null; + } + CategoryEntity entity = baseDao.getById(id); + + return ConvertUtils.sourceToTarget(entity, CategoryDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(CategoryDTO dto) { + String categoryCode = dto.getCategoryCode(); + if (StringUtils.isNotBlank(categoryCode)) { + if (getCodeCount(dto) > 0) { + throw new RenException("您输入的编码已存在"); + } + } + CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); + List list = getPidListByPid(entity.getPid()); + if (list.size() == 0) { + entity.setPids("0"); + } else { + String pids = ""; + for (int i = 0; i < list.size(); i++) { + if (i == list.size() - 1) { + pids = pids + list.get(i).getId().toString(); + } else { + pids = pids + list.get(i).getId().toString() + ","; + } + } + entity.setPids(pids); + } + insert(entity); + this.packageCategoryOption(); + } + + /** + * 获取所有上级分类 + * + * @param pid 上级ID + */ + private List getPidListByPid(Long pid) { + //顶级部门,无上级部门 + if (Constant.CATEGORY_ROOT.equals(pid)) { + return new ArrayList<>(); + } + + //所有的分类列表 + QueryWrapper wrapper = new QueryWrapper<>(); + List categoryEntityList = baseDao.selectList(wrapper); + + //list转map + Map map = new HashMap<>(categoryEntityList.size()); + for (CategoryEntity entity : categoryEntityList) { + map.put(entity.getId(), entity); + } + + //递归查询所有上级分类列表 + List pCategoryEntityList = new ArrayList<>(); + + getPidTree(pid, map, pCategoryEntityList); + + return pCategoryEntityList; + } + + @Override + public List getPidListById(Long id) { + //所有的分类列表 + CategoryEntity categoryEntity = baseDao.selectById(id); + return getPidListByPid(categoryEntity.getPid()); + } + + private void getPidTree(Long pid, Map map, List pCategoryEntityList) { + //顶级,无上级 + if (Constant.CATEGORY_ROOT.equals(pid)) { + return; + } + //上级存在 + CategoryEntity parent = map.get(pid); + if (parent != null) { + getPidTree(parent.getPid(), map, pCategoryEntityList); + } + + pCategoryEntityList.add(parent); + } + + @Override + public Integer getCodeCount(CategoryDTO dto) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("category_code", dto.getCategoryCode()); + Long id = dto.getId(); + wrapper.ne(id != null, "id", dto.getId()); + wrapper.eq("del_flag", "0"); + return baseDao.selectCount(wrapper); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(CategoryDTO dto) { + String categoryCode = dto.getCategoryCode(); + if (StringUtils.isNotBlank(categoryCode)) { + if (getCodeCount(dto) > 0) { + throw new RenException("您输入的编码已存在"); + } + } + CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); + //上级部门不能为自身 + if (entity.getId().equals(entity.getPid())) { + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } + List list = getPidListByPid(entity.getPid()); + if (list.size() == 0) { + entity.setPids("0"); + } else { + String pids = ""; + for (int i = 0; i < list.size(); i++) { + if (i == list.size() - 1) { + pids = pids + list.get(i).getId().toString(); + } else { + pids = pids + list.get(i).getId().toString() + ","; + } + } + entity.setPids(pids); + } + updateById(entity); + this.packageCategoryOption(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + //判断是否有子部门 + List subList = getSubCategoryIdList(id); + if (subList.size() > 1) { + throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); + } + baseDao.deleteBatchIds(Arrays.asList(new Long[]{id})); + + // 逻辑删除(@TableLogic 注解) + //logicDelete(new Long[]{id}, CategoryEntity.class); + this.packageCategoryOption(); + } + + @Override + public List getSubCategoryIdList(Long id) { + List subCategoryIdList = baseDao.getSubCategoryIdList("%" + id + "%"); + subCategoryIdList.add(id); + return subCategoryIdList; + } + + @Override + public Result insertPartyList(MultipartFile file) { + //获取excle版本 + String isExcel2003 = getExcelInfo(file); + Result result = new Result(); + //需存储的实体 + List list = new ArrayList(); + try { + Workbook wb = null; + InputStream is = file.getInputStream(); + if ("true".equals(isExcel2003)) { + // 当excel是2003时,创建excel2003 + wb = new HSSFWorkbook(is); + } else if ("false".equals(isExcel2003)) { + // 当excel是2007时,创建excel2007 + wb = new XSSFWorkbook(is); + } else { + result.setMsg("defeat"); + result.setCode(1); + result.setData("excle格式错误!"); + return result; + } + // 得到第一个shell + Sheet sheet = wb.getSheetAt(0); + // 得到Excel的行数 + this.totalRows = sheet.getPhysicalNumberOfRows(); + // 得到Excel的列数(前提是有行数) + if (totalRows > 1 && sheet.getRow(0) != null) { + this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells(); + } + //查询根分类开始序号 + CategoryEntity categoryEntity = new CategoryEntity(); + categoryEntity.setPid(0L); + QueryWrapper wrapper = new QueryWrapper(categoryEntity); + List categoryEntityList = baseDao.selectList(wrapper); + int numm = categoryEntityList.size(); + if (numm >= 0) { + numm -= 1; + } + //一级分类 + String firstClassName = ""; + Long firstClassId = 0L; + Integer firstClassSort = Integer.parseInt(numm + ""); + //二级分类 + String secondClassName = ""; + Long secondClassId = 0L; + Integer secondClassSort = -1; + //三级分类 + String thirdClassName = ""; + Long thirdClassId = 0L; + Integer thirdClassSort = -1; + //四级分类 + String fourthClassName = ""; + Long fourthClassId = 0L; + Integer fourthClassSort = -1; + // 循环Excel行数(不要表头,从2开始) ;0是excle表头、1是列名 + for (int r = 2; r < totalRows; r++) { + Row row = sheet.getRow(r); + if (row == null) { + continue; + } + // 循环Excel的列 只需要读取2-5列 + String firstClassNameCurrent = "";//本行一级分类 + String secondClassNameCurrent = "";//本行二级分类 + String thirdClassNameCurrent = "";//本行三级分类 + String fourthClassNameCurrent = "";//本行四级分类 + for (int c = 1; c < 5; c++) { + Cell cell = row.getCell(c); + if (null != cell) { + if (c == 1) { + //领域列 + firstClassNameCurrent = ""; + String value = getCellContent(cell); + if (!"".equals(value)) { + firstClassName = value; + firstClassNameCurrent = value; + firstClassId = getLongRandom(); + firstClassSort++; + secondClassSort = -1; + thirdClassSort = -1; + fourthClassSort = -1; + } + } else if (c == 2) { + //大类列 + secondClassNameCurrent = ""; + String value = getCellContent(cell); + if (!"".equals(value)) { + secondClassName = value; + secondClassNameCurrent = value; + secondClassId = getLongRandom(); + secondClassSort++; + thirdClassSort = -1; + fourthClassSort = -1; + } + } else if (c == 3) { + //小类列 + thirdClassNameCurrent = ""; + String value = getCellContent(cell); + if (!"".equals(value)) { + thirdClassName = value; + thirdClassNameCurrent = value; + thirdClassId = getLongRandom(); + thirdClassSort++; + fourthClassSort = -1; + } + } else if (c == 4) { + //细类名称列 + fourthClassNameCurrent = ""; + String value = getCellContent(cell); + if (!"".equals(value)) { + fourthClassName = value; + fourthClassNameCurrent = value; + fourthClassId = getLongRandom(); + fourthClassSort++; + } + } + } + } + if (!"".equals(firstClassNameCurrent)) { + //领域 + CategoryEntity insertEntity = getCategoryEntity(firstClassId, 0L, "0", firstClassName, + firstClassId + "", "0", firstClassSort, 0, ""); + list.add(insertEntity); + } + if (!"".equals(secondClassNameCurrent)) { + //大类 + CategoryEntity insertEntity = getCategoryEntity(secondClassId, firstClassId, firstClassId + "", secondClassName, + secondClassId + "", "1", secondClassSort, 0, firstClassName); + list.add(insertEntity); + } + if (!"".equals(thirdClassNameCurrent)) { + //小类 + String pids = firstClassId + "," + secondClassId + ""; + CategoryEntity insertEntity = getCategoryEntity(thirdClassId, secondClassId, pids, thirdClassName, + thirdClassId + "", "2", thirdClassSort, 0, secondClassName); + list.add(insertEntity); + } + if (!"".equals(fourthClassNameCurrent)) { + //细分类 + String pids = firstClassId + "," + secondClassId + "," + thirdClassId + ""; + CategoryEntity insertEntity = getCategoryEntity(fourthClassId, thirdClassId, pids, fourthClassName, + fourthClassId + "", "3", fourthClassSort, 0, thirdClassName); + list.add(insertEntity); + } + } + if (list.size() > 0) { + CategoryEntity[] categoryEntities = new CategoryEntity[list.size()]; + for (int k = 0; k < list.size(); k++) { + categoryEntities[k] = list.get(k); + } + baseDao.insertList(categoryEntities); + } + result.setMsg("success"); + result.setCode(0); + result.setData("数据导入成功!"); + return result; + } catch (Exception e) { + + } + result.setMsg("defeat"); + result.setCode(1); + result.setData("数据导入失败!"); + return result; + } + + /** + * 获取单元格内容 + * + * @param cell + * @return + */ + public String getCellContent(Cell cell) { + String value = ""; + if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { + value = String.valueOf(cell.getNumericCellValue()); + } else { + value = cell.getStringCellValue(); + } + //内容超过25个字进行长度限制,否则数据库会超限 + if (value.length() > 25) { + value = value.substring(0, 25) + "..."; + } + return value; + } + + /** + * 获取19位随机数 + * + * @return + */ + public Long getLongRandom() { + Guid += 1; + long now = System.currentTimeMillis(); + SimpleDateFormat dateFormat = new SimpleDateFormat("MMdd"); + String time = dateFormat.format(now); + String currentTimeMillis = now + ""; + int ran = 0; + if (Guid > 999) { + Guid = 100; + } + ran = Guid; + String str = time + currentTimeMillis.substring(1, currentTimeMillis.length()) + ran; + return Long.parseLong(str); + } + + /** + * 拼接entity + * + * @param id ID + * @param pid 上级分类ID + * @param categoryName 分类名称 + * @param categoryCode 分类编码 + * @param categoryType 分类类别 + * @param sort 排序 + * @param delFlag 删除标识 0:未删除 1:删除 + * @param parentName 上级部门名称 + */ + public CategoryEntity getCategoryEntity(Long id, Long pid, String pids, String categoryName, String categoryCode, + String categoryType, Integer sort, Integer delFlag, String parentName) { + CategoryEntity entity = new CategoryEntity(); + Long userId = SecurityUser.getUserId(); + entity.setId(id); + entity.setPid(pid); + entity.setPids(pids); + entity.setCategoryName(categoryName);//分类名称 + entity.setCategoryCode(categoryCode);//分类编码(暂时使用ID) + entity.setCategoryType(categoryType);//分类类别(默认1) + entity.setSort(sort);//排序 + entity.setDelFlag(delFlag);//删除标识 0:未删除 1:删除 + entity.setParentName(parentName);//上级部门名称 + entity.setCreator(userId); + entity.setUpdater(userId); + entity.setCreateDate(new Date()); + entity.setUpdateDate(new Date()); + return entity; + } + + /** + * 获取excle版本 + * + * @param mFile + * @return + */ + public String getExcelInfo(MultipartFile mFile) { + String fileName = mFile.getOriginalFilename();// 获取文件名 + String isExcel2003 = "true";// 根据文件名判断文件是2003版本还是2007版本 + try { + if (!validateExcel(fileName)) {// 验证文件名是否合格 + return ""; + } + if (isExcel2007(fileName)) { + isExcel2003 = "false"; + } + return isExcel2003; + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + /** + * 验证EXCEL文件 + * + * @param filePath + * @return + */ + public boolean validateExcel(String filePath) { + if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))) { + return false; + } + return true; + } + + // @描述:是否是2003的excel,返回true是2003 + public static boolean isExcel2003(String filePath) { + return filePath.matches("^.+\\.(?i)(xls)$"); + } + + // @描述:是否是2007的excel,返回true是2007 + public static boolean isExcel2007(String filePath) { + return filePath.matches("^.+\\.(?i)(xlsx)$"); + } + + /** + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 查询事件类别树, 供下拉框调用 + * @Date 2019/12/3 18:07 + **/ + @Override + public Result getCategoryTree() { + String eventsCategoryKey = RedisKeys.getEventsCategoryKey(); + Object obj = redisUtils.get(eventsCategoryKey); + if (null == obj) { + this.packageCategoryOption(); + obj = redisUtils.get(eventsCategoryKey); + } + return new Result().ok((CategoryOption) obj); + } + + /** + * @param formDTO + * @return java.util.List + * @Author yinzuomei + * @Description 根据id查询事件分类基本信息 + * @Date 2019/12/4 9:43 + **/ + @Override + public List listCategoryInfo(CategoryInfoFormDTO formDTO) { + List result = Lists.newArrayList(); + CategoryInfoResultDTO categoryInfoResult; + + for (Long id : formDTO.getIds()) { + CategoryEntity entity = baseDao.getById(id); + if (null == entity) { + continue; + } + if(StringUtils.isBlank(entity.getPids())){ + categoryInfoResult = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); + result.add(categoryInfoResult); + continue; + } + List parentNameList = Lists.newArrayList(); + String[] pidList = entity.getPids().split(StrConstant.COMMA); + if (null != pidList && pidList.length > NumConstant.ZERO) { + CategoryEntity parentEntity; + for (int i = 0; i < pidList.length; i++) { + parentEntity = baseDao.getById(Long.valueOf(pidList[i])); + if (null != parentEntity) { + parentNameList.add(parentEntity.getCategoryName()); + } + } + } + categoryInfoResult = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); + if (CollUtil.isNotEmpty(parentNameList)) { + categoryInfoResult.setParentNames(StringUtils.join(parentNameList, StrConstant.HYPHEN)); + } + result.add(categoryInfoResult); + } + return result; + } + + /** + * @param + * @return void + * @Author yinzuomei + * @Description 组装事件类别 + * @Date 2019/12/3 18:18 + **/ + @Override + public void packageCategoryOption() { + List dtoList = baseDao.selectListCategoryTreeDTO(); + JSONObject node; + JSONArray headNodes = new JSONArray(); + for (CategoryTreeDTO categoryTreeDto : dtoList) { + + if (categoryTreeDto.getPid().longValue() == NumConstant.ZERO_L) { + node = new JSONObject(); + node.put("value", categoryTreeDto.getId()); + node.put("label", categoryTreeDto.getCategoryName()); + headNodes.add(node); + } + } + + // 用于存放所有父级节点 + JSONArray parent; + // 用于存放所有子级节点 + JSONArray allChildren = new JSONArray(); + JSONArray children; + // 用于存放单个子级节点 + JSONObject childNode; + + parent = headNodes; + // 存放其余未处理的类别(节点) + List others = this.getOtherCategory(dtoList, parent); + + while (!others.isEmpty()) { + for (int i = 0; i < parent.size(); i++) { + node = parent.getJSONObject(i); + children = new JSONArray(); + for (CategoryTreeDTO categoryTreeDto : others) { + if (categoryTreeDto.getPid().equals(node.get("value"))) { + childNode = new JSONObject(); + childNode.put("value", categoryTreeDto.getId()); + childNode.put("label", categoryTreeDto.getCategoryName()); + + children.add(childNode); + allChildren.add(childNode); + } + } + if (!children.isEmpty()) { + node.put("children", children); + } + } + parent = allChildren; + + others = this.getOtherCategory(others, parent); + + } // JSONObject treeNodes = new JSONObject(); // treeNodes.put("options", headNodes); // logger.info(treeNodes.toJSONString()); - //存放到redis中 - List cache = Lists.newArrayList(); - cache.add(headNodes); - CategoryOption option = new CategoryOption(); - option.setOptions(cache.get(0)); - redisUtils.set(RedisKeys.getEventsCategoryKey(), option); - } - - /* - * @param dtoList 上次进行筛选的分类集合 - * @param parent 已处理过的上级节点 - * @return java.util.List - * @Author yinzuomei - * @Description 组装其余未处理过的分类集合 - * @Date 2019/12/3 17:27 - **/ - private List getOtherCategory(List dtoList, JSONArray parent) { - List already = Lists.newArrayList(); - for (int i = 0; i < parent.size(); i++) { - already.add((Long) parent.getJSONObject(i).get("value")); - } - - List others = Lists.newArrayList(); - - for (CategoryTreeDTO categoryTreeDto : dtoList) { - Long categoryTreeDtoId = categoryTreeDto.getId(); - if (!already.contains(categoryTreeDtoId)) { - others.add(categoryTreeDto); - } - } - return others; - } + //存放到redis中 + List cache = Lists.newArrayList(); + cache.add(headNodes); + CategoryOption option = new CategoryOption(); + option.setOptions(cache.get(0)); + redisUtils.set(RedisKeys.getEventsCategoryKey(), option); + } + + /* + * @param dtoList 上次进行筛选的分类集合 + * @param parent 已处理过的上级节点 + * @return java.util.List + * @Author yinzuomei + * @Description 组装其余未处理过的分类集合 + * @Date 2019/12/3 17:27 + **/ + private List getOtherCategory(List dtoList, JSONArray parent) { + List already = Lists.newArrayList(); + for (int i = 0; i < parent.size(); i++) { + already.add((Long) parent.getJSONObject(i).get("value")); + } + + List others = Lists.newArrayList(); + + for (CategoryTreeDTO categoryTreeDto : dtoList) { + Long categoryTreeDtoId = categoryTreeDto.getId(); + if (!already.contains(categoryTreeDtoId)) { + others.add(categoryTreeDto); + } + } + return others; + } } diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiTimeLimitItemDTO.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiTimeLimitItemDTO.java index 57cdc6650..02ee5b09e 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiTimeLimitItemDTO.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiTimeLimitItemDTO.java @@ -53,7 +53,7 @@ public class KpiTimeLimitItemDTO implements Serializable { /** * 项目类别id */ - private String categoryId; + private Long categoryId; /** * 所有上级项目类别id @@ -108,6 +108,6 @@ public class KpiTimeLimitItemDTO implements Serializable { /** * 项目类别集合 */ - private List categoryIds; + private List categoryIds; } diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiTimeLimitItemDao.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiTimeLimitItemDao.java index 864818d4b..bbd50990e 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiTimeLimitItemDao.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiTimeLimitItemDao.java @@ -20,6 +20,9 @@ package com.elink.esua.epdc.dao; import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; import com.elink.esua.epdc.entity.KpiTimeLimitItemEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 项目响应时限 @@ -29,5 +32,16 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface KpiTimeLimitItemDao extends BaseDao { - + + + /** + * 按类别id,批量删除配置 + * + * @param categoryIds + * @return int + * @author work@yujt.net.cn + * @date 2019/12/16 19:19 + */ + int deleteBatchByCategoryIds(@Param("categoryIds") List categoryIds); + } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiTimeLimitItemEntity.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiTimeLimitItemEntity.java index d29045146..9a0ce5a83 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiTimeLimitItemEntity.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiTimeLimitItemEntity.java @@ -51,7 +51,7 @@ public class KpiTimeLimitItemEntity extends BaseEpdcEntity { /** * 项目类别id */ - private String categoryId; + private Long categoryId; /** * 所有上级项目类别id diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/feign/EventFeignClient.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/feign/EventFeignClient.java index e5c06cb0d..c061f68bd 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/feign/EventFeignClient.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/feign/EventFeignClient.java @@ -7,7 +7,7 @@ import com.elink.esua.epdc.dto.category.result.CategoryInfoResultDTO; import com.elink.esua.epdc.feign.fallback.EventFeignClientFallback; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.GetMapping; import java.util.List; @@ -19,13 +19,13 @@ import java.util.List; @FeignClient(name = ServiceConstant.EPDC_EVENTS_SERVER, fallback = EventFeignClientFallback.class) public interface EventFeignClient { - /** - * @param categoryInfoFormDTO - * @return com.elink.esua.epdc.commons.tools.utils.Result> - * @Author yinzuomei - * @Description 根据id查询事件分类基本信息 - * @Date 2019/12/4 10:37 - **/ - @PostMapping(value = "events/category/queryCategoryInfo", consumes = MediaType.APPLICATION_JSON_VALUE) - Result> queryCategoryInfo(CategoryInfoFormDTO categoryInfoFormDTO); + /** + * @param categoryInfoFormDTO + * @return com.elink.esua.epdc.commons.tools.utils.Result> + * @Author yinzuomei + * @Description 根据id查询事件分类基本信息 + * @Date 2019/12/4 10:37 + **/ + @GetMapping(value = "events/category/queryCategoryInfo", consumes = MediaType.APPLICATION_JSON_VALUE) + Result> queryCategoryInfo(CategoryInfoFormDTO categoryInfoFormDTO); } diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiTimeLimitItemServiceImpl.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiTimeLimitItemServiceImpl.java index 28b44ee8e..e6f92b535 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiTimeLimitItemServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiTimeLimitItemServiceImpl.java @@ -21,6 +21,8 @@ import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.constant.StrConstant; import com.elink.esua.epdc.commons.tools.page.PageData; import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; import com.elink.esua.epdc.commons.tools.constant.FieldConstant; @@ -33,6 +35,7 @@ import com.elink.esua.epdc.entity.KpiTimeLimitItemEntity; import com.elink.esua.epdc.feign.EventFeignClient; import com.elink.esua.epdc.redis.KpiTimeLimitItemRedis; import com.elink.esua.epdc.service.KpiTimeLimitItemService; +import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,8 +58,6 @@ import java.util.Map; public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl implements KpiTimeLimitItemService { private Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired - private KpiTimeLimitItemRedis kpiTimeLimitItemRedis; @Autowired private EventFeignClient eventFeignClient; @@ -80,8 +81,8 @@ public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); @@ -98,47 +99,82 @@ public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl> res = eventFeignClient.queryCategoryInfo(categoryInfoFormDTO); - if (res.getCode() != 0 || CollUtil.isEmpty(res.getData()) || res.getData().size() == 0) { - return new Result().error("查询分类详情失败" + res.getMsg()); + List selectedCategoryIds = dto.getCategoryIds(); + // 用户选择的所有部门id(去重之后) + List distinctCategoryIds = Lists.newArrayList(); + + for (Long[] oneOptionCategoryIdArray : selectedCategoryIds) { + for (Long categoryId : oneOptionCategoryIdArray) { + if (!distinctCategoryIds.contains(categoryId)) { + distinctCategoryIds.add(categoryId); + } } - String allCategoryNames = ""; - String parentCategoryIds = ""; - String parentCategoryNames = ""; - CategoryInfoResultDTO categoryInfoResultDTO = res.getData().get(0); - for (String parentName : categoryInfoResultDTO.getParentNames()) { - parentCategoryNames += (parentName + "-"); + } + CategoryInfoFormDTO categoryInfoFormDto = new CategoryInfoFormDTO(); + categoryInfoFormDto.setIds(distinctCategoryIds.toArray(new Long[distinctCategoryIds.size()])); + Result> eventResult = eventFeignClient.queryCategoryInfo(categoryInfoFormDto); + if (!eventResult.success() || CollUtil.isEmpty(eventResult.getData())) { + return new Result().error(); + } + + List categoryInfoList = eventResult.getData(); + + KpiTimeLimitItemEntity timeLimit; + List entityList = Lists.newArrayList(); + + for (CategoryInfoResultDTO categoryInfo : categoryInfoList) { + delteTimeLimitByCategoryId(categoryInfo.getId()); + + timeLimit = new KpiTimeLimitItemEntity(); + timeLimit.setValidCloseTime(dto.getValidCloseTime()); + timeLimit.setValidRespondTime(dto.getValidRespondTime()); + + timeLimit.setCategoryId(categoryInfo.getId()); + // 父id为根节点0,表示一级类别,不拼接根节点 + if (categoryInfo.getPids().equals(NumConstant.ZERO_STR)) { + timeLimit.setAllCategoryIds(String.valueOf(categoryInfo.getId())); + timeLimit.setAllCategoryNames(categoryInfo.getCategoryName()); + } else { + timeLimit.setAllCategoryIds(categoryInfo.getPids().concat(StrConstant.COMMA).concat(String.valueOf(categoryInfo.getId()))); + timeLimit.setAllCategoryNames(categoryInfo.getParentNames().concat(StrConstant.HYPHEN.concat(categoryInfo.getCategoryName()))); } - //去除最后一个- - parentCategoryNames = parentCategoryNames.substring(0, parentCategoryNames.length() - 1); - allCategoryNames = parentCategoryNames + "-" + categoryInfoResultDTO.getCategoryName(); - int index = categoryIds.lastIndexOf(","); -// logger.info("最后一个逗号所在的位置"+index); - parentCategoryIds = categoryIds.substring(0, index); - dto.setCategoryId(categoryId); - dto.setAllCategoryIds(categoryIds); - dto.setAllCategoryNames(allCategoryNames); - dto.setParentCategoryIds(parentCategoryIds); - dto.setParentCategoryNames(parentCategoryNames); - KpiTimeLimitItemEntity entity = ConvertUtils.sourceToTarget(dto, KpiTimeLimitItemEntity.class); - // 删除已存在的记录 - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(categoryId), "CATEGORY_ID", categoryId); - baseDao.delete(wrapper); - //插入 - insert(entity); + + timeLimit.setParentCategoryIds(categoryInfo.getPids()); + timeLimit.setParentCategoryNames(categoryInfo.getParentNames()); + entityList.add(timeLimit); } + + baseDao.deleteBatchByCategoryIds(distinctCategoryIds); + this.insertBatch(entityList, NumConstant.THIRTY); + return new Result(); } + /** + * 根据类别id删除类别设置 + * + * @param categoryId + * @return int + * @author work@yujt.net.cn + * @date 2019/12/16 17:49 + */ + private int delteTimeLimitByCategoryId(Long categoryId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("CATEGORY_ID", categoryId); + return baseDao.delete(wrapper); + } + + public static void main(String[] args) { + List aa = Lists.newArrayList(); + aa.add(0L); + aa.add(1L); + + Long[] bb = aa.toArray(new Long[aa.size()]); + for (Long aLong : bb) { + System.out.println(aLong); + } + } + @Override @Transactional(rollbackFor = Exception.class) public void update(KpiTimeLimitItemDTO dto) { diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiTimeLimitItemDao.xml b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiTimeLimitItemDao.xml index 83044e824..a35805931 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiTimeLimitItemDao.xml +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiTimeLimitItemDao.xml @@ -3,22 +3,10 @@ - - - - - - - - - - - - - - - - + + delete from epdc_kpi_time_limit_item where category_id in + #{item} + \ No newline at end of file