diff --git a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/entity/WtSpBasicEntity.java b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/entity/WtSpBasicEntity.java index 82c550c..c77f508 100644 --- a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/entity/WtSpBasicEntity.java +++ b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/entity/WtSpBasicEntity.java @@ -1,5 +1,7 @@ package com.hnac.hzims.spare.entity; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; @@ -20,6 +22,7 @@ import java.math.BigDecimal; @Data @TableName("WT_SP_BASIC") @EqualsAndHashCode(callSuper = true) +@ExcelIgnoreUnannotated @ApiModel(value = "WtSpBasic对象", description = "") public class WtSpBasicEntity extends TenantEntity { @@ -33,52 +36,63 @@ public class WtSpBasicEntity extends TenantEntity { /** * 名称 */ + @ExcelProperty(value = "物品名称(必填)",index = 1 ) @ApiModelProperty(value = "名称") private String name; /** * 编码 */ + @ExcelProperty(value = "物品编码(必填)",index = 0 ) @ApiModelProperty(value = "编码") private String code; /** * 规格 */ + @ExcelProperty(value = "规格型号",index = 2 ) @ApiModelProperty(value = "规格") private String specifications; /** * 品牌 */ + @ExcelProperty(value = "物品品牌(必填)",index = 3 ) @ApiModelProperty(value = "品牌") private String brand; /** * 单位 */ + @ExcelProperty(value = "物品单位(必填)",index = 5 ) @ApiModelProperty(value = "单位") private String unit; /** * 单价 */ + @ExcelProperty(value = "单价(元)(必填)",index = 10) @ApiModelProperty(value = "单价") @JsonSerialize(nullsUsing = NullSerializer.class) private BigDecimal price; + @ExcelProperty(value = "重量(kg)",index = 6 ) @ApiModelProperty(value = "重量") @JsonSerialize(nullsUsing = NullSerializer.class) private BigDecimal weight; + @ExcelProperty(value = "库存上限(必填)",index = 7 ) @ApiModelProperty(value = "库存上限") @JsonSerialize(nullsUsing = NullSerializer.class) private Integer upperLimit; + @ExcelProperty(value = "库存下限(必填)",index = 8 ) @ApiModelProperty(value = "库存下限") @JsonSerialize(nullsUsing = NullSerializer.class) private Integer lowerLimit; + @ExcelProperty(value = "是否回收废品(必填)",index = 9 ) @ApiModelProperty(value = "是否回收废品") private String isWaste; /** * 主要参数 */ + @ExcelProperty(value = "物品类别代码(必填)",index = 4 ) @ApiModelProperty(value = "主要参数") private String parameter; /** diff --git a/hzims-service/assets/pom.xml b/hzims-service/assets/pom.xml index 7a4a75d..80a5994 100644 --- a/hzims-service/assets/pom.xml +++ b/hzims-service/assets/pom.xml @@ -64,6 +64,10 @@ message-api compile + + cn.afterturn + easypoi-base + diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java index 02bf825..bcb74c0 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java @@ -12,8 +12,6 @@ import com.hnac.hzims.spare.entity.WtSpBasicEntity; import com.hnac.hzims.spare.service.IWtSpBasicService; import com.hnac.hzims.spare.service.IWtSpManagementService; import com.hnac.hzims.spare.vo.WtSpBasicVO; -import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; -import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; import io.swagger.annotations.*; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; @@ -28,8 +26,10 @@ import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.List; import java.util.Map; @@ -128,13 +128,12 @@ public class WtSpBasicController extends BladeController { @ApiOperation(value = "新增", notes = "传入SP_BASIC") public R save(@Valid @RequestBody WtSpBasicEntity SP_BASIC) { List wtSpBasicEntityList = SP_BASICService.list(Wrappers.lambdaQuery() - .eq(WtSpBasicEntity::getCode, SP_BASIC.getCode())); + .eq(WtSpBasicEntity::getCode, SP_BASIC.getCode())); Assert.isTrue(CollectionUtil.isEmpty(wtSpBasicEntityList),()->{ throw new ServiceException("物资台账物品编码不能重复,保存失败!"); }); return R.status(SP_BASICService.save(SP_BASIC)); } - /** * 修改 代码自定义代号 */ @@ -174,4 +173,26 @@ public class WtSpBasicController extends BladeController { return R.status(SP_BASICService.deleteLogic(Func.toLongList(ids))); } + /** + * 库存填写模板导出 + * @param response + */ + @ApiOperationSupport(order = 8) + @ApiOperation(value = "库存填写模板导出", notes = "库存填写模板导出") + @RequestMapping(value = "/writeTemplateDownload", method = {RequestMethod.GET, RequestMethod.POST}) + public void writeTemplateDownload(HttpServletResponse response) { + SP_BASICService.writeTemplateDownload(response); + } + + /** + * 导入数据 + */ + @ApiOperationSupport(order = 9) + @ApiOperation(value = "导入台账填写Excel") + @RequestMapping(value = "/importExcel", method = {RequestMethod.POST}) + public R importExcel( @RequestParam MultipartFile file) throws Exception { + System.out.println(11); + return SP_BASICService.importExcel(file); + } + } diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java index ab6d8a1..64fcef5 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java @@ -7,7 +7,10 @@ import com.hnac.hzims.spare.entity.WtSpBasicEntity; import com.hnac.hzims.spare.vo.WtSpBasicVO; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -63,6 +66,14 @@ public interface IWtSpBasicService extends BaseService { List stockDetail(Long spBasicId); /** + * 库存填写模板导出 + * @param response + */ + void writeTemplateDownload(HttpServletResponse response); + + R importExcel(MultipartFile file) throws Exception; + + /** * 获取流程中的用户 * @param deptId * @param role diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java index 634f885..53cc782 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java @@ -1,6 +1,15 @@ package com.hnac.hzims.spare.service.impl; -import com.alibaba.excel.util.DateUtils; +import cn.afterturn.easypoi.excel.entity.ImportParams; +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -16,29 +25,43 @@ import com.hnac.hzims.spare.service.IWtSpBasicService; import com.hnac.hzims.spare.service.IWtSpManagementService; import com.hnac.hzims.spare.service.IWtSpTotalService; import com.hnac.hzims.spare.service.IWtSpWarehouseService; +import com.hnac.hzims.spare.utils.ExcelToolListener; +import com.hnac.hzims.spare.utils.SheetWriteStyleHandler; import com.hnac.hzims.spare.vo.WtSpBasicVO; import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springblade.core.launch.constant.FlowConstant; +import org.springblade.core.excel.support.ExcelException; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; import java.util.*; +import java.util.stream.Collectors; + +import static com.hnac.hzims.spare.utils.ExcelUtil.asyncReadModel; /** * 服务实现类 @@ -66,10 +89,11 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl voList = new ArrayList<>(); IPage voPages = new Page<>(); - if(Func.isNotEmpty(spBasicEntity.getName()) && "工具".equals(spBasicEntity.getName())){ + if (Func.isNotEmpty(spBasicEntity.getName()) && "工具".equals(spBasicEntity.getName())) { // if(Func.isNotEmpty(spBasicEntity.getName())){ - List list = managementService.list(Wrappers.query().lambda(). - eq(WtSpManagementEntity::getName,spBasicEntity.getName())); - if(list.size()==0){ + List list = managementService.list(Wrappers.query().lambda(). + eq(WtSpManagementEntity::getName, spBasicEntity.getName())); + if (list.size() == 0) { return null; } List result = managementService.list(Wrappers.query().lambda().like(WtSpManagementEntity::getAncestors, list.get(0).getId())); List longList = new ArrayList<>(); - if(result.size()>0){ + if (result.size() > 0) { for (int i = 0; i < result.size(); i++) { longList.add(result.get(i).getId()); } } - if(longList.size() >0){ + if (longList.size() > 0) { queryWrapper.lambda().in(WtSpBasicEntity::getManagementId, longList); - }else{ + } else { return voPages; } spBasicEntity.setName(null); @@ -173,63 +197,63 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl pages = super.page(Condition.getPage(query), queryWrapper); for (int i = 0; i < pages.getRecords().size(); i++) { - if(null == warehouseId ){ + if (null == warehouseId) { WtSpBasicVO basicVO = new WtSpBasicVO(); WtSpBasicEntity basicEntity = pages.getRecords().get(i); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); - if(null!=managementEntity){ + if (null != managementEntity) { basicVO.setSparePartsName(managementEntity.getName()); } List totalList = totalService.list(Wrappers.query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); - if(totalList.size() >0){ + if (totalList.size() > 0) { basicVO.setStock(totalList.get(0).getStock()); - }else{ + } else { basicVO.setStock(0L); } - BeanUtils.copyProperties(basicEntity,basicVO); + BeanUtils.copyProperties(basicEntity, basicVO); - List ticketVOS = ticketInfoAllClient.getTicketStatistic("2022-02"); + List ticketVOS = ticketInfoAllClient.getTicketStatistic("2022-02"); // R deptR = sysClient.getDept(basicEntity.getWaterPlantId()); // if(Func.isNotEmpty(deptR.getData())){ // basicVO.setWaterPlantName(deptR.getData().getDeptName()); // } voList.add(basicVO); - }else{ + } else { WtSpBasicVO basicVO = new WtSpBasicVO(); WtSpBasicEntity basicEntity = pages.getRecords().get(i); - Map params = new HashMap<>(); - params.put("spBasicId",basicEntity.getId()); - params.put("warehouseId",warehouseId); + Map params = new HashMap<>(); + params.put("spBasicId", basicEntity.getId()); + params.put("warehouseId", warehouseId); WtSpTotalEntity totalEntity = totalMapper.selectByBasicId(params); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); - if(null!=managementEntity){ + if (null != managementEntity) { basicVO.setSparePartsName(managementEntity.getName()); } - if(null!=totalEntity){ + if (null != totalEntity) { List totalList = totalService.list(Wrappers.query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); - if(totalList.size() >0){ + if (totalList.size() > 0) { // basicVO.setStock(totalList.get(0).getStock()); basicVO.setStock(totalEntity.getStock()); - }else{ + } else { basicVO.setStock(0L); } - BeanUtils.copyProperties(basicEntity,basicVO); + BeanUtils.copyProperties(basicEntity, basicVO); // R deptR = sysClient.getDept(basicEntity.getWaterPlantId()); // if(Func.isNotEmpty(deptR.getData())){ // basicVO.setWaterPlantName(deptR.getData().getDeptName()); // } voList.add(basicVO); } - List totalEntities = totalMapper.selectByWarehouseId(warehouseId); - pages.setTotal(totalEntities.size()); + List totalEntities = totalMapper.selectByWarehouseId(warehouseId); + pages.setTotal(totalEntities.size()); } } voPages.setRecords(voList); - if (Func.isNotEmpty(sign)){ + if (Func.isNotEmpty(sign)) { voPages.setTotal(pages.getTotal()); - }else { + } else { if (null == warehouseId) { voPages.setTotal(pages.getTotal()); } else { @@ -243,7 +267,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl params) { + public Integer selectTotal(Map params) { return baseMapper.selectTotal(params); } @@ -251,7 +275,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl getBasicList(String tenantId) { WtSpBasicEntity spBasicEntity = new WtSpBasicEntity(); spBasicEntity.setTenantId(tenantId); - QueryWrapper queryWrapper = Condition.getQueryWrapper(spBasicEntity); + QueryWrapper queryWrapper = Condition.getQueryWrapper(spBasicEntity); List list = super.list(queryWrapper); return list; } @@ -274,7 +298,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl stockList(WtSpBasicEntity spBasicEntity, Query query) { WtSpBasicEntity entity = new WtSpBasicEntity(); - if(Func.isNotEmpty(spBasicEntity.getCode())){ + if (Func.isNotEmpty(spBasicEntity.getCode())) { entity.setCode(spBasicEntity.getCode()); } QueryWrapper queryWrapper = Condition.getQueryWrapper(entity); @@ -286,23 +310,23 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl typeList = new ArrayList<>(); - if(null!= spBasicEntity.getManagementId()){ + if (null != spBasicEntity.getManagementId()) { List managementEntityList = managementMapper.selectList(Wrappers.query().lambda().like(WtSpManagementEntity::getAncestors, spBasicEntity.getManagementId())); for (int i = 0; i < managementEntityList.size(); i++) { typeList.add(managementEntityList.get(i).getId()); } typeList.add(spBasicEntity.getManagementId()); } - if(typeList.size()>0){ - queryWrapper.lambda().in(WtSpBasicEntity::getManagementId,typeList); + if (typeList.size() > 0) { + queryWrapper.lambda().in(WtSpBasicEntity::getManagementId, typeList); } IPage pages = super.page(Condition.getPage(query), queryWrapper); List voList = new ArrayList<>(); IPage voPages = new Page<>(); List warehouseList = wtSpWarehouseService.list(Wrappers.query().lambda(). - in(WtSpWarehouseEntity::getAffiliatedUnit,Func.toLongList(String.valueOf(waterPlantId)))); + in(WtSpWarehouseEntity::getAffiliatedUnit, Func.toLongList(String.valueOf(waterPlantId)))); List longList = new ArrayList<>(); for (int i = 0; i < warehouseList.size(); i++) { longList.add(warehouseList.get(i).getId()); @@ -310,14 +334,14 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl0){ + if (longList.size() > 0) { List totalList = totalService.list(Wrappers.query().lambda() - .eq(WtSpTotalEntity::getSpBasicId,basicEntity.getId()) - .in(WtSpTotalEntity::getWarehouseId,longList)); - if(totalList.size() >0){ + .eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId()) + .in(WtSpTotalEntity::getWarehouseId, longList)); + if (totalList.size() > 0) { SpTemporaryStockEntity stockEntity = new SpTemporaryStockEntity(); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); - if(null!=managementEntity){ + if (null != managementEntity) { stockEntity.setManagementId(managementEntity.getId()); stockEntity.setSparePartsName(managementEntity.getName()); } @@ -327,21 +351,21 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl deptR = sysClient.getDept(basicEntity.getCreateDept()); - if(Func.isNotEmpty(deptR.getData())){ + R deptR = sysClient.getDept(basicEntity.getCreateDept()); + if (Func.isNotEmpty(deptR.getData())) { stockEntity.setWaterPlantName(deptR.getData().getDeptName()); } stockEntity.setQuantity(totalList.get(0).getStock().intValue()); stockEntity.setWarehouseId(totalList.get(0).getWarehouseId()); WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.getById(totalList.get(0).getWarehouseId()); - if(null != wtSpWarehouseEntity){ + if (null != wtSpWarehouseEntity) { stockEntity.setWarehouseName(wtSpWarehouseEntity.getName()); } //查询出库数量 Integer deliveryQuantity = totalMapper.getListByBasicId(basicEntity.getId()); - if(null !=deliveryQuantity){ + if (null != deliveryQuantity) { stockEntity.setDeliveryQuantity(deliveryQuantity); - }else{ + } else { stockEntity.setDeliveryQuantity(0); } //查询工单消耗数量 @@ -356,13 +380,13 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl data = new ArrayList<>(); + data.add(wtSpBasicEntity); + List list = wtSpManagementMapper.findAll(AuthUtil.getTenantId()); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 + String fileName = URLEncoder.encode("库存填写模板", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + //ExcelWriter初始化 + ExcelWriter excelWriter = EasyExcel + .write(response.getOutputStream()) + .autoCloseStream(Boolean.TRUE) + .registerConverter(new LongStringConverter()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + Set excludeColumnFiledNames = new HashSet(); + excludeColumnFiledNames.add("managementId"); + excludeColumnFiledNames.add("remarks"); + excludeColumnFiledNames.add("codeNumber"); + excludeColumnFiledNames.add("tenantId"); + excludeColumnFiledNames.add("id"); + excludeColumnFiledNames.add("createUser"); + excludeColumnFiledNames.add("createDept"); + excludeColumnFiledNames.add("createTime"); + excludeColumnFiledNames.add("updateUser"); + excludeColumnFiledNames.add("updateTime"); + excludeColumnFiledNames.add("status"); + excludeColumnFiledNames.add("isDeleted"); + WriteSheet writeSheet = EasyExcel.writerSheet(1, "库存台账表头模板").head(WtSpBasicEntity.class).registerWriteHandler(new SheetWriteStyleHandler()).excludeColumnFiledNames(excludeColumnFiledNames).build(); + excelWriter.write(data, writeSheet); + WriteSheet writeSheet2 = EasyExcel.writerSheet(2, "物品类别代码").head(WtSpManagementeExcelEntity.class).build(); + excelWriter.write(list, writeSheet2); + excelWriter.finish(); +// // 这里需要设置不关闭流 +// EasyExcel.write(response.getOutputStream(), WtSpBasicEntity.class).autoCloseStream(Boolean.TRUE).sheet(1,"库存台账表头模板") +// .head(WtSpBasicEntity.class) +// .registerWriteHandler(new SheetWriteStyleHandler()); +//// .doWrite(data); +// EasyExcel.write(response.getOutputStream(), WtSpManagementeExcelEntity.class).autoCloseStream(Boolean.TRUE).sheet(2,"库存填写模板") +// .doWrite(list); +// response.getOutputStream().close(); + } catch (Exception e) { + System.out.println("exportExcel = " + e.toString()); + // 重置response + response.reset(); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + Map map = new HashMap<>(); + map.put("success", "false"); + map.put("msg", "库存填写模板导出失败" + e.getMessage()); + try { + response.getWriter().println(JSONUtils.toJSONString(map)); + } catch (IOException e3) { + throw new ServiceException("发生异常 :" + e.toString()); + } + } + } + + + @Transactional(rollbackFor = Exception.class) + @Override + public R importExcel(MultipartFile file) throws Exception { + ImportParams params = new ImportParams(); + params.setHeadRows(2); + List list = wtSpManagementMapper.findAll(AuthUtil.getTenantId()); + List codeList = list.stream().map(s -> s.getOneCode()).collect(Collectors.toList()); + List twoCodeList = list.stream().map(s -> s.getTwoCode()).collect(Collectors.toList()); + codeList.addAll(twoCodeList); + String filename = file.getOriginalFilename(); + ExcelToolListener excelToolListener = new ExcelToolListener(); + if (org.springframework.util.StringUtils.isEmpty(filename)) { + throw new ExcelException("请上传文件!"); + } else if (!org.springframework.util.StringUtils.endsWithIgnoreCase(filename, ".xls") && !org.springframework.util.StringUtils.endsWithIgnoreCase(filename, ".xlsx")) { + throw new ExcelException("请上传正确的excel文件!"); + } else { + try { + InputStream inputStream = file.getInputStream(); + asyncReadModel(inputStream, excelToolListener, WtSpBasicEntity.class, 0, 1); + } catch (IOException e) { + e.printStackTrace(); + } + } + List entityList = excelToolListener.getDataList(); + List data = new ArrayList<>(); + data = JSONArray.parseArray(JSON.toJSONString(entityList), WtSpBasicEntity.class).stream() + .filter(entity -> Func.isNotEmpty(entity.getName())).collect(Collectors.toList()); + Assert.isTrue(CollectionUtil.isNotEmpty(data), () -> { + throw new ServiceException("填入工器具编码不能为空"); + }); +// List data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params); +// List data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params); + + + try { + for (WtSpBasicEntity libraryExcel : data) { + Integer counter = 2; + //数据校验 + R r = this.validExcel(libraryExcel, codeList, counter); + if (r == null && r.getCode() == 500) { + return r; + } + } + boolean flag = this.saveBatch(data); + return R.status(flag); + } catch (Exception ex) { + throw new RuntimeException( ex); +// String.format("导入数据异常!"), + } + + } + + private InputStream copyStream(InputStream source) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len; + while ((len = source.read(buffer)) > -1) { + baos.write(buffer, 0, len); + } + baos.flush(); + return new ByteArrayInputStream(baos.toByteArray()); + } + + /** + * 校验Excel数据 + **/ + private R validExcel(WtSpBasicEntity libraryExcel, List list, Integer counter) { + List errors = new ArrayList<>(); + //数据库操作 + List wtSpBasicEntityList = this.list(Wrappers.lambdaQuery() + .eq(WtSpBasicEntity::getCode, libraryExcel.getCode())); + Assert.isTrue(CollectionUtil.isEmpty(wtSpBasicEntityList), () -> { + throw new ServiceException("物资台账物品编码不能重复,保存失败!"); + }); + + if (StringUtils.isBlank(libraryExcel.getCode())) { + errors.add("物品编码不能为空"); + } + if (StringUtils.isBlank(libraryExcel.getName())) { + errors.add("物品名称不能为空"); + } + if (StringUtils.isBlank(libraryExcel.getBrand())) { + errors.add("物品品牌不能为空"); + } + if (StringUtils.isBlank(libraryExcel.getSpecifications())) { + errors.add("规格型号不能为空"); + } + if (StringUtils.isBlank(libraryExcel.getParameter())) { + errors.add("物品类别代码不能为空"); + } else { + if (!list.contains(libraryExcel.getParameter())) { + errors.add("物品类别代码不规范"); + } else { + //物品类别代码规范的情况下,把managerID写入 + WtSpManagementEntity wtSpManagementeExcelEntity = wtSpManagementMapper.selectOne(new LambdaQueryWrapper() {{ + eq(WtSpManagementEntity::getCode, libraryExcel.getParameter()); + }}); + libraryExcel.setManagementId(wtSpManagementeExcelEntity.getId()); + libraryExcel.setParameter(null); + } + } + if (StringUtils.isBlank(libraryExcel.getUnit())) { + errors.add("物品单位不能为空"); + } + if (ObjectUtil.isEmpty(libraryExcel.getUpperLimit()) && libraryExcel.getUpperLimit() < 0) { + errors.add("库存上限不能为空"); + } + if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) && libraryExcel.getLowerLimit() < 0) { + errors.add("库存下限不能为空"); + } + if (ObjectUtil.isEmpty(libraryExcel.getLowerLimit()) && ObjectUtil.isEmpty(libraryExcel.getLowerLimit())) { + if (libraryExcel.getLowerLimit() > libraryExcel.getLowerLimit()) { + errors.add("库存下限不能大于库存上限"); + } + } + if (StringUtils.isBlank(libraryExcel.getIsWaste())) { + errors.add("回收废品不能为空"); + } + if (ObjectUtil.isEmpty(libraryExcel.getPrice())) { + errors.add("单价不能为空"); + } + counter++; + if (CollectionUtils.isEmpty(errors)) { + return R.success("OK"); + } else { + return R.data(500, errors, String.format("第%s行导入异常", counter)); + } + } + // @Override // public String getTaskUser(Long deptId, String role, String tenantId) { // R> userR = userClient.userByDeptAndRole(deptId, role, tenantId); diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelToolListener.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelToolListener.java new file mode 100644 index 0000000..6dfa6df --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelToolListener.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.spare.utils; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Slf4j +@Data +public class ExcelToolListener extends AnalysisEventListener { + + /**保存数据**/ + private List dataList = Collections.synchronizedList(new ArrayList<>()); + + public ExcelToolListener() { + } + + @Override + public void invoke(Object data, AnalysisContext context) { + dataList.add(data); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + log.info("解析完成"); + log.info("------结果集为:{}------", JSONObject.toJSONString(dataList)); + } +} diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelUtil.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelUtil.java new file mode 100644 index 0000000..6e8989f --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelUtil.java @@ -0,0 +1,347 @@ +package com.hnac.hzims.spare.utils; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.write.handler.WriteHandler; +import org.apache.poi.ss.formula.functions.T; + +import java.io.File; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author hx + */ +public class ExcelUtil { + /** + * 同步无模型读(默认读取sheet0,从第2行开始读) + * @param filePath + * @return + */ + public static List> syncRead(String filePath){ + return EasyExcelFactory.read(filePath).sheet().doReadSync(); + } + + /** + * 同步无模型读(默认表头占一行,从第2行开始读) + * @param filePath + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static List> syncRead(String filePath, Integer sheetNo){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param inputStream + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(InputStream inputStream, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(inputStream).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param file + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(File file, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(file).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param filePath + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(String filePath, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步按模型读(默认读取sheet0,从第2行开始读) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @return + */ + public static List syncReadModel(String filePath, Class clazz){ + return EasyExcelFactory.read(filePath).sheet().head(clazz).doReadSync(); + } + + /** + * 同步按模型读(默认表头占一行,从第2行开始读) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static List syncReadModel(String filePath, Class clazz, Integer sheetNo){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param inputStream + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(InputStream inputStream, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(inputStream).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param file + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(File file, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(file).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(String filePath, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 异步无模型读(默认读取sheet0,从第2行开始读) + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param filePath 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener){ + EasyExcelFactory.read(filePath, excelListener).sheet().doRead(); + } + + /** + * 异步无模型读(默认表头占一行,从第2行开始读) + * @param filePath 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener, Integer sheetNo){ + EasyExcelFactory.read(filePath, excelListener).sheet(sheetNo).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param inputStream + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(InputStream inputStream, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(inputStream, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param file + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(File file, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(file, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(filePath, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取(默认读取sheet0,从第2行开始读) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet().doRead(); + } + + /** + * 异步按模型读取(默认表头占一行,从第2行开始读) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz, Integer sheetNo){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet(sheetNo).doRead(); + } + + /** + * 异步按模型读取 + * @param inputStream + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(InputStream inputStream, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(inputStream, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取 + * @param file + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(File file, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(file, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取 + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 无模板写文件 + * @param filePath + * @param head 表头数据 + * @param data 表内容数据 + */ + public static void write(String filePath, List> head, List> data){ + EasyExcel.write(filePath).head(head).sheet().doWrite(data); + } + + /** + * 无模板写文件 + * @param filePath + * @param head 表头数据 + * @param data 表内容数据 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, List> head, List> data, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath).head(head).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 根据excel模板文件写入文件 + * @param filePath + * @param templateFileName + * @param headClazz + * @param data + */ + public static void writeTemplate(String filePath, String templateFileName, Class headClazz, List data){ + EasyExcel.write(filePath, headClazz).withTemplate(templateFileName).sheet().doWrite(data); + } + + /** + * 根据excel模板文件写入文件 + * @param filePath + * @param templateFileName + * @param data + */ + public static void writeTemplate(String filePath, String templateFileName, List data){ + EasyExcel.write(filePath).withTemplate(templateFileName).sheet().doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + */ + public static void write(String filePath, Class headClazz, List data){ + EasyExcel.write(filePath, headClazz).sheet().doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, Class headClazz, List data, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param writeHandler 自定义的处理器,比如设置table样式,设置超链接、单元格下拉框等等功能都可以通过这个实现(需要注册多个则自己通过链式去调用) + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, Class headClazz, List data, WriteHandler writeHandler, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).registerWriteHandler(writeHandler).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件(包含某些字段) + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param includeCols 过滤包含的字段,根据字段名称过滤 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void writeInclude(String filePath, Class headClazz, List data, Set includeCols, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).includeColumnFiledNames(includeCols).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件(排除某些字段) + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param excludeCols 过滤排除的字段,根据字段名称过滤 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void writeExclude(String filePath, Class headClazz, List data, Set excludeCols, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).excludeColumnFiledNames(excludeCols).sheet(sheetNo, sheetName).doWrite(data); + } + + +} diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/SheetWriteStyleHandler.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/SheetWriteStyleHandler.java new file mode 100644 index 0000000..16bc076 --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/SheetWriteStyleHandler.java @@ -0,0 +1,77 @@ +package com.hnac.hzims.spare.utils; + +import com.alibaba.excel.write.handler.SheetWriteHandler; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; +import org.apache.poi.ss.usermodel.DataValidation; +import org.apache.poi.ss.usermodel.DataValidationConstraint; +import org.apache.poi.ss.usermodel.DataValidationHelper; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.springblade.system.cache.DictCache; +import org.springblade.system.entity.Dict; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class SheetWriteStyleHandler implements SheetWriteHandler { + + @Override + public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { + + } + + @Override + public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { + + // 定义一个Map key 是需要添加下拉框的列的index value是下拉框的数据 + Map mapDropDown=new HashMap<>(); + // 变量类型 单选 多选 日期 时间 日期时间 数值 字符 字符数值 字符日期 字符时间 长字符 + List spareUnit = DictCache.getList("spare_unit"); + List unitList = spareUnit.stream().map(s -> s.getDictValue()).collect(Collectors.toList()); + String[] strings = unitList.toArray(new String[unitList.size()]); +// //只读 是否 +// String[] readOnly={"是","否"}; +// // 文本区只读 是否 +// String[] textReadOnly={"是","否"}; +// //必填项 是否 +// String[] require={"是","否"}; +// +// // 精确度 精确到时 精确到分 精确到秒 精确到日 精确到月 +// String[] accuracy={"精确到时","精确到分","精确到秒","精确到日","精确到月",}; +// //编码排列方式 单行Radio 多行Radio 下拉菜单 +// String[] codeArrangement={"单行Radio","多行Radio","下拉菜单"}; +// // 是否生效 是否 +// String[] operation={"是","否"}; + + // 下拉框在excel中对应的值 + mapDropDown.put(5,strings); + String[] modifyEntryDateYesNo={"是","否"}; + mapDropDown.put(9,modifyEntryDateYesNo); +// mapDropDown.put(11,readOnly); +// mapDropDown.put(12,textReadOnly); +// mapDropDown.put(13,require); +// mapDropDown.put(17,accuracy); +// mapDropDown.put(20,codeArrangement); +// mapDropDown.put(24,operation); + + //获取工作簿sheet + Sheet sheet = writeSheetHolder.getSheet(); + // 开始设置下拉框 + DataValidationHelper helper = sheet.getDataValidationHelper(); + //设置下拉框 + for(Map.Entry entry:mapDropDown.entrySet()){ + /*起始行、终止行、起始列、终止列 起始行为1即表示表头不设置**/ + CellRangeAddressList addressList = new CellRangeAddressList(1, 65535, entry.getKey(), entry.getKey()); + /*设置下拉框数据**/ + DataValidationConstraint constraint = helper.createExplicitListConstraint(entry.getValue()); + DataValidation dataValidation = helper.createValidation(constraint, addressList); + sheet.addValidationData(dataValidation); + + } + + + } +} \ No newline at end of file diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java index bd3e82f..1c1a221 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java @@ -66,22 +66,23 @@ public class ThreadTask { } } - //诊断 - public static void fdpTaskNew(FdpTaskDTO taskDTO, FdpFaultEntity fdpFaultEntity, FdpRealTimeAndHisDataVo vo, String key) { - try { - Runnable runnable = new Runnable() { - @Override - public void run() { - //异步任务 - updateFaultStateNew(taskDTO, fdpFaultEntity, vo, key); - } - }; - Thread thread = new Thread(runnable); - thread.start(); - } catch (Exception e) { - log.error(e.getMessage(), e.toString()); - } - } +//20230426 此接口弃用 +// //诊断 +// public static void fdpTaskNew(FdpTaskDTO taskDTO, FdpFaultEntity fdpFaultEntity, FdpRealTimeAndHisDataVo vo, String key) { +// try { +// Runnable runnable = new Runnable() { +// @Override +// public void run() { +// //异步任务 +// updateFaultStateNew(taskDTO, fdpFaultEntity, vo, key); +// } +// }; +// Thread thread = new Thread(runnable); +// thread.start(); +// } catch (Exception e) { +// log.error(e.getMessage(), e.toString()); +// } +// } // 声明对象 public static ThreadTask threadTask; diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java index fac5174..c629c67 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java @@ -1,12 +1,8 @@ package com.hnac.hzims.fdp.scheduled; -import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import com.hnac.hzims.fdp.config.FdpUrlConfiguration; -import com.hnac.hzims.fdp.request.MonitorBandingReq; import com.hnac.hzims.fdp.service.IDiagnoseService; import com.hnac.hzims.fdp.service.IFdpFaultService; import com.hnac.hzims.fdp.service.IFdpMonitorService; @@ -18,12 +14,9 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Component; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static com.hnac.hzims.fdp.constants.ScheduledConstant.TRAIN_PREDICT_MODEL; -import static com.hnac.hzims.fdp.constants.ScheduledConstant.MONITOR_BANDING_PUSH; /** * @author hx @@ -53,20 +46,21 @@ public class TrainPredictModelSchedule { return ReturnT.SUCCESS; } - @XxlJob(MONITOR_BANDING_PUSH) - public ReturnT monitorBandingPush(String params) { - XxlJobLogger.log("===============监测点绑定关系推送开始==============="); - List monitorBandingReqList = monitorService.getMonitorBanding(); - Map body = new HashMap(1){{ - put("data", monitorBandingReqList); - }}; - String result = HttpUtil.createPost(urlConfigure.getSetDataLink()).contentType("application/json") - .body(JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)).execute().body(); - JSONObject resultJson = JSONObject.parseObject(result); - if(200 != resultJson.getIntValue("code")) { - XxlJobLogger.log("推送失败,错误信息为:"+result + "推送内容为:"+JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)); - } - XxlJobLogger.log("===============监测点绑定关系推送结束==============="); - return ReturnT.SUCCESS; - } + //20230426 此接口弃用 +// @XxlJob(MONITOR_BANDING_PUSH) +// public ReturnT monitorBandingPush(String params) { +// XxlJobLogger.log("===============监测点绑定关系推送开始==============="); +// List monitorBandingReqList = monitorService.getMonitorBanding(); +// Map body = new HashMap(1){{ +// put("data", monitorBandingReqList); +// }}; +// String result = HttpUtil.createPost(urlConfigure.getSetDataLink()).contentType("application/json") +// .body(JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)).execute().body(); +// JSONObject resultJson = JSONObject.parseObject(result); +// if(200 != resultJson.getIntValue("code")) { +// XxlJobLogger.log("推送失败,错误信息为:"+result + "推送内容为:"+JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)); +// } +// XxlJobLogger.log("===============监测点绑定关系推送结束==============="); +// return ReturnT.SUCCESS; +// } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java index 8fe5f86..4bcb9c1 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java @@ -454,18 +454,16 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl map = new HashMap<>(); map.put("id", key); diff --git a/hzims-service/inspect/pom.xml b/hzims-service/inspect/pom.xml index 3da9278..692cb18 100644 --- a/hzims-service/inspect/pom.xml +++ b/hzims-service/inspect/pom.xml @@ -7,6 +7,7 @@ BladeX org.springblade 2.7.6.RELEASE + 4.0.0 diff --git a/hzims-service/ticket/pom.xml b/hzims-service/ticket/pom.xml index 4169881..33b15c7 100644 --- a/hzims-service/ticket/pom.xml +++ b/hzims-service/ticket/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 2.3.7.RELEASE - 3.15 + 3.17 3.2.0 1.0.3 1.9.6 diff --git a/pom.xml b/pom.xml index bffec03..ea3c8ef 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ blade 1.4.13 - 3.15 + 3.17 UTF-8