From 1b223b109ec65a2934e283bb0be2c0e116b013e4 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期二, 30 七月 2024 15:47:40 +0800 Subject: [PATCH] 状态池相关接口上传(已测试待联调) --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java | 1 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/VciOsStatusController.java | 103 ++++++++++ Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsStatusPO.java | 54 ++++++ Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java | 267 +++++++++++++++++++++++++---- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java | 29 +++ Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsAttributePO.java | 4 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsStatusServiceI.java | 31 +++ 7 files changed, 436 insertions(+), 53 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsAttributePO.java b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsAttributePO.java index 71aa533..d64806f 100644 --- a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsAttributePO.java +++ b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsAttributePO.java @@ -52,7 +52,7 @@ /** * 灞炴�х被鍨� */ - @ExcelColumn(value="灞炴�х被鍨�",nullable = false) + @ExcelColumn(value="灞炴�х被鍨�(璇峰弬鐓ф柊澧炵晫闈㈢殑灞炴�х被鍨嬪~鍐�)",nullable = false) private String attributeDataType; /** @@ -112,7 +112,7 @@ /** * 灞炴�ч暱搴� */ - @ExcelColumn(value="鍙栧�艰寖鍥�") + @ExcelColumn(value="鍙栧�艰寖鍥�)") private String range; } diff --git a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsStatusPO.java b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsStatusPO.java new file mode 100644 index 0000000..c443178 --- /dev/null +++ b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsStatusPO.java @@ -0,0 +1,54 @@ +package com.vci.po; + +import com.vci.starter.poi.annotation.ExcelColumn; +import com.vci.starter.web.pagemodel.BaseModelVO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 灞炴�ф睜瀵煎叆瀵硅薄 + * @author ludc + * @date 2024/7/19 11:11 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OsStatusPO extends BaseModelVO { + + /** + * 绂佹淇敼杩欎釜鍊� + */ + private static final long serialVersionUID = -2239512786206928201L; + + /** + * 鎵�鍦ㄦ暟鎹 + */ + @ExcelColumn(rowIndexColumn = true,value = "") + private String rowIndex; + + /** + * 灞炴�ц嫳鏂囧悕绉� + */ + @ExcelColumn(value="鍚嶇О(涓嶈兘涓虹┖)",nullable = false) + private String id; + + /** + * 鏍囩 + */ + @ExcelColumn(value="鏍囩(瀵瑰悕绉扮殑瑙i噴)") + private String name; + + /** + * 灞炴�х被鍨� + */ + @ExcelColumn(value="鍥剧墖(璺緞)") + private String imagePath; + + /** + * 鎻忚堪 + */ + @ExcelColumn(value="鎻忚堪(鍙互涓虹┖)") + private String description; + +} diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java index 6400b16..5d9a344 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java @@ -60,7 +60,6 @@ * @return 閾炬帴绫诲瀷鐨勬樉绀哄璞� */ @GetMapping("/getAllLtName") - @VciUnCheckRight public BaseResult getAllLtName(){ try { return BaseResult.dataList(linkTypeService.getAllLtName()); diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/VciOsStatusController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/VciOsStatusController.java index db761d4..2371ba8 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/VciOsStatusController.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/VciOsStatusController.java @@ -1,20 +1,33 @@ package com.vci.web.controller; +import com.vci.constant.FrameWorkLangCodeConstant; +import com.vci.dto.OsAttributeDTO; import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.annotation.log.VciBusinessLog; +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.dto.OsStatusDTO; import com.vci.pagemodel.OsLifeCycleVO; import com.vci.pagemodel.OsStatusVO; +import com.vci.starter.web.util.ControllerUtil; +import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.web.service.OsLifeCycleServiceI; import com.vci.web.service.OsStatusServiceI; +import com.vci.web.util.Func; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.List; /** * 鐘舵�佺殑鎺у埗鍣� @@ -87,7 +100,6 @@ * @return 鎵ц缁撴灉 */ @PostMapping("/addSave") - @VciUnCheckRight public BaseResult addSave(@RequestBody OsStatusDTO statusDTO){ try { return statusService.addSave(statusDTO) ? BaseResult.success("娣诲姞鐘舵�佹垚鍔燂紒"):BaseResult.fail("娣诲姞鐘舵�佸け璐ワ紒"); @@ -118,13 +130,19 @@ /** * 鍒犻櫎鐘舵�� - * @param oids 鐘舵�佺殑涓婚敭 + * @param osStatusDTOS 鐘舵�佺殑DTO瀵硅薄 * @return 鎵ц缁撴灉 */ - @DeleteMapping("/delete") - public BaseResult delete(String oids){ - statusService.delete(oids); - return BaseResult.success(); + @DeleteMapping("/deleteStatus") + public BaseResult deleteStatus(@RequestBody List<OsStatusDTO> osStatusDTOS){ + try { + return statusService.deleteStatus(osStatusDTOS) ? BaseResult.success("鍒犻櫎鐘舵�佹垚鍔燂紒"):BaseResult.fail("鍒犻櫎鐘舵�佸け璐ワ紒"); + }catch (Exception e) { + e.printStackTrace(); + String exceptionMessage = "鍒犻櫎鐘舵�佹椂鍑虹幇閿欒锛屽師鍥狅細" + VciBaseUtil.getExceptionMessage(e); + logger.error(exceptionMessage); + return BaseResult.fail(exceptionMessage); + } } /** @@ -137,4 +155,75 @@ return BaseResult.success(statusService.getObjectByOid(oid)); } + /** + * 瀵煎嚭鐘舵�� + * @param exportFileName + * @param statusOids + * @param response + */ + @GetMapping( "/exportStatus") + @VciBusinessLog(operateName = "瀵煎嚭鐘舵��") + public void exportStatus(String exportFileName,String statusOids, HttpServletResponse response){ + try { + String excelPath = statusService.exportStatus(exportFileName,statusOids); + ControllerUtil.writeFileToResponse(response,excelPath); + } catch (Exception e) { + String msg = "瀵煎嚭鐘舵�佹椂鍑虹幇閿欒锛屽師鍥狅細" + VciBaseUtil.getExceptionMessage(e); + try { + //鍑洪敊鏃� + e.printStackTrace(); + ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } + + /** + * 涓嬭浇鐘舵�佸鍏ユā鏉� + * @param exportFileName + * @param response + */ + @GetMapping( "/downloadStatusTemplate") + @VciBusinessLog(operateName = "瀵煎嚭鐘舵��") + public void downloadStatusTemplate(String exportFileName, HttpServletResponse response){ + try { + String excelPath = statusService.downloadStatusTemplate(exportFileName); + ControllerUtil.writeFileToResponse(response,excelPath); + } catch (Exception e) { + String msg = "涓嬭浇鏋氫妇瀵煎叆妯℃澘鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e); + try { + //鍑洪敊鏃� + e.printStackTrace(); + ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } + + /** + * 瀵煎叆鐘舵�� + * @param file + * @return + */ + @PostMapping("/importStatus") + @VciBusinessLog(operateName = "瀵煎叆鐘舵��") + public BaseResult importStatus(MultipartFile file){ + String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); + File file1 = new File(excelFileName); + try { + file.transferTo(new File(excelFileName)); + if (file != null) { + return statusService.importStatus(file1); + } else { + return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"}); + } + }catch (Throwable e) { + throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e); + }finally { + file1.delete(); + } + } + } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsStatusServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsStatusServiceI.java index 823735a..4b1b4a7 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsStatusServiceI.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsStatusServiceI.java @@ -1,11 +1,14 @@ package com.vci.web.service; +import com.vci.corba.common.PLException; import com.vci.corba.omd.stm.StatePool; +import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.DataGrid; import com.vci.starter.web.pagemodel.PageHelper; import com.vci.dto.OsStatusDTO; import com.vci.pagemodel.OsStatusVO; +import java.io.File; import java.util.Collection; import java.util.List; import java.util.Map; @@ -98,9 +101,9 @@ /** * 鍒犻櫎鐘舵�� - * @param oids 涓婚敭 + * @param osStatusDTOS */ - boolean delete(String oids); + boolean deleteStatus(List<OsStatusDTO> osStatusDTOS) throws PLException; /** * 鐘舵�佺殑鏁版嵁浼犺緭瀵硅薄杞崲涓烘暟鎹璞� @@ -108,4 +111,28 @@ * @return 骞冲彴鐨勬暟鎹璞� */ StatePool statusDTO2DO(OsStatusDTO statusDTO); + + /** + * 瀵煎嚭閫変腑鐨勭姸鎬� + * @param exportFileName 瀵煎嚭鐨勬枃浠跺悕 + * @param statusOids 闇�瑕佸鍑虹殑灞炴�у悕绉� + * @return + */ + String exportStatus(String exportFileName,String statusOids) throws PLException; + + /** + * 涓嬭浇鐘舵�佸鍏ユā鏉� + * @param exportFileName + * @return + * @throws PLException + */ + String downloadStatusTemplate(String exportFileName) throws Exception; + + /** + * 瀵煎叆鐘舵�� + * @param file + * @return + */ + BaseResult importStatus(File file) throws Exception; + } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java index 7a4ac81..8b6c442 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java @@ -33,6 +33,7 @@ import com.vci.web.properties.UsedNames; import com.vci.web.service.OsAttributeServiceI; import com.vci.web.service.OsBaseServiceI; +import com.vci.web.service.OsEnumServiceI; import com.vci.web.service.OsLinkTypeServiceI; import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; @@ -111,6 +112,13 @@ @Autowired(required = false) @Lazy private OsBtmServiceImpl osBtmService; + + /** + * 鏋氫妇鐨勬湇鍔� + */ + @Autowired + @Lazy + private OsEnumServiceI enumService; /** * 蹇呭~鍒� @@ -600,6 +608,7 @@ if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){ //鍙傜収閾炬帴绫诲瀷 sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";"); + sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).append(";"); } sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { @@ -812,7 +821,7 @@ if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ throw new PLException("500",new String[]{"寰呭垹闄ょ殑灞炴�у垪琛ㄤ腑涓婚敭銆恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佸睘鎬у悕銆恘ame銆戜笉鑳戒负绌猴紒"}); } - //鍒ゆ柇鏋氫妇鏄惁鏈夎寮曠敤 + //鍒ゆ柇灞炴�ф槸鍚︽湁琚紩鐢� List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name); if(Func.isNotEmpty(usedAttrList)){ throw new PLException("500",new String[]{"鍒犻櫎鐨勫睘鎬т腑锛屽睘鎬у悕绉颁负锛氥��" + name + "銆�,宸茶寮曠敤锛�"}); @@ -934,7 +943,7 @@ //璁剧疆鍒楀悕 List<String> columns = new ArrayList<>( Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪", - "灞炴�х被鍨�", "鍏佽涓虹┖(鏄�/鍚�)", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�", "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", + "灞炴�х被鍨�(璇峰弬鐓ф柊澧炵晫闈㈢殑灞炴�х被鍨嬪~鍐�)", "鍏佽涓虹┖(鏄�/鍚�)", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�", "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", "鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�") ); //璁剧疆蹇呭~鍒� @@ -1010,6 +1019,22 @@ //灞炴�у悕excel涓垽閲嶅鐞� excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex()); OsAttributeDTO osAttributeDTO = new OsAttributeDTO(); + //鏌ヨ鏋氫妇鏄惁瀛樺湪锛屽~鍐欎簡鏋氫妇浣嗘病濉啓鍙栧�艰寖鍥达紝杩欐椂鍊欑洿鎺ヤ娇鐢ㄦ灇涓鹃」鍊间綔涓洪粯璁ょ殑range + if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){ + try { + OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId()); + if(Func.isEmpty(enumVO)){ + throw new VciBaseException("绗��" + osAttributePO.getRowIndex() + "銆戣鏁版嵁,閫氳繃鏋氫妇鍚嶇О銆�" + osAttributePO.getEnumId() + + "銆戞湭鑾峰彇鍒版灇涓句俊鎭�!"); + } + String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";")); + osAttributeDTO.setRange(itemValues); + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException("鏋氫妇鏌ヨ澶辫触锛屽師鍥狅細"+e.getMessage()); + } + osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId()); + } osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); osAttributeDTO.setId(osAttributePO.getId()); osAttributeDTO.setName(osAttributePO.getName()); diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java index 7bae860..033c3f4 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsStatusServiceImpl.java @@ -1,19 +1,27 @@ 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; @@ -21,6 +29,7 @@ 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; @@ -28,8 +37,9 @@ 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; @@ -66,6 +76,11 @@ @Autowired(required = false) @Lazy private OsLifeCycleServiceI lifeCycleService; + + /** + * 蹇呭~鍒� + */ + private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); /** * 鍔犺浇鑷韩 @@ -182,8 +197,9 @@ throw WebUtil.getVciBaseException(e); } } + return true; } - return true; + return false; } /** @@ -267,24 +283,26 @@ 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[]{"鍚嶇О鍙兘涓鸿嫳鏂囷紒"}); } //铏界劧浼氳嚜鍔ㄧ敓鎴恛id锛屼絾鏄繖鍎胯缃富閿紝閬垮厤鏀惧叆缂撳瓨鐨勬暟鎹槸娌℃湁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; + } } /** @@ -304,34 +322,53 @@ 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); + //骞冲彴鐨刣eleteStatus鏂规硶蹇呬紶涓変釜鍙傛暟锛宱id銆乶ame鍜宼s + List<StatePool> statePoolList = new ArrayList<>(); + for(OsStatusDTO statusDTO : osStatusDTOS){ + //oid鍜宼s鍒ょ┖ + 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[]{"寰呭垹闄ょ殑鐘舵�佸垪琛ㄤ腑涓婚敭銆恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佺姸鎬佸悕绉般�恘ame銆戜笉鑳戒负绌猴紒"}); } - }); - 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; } @@ -351,13 +388,167 @@ 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("鍚嶇О", "鏍囩", "鍥剧墖", "鎻忚堪")); + + //鍐檈xcel + 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("鍚嶇О(涓嶈兘涓虹┖)", "鏍囩(瀵瑰悕绉扮殑瑙i噴)","鍥剧墖(璺緞)", "鎻忚堪(鍙互涓虹┖)") + ); + //璁剧疆蹇呭~鍒� + ColumnNameisRed.clear(); + ColumnNameisRed.add(0); + + //鍐檈xcel + 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("瀵煎叆鐨別xcel鏂囦欢涓嶅瓨鍦�,{0}",new String[]{file.getPath()}); + } + try{ + //1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞� + 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涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝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()+"銆戣锛宔numnameerror"); + }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("鏋氫妇瀵煎叆鎴愬姛锛�"); } /** @@ -381,7 +572,5 @@ statePool.tag = statusVO.getName(); return statePool; } - - } -- Gitblit v1.9.3