¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.tms.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import liquibase.pro.packaged.Q; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.CommonGenericTree; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.ImportExcelUtil; |
| | | import org.jeecg.common.util.StrUtils; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.system.mapper.SysDictItemMapper; |
| | | import org.jeecg.modules.system.mapper.SysDictMapper; |
| | | import org.jeecg.modules.tms.entity.ToolsClassify; |
| | | import org.jeecg.modules.tms.mapper.ToolsClassifyMapper; |
| | | import org.jeecg.modules.tms.service.IToolsClassifyService; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | | import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.tools.Tool; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: tms_tools_classify |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-05-06 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class ToolsClassifyServiceImpl extends ServiceImpl<ToolsClassifyMapper, ToolsClassify> implements IToolsClassifyService { |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | private String upLoadPath; |
| | | |
| | | @Autowired |
| | | private SysDictMapper sysDictMapper; |
| | | |
| | | @Autowired |
| | | private SysDictItemMapper sysDictItemMapper; |
| | | @Override |
| | | public IPage<ToolsClassify> queryPageList(Page<ToolsClassify> page, Map<String, String[]> parameterMap) { |
| | | QueryWrapper<ToolsClassify> queryWrapper = Wrappers.query(); |
| | | String[] classifyIds = parameterMap.get("classifyId"); |
| | | if (classifyIds != null && classifyIds.length > 0) { |
| | | queryWrapper.like("t.classify_id", classifyIds[0]); |
| | | } |
| | | String[] typeNames = parameterMap.get("typeName"); |
| | | if (typeNames != null && typeNames.length > 0) { |
| | | queryWrapper.like("t.type_name", typeNames[0]); |
| | | } |
| | | String[] parentIds = parameterMap.get("parentId"); |
| | | if (parentIds != null && parentIds.length > 0) { |
| | | queryWrapper.eq("t.parent_id", parentIds[0]); |
| | | } |
| | | queryWrapper.orderByAsc("t.seq"); |
| | | return this.baseMapper.queryPageList(page, queryWrapper); |
| | | } |
| | | public List<CommonGenericTree> loadTree() { |
| | | List<ToolsClassify> toolsClassifyList = this.lambdaQuery().orderByAsc(ToolsClassify::getId).list(); |
| | | List<CommonGenericTree> commonGenericTreeList = loadTree(toolsClassifyList); |
| | | return commonGenericTreeList; |
| | | } |
| | | |
| | | public List<CommonGenericTree> loadTree(List<ToolsClassify> toolsClassifyList) { |
| | | @SuppressWarnings("unused") ToolsClassify toolsClassify = new ToolsClassify(); |
| | | List<CommonGenericTree> list = new ArrayList<>(); |
| | | Map<String, CommonGenericTree> map = new HashMap<>(); |
| | | if (CollectionUtils.isNotEmpty(toolsClassifyList)) { |
| | | CommonGenericTree<ToolsClassify> tcNode; |
| | | CommonGenericTree<ToolsClassify> childNode; |
| | | for (ToolsClassify tc : toolsClassifyList) { |
| | | ToolsClassify child = tc; |
| | | if (StrUtils.isBlankOrNull(tc.getParentId())) { |
| | | tcNode = new CommonGenericTree<>(); |
| | | tcNode.setKey(tc.getId()); |
| | | tcNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName()); |
| | | tcNode.setIcon(""); |
| | | tcNode.setType(1); |
| | | tcNode.setValue(tc.getId()); |
| | | tcNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false); |
| | | tcNode.setRField1(tc.getClassifyId()); |
| | | //tcNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId()); |
| | | tcNode.setEntity(tc); |
| | | list.add(tcNode); |
| | | map.put(tc.getId(), tcNode); |
| | | } else { |
| | | tcNode = map.get(child.getParentId()); |
| | | childNode = new CommonGenericTree<>(); |
| | | childNode.setKey(tc.getId()); |
| | | childNode.setTitle(tc.getClassifyId() + "/" + tc.getTypeName()); |
| | | childNode.setParentId(tc.getParentId()); |
| | | childNode.setIcon(""); |
| | | childNode.setType(0); |
| | | childNode.setValue(tc.getId()); |
| | | childNode.setDisabled(CommonConstant.STATUS_0.equals(tc.getStatus()) ? true : false); |
| | | childNode.setRField1(tc.getClassifyId()); |
| | | //childNode.setRField2(getBaseParent(tc.getId(), 0).getClassifyId()); |
| | | childNode.setEntity(tc); |
| | | tcNode.addChildren(childNode); |
| | | map.put(child.getId(), childNode); |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public ToolsClassify getBaseParent(String id, int index) { |
| | | ToolsClassify toolsClassify = null; |
| | | if (index < 99) { |
| | | toolsClassify = getById(id); |
| | | if (StrUtils.isNotBlankOrNull(toolsClassify.getParentId())) { |
| | | if (!toolsClassify.getParentId().equals("-1")) { |
| | | toolsClassify = getBaseParent(toolsClassify.getParentId(), index++); |
| | | } |
| | | } |
| | | } |
| | | return toolsClassify; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ModelAndView toolClassifyExport(HttpServletRequest request, ToolsClassify toolsClassify, Class<ToolsClassify> clazz, String title) { |
| | | // Step.1 ç»è£
æ¥è¯¢æ¡ä»¶ |
| | | QueryWrapper<ToolsClassify> queryWrapper = new QueryWrapper<>(); |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | // è¿æ»¤é䏿°æ® |
| | | String selections = request.getParameter("selections"); |
| | | if (oConvertUtils.isNotEmpty(selections)) { |
| | | List<String> selectionList = Arrays.asList(selections.split(",")); |
| | | queryWrapper.in("t.id",selectionList); |
| | | } |
| | | // Step.2 è·åå¯¼åºæ°æ® |
| | | List<ToolsClassify> exportList = this.baseMapper.queryExportList(queryWrapper); |
| | | |
| | | // Step.3 AutoPoi 导åºExcel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | //æ¤å¤è®¾ç½®çfilenameæ æ ,å端ä¼éæ´æ°è®¾ç½®ä¸ä¸ |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, title); |
| | | mv.addObject(NormalExcelConstants.CLASS, clazz); |
| | | //update-begin--Author:liusq Date:20210126 forï¼å¾çå¯¼åºæ¥éï¼ImageBasePathæªè®¾ç½®-------------------- |
| | | ExportParams exportParams=new ExportParams(title + "æ¥è¡¨", "导åºäºº:" + sysUser.getRealname(), title); |
| | | exportParams.setImageBasePath(upLoadPath); |
| | | //update-end--Author:liusq Date:20210126 forï¼å¾çå¯¼åºæ¥éï¼ImageBasePathæªè®¾ç½®---------------------- |
| | | mv.addObject(NormalExcelConstants.PARAMS,exportParams); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, exportList); |
| | | return mv; |
| | | } |
| | | |
| | | @Override |
| | | public Result<?> toolClassifyImportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | // è·åä¸ä¼ æä»¶å¯¹è±¡ |
| | | MultipartFile file = multipartRequest.getFile("file"); |
| | | //éè¯¯ä¿¡æ¯ |
| | | List<String> errorMessage = new ArrayList<>(); |
| | | int successLines = 0, errorLines = 0; |
| | | try (InputStream fis = file.getInputStream()) { |
| | | Workbook workbook = WorkbookFactory.create(fis); |
| | | |
| | | // è·å第ä¸ä¸ªå·¥ä½è¡¨ |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | for(Row row : sheet) { |
| | | int rowNum = row.getRowNum()+1; |
| | | ToolsClassify newToolsClassify = new ToolsClassify(); |
| | | if (row.getRowNum() == 0) |
| | | continue; |
| | | Cell numCell = row.getCell(0); |
| | | String num = numCell.getStringCellValue(); |
| | | Cell nameCell = row.getCell(1); |
| | | String name = nameCell.getStringCellValue(); |
| | | Cell parentNumCell = row.getCell(2); |
| | | String parentNum = parentNumCell.getStringCellValue(); |
| | | Cell seqCell = row.getCell(3); |
| | | String seq = seqCell.getStringCellValue(); |
| | | Cell leafFlagCell = row.getCell(4); |
| | | String leafFlag = leafFlagCell.getStringCellValue(); |
| | | Cell paraTypeFlagCell = row.getCell(5); |
| | | String paraTypeFlag = paraTypeFlagCell.getStringCellValue(); |
| | | //è½¬ä¹æ¯å¦ä¸ºå¶åèç¹ |
| | | if("æ¯".equals(leafFlag)){ |
| | | leafFlag = "1"; |
| | | }else if("å¦".equals(leafFlag)){ |
| | | leafFlag = "2"; |
| | | }else { |
| | | errorMessage.add("第"+rowNum+"è¡ï¼æ¯å¦ä¸ºå¶åèç¹å¡«åé误ï¼è¯·å¡«åâæ¯âæâå¦â"); |
| | | errorLines++; |
| | | continue; |
| | | } |
| | | if(StringUtils.isBlank(num)){ |
| | | errorMessage.add("第"+rowNum+"è¡ï¼åç±»ç¼ç ä¸è½ä¸ºç©º"); |
| | | errorLines++; |
| | | continue; |
| | | } |
| | | if(StringUtils.isBlank(name)){ |
| | | errorMessage.add("第"+rowNum+"è¡ï¼åç±»åç§°ä¸è½ä¸ºç©º"); |
| | | errorLines++; |
| | | continue; |
| | | //夿æ¯å¦æä¸çº§åç±» |
| | | } |
| | | //å¤æåæ°æ¨¡æ¿æ¯å¦åå¨ |
| | | if(StringUtils.isNotBlank(paraTypeFlag)){ |
| | | List<DictModel> dictList = sysDictMapper.queryDictItemValueByCodeAndText("tool_para_type",paraTypeFlag); |
| | | if(CollectionUtils.isNotEmpty(dictList)){ |
| | | paraTypeFlag = dictList.get(0).getValue(); |
| | | }else { |
| | | errorMessage.add("第"+rowNum+"è¡ï¼åæ°æ¨¡æ¿ä¸åå¨"); |
| | | errorLines++; |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(parentNum)){ |
| | | ToolsClassify toolsClassify = this.lambdaQuery() |
| | | .eq(ToolsClassify::getClassifyId,parentNum) |
| | | .eq(ToolsClassify::getLeafFlag,"2").one(); |
| | | if(toolsClassify == null){ |
| | | errorMessage.add("第"+rowNum+"è¡ï¼åç±»ç¼ç 为"+num+"çæ°æ®çä¸çº§åç±»ç¼å·ä¸åå¨æä¸ºå¶åèç¹"); |
| | | errorLines++; |
| | | }else { |
| | | //夿ç¼ç æ¯å¦éå¤ï¼éå¤çè¿è¡æ´æ° |
| | | ToolsClassify tools = this.lambdaQuery().eq(ToolsClassify::getClassifyId,num).one(); |
| | | if(tools != null){ |
| | | tools.setClassifyId(num) |
| | | .setTypeName(name) |
| | | .setStatus("1") |
| | | .setLeafFlag(leafFlag) |
| | | .setEncodingType("3") |
| | | .setSeq(seq) |
| | | .setParentId(toolsClassify.getId()) |
| | | .setParaTypeFlag(paraTypeFlag); |
| | | this.updateById(tools); |
| | | }else{ |
| | | newToolsClassify.setClassifyId(num) |
| | | .setTypeName(name) |
| | | .setStatus("1") |
| | | .setLeafFlag(leafFlag) |
| | | .setEncodingType("3") |
| | | .setSeq(seq) |
| | | .setParentId(toolsClassify.getId()) |
| | | .setParaTypeFlag(paraTypeFlag); |
| | | this.save(newToolsClassify); |
| | | } |
| | | successLines++; |
| | | } |
| | | //å¦ææ²¡å¡«åä¸çº§åç±»ç¼å·ï¼åæ°å¢å°æ ¹èç¹ |
| | | }else { |
| | | //夿ç¼ç æ¯å¦éå¤ï¼éå¤çè¿è¡æ´æ° |
| | | ToolsClassify tools = this.lambdaQuery().eq(ToolsClassify::getClassifyId,num).one(); |
| | | if(tools != null){ |
| | | tools.setClassifyId(num) |
| | | .setTypeName(name) |
| | | .setStatus("1") |
| | | .setLeafFlag(leafFlag) |
| | | .setEncodingType("3") |
| | | .setSeq(seq) |
| | | .setParentId("-1") |
| | | .setParaTypeFlag(paraTypeFlag); |
| | | this.updateById(tools); |
| | | }else { |
| | | newToolsClassify.setClassifyId(num) |
| | | .setTypeName(name) |
| | | .setStatus("1") |
| | | .setParentId("-1") |
| | | .setSeq(seq) |
| | | .setLeafFlag(leafFlag) |
| | | .setEncodingType("3") |
| | | .setParaTypeFlag(paraTypeFlag); |
| | | this.save(newToolsClassify); |
| | | } |
| | | successLines++; |
| | | } |
| | | } |
| | | }catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage); |
| | | } |
| | | } |