| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.google.protobuf.ServiceException; |
| | | import com.vci.ubcs.code.applyjtcodeservice.entity.DockingPreAttrMapping; |
| | | import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient; |
| | | import com.vci.ubcs.code.applyjtcodeservice.vo.DockingPreAttrMappingVO; |
| | | import com.vci.ubcs.code.bo.AttributeValue; |
| | | import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; |
| | | import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO; |
| | | import com.vci.ubcs.code.dto.CodeExportAttrDTO; |
| | | import com.vci.ubcs.code.dto.CodeOrderDTO; |
| | | import com.vci.ubcs.code.constant.MdmEngineConstant; |
| | | import com.vci.ubcs.code.dto.*; |
| | | import com.vci.ubcs.code.entity.CodeAllCode; |
| | | import com.vci.ubcs.code.enumpack.CodeDefaultLC; |
| | | import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum; |
| | |
| | | import com.vci.ubcs.starter.web.util.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import oracle.sql.TIMESTAMP; |
| | | import org.apache.commons.collections4.map.HashedMap; |
| | | import org.apache.poi.hssf.usermodel.HSSFRichTextString; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | |
| | | import org.apache.poi.ss.usermodel.RichTextString; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import javax.annotation.Resource; |
| | | import java.beans.BeanInfo; |
| | | import java.beans.Introspector; |
| | | import java.beans.PropertyDescriptor; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Method; |
| | | import java.math.BigDecimal; |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | |
| | | } |
| | | |
| | | /** |
| | | * çææ¹éä¿®æ¹å¯¼å
¥çæä»¶ |
| | | * |
| | | * @param codeClassifyOid åç±»çä¸»é® |
| | | * @return excelçæä»¶å°å |
| | | */ |
| | | @Override |
| | | public String downloadImportExcelBatchEdit(String codeClassifyOid) { |
| | | List<CodeClassifyTemplateVO> templateVOList=new ArrayList<>(); |
| | | VciBaseUtil.alertNotNull("å¯¼åºæ¨¡æ¿","导åºçé
ç½®",codeClassifyOid,"主é¢åºåç±»ç主é®"); |
| | | |
| | | CodeClassifyVO codeClassifyVO = classifyService.getObjectByOid(codeClassifyOid); |
| | | |
| | | templateVOList= templateService.childTemplates(codeClassifyOid); |
| | | |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | eo.setAppend(true); |
| | | //å¢å 模æ¿çä¿¡æ¯å¯¼å
¥ |
| | | LinkedList<WriteExcelData> tempEDList = new LinkedList<>(); |
| | | tempEDList.add(new WriteExcelData(0,0,"ç¼å·")); |
| | | for(int j=0;j<templateVOList.size();j++){ |
| | | CodeClassifyTemplateVO templateVO=templateVOList.get(j); |
| | | CodeClassifyTemplateVO codeClassifyTemplateVO = new CodeClassifyTemplateVO(); |
| | | BeanUtils.copyProperties(templateVO,codeClassifyTemplateVO); |
| | | //ç»åæ ¼å¼çä¸å¯¼å
¥ï¼ |
| | | // æä¸¾çæä¾åºåçéæ© |
| | | //æ¶é´å
¨é¨ç»ä¸ä¸ºyyyy-MM-dd HH:mm:ss |
| | | //åç
§çèªè¡è¾å
¥åç§° |
| | | //å类注å
¥çä¸ç¨ï¼é½æ¯å¯¼å
¥åèªå¨å¤çç |
| | | //ç¼ç ï¼ç¶æçåæ®µä¸å¯¼å
¥ |
| | | List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList=codeClassifyTemplateVO.getAttributes(); |
| | | if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) { |
| | | if (CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) { |
| | | throw new VciBaseException("æ¨¡æ¿æ²¡æé
ç½®å±æ§"); |
| | | } |
| | | } |
| | | List<CodeClassifyTemplateAttrVO> templateAttrVOS = codeClassifyTemplateAttrVOList.stream().filter(s -> |
| | | !DEFAULT_ATTR_LIST.contains(s.getId()) |
| | | && StringUtils.isBlank(s.getComponentRule()) |
| | | && StringUtils.isBlank(s.getClassifyInvokeAttr()) |
| | | && (VciBaseUtil.getBoolean(s.getFormDisplayFlag())) |
| | | ).collect(Collectors.toList()); |
| | | |
| | | if (CollectionUtils.isEmpty(templateAttrVOS)) { |
| | | throw new VciBaseException("æ¨¡æ¿æ²¡æé
置任ä½ãè¡¨åæ¾ç¤ºãä¸ºãæ¯ãç屿§"); |
| | | } |
| | | |
| | | // List<CodeClassifyTemplateAttrVO> idAttrVOList = codeClassifyTemplateVO.getAttributes().stream().filter(s -> s.getId().equalsIgnoreCase(CODE_FIELD)).collect(Collectors.toList()); |
| | | LinkedList<WriteExcelData> excelDataList = new LinkedList<>(); |
| | | Workbook workbook = new HSSFWorkbook(); |
| | | // if(isHistory){ |
| | | excelDataList.add(new WriteExcelData(0,0,"ç¼ç (id)","")); |
| | | // excelDataList.add(new WriteExcelData(0,1,"ç æ®µå®½åº¦","")); |
| | | // excelDataList.add(new WriteExcelData(0,1,!CollectionUtils.isEmpty(idAttrVOList)?idAttrVOList.get(0).getName():"ä¼ä¸ç¼ç ",idAttrVOList.get(0).getId())); |
| | | // } |
| | | for (int i = 0; i < templateAttrVOS.size(); i++) { |
| | | CodeClassifyTemplateAttrVO attrVO = templateAttrVOS.get(i); |
| | | |
| | | Object text = attrVO.getName(); |
| | | text = exportKeyAndRequired(workbook,attrVO,text); |
| | | int colIndex = 1 + i; |
| | | WriteExcelData excelData = new WriteExcelData(0, colIndex, text,attrVO.getId()); |
| | | if(StringUtils.isNotBlank(attrVO.getCodeDateFormat()) |
| | | || VciFieldTypeEnum.VTDateTime.name().equalsIgnoreCase(attrVO.getAttributeDataType()) |
| | | || VciFieldTypeEnum.VTDate.name().equalsIgnoreCase(attrVO.getAttributeDataType()) |
| | | ||VciFieldTypeEnum.VTTime.name().equalsIgnoreCase(attrVO.getAttributeDataType())){ |
| | | excelData.setDateFormat(VciDateUtil.DateTimeFormat); |
| | | } |
| | | if(text instanceof RichTextString){ |
| | | excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); |
| | | } |
| | | excelDataList.add(excelData); |
| | | if(StringUtils.isNotBlank(attrVO.getEnumString()) || StringUtils.isNotBlank(attrVO.getEnumId())){ |
| | | //æ·»å æ°æ®æææ§ |
| | | List<String> enumValueList = new ArrayList<>(); |
| | | enumValueList.add(""); |
| | | List<KeyValue> valueList = engineService.listComboboxItems(attrVO); |
| | | if(!CollectionUtils.isEmpty(valueList)){ |
| | | valueList.stream().forEach(kv->{ |
| | | enumValueList.add(kv.getValue()); |
| | | }); |
| | | } |
| | | //é»è®¤å 1䏿¡ |
| | | WriteExcelData ed = new WriteExcelData(1,colIndex,""); |
| | | ed.setRowTo(100); |
| | | ed.setColTo(colIndex); |
| | | ed.setValidation(true); |
| | | ed.setValidationDataList(enumValueList); |
| | | ed.setValidationErrorMsg("请å¨åºåä¸éæ©æ£ç¡®çå¼"); |
| | | excelDataList.add(ed); |
| | | } |
| | | if(VciFieldTypeEnum.VTBoolean.name().equalsIgnoreCase(attrVO.getAttributeDataType())){ |
| | | List<String> booleanList = new ArrayList<>(); |
| | | |
| | | booleanList.add("æ¯"); |
| | | booleanList.add("å¦"); |
| | | //é»è®¤å 1䏿¡ |
| | | WriteExcelData ed = new WriteExcelData(1,colIndex,""); |
| | | ed.setRowTo(100); |
| | | ed.setColTo(colIndex); |
| | | ed.setValidation(true); |
| | | ed.setValidationDataList(booleanList); |
| | | ed.setValidationErrorMsg("请å¨åºåä¸éæ©æ£ç¡®çå¼"); |
| | | excelDataList.add(ed); |
| | | } |
| | | } |
| | | eo.addSheetDataList(j+templateVO.getName(),excelDataList); |
| | | tempEDList.add(new WriteExcelData(j+1,0,templateVO.getOid())); |
| | | tempEDList.add(new WriteExcelData(j+1,1,templateVO.getId())); |
| | | tempEDList.add(new WriteExcelData(j+1,2,templateVO.getName())); |
| | | } |
| | | String excelName = LocalFileUtil.getDefaultTempFolder() + File.separator + codeClassifyVO.getName() + ("_屿§æ¹éä¿®æ¹æ¨¡æ¿.xls"); |
| | | eo.addSheetDataList(templateVOList.size()+"模æ¿ä¿¡æ¯ã请å¿å é¤æç§»å¨ã",tempEDList); |
| | | ExcelUtil.writeDataToFile(excelName,eo); |
| | | return excelName; |
| | | } |
| | | /** |
| | | * è·åç æ®µå®½åº¦ |
| | | * @param codeClassifyOid |
| | | * @return |
| | |
| | | } |
| | | // 忬¡å¯¼å
¥æ°ééå¶ |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为äºä¿è¯ç³»ç»çç¨³å®æ§ï¼è¯·ä¸æ¬¡ä¸è¦å¯¼å
¥è¶
è¿"+IMPORT_DATA_LIMIT+"æ¡çæ°æ®"); |
| | | throw new ServiceException(StringUtil.format("为äºä¿è¯ç³»ç»çç¨³å®æ§ï¼è¯·ä¸æ¬¡ä¸è¦å¯¼å
¥è¶
è¿{}æ¡çæ°æ®",IMPORT_DATA_LIMIT)); |
| | | } |
| | | //åå²å¯¼å
¥çæ¶åä¸å¤çç¼ç |
| | | //----é»è¾å
容---- |
| | |
| | | if(StringUtils.isNotBlank(excelFileName)) { |
| | | codeImProtRusultVO.setFilePath(excelFileName); |
| | | codeImProtRusultVO.setFileOid(""); |
| | | saveLogUtil.operateLog("å岿°æ®å¯¼å
¥",true, StringUtil.format("é误信æ¯ï¼{}",JSON.toJSONString(shetNameMap)) ); |
| | | saveLogUtil.operateLog("å岿°æ®å¯¼å
¥",true, StringUtil.format("é误信æ¯ï¼{}",JSON.toJSONString(shetNameMap))); |
| | | }else{ |
| | | saveLogUtil.operateLog("å岿°æ®å¯¼å
¥",false, StringUtil.format("导å
¥å°åç±»{}ä¸ï¼å¯¼å
¥æåæ»æ°ä¸ºï¼{}", JSON.toJSONString(classifyFullInfo),importCount.get(0))); |
| | | } |
| | |
| | | } |
| | | return codeImProtRusultVO; |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("å岿°æ®å¯¼å
¥",true,e.getMessage()); |
| | | saveLogUtil.operateLog("å岿°æ®å¯¼å
¥",true,e.toString()); |
| | | throw e; |
| | | } |
| | | } |
| | | /** |
| | | * 导å
¥æ¹éç¼è¾æ°æ® |
| | | * |
| | | * @param codeClassifyOid åç±»çä¸»é® |
| | | * @param classifyAttr å类路å¾ä½¿ç¨ç屿§ |
| | | * @param file excelæä»¶çä¿¡æ¯ |
| | | * @return æé误信æ¯çexcel |
| | | */ |
| | | @Override |
| | | public CodeImProtRusultVO batchImportEdit(String codeClassifyOid, String classifyAttr,File file) throws Throwable{ |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"åç±»ç主é®"); |
| | | ReadExcelOption reo = new ReadExcelOption(); |
| | | reo.setReadAllSheet(true); |
| | | List<SheetDataSet> sheetDataSetList = ExcelUtil.readDataObjectFromExcel(file,null,reo); |
| | | if (sheetDataSetList.size() > LIMIT + 1) { |
| | | throw new VciBaseException("为äºä¿è¯ç³»ç»çç¨³å®æ§ï¼è¯·ä¸æ¬¡ä¸è¦å¯¼å
¥è¶
è¿1䏿¡çæ°æ®"); |
| | | } |
| | | boolean isExport=false; |
| | | Map<String,List<WriteExcelData>> shetNameMap=new HashMap<>(); |
| | | for(int i=0;i<sheetDataSetList.size()-1;i++) { |
| | | if (CollectionUtils.isEmpty(sheetDataSetList) || CollectionUtils.isEmpty(sheetDataSetList.get(i).getRowData()) |
| | | || sheetDataSetList.get(i).getRowData().size() < 1) { |
| | | continue; |
| | | } |
| | | // 忬¡å¯¼å
¥æ°ééå¶ |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为äºä¿è¯ç³»ç»çç¨³å®æ§ï¼è¯·ä¸æ¬¡ä¸è¦å¯¼å
¥è¶
è¿"+IMPORT_DATA_LIMIT+"æ¡çæ°æ®"); |
| | | } |
| | | //æ¥è¯¢åç±»åæ¨¡æ¿ |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | |
| | | //å
æ¾å°æ¯ä¸è¡çæ é¢ï¼ç¶åæ ¹æ®æ 颿¥è·å对åºç屿§ |
| | | SheetDataSet dataSet = sheetDataSetList.get(i); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | |
| | | //æ¾ç¬¬ä¸è¡ï¼ä¸ºäºæ¾æ é¢ |
| | | CodeClassifyTemplateVO templateVO ; |
| | | //é½è½¬æ¢å®äºãéè¦æ¹éæ£æ¥ |
| | | //æ¾ææçå类路å¾,éè¦æ ¡éªè·¯å¾æ¯å¦æ£ç¡®ï¼æ¯å¦é½å¨å½åçåç±»çä¸çº§ |
| | | List<CodeClassifyVO> childClassifyVOs = classifyService.listChildrenClassify(codeClassifyOid, true, classifyAttr, true); |
| | | Map<String/**è·¯å¾**/, CodeClassifyVO> pathMap = Optional.ofNullable(childClassifyVOs).orElseGet(() -> new ArrayList<>()).stream().collect(Collectors.toMap(s -> s.getPath().startsWith("#") ? s.getPath().substring(1) : s.getPath(), t -> t)); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<String, String> errorMap = new ConcurrentHashMap<>(); |
| | | pathMap.put("#current#",classifyFullInfo.getCurrentClassifyVO()); |
| | | |
| | | try { |
| | | titleRowData.add("å类路å¾"); |
| | | List<CodeClassifyTemplateVO> templateVOList= checkSamesTemplate(titleRowData,sheetDataSetList,i,pathMap,errorMap); |
| | | titleRowData.remove(titleRowData.size()-1); |
| | | templateVO= templateVOList.get(0); |
| | | }catch (Throwable e){ |
| | | throw new VciBaseException(e.getMessage()); |
| | | } |
| | | |
| | | CodeClassifyTemplateVO finalTemplateVO = templateVO; |
| | | |
| | | List<SheetRowData> needowDataList = rowDataList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getRowIndex(); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | //è¿éä¸é¤å»é»è®¤ç屿§ |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes(); |
| | | Map<Integer/**åå·**/, String/**åæ®µçåç§°**/> fieldIndexMap = new HashMap<>(); |
| | | |
| | | Map<String/**䏿åç§°**/, String/**è±æåç§°**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId())); |
| | | fieldIndexMap.put(0,"id"); |
| | | getFieldIndexMap(titleRowData, attrNameIdMap, fieldIndexMap); |
| | | //å
ä¸ç¨ç®¡å±æ§æ¯å¦é½åå¨ï¼å
转æ¢ä¸ä¸æ°æ® |
| | | CodeOrderDTO orderDTO = new CodeOrderDTO(); |
| | | for (SheetRowData sheetRowData : needowDataList) { |
| | | //æ¥è¯¢æ°æ® |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("t.id", sheetRowData.getData().get(0)); |
| | | conditionMap.put("t.lastv", "1"); |
| | | CodeTemplateAttrSqlBO sqlBO = mdmEngineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, new PageHelper(-1)); |
| | | //æä»¬ä½¿ç¨åä¸å¡ç±»åçæ¥æ¥è¯¢ |
| | | List<Map> cbosB = commonsMapper.selectBySql(sqlBO.getSqlUnPage()); |
| | | if(cbosB.size() == 0){ |
| | | throw new ServiceException("ç¼ç ï¼"+ sheetRowData.getData().get(0) + ",æªè½æ¥è¯¢å°ç¸å
³æ°æ®ã"); |
| | | } |
| | | excelToCboEdit(fieldIndexMap, sheetRowData, orderDTO, cbosB.get(0)); |
| | | orderDTO.setCopyFromVersion(orderDTO.getOid()); |
| | | orderDTO.setOid(null); |
| | | try { |
| | | mdmEngineService.upSaveCode(orderDTO); |
| | | List<Map> newCbos = commonsMapper.selectBySql(sqlBO.getSqlUnPage()); |
| | | //对ç å¼è¡¨è¿è¡å¤çæ¿æ¢åå»ºæ°æ®çoid |
| | | QueryWrapper<CodeAllCode> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("CREATECODEOID",orderDTO.getCopyFromVersion()); |
| | | List<CodeAllCode> codeAllCodes = codeAllCodeService.selectByWrapper(wrapper); |
| | | codeAllCodes.get(0).setCreateCodeOid(newCbos.get(0).get("OID").toString()); |
| | | codeAllCodes.get(0).setLastModifyTime(new Date()); |
| | | codeAllCodes.get(0).setTs(new Date()); |
| | | codeAllCodes.get(0).setLastModifier(AuthUtil.getUser().getUserName()); |
| | | codeAllCodeService.updateBatchById(codeAllCodes); |
| | | } catch (Throwable e) { |
| | | log.error("æ¹é产çç¼ç çæ¶ååºéäº", e); |
| | | // thisCbos.stream().forEach(cbo -> { |
| | | // String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(sheetRowData.getRowIndex(), ";ç³»ç»é误ï¼å卿°æ®çæ¶ååºéäº:"+e.getMessage()); |
| | | // }); |
| | | } |
| | | } |
| | | |
| | | if (errorMap.size() > 0) { |
| | | isExport = true; |
| | | } |
| | | createWriteExcelData(rowDataList, errorMap, new ArrayList<>(), titleRowData, shetNameMap, finalTemplateVO); |
| | | |
| | | } |
| | | String excelFileName=""; |
| | | if(isExport&&!CollectionUtils.isEmpty(shetNameMap)) { |
| | | excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "é误信æ¯.xls"; |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | shetNameMap.forEach((shetName, errorDataList) -> { |
| | | eo.addSheetDataList(shetName, errorDataList); |
| | | }); |
| | | try { |
| | | new File(excelFileName).createNewFile(); |
| | | } catch (IOException e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e)); |
| | | } |
| | | ExcelUtil.writeDataToFile(excelFileName, eo); |
| | | } |
| | | CodeImProtRusultVO codeImProtRusultVO=new CodeImProtRusultVO(); |
| | | if(StringUtils.isNotBlank(excelFileName)) { |
| | | codeImProtRusultVO.setFilePath(excelFileName); |
| | | codeImProtRusultVO.setFileOid(""); |
| | | saveLogUtil.operateLog("æ°æ®æ¹éæ´æ¹",true, StringUtil.format("é误信æ¯ï¼{}",JSON.toJSONString(shetNameMap)) ); |
| | | }else{ |
| | | saveLogUtil.operateLog("æ°æ®æ¹éæ´æ¹",false, StringUtil.format("导å
¥æåæ»æ°ä¸ºï¼{}", |
| | | sheetDataSetList.size()-1)); |
| | | } |
| | | return codeImProtRusultVO; |
| | | } |
| | | /*private void converBaseModels(List<ClientBusinessObject> clientBusinessObjects,List<BaseModel>dataCBOList){ |
| | | clientBusinessObjects.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | |
| | | } |
| | | saveLogUtil.operateLog("æ¹éç³è¯·ç¼ç ",false, StringUtil.format("æ¹é导å
¥ç³è¯·æåå
±{}æ¡æ°æ®ï¼çæçç å¼å¦ä¸ã{}ã",codeList.size(),codeList)); |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("æ¹éç³è¯·ç¼ç ",true,e.getMessage()); |
| | | saveLogUtil.operateLog("æ¹éç³è¯·ç¼ç ",true,e.toString()); |
| | | throw e; |
| | | } |
| | | return uuid; |
| | |
| | | } |
| | | |
| | | /** |
| | | * excel转æ¢ä¸ºcboç对象 |
| | | * @param fieldIndexMap åæ®µçä½ç½® |
| | | * @param rowDataList exceléçè¡æ°æ® |
| | | * @param orderDTO æ´ççæ°æ® |
| | | * @param map æ°æ®çå表 |
| | | */ |
| | | private void excelToCboEdit(Map<Integer,String> fieldIndexMap,SheetRowData rowDataList, |
| | | CodeOrderDTO orderDTO, |
| | | Map map){ |
| | | rowDataList.getData().forEach((index,value)->{ |
| | | String field = fieldIndexMap.get(index); |
| | | if (StringUtils.isBlank(field)) { |
| | | throw new VciBaseException("第" + (index + 1) + "åçæ é¢å¨ç³»ç»ä¸ä¸åå¨"); |
| | | } |
| | | map.put(field,value); |
| | | }); |
| | | |
| | | try { |
| | | // for (Map map : cbos) { |
| | | // Object obj = CodeOrderDTO.class.newInstance(); |
| | | BeanInfo beanInfo = Introspector.getBeanInfo(orderDTO.getClass()); |
| | | PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); |
| | | for (PropertyDescriptor property : propertyDescriptors) { |
| | | Method setter = property.getWriteMethod(); |
| | | if (setter != null) { |
| | | //oracleçæ¶é´ä¸ºTIMESTAMPçï¼éè¦è¿è¡è½¬æ¢ædataï¼å¦åå°æ¥é |
| | | if (map.get(property.getName().toUpperCase()) instanceof TIMESTAMP) { |
| | | LocalDateTime localDateTime = ((TIMESTAMP) map.get(property.getName().toUpperCase())).toLocalDateTime(); |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | ZonedDateTime zdt = localDateTime.atZone(zoneId); |
| | | Date date = Date.from(zdt.toInstant()); |
| | | setter.invoke(orderDTO, date); |
| | | map.remove(property.getName().toUpperCase()); |
| | | } //oracleçæ°å为BigDecimalçï¼éè¦è¿è¡è½¬æ¢æIntegerï¼å¦åå°æ¥é |
| | | else if (map.get(property.getName().toUpperCase()) instanceof BigDecimal |
| | | && ("Integer").equals(setter.getParameterTypes()[0].getSimpleName())) { |
| | | setter.invoke(orderDTO, ((BigDecimal) map.get(property.getName().toUpperCase())).intValue()); |
| | | map.remove(property.getName().toUpperCase()); |
| | | } else if (map.containsKey(property.getName().toUpperCase())) { |
| | | if(setter.getParameterTypes()[0].getSimpleName().equals("String")){ |
| | | setter.invoke(orderDTO, map.get(property.getName().toUpperCase()) == null ? null:String.valueOf(map.get(property.getName().toUpperCase()))); |
| | | }else{ |
| | | setter.invoke(orderDTO, map.get(property.getName().toUpperCase())); |
| | | } |
| | | map.remove(property.getName().toUpperCase()); |
| | | } |
| | | } |
| | | } |
| | | for (Object key : map.keySet()) { |
| | | map.put(key, map.get(key) == null ? null : String.valueOf(map.get(key))); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new VciBaseException("æ¥è¯¢å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | |
| | | |
| | | |
| | | // Iterator<Map.Entry<String, String>> iterator = cbos.entrySet().iterator(); |
| | | // |
| | | // Map.Entry<String, String> entry; |
| | | // while (iterator.hasNext()) { |
| | | // entry = iterator.next(); |
| | | //// if (WebUtil.isDefaultField(entry.getKey())) { |
| | | // Object obj = BaseModel.class.newInstance(); |
| | | // BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); |
| | | // PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); |
| | | // for (PropertyDescriptor property : propertyDescriptors) { |
| | | // Method setter = property.getWriteMethod(); |
| | | // if (setter != null) { |
| | | // //oracleçæ¶é´ä¸ºTIMESTAMPçï¼éè¦è¿è¡è½¬æ¢ædataï¼å¦åå°æ¥é |
| | | // if (map.get(property.getName().toUpperCase()) instanceof TIMESTAMP) { |
| | | // LocalDateTime localDateTime = ((TIMESTAMP) map.get(property.getName().toUpperCase())).toLocalDateTime(); |
| | | // ZoneId zoneId = ZoneId.systemDefault(); |
| | | // ZonedDateTime zdt = localDateTime.atZone(zoneId); |
| | | // Date date = Date.from(zdt.toInstant()); |
| | | // setter.invoke(obj, date); |
| | | // map.remove(property.getName().toUpperCase()); |
| | | // } //oracleçæ°å为BigDecimalçï¼éè¦è¿è¡è½¬æ¢æIntegerï¼å¦åå°æ¥é |
| | | // else if (map.get(property.getName().toUpperCase()) instanceof BigDecimal |
| | | // && ("Integer").equals(setter.getParameterTypes()[0].getSimpleName())) { |
| | | // setter.invoke(obj, ((BigDecimal) map.get(property.getName().toUpperCase())).intValue()); |
| | | // map.remove(property.getName().toUpperCase()); |
| | | // } else if (map.containsKey(property.getName().toUpperCase())) { |
| | | // if(setter.getParameterTypes()[0].getSimpleName().equals("String")){ |
| | | // setter.invoke(obj, map.get(property.getName().toUpperCase()) == null ? null:String.valueOf(map.get(property.getName().toUpperCase()))); |
| | | // }else{ |
| | | // setter.invoke(obj, map.get(property.getName().toUpperCase())); |
| | | // } |
| | | // map.remove(property.getName().toUpperCase()); |
| | | // } |
| | | // } |
| | | // } |
| | | // WebUtil.setValueToField(entry.getKey(), orderDTO, entry.getValue()); |
| | | // iterator.remove(); |
| | | //// } |
| | | // } |
| | | orderDTO.setData(map); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ ¡éªè§å没æéè¿çå
容 |
| | | * @param attrVOS éè¦æ ¡éªç屿§ |
| | | * @param dataList æ°æ®çå表 |
| | |
| | | } else { |
| | | Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO); |
| | | String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), ""); |
| | | log.error("================================å½åå类注å
¥çvalueå¼ä¸ºï¼==========================",value); |
| | | cbo.setAttributeValue(attrId, value); |
| | | } |
| | | } catch (Throwable e) { |
| | |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * @param codeClassifyOid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportGroupCodeExcel(String codeClassifyOid) throws ServiceException { |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"主é¢åºåç±»ç主é®"); |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | CodeClassifyVO codeClassifyVO= classifyFullInfo.getCurrentClassifyVO(); |
| | | //è·åææ°çæ¨¡æ¿ |
| | | CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyOid); |
| | | LinkedList<String> colName=new LinkedList<>();//å头 |
| | | LinkedList<String> fieldList=new LinkedList<>();//ååæ®µ |
| | | |
| | | ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO(); |
| | | createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//ç»ç»æ°æ® |
| | | if(!CollectionUtils.isEmpty(execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS())){ |
| | | throw new ServiceException("éå¢å±æ§æ å°æªé
ç½®"); |
| | | } |
| | | fieldList=execGroupCodePortDataDTO.getFieldList(); |
| | | List<Map<String,String>>dataList=new ArrayList<>(); |
| | | getDatas(classifyFullInfo,templateVO,fieldList,dataList); |
| | | execGroupCodePortDataDTO.setDataList(dataList);//æ¾æ°æ® |
| | | execGroupCodePortDataDTO.setSheetName(codeClassifyVO.getName()+"éå¢ç 导å
¥æ¨¡æ¿"); |
| | | String tempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | | String excelName = tempFolder + File.separator + |
| | | classifyFullInfo.getCurrentClassifyVO().getId() + "_" + classifyFullInfo.getCurrentClassifyVO().getName() + "_éå¢ç å¯¼åºæ¨¡æ¿.xls"; |
| | | try { |
| | | new File(excelName).createNewFile(); |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelName}, e); |
| | | } |
| | | LinkedList<String> finalFieldList = fieldList; |
| | | Map<String, CodeClassifyTemplateAttrVO> attrVOMap = templateVO.getAttributes().stream().filter(s-> finalFieldList.contains(s.getId().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | Workbook workbook = new HSSFWorkbook(); |
| | | List<CodeAndGroupCodeAttrMappingDTO> codeAndGroupCodeAttrMappingDTOList= execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS(); |
| | | |
| | | Map<String, CodeAndGroupCodeAttrMappingDTO> jAttrVOMap = codeAndGroupCodeAttrMappingDTOList.stream().filter(s-> finalFieldList.contains(s.getTargetAttrKey().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getTargetAttrKey().toLowerCase(Locale.ROOT), t -> t)); |
| | | |
| | | WriteExcelData codeExcelData = new WriteExcelData(0, 0, "ä¼ä¸ç¼ç "); |
| | | WriteExcelData groupExcelData = new WriteExcelData(0, 1, "éå¢ç "); |
| | | excelDataList.add(codeExcelData); |
| | | excelDataList.add(groupExcelData); |
| | | for (int i = 0; i < fieldList.size(); i++) { |
| | | String attrId=fieldList.get(i); |
| | | if(attrId.equals(CODE_FIELD)||attrId.equals(CODE_GROUP_FIELD)){ |
| | | continue; |
| | | } |
| | | if (attrVOMap.containsKey(attrId)) { |
| | | CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId); |
| | | //Object text = attrVO.getName(); |
| | | CodeAndGroupCodeAttrMappingDTO codeAttrMappingDTO = jAttrVOMap.get(attrId); |
| | | Object text = codeAttrMappingDTO.getSourceAttrName(); |
| | | text = exportKeyAndRequired(workbook, attrVO, text); |
| | | WriteExcelData excelData = new WriteExcelData(0, i, text); |
| | | if (text instanceof RichTextString) { |
| | | excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); |
| | | } |
| | | excelDataList.add(excelData); |
| | | } |
| | | } |
| | | final Integer[] rowIndex = {0}; |
| | | dataList.stream().forEach(data -> { |
| | | rowIndex[0]++; |
| | | String id=data.getOrDefault("id", ""); |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], 0, id)); |
| | | String groupCode=data.getOrDefault("groupcode", ""); |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], 1, groupCode)); |
| | | List<String> newFieldList = finalFieldList.stream().filter(e -> !e.equals("id") &&!e.equals("groupcode")).collect(Collectors.toList()); |
| | | |
| | | for (int i = 0; i < newFieldList.size(); i++) { |
| | | String attrId = newFieldList.get(i).toLowerCase(Locale.ROOT); |
| | | if(attrId.equals("id")){ |
| | | |
| | | }else if(attrId.equals("groupcode")){ |
| | | |
| | | }else{ |
| | | if (attrVOMap.containsKey(attrId)) { |
| | | CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId); |
| | | if (StringUtils.isNotBlank(attrVO.getEnumId()) || StringUtils.isNotBlank(attrVO.getEnumString())) { |
| | | attrId = attrId + "Text"; |
| | | } |
| | | if (StringUtils.isNotBlank(attrVO.getReferBtmId()) || StringUtils.isNotBlank(attrVO.getReferConfig())) { |
| | | attrId = attrId + "name"; |
| | | } |
| | | if (VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(attrId)) { |
| | | attrId = VciQueryWrapperForDO.LC_STATUS_FIELD_TEXT.toLowerCase(Locale.ROOT); |
| | | } |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], i+2, data.getOrDefault(attrId, ""))); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | WriteExcelOption excelOption = new WriteExcelOption(); |
| | | excelOption.addSheetDataList(execGroupCodePortDataDTO.getSheetName(),excelDataList); |
| | | |
| | | //å¢å 模æ¿çä¿¡æ¯å¯¼å
¥ |
| | | LinkedList<WriteExcelData> tempEDList = new LinkedList<>(); |
| | | tempEDList.add(new WriteExcelData(0,0,"模æ¿ä¸»é®")); |
| | | tempEDList.add(new WriteExcelData(0,1,"模æ¿ä»£å·")); |
| | | tempEDList.add(new WriteExcelData(0,2,"模æ¿åç§°")); |
| | | tempEDList.add(new WriteExcelData(1,0,templateVO.getOid())); |
| | | tempEDList.add(new WriteExcelData(1,1,templateVO.getId())); |
| | | tempEDList.add(new WriteExcelData(1,2,templateVO.getName())); |
| | | excelOption.addSheetDataList("模æ¿ä¿¡æ¯ã请å¿å é¤æç§»å¨ã",tempEDList); |
| | | ExcelUtil.writeDataToFile(excelName, excelOption); |
| | | log.info("æä»¶è·¯å¾"+excelName); |
| | | return excelName; |
| | | } |
| | | |
| | | /*** |
| | | * éå¢å¯¼åºæ¨¡æ¿å±æ§æ å°ä¿¡æ¯è·å |
| | | * @param templateVO |
| | | * @param execGroupCodePortDataDTO |
| | | */ |
| | | private void createExportGroupCodeMapConfig(CodeClassifyTemplateVO templateVO,ExecGroupCodePortDataDTO execGroupCodePortDataDTO){ |
| | | String classOid=templateVO.getCodeclassifyoid(); |
| | | String templateOid=templateVO.getOid(); |
| | | R r=mdmInterJtClient.list_mapping(classOid); |
| | | if(r.isSuccess()){ |
| | | List<DockingPreAttrMappingVO>dockingPreAttrMappingVOList= (List<DockingPreAttrMappingVO>) r.getData(); |
| | | List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS=new ArrayList<>(); |
| | | LinkedList<String> fieldList=new LinkedList<>(); |
| | | LinkedList<String> colNameList=new LinkedList<>(); |
| | | dockingPreAttrMappingVOList.stream().forEach(dockingPreAttrMappingVO -> { |
| | | CodeAndGroupCodeAttrMappingDTO codeAndGroupCodeAttrMappingDTO=new CodeAndGroupCodeAttrMappingDTO(); |
| | | if(StringUtils.isNotBlank(dockingPreAttrMappingVO.getTargetAttrId())){ |
| | | codeAndGroupCodeAttrMappingDTO.setDefaultValue(dockingPreAttrMappingVO.getDefaultValue()); |
| | | codeAndGroupCodeAttrMappingDTO.setMetaListId(dockingPreAttrMappingVO.getMetaListId()); |
| | | codeAndGroupCodeAttrMappingDTO.setSourceAttrKey(dockingPreAttrMappingVO.getSourceAttrKey()); |
| | | codeAndGroupCodeAttrMappingDTO.setSourceAttrName(dockingPreAttrMappingVO.getSourceAttrName()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrId(dockingPreAttrMappingVO.getTargetAttrId()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrKey(dockingPreAttrMappingVO.getTargetAttrKey()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrName(dockingPreAttrMappingVO.getTargetAttrName()); |
| | | fieldList.add(dockingPreAttrMappingVO.getTargetAttrKey()); |
| | | colNameList.add(dockingPreAttrMappingVO.getSourceAttrName()); |
| | | } |
| | | codeAttrMapGroupAttrDTOS.add(codeAndGroupCodeAttrMappingDTO); |
| | | }); |
| | | execGroupCodePortDataDTO.setCodeAttrMapGroupAttrDTOS(codeAttrMapGroupAttrDTOS); |
| | | execGroupCodePortDataDTO.setFieldList(fieldList); |
| | | execGroupCodePortDataDTO.setColName(colNameList); |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * æ¥è¯¢æªæéå¢ç çæ°æ® |
| | | * @param classifyFullInfo |
| | | * @param templateVO |
| | | * @param selectFieldList |
| | | * @param dataList |
| | | */ |
| | | private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList){ |
| | | //å
æ¥è¯¢æ°æ® |
| | | String btmTypeId = classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | String codeClassifyOid=classifyFullInfo.getCurrentClassifyVO().getOid(); |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<>(); |
| | | } |
| | | if(conditionMap.containsKey(VciQueryWrapperForDO.OID_FIELD)){ |
| | | conditionMap.put(VciQueryWrapperForDO.OID_FIELD,QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(conditionMap.get(VciQueryWrapperForDO.OID_FIELD)) + ")"); |
| | | } |
| | | conditionMap.put("codeclsfpath","*" + codeClassifyOid + "*"); |
| | | conditionMap.put("groupcode_null", "null"); |
| | | conditionMap.put("lastr", "1"); |
| | | conditionMap.put("lastv", "1"); |
| | | |
| | | R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Arrays.asList(btmTypeId)); |
| | | String tableName = ""; |
| | | if(listR.isSuccess() && !listR.getData().isEmpty()){ |
| | | tableName = Func.isNotBlank(listR.getData().get(0).getTableName()) ? listR.getData().get(0).getTableName():VciBaseUtil.getTableName(btmTypeId); |
| | | }else{ |
| | | tableName = VciBaseUtil.getTableName(btmTypeId); |
| | | } |
| | | PageHelper pageHelper = new PageHelper(); |
| | | pageHelper.setLimit(1000000); |
| | | pageHelper.setPage(1); |
| | | pageHelper.addDefaultDesc("createTime"); |
| | | DataGrid<Map<String, String>> dataGrid = engineService.queryGrid(btmTypeId, templateVO, conditionMap, pageHelper); |
| | | //è½¬æ¢æ°æ® |
| | | if(!CollectionUtils.isEmpty(dataGrid.getData())){ |
| | | dataList.addAll(dataGrid.getData()); |
| | | } |
| | | //å°è£
æ¥è¯¢åºæ¥çæ°æ® |
| | | engineService.wrapperData(dataList, templateVO, selectFieldList,false); |
| | | //modify by weidy@2022-09-27 |
| | | //å 为å¨å表å表åçæ¾ç¤ºçæ¶åï¼æä»¬çå¼å
³ç±»å页é¢ä¼å¤çï¼ä½æ¯å¨å¯¼åºçæ¶åï¼æä»¬éè¦å°trueåfalse齿¿æ¢æä¸æ |
| | | engineService.wrapperBoolean(dataList,templateVO); |
| | | log.info("å¯¼åºæ¨¡æ¿çæ°æ®æ¡ç®æ°:"+dataList.size()); |
| | | } |
| | | } |