| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.atm.AttributeDef; |
| | | import com.vci.corba.omd.stm.StatePool; |
| | | import com.vci.dto.OsAttributeDTO; |
| | | import com.vci.pagemodel.OsEnumVO; |
| | | import com.vci.po.OsAttributePO; |
| | | import com.vci.po.OsStatusPO; |
| | | import com.vci.starter.poi.bo.ReadExcelOption; |
| | | import com.vci.starter.poi.bo.WriteExcelData; |
| | | import com.vci.starter.poi.bo.WriteExcelOption; |
| | | import com.vci.starter.poi.constant.ExcelLangCodeConstant; |
| | | import com.vci.starter.poi.util.ExcelUtil; |
| | | import com.vci.starter.web.annotation.log.VciUnLog; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.BaseQueryObject; |
| | | import com.vci.starter.web.pagemodel.BaseResult; |
| | | import com.vci.starter.web.pagemodel.DataGrid; |
| | | import com.vci.starter.web.pagemodel.PageHelper; |
| | | import com.vci.starter.web.util.LangBaseUtil; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.util.VciDateUtil; |
| | | import com.vci.starter.web.util.*; |
| | | import com.vci.dto.OsStatusDTO; |
| | | import com.vci.model.OsStatusDO; |
| | | import com.vci.pagemodel.OsStatusVO; |
| | | import com.vci.starter.web.util.WebThreadLocalUtil; |
| | | import com.vci.web.service.OsLifeCycleServiceI; |
| | | import com.vci.web.service.OsStatusServiceI; |
| | | import com.vci.web.service.WebBoServiceI; |
| | |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.hssf.util.HSSFColor; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.swing.*; |
| | | import java.io.File; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; |
| | |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsLifeCycleServiceI lifeCycleService; |
| | | |
| | | /** |
| | | * å¿
å¡«å |
| | | */ |
| | | private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | | |
| | | /** |
| | | * å è½½èªèº« |
| | |
| | | throw WebUtil.getVciBaseException(e); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | statusDTO.getId(),"ç¶æçè±æåç§°", |
| | | statusDTO.getName(),"ç¶æç䏿åç§°" |
| | | ); |
| | | StatePool dbStatePool = platformClientUtil.getStatePoolService().getStatePool(statusDTO.getName()); |
| | | if (Func.isNotEmpty(dbStatePool) || Func.isNotBlank(dbStatePool.oid)) { |
| | | StatePool dbStatePool = platformClientUtil.getStatePoolService().getStatePool(statusDTO.getId()); |
| | | if (Func.isNotEmpty(dbStatePool) && Func.isNotBlank(dbStatePool.oid)) { |
| | | throw new PLException("500",new String[]{"åç§°éå¤è¯·æ´æ¢åç§°ï¼"}); |
| | | } |
| | | // ç¶ææ± åç§°åªè½ä¸ºè±æåæ¯ |
| | | String regex = "[a-z A-Z]*"; |
| | | if ((!dbStatePool.name.matches(regex))) { |
| | | if ((!statusDTO.getId().matches(regex))) { |
| | | throw new PLException("500",new String[]{"åç§°åªè½ä¸ºè±æï¼"}); |
| | | } |
| | | //è½ç¶ä¼èªå¨çæoidï¼ä½æ¯è¿å¿è®¾ç½®ä¸»é®ï¼é¿å
æ¾å
¥ç¼åçæ°æ®æ¯æ²¡æoidç |
| | | statusDTO.setOid(VciBaseUtil.getPk()); |
| | | StatePool pool = statusDTO2DO(statusDTO); |
| | | List<StatePool> poolList = new ArrayList<>(); |
| | | poolList.add(pool); |
| | | batchAddStatus(poolList); |
| | | //clearCache(); |
| | | self.selectAllStatusMap(); |
| | | return true; |
| | | statusDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | try { |
| | | boolean res = batchAddStatus(Arrays.asList(statusDTO2DO(statusDTO))); |
| | | self.selectAllStatusMap(); |
| | | return res; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | logger.error(e.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | StatePool pool = statusDTO2DO(statusDTO); |
| | | pool.creator = statusVO.getCreator(); |
| | | pool.createTime = VciDateUtil.getTime(statusVO.getCreateTime()); |
| | | List<StatePool> poolList = new ArrayList<>(); |
| | | poolList.add(pool); |
| | | batchEditSave(poolList); |
| | | clearCache(); |
| | | self.selectAllStatusMap(); |
| | | return true; |
| | | try { |
| | | boolean res = batchEditSave(Arrays.asList(pool)); |
| | | self.selectAllStatusMap(); |
| | | return res; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | logger.error(e.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å é¤ç¶æ |
| | | * @param oids ä¸»é® |
| | | * @param osStatusDTOS |
| | | */ |
| | | @Override |
| | | public boolean delete(String oids){ |
| | | VciBaseUtil.alertNotNull(oids,"主é®"); |
| | | //夿æ¯å¦è¢«å¼ç¨ |
| | | List<OsStatusVO> statusVOList1 = selectByOidCollection(VciBaseUtil.str2List(oids)); |
| | | if(statusVOList1.stream().anyMatch(statusVO -> lifeCycleService.checkStatusUsed(statusVO))){ |
| | | public boolean deleteStatus(List<OsStatusDTO> osStatusDTOS) throws PLException { |
| | | VciBaseUtil.alertNotNull(osStatusDTOS,"å¾
å é¤ç屿§å表"); |
| | | Set<String> oids = osStatusDTOS.stream().map(OsStatusDTO::getOid).collect(Collectors.toSet()); |
| | | List<OsStatusVO> osStatusVOList = selectByOidCollection(oids); |
| | | //夿æä¸¾æ¯å¦æè¢«å¼ç¨ |
| | | if(osStatusVOList.stream().anyMatch(statusVO -> lifeCycleService.checkStatusUsed(statusVO))){ |
| | | throw new VciBaseException("ç¶æå¨çå½å¨æä¸è¢«ä½¿ç¨ï¼ä¸è½å é¤"); |
| | | } |
| | | statusVOList1.stream().forEach(statusVO -> { |
| | | try { |
| | | platformClientUtil.getStatePoolService().deleteStatePool(statusVO2DO(statusVO)); |
| | | }catch (Throwable e){ |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); |
| | | //å¹³å°çdeleteStatusæ¹æ³å¿
ä¼ ä¸ä¸ªåæ°ï¼oidãnameåts |
| | | List<StatePool> statePoolList = new ArrayList<>(); |
| | | for(OsStatusDTO statusDTO : osStatusDTOS){ |
| | | //oidåtså¤ç©º |
| | | String oid = statusDTO.getOid(); |
| | | //name主è¦ç¨æ¥å¯¹ç¼åæ°æ®å é¤ |
| | | String name = statusDTO.getName(); |
| | | //åå°ä¼ç¨tsè¿è¡æ°æ®ä¸è´æ§æ ¡éª |
| | | Date ts = statusDTO.getTs(); |
| | | if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ |
| | | throw new PLException("500",new String[]{"å¾
å é¤çç¶æå表ä¸ä¸»é®ãoidããè°æ´æ¶é´ãtsããç¶æåç§°ãnameãä¸è½ä¸ºç©ºï¼"}); |
| | | } |
| | | }); |
| | | clearCache(); |
| | | StatePool statePool = new StatePool(); |
| | | statePool.oid = oid; |
| | | statePool.name = name; |
| | | statePool.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); |
| | | statePoolList.add(statePool); |
| | | boolean res = platformClientUtil.getStatePoolService().deleteStatePool(statePool); |
| | | if(!res){ |
| | | throw new PLException("500",new String[]{"å é¤ç¶æå称为ã" + name + "ãçæ°æ®æ¶åºç°é误!"}); |
| | | } |
| | | } |
| | | //clearCache(); |
| | | self.selectAllStatusMap(); |
| | | return true; |
| | | } |
| | |
| | | statePool.description = statusDTO.getDescription()==null?"":statusDTO.getDescription(); |
| | | String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | long now = VciDateUtil.getNowTime(); |
| | | statePool.creator = userId; |
| | | statePool.creator = Func.isBlank(statusDTO.getCreator()) ? userId:statusDTO.getCreator(); |
| | | statePool.createTime = now; |
| | | statePool.modifier = userId; |
| | | statePool.modifyTime = now; |
| | | statePool.ts = statusDTO.getTs()==null?VciDateUtil.getNowString(VciDateUtil.DateTimeMillFormat):VciDateUtil.date2Str(statusDTO.getTs(),VciDateUtil.DateTimeMillFormat); |
| | | statePool.tag = statusDTO.getName(); |
| | | return statePool; |
| | | } |
| | | |
| | | /** |
| | | * 导åºéä¸çç¶æ |
| | | * @param exportFileName 导åºçæä»¶å |
| | | * @param statusOids éè¦å¯¼åºç屿§åç§° |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportStatus(String exportFileName, String statusOids) throws PLException { |
| | | if(Func.isBlank(statusOids)){ |
| | | throw new PLException("500",new String[]{"请å¾éè¦å¯¼åºç屿§!"}); |
| | | } |
| | | //ç颿²¡ä¼ åç§°ï¼ä½¿ç¨é»è®¤å¯¼åºåç§° |
| | | exportFileName = Func.isBlank(exportFileName) ? "ç¶ææ± ç¶æå¯¼åº_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置åå |
| | | List<String> columns = new ArrayList<>(Arrays.asList("åç§°", "æ ç¾", "å¾ç", "æè¿°")); |
| | | |
| | | //åexcel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | | try { |
| | | new File(excelPath).createNewFile(); |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); |
| | | } |
| | | //设置å |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | //设置å头 |
| | | for (int index = 0; index < columns.size(); index++) { |
| | | excelDataList.add(new WriteExcelData(0,index, columns.get(index))); |
| | | } |
| | | //æç
§å±æ§åæ¥è¯¢å±æ§ï¼ç¶åå¤ç屿§å¯¼åº |
| | | List<String> statusOidList = Func.toStrList(statusOids); |
| | | AtomicInteger i = new AtomicInteger(1); |
| | | statusOidList.stream().forEach(oid->{ |
| | | OsStatusVO osStatusVO = this.getObjectByOid(oid); |
| | | excelDataList.add(new WriteExcelData(i.get(),0, osStatusVO.getId())); |
| | | excelDataList.add(new WriteExcelData(i.get(),1, osStatusVO.getName())); |
| | | excelDataList.add(new WriteExcelData(i.get(),2, osStatusVO.getImagePath())); |
| | | excelDataList.add(new WriteExcelData(i.get(),3, osStatusVO.getDescription())); |
| | | i.getAndIncrement(); |
| | | }); |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | return excelPath; |
| | | } |
| | | |
| | | /** |
| | | * ä¸è½½ç¶æå¯¼å
¥æ¨¡æ¿ |
| | | * @param exportFileName |
| | | * @return |
| | | * @throws PLException |
| | | */ |
| | | @Override |
| | | public String downloadStatusTemplate(String exportFileName) throws Exception { |
| | | //ç颿²¡ä¼ åç§°ï¼ä½¿ç¨é»è®¤å¯¼åºåç§° |
| | | exportFileName = Func.isBlank(exportFileName) ? "ç¶ææ± å¯¼å
¥æ¨¡æ¿_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置åå |
| | | List<String> columns = new ArrayList<>( |
| | | Arrays.asList("åç§°(ä¸è½ä¸ºç©º)", "æ ç¾(对åç§°çè§£é)","å¾ç(è·¯å¾)", "æè¿°(å¯ä»¥ä¸ºç©º)") |
| | | ); |
| | | //设置å¿
å¡«å |
| | | ColumnNameisRed.clear(); |
| | | ColumnNameisRed.add(0); |
| | | |
| | | //åexcel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | | try { |
| | | new File(excelPath).createNewFile(); |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); |
| | | } |
| | | //设置å |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | //设置å头 |
| | | for (int index = 0; index < columns.size(); index++) { |
| | | //夿æ¯å¦ä¸ºå¿
å¡«åï¼ç»å¿
å¡«å设置é¢è² |
| | | if(ColumnNameisRed.contains(index)){ |
| | | WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index)); |
| | | excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); |
| | | excelDataList.add(excelData); |
| | | }else{ |
| | | excelDataList.add(new WriteExcelData(0,index, columns.get(index))); |
| | | } |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | return excelPath; |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥ç¶æ |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseResult importStatus(File file) throws Exception { |
| | | VciBaseUtil.alertNotNull(file,"excelæä»¶"); |
| | | if(!file.exists()){ |
| | | throw new VciBaseException("导å
¥çexcelæä»¶ä¸åå¨,{0}",new String[]{file.getPath()}); |
| | | } |
| | | try{ |
| | | //1ã读åexcelä¸çæ°æ®ï¼ç»æå¯¹è±¡ |
| | | ReadExcelOption excelOption = new ReadExcelOption(); |
| | | List<OsStatusPO> poList = ExcelUtil.readDataObjectFromExcel(file, OsStatusPO.class,excelOption,(value, po, fieldName)->{}); |
| | | //å»é¤é½æ¯ç©ºçæ
åµ |
| | | if(CollectionUtils.isEmpty(poList)){ |
| | | return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); |
| | | } |
| | | //excelå¤éï¼æ°æ®æ ¡éªï¼dto对象转æ¢ï¼åå¨å¯¹è±¡è½¬æ¢ï¼æ§è¡ä¿å |
| | | List<StatePool> statePoolList = new ArrayList<>(); |
| | | //å½åexcel䏿¯å¦éå¤ç¨çå¤éMap:ï¼keyï¼å¤é屿§ï¼valueï¼è¡å·ï¼ |
| | | Map<String, String> excelReapeat = new HashMap<>(); |
| | | //夿å¿
填屿§æ¯å¦ä¸ºç©ºï¼ç¨æ·æ¯å¦å·²åå¨ï¼ä»¥åé¨é¨æ¯å¦å¡«éçæ ¡éªé»è¾ |
| | | poList.stream().forEach(osStatusPO -> { |
| | | try { |
| | | StatePool dbStatePool = platformClientUtil.getStatePoolService().getStatePool(osStatusPO.getId()); |
| | | if(Func.isNotEmpty(dbStatePool) && Func.isNotBlank(dbStatePool.oid)){ |
| | | throw new VciBaseException("第ã"+osStatusPO.getRowIndex()+"ãè¡ï¼åç§°å¨ç³»ç»ä¸å·²ç»åå¨,请修æ¹!"); |
| | | } |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | logger.error(e.getMessage()); |
| | | throw new VciBaseException(e.getMessage()); |
| | | } |
| | | if(Func.isBlank(osStatusPO.getId())){//屿§åå¤ç©º |
| | | throw new VciBaseException("第ã"+osStatusPO.getRowIndex()+"ãè¡ï¼enumnameerror"); |
| | | }else if(!osStatusPO.getId().matches("[a-z A-Z]*")){ |
| | | // ç¶ææ± åç§°åªè½ä¸ºè±æåæ¯ |
| | | throw new VciBaseException("åç§°åªè½ä¸ºè±æï¼"); |
| | | }else if(excelReapeat.containsKey(osStatusPO.getId())){//屿§åè¡¨æ ¼ä¸å¤é |
| | | throw new VciBaseException("第ã"+excelReapeat.get(osStatusPO.getId())+"ãè¡å第ã"+osStatusPO.getRowIndex()+"ãè¡æ°æ®ï¼åç§°éå¤"); |
| | | } |
| | | //ç¶æåexcelä¸å¤éå¤ç |
| | | excelReapeat.put(osStatusPO.getId(),osStatusPO.getRowIndex()); |
| | | OsStatusDTO osStatusDTO = new OsStatusDTO(); |
| | | osStatusDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | osStatusDTO.setId(osStatusPO.getId()); |
| | | osStatusDTO.setName(osStatusPO.getName()); |
| | | osStatusDTO.setImagePath(osStatusPO.getImagePath()); |
| | | osStatusDTO.setDescription(osStatusPO.getDescription()); |
| | | statePoolList.add(statusDTO2DO(osStatusDTO)); |
| | | |
| | | }); |
| | | //æ§è¡ä¿åæä½ |
| | | batchAddStatus(statePoolList); |
| | | }catch (Exception e){ |
| | | if(logger.isErrorEnabled()){ |
| | | logger.error("读åexcelå
å®¹æ¶æä¿åç¨æ·ä¿¡æ¯æ¶åºç°äºé误ï¼å
·ä½åå ï¼",VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | e.printStackTrace(); |
| | | return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); |
| | | } |
| | | return BaseResult.success("æä¸¾å¯¼å
¥æåï¼"); |
| | | } |
| | | |
| | | /** |
| | |
| | | statePool.tag = statusVO.getName(); |
| | | return statePool; |
| | | } |
| | | |
| | | |
| | | |
| | | } |