Browse Source

台账导入导出模板

注释智能诊断部分代码
zhongwei
tyty 2 years ago
parent
commit
60f0a96a91
  1. 14
      hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/entity/WtSpBasicEntity.java
  2. 4
      hzims-service/assets/pom.xml
  3. 27
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java
  4. 11
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java
  5. 315
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java
  6. 33
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelToolListener.java
  7. 347
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/ExcelUtil.java
  8. 77
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/utils/SheetWriteStyleHandler.java
  9. 33
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java
  10. 40
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java
  11. 10
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java
  12. 2
      pom.xml

14
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; 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.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer; import com.fasterxml.jackson.databind.ser.std.NullSerializer;
@ -20,6 +22,7 @@ import java.math.BigDecimal;
@Data @Data
@TableName("WT_SP_BASIC") @TableName("WT_SP_BASIC")
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
@ApiModel(value = "WtSpBasic对象", description = "") @ApiModel(value = "WtSpBasic对象", description = "")
public class WtSpBasicEntity extends TenantEntity { public class WtSpBasicEntity extends TenantEntity {
@ -33,52 +36,63 @@ public class WtSpBasicEntity extends TenantEntity {
/** /**
* 名称 * 名称
*/ */
@ExcelProperty(value = "物品名称(必填)",index = 1 )
@ApiModelProperty(value = "名称") @ApiModelProperty(value = "名称")
private String name; private String name;
/** /**
* 编码 * 编码
*/ */
@ExcelProperty(value = "物品编码(必填)",index = 0 )
@ApiModelProperty(value = "编码") @ApiModelProperty(value = "编码")
private String code; private String code;
/** /**
* 规格 * 规格
*/ */
@ExcelProperty(value = "规格型号",index = 2 )
@ApiModelProperty(value = "规格") @ApiModelProperty(value = "规格")
private String specifications; private String specifications;
/** /**
* 品牌 * 品牌
*/ */
@ExcelProperty(value = "物品品牌(必填)",index = 3 )
@ApiModelProperty(value = "品牌") @ApiModelProperty(value = "品牌")
private String brand; private String brand;
/** /**
* 单位 * 单位
*/ */
@ExcelProperty(value = "物品单位(必填)",index = 5 )
@ApiModelProperty(value = "单位") @ApiModelProperty(value = "单位")
private String unit; private String unit;
/** /**
* 单价 * 单价
*/ */
@ExcelProperty(value = "单价(元)(必填)",index = 10)
@ApiModelProperty(value = "单价") @ApiModelProperty(value = "单价")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal price; private BigDecimal price;
@ExcelProperty(value = "重量(kg)",index = 6 )
@ApiModelProperty(value = "重量") @ApiModelProperty(value = "重量")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal weight; private BigDecimal weight;
@ExcelProperty(value = "库存上限(必填)",index = 7 )
@ApiModelProperty(value = "库存上限") @ApiModelProperty(value = "库存上限")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
private Integer upperLimit; private Integer upperLimit;
@ExcelProperty(value = "库存下限(必填)",index = 8 )
@ApiModelProperty(value = "库存下限") @ApiModelProperty(value = "库存下限")
@JsonSerialize(nullsUsing = NullSerializer.class) @JsonSerialize(nullsUsing = NullSerializer.class)
private Integer lowerLimit; private Integer lowerLimit;
@ExcelProperty(value = "是否回收废品(必填)",index = 9 )
@ApiModelProperty(value = "是否回收废品") @ApiModelProperty(value = "是否回收废品")
private String isWaste; private String isWaste;
/** /**
* 主要参数 * 主要参数
*/ */
@ExcelProperty(value = "物品类别代码(必填)",index = 4 )
@ApiModelProperty(value = "主要参数") @ApiModelProperty(value = "主要参数")
private String parameter; private String parameter;
/** /**

4
hzims-service/assets/pom.xml

@ -64,6 +64,10 @@
<artifactId>message-api</artifactId> <artifactId>message-api</artifactId>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
</dependency>
</dependencies> </dependencies>

27
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.IWtSpBasicService;
import com.hnac.hzims.spare.service.IWtSpManagementService; import com.hnac.hzims.spare.service.IWtSpManagementService;
import com.hnac.hzims.spare.vo.WtSpBasicVO; 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 io.swagger.annotations.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController; 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.springblade.core.tool.utils.Func;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -134,7 +134,6 @@ public class WtSpBasicController extends BladeController {
}); });
return R.status(SP_BASICService.save(SP_BASIC)); 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))); 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);
}
} }

11
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 com.hnac.hzims.spare.vo.WtSpBasicVO;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query; 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.List;
import java.util.Map; import java.util.Map;
@ -63,6 +66,14 @@ public interface IWtSpBasicService extends BaseService<WtSpBasicEntity> {
List<SpTemporaryStockDetailEntity> stockDetail(Long spBasicId); List<SpTemporaryStockDetailEntity> stockDetail(Long spBasicId);
/** /**
* 库存填写模板导出
* @param response
*/
void writeTemplateDownload(HttpServletResponse response);
R importExcel(MultipartFile file) throws Exception;
/**
* 获取流程中的用户 * 获取流程中的用户
* @param deptId * @param deptId
* @param role * @param role

315
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; 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.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.IWtSpManagementService;
import com.hnac.hzims.spare.service.IWtSpTotalService; import com.hnac.hzims.spare.service.IWtSpTotalService;
import com.hnac.hzims.spare.service.IWtSpWarehouseService; 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.spare.vo.WtSpBasicVO;
import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient;
import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoStatisticVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; 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.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; 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.*;
import java.util.stream.Collectors;
import static com.hnac.hzims.spare.utils.ExcelUtil.asyncReadModel;
/** /**
* 服务实现类 * 服务实现类
@ -66,6 +89,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
private IWtSpTotalService totalService; private IWtSpTotalService totalService;
private WtSpBasicMapper basicMapper; private WtSpBasicMapper basicMapper;
private WtSpManagementMapper wtSpManagementMapper;
private IUserClient userClient; private IUserClient userClient;
@ -134,28 +158,28 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
// }else{ // }else{
// queryWrapper.lambda().eq(WtSpBasicEntity::getWaterPlantId,spBasicEntity.getWaterPlantId()); // queryWrapper.lambda().eq(WtSpBasicEntity::getWaterPlantId,spBasicEntity.getWaterPlantId());
// } // }
if(Func.isNotEmpty(spBasicEntity.getNameQuery())){ if (Func.isNotEmpty(spBasicEntity.getNameQuery())) {
queryWrapper.lambda().like(WtSpBasicEntity::getName,spBasicEntity.getNameQuery()); queryWrapper.lambda().like(WtSpBasicEntity::getName, spBasicEntity.getNameQuery());
} }
List<WtSpBasicVO> voList = new ArrayList<>(); List<WtSpBasicVO> voList = new ArrayList<>();
IPage<WtSpBasicVO> voPages = new Page<>(); IPage<WtSpBasicVO> voPages = new Page<>();
if(Func.isNotEmpty(spBasicEntity.getName()) && "工具".equals(spBasicEntity.getName())){ if (Func.isNotEmpty(spBasicEntity.getName()) && "工具".equals(spBasicEntity.getName())) {
// if(Func.isNotEmpty(spBasicEntity.getName())){ // if(Func.isNotEmpty(spBasicEntity.getName())){
List<WtSpManagementEntity> list = managementService.list(Wrappers.<WtSpManagementEntity>query().lambda(). List<WtSpManagementEntity> list = managementService.list(Wrappers.<WtSpManagementEntity>query().lambda().
eq(WtSpManagementEntity::getName,spBasicEntity.getName())); eq(WtSpManagementEntity::getName, spBasicEntity.getName()));
if(list.size()==0){ if (list.size() == 0) {
return null; return null;
} }
List<WtSpManagementEntity> result = managementService.list(Wrappers.<WtSpManagementEntity>query().lambda().like(WtSpManagementEntity::getAncestors, list.get(0).getId())); List<WtSpManagementEntity> result = managementService.list(Wrappers.<WtSpManagementEntity>query().lambda().like(WtSpManagementEntity::getAncestors, list.get(0).getId()));
List<Long> longList = new ArrayList<>(); List<Long> longList = new ArrayList<>();
if(result.size()>0){ if (result.size() > 0) {
for (int i = 0; i < result.size(); i++) { for (int i = 0; i < result.size(); i++) {
longList.add(result.get(i).getId()); longList.add(result.get(i).getId());
} }
} }
if(longList.size() >0){ if (longList.size() > 0) {
queryWrapper.lambda().in(WtSpBasicEntity::getManagementId, longList); queryWrapper.lambda().in(WtSpBasicEntity::getManagementId, longList);
}else{ } else {
return voPages; return voPages;
} }
spBasicEntity.setName(null); spBasicEntity.setName(null);
@ -173,20 +197,20 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
IPage<WtSpBasicEntity> pages = super.page(Condition.getPage(query), queryWrapper); IPage<WtSpBasicEntity> pages = super.page(Condition.getPage(query), queryWrapper);
for (int i = 0; i < pages.getRecords().size(); i++) { for (int i = 0; i < pages.getRecords().size(); i++) {
if(null == warehouseId ){ if (null == warehouseId) {
WtSpBasicVO basicVO = new WtSpBasicVO(); WtSpBasicVO basicVO = new WtSpBasicVO();
WtSpBasicEntity basicEntity = pages.getRecords().get(i); WtSpBasicEntity basicEntity = pages.getRecords().get(i);
WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId());
if(null!=managementEntity){ if (null != managementEntity) {
basicVO.setSparePartsName(managementEntity.getName()); basicVO.setSparePartsName(managementEntity.getName());
} }
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId()));
if(totalList.size() >0){ if (totalList.size() > 0) {
basicVO.setStock(totalList.get(0).getStock()); basicVO.setStock(totalList.get(0).getStock());
}else{ } else {
basicVO.setStock(0L); basicVO.setStock(0L);
} }
BeanUtils.copyProperties(basicEntity,basicVO); BeanUtils.copyProperties(basicEntity, basicVO);
List<TicketInfoStatisticVO> ticketVOS = ticketInfoAllClient.getTicketStatistic("2022-02"); List<TicketInfoStatisticVO> ticketVOS = ticketInfoAllClient.getTicketStatistic("2022-02");
@ -195,26 +219,26 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
// basicVO.setWaterPlantName(deptR.getData().getDeptName()); // basicVO.setWaterPlantName(deptR.getData().getDeptName());
// } // }
voList.add(basicVO); voList.add(basicVO);
}else{ } else {
WtSpBasicVO basicVO = new WtSpBasicVO(); WtSpBasicVO basicVO = new WtSpBasicVO();
WtSpBasicEntity basicEntity = pages.getRecords().get(i); WtSpBasicEntity basicEntity = pages.getRecords().get(i);
Map<String,Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("spBasicId",basicEntity.getId()); params.put("spBasicId", basicEntity.getId());
params.put("warehouseId",warehouseId); params.put("warehouseId", warehouseId);
WtSpTotalEntity totalEntity = totalMapper.selectByBasicId(params); WtSpTotalEntity totalEntity = totalMapper.selectByBasicId(params);
WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId());
if(null!=managementEntity){ if (null != managementEntity) {
basicVO.setSparePartsName(managementEntity.getName()); basicVO.setSparePartsName(managementEntity.getName());
} }
if(null!=totalEntity){ if (null != totalEntity) {
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId()));
if(totalList.size() >0){ if (totalList.size() > 0) {
// basicVO.setStock(totalList.get(0).getStock()); // basicVO.setStock(totalList.get(0).getStock());
basicVO.setStock(totalEntity.getStock()); basicVO.setStock(totalEntity.getStock());
}else{ } else {
basicVO.setStock(0L); basicVO.setStock(0L);
} }
BeanUtils.copyProperties(basicEntity,basicVO); BeanUtils.copyProperties(basicEntity, basicVO);
// R<Dept> deptR = sysClient.getDept(basicEntity.getWaterPlantId()); // R<Dept> deptR = sysClient.getDept(basicEntity.getWaterPlantId());
// if(Func.isNotEmpty(deptR.getData())){ // if(Func.isNotEmpty(deptR.getData())){
// basicVO.setWaterPlantName(deptR.getData().getDeptName()); // basicVO.setWaterPlantName(deptR.getData().getDeptName());
@ -227,9 +251,9 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
} }
} }
voPages.setRecords(voList); voPages.setRecords(voList);
if (Func.isNotEmpty(sign)){ if (Func.isNotEmpty(sign)) {
voPages.setTotal(pages.getTotal()); voPages.setTotal(pages.getTotal());
}else { } else {
if (null == warehouseId) { if (null == warehouseId) {
voPages.setTotal(pages.getTotal()); voPages.setTotal(pages.getTotal());
} else { } else {
@ -243,7 +267,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
} }
@Override @Override
public Integer selectTotal(Map<String,Object> params) { public Integer selectTotal(Map<String, Object> params) {
return baseMapper.selectTotal(params); return baseMapper.selectTotal(params);
} }
@ -274,7 +298,7 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
@Override @Override
public IPage<SpTemporaryStockEntity> stockList(WtSpBasicEntity spBasicEntity, Query query) { public IPage<SpTemporaryStockEntity> stockList(WtSpBasicEntity spBasicEntity, Query query) {
WtSpBasicEntity entity = new WtSpBasicEntity(); WtSpBasicEntity entity = new WtSpBasicEntity();
if(Func.isNotEmpty(spBasicEntity.getCode())){ if (Func.isNotEmpty(spBasicEntity.getCode())) {
entity.setCode(spBasicEntity.getCode()); entity.setCode(spBasicEntity.getCode());
} }
QueryWrapper<WtSpBasicEntity> queryWrapper = Condition.getQueryWrapper(entity); QueryWrapper<WtSpBasicEntity> queryWrapper = Condition.getQueryWrapper(entity);
@ -286,23 +310,23 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
// waterPlantId = shuiChangId.get(0); // waterPlantId = shuiChangId.get(0);
// } // }
// } // }
queryWrapper.lambda().eq(WtSpBasicEntity::getCreateDept,waterPlantId); queryWrapper.lambda().eq(WtSpBasicEntity::getCreateDept, waterPlantId);
List<Long> typeList = new ArrayList<>(); List<Long> typeList = new ArrayList<>();
if(null!= spBasicEntity.getManagementId()){ if (null != spBasicEntity.getManagementId()) {
List<WtSpManagementEntity> managementEntityList = managementMapper.selectList(Wrappers.<WtSpManagementEntity>query().lambda().like(WtSpManagementEntity::getAncestors, spBasicEntity.getManagementId())); List<WtSpManagementEntity> managementEntityList = managementMapper.selectList(Wrappers.<WtSpManagementEntity>query().lambda().like(WtSpManagementEntity::getAncestors, spBasicEntity.getManagementId()));
for (int i = 0; i < managementEntityList.size(); i++) { for (int i = 0; i < managementEntityList.size(); i++) {
typeList.add(managementEntityList.get(i).getId()); typeList.add(managementEntityList.get(i).getId());
} }
typeList.add(spBasicEntity.getManagementId()); typeList.add(spBasicEntity.getManagementId());
} }
if(typeList.size()>0){ if (typeList.size() > 0) {
queryWrapper.lambda().in(WtSpBasicEntity::getManagementId,typeList); queryWrapper.lambda().in(WtSpBasicEntity::getManagementId, typeList);
} }
IPage<WtSpBasicEntity> pages = super.page(Condition.getPage(query), queryWrapper); IPage<WtSpBasicEntity> pages = super.page(Condition.getPage(query), queryWrapper);
List<SpTemporaryStockEntity> voList = new ArrayList<>(); List<SpTemporaryStockEntity> voList = new ArrayList<>();
IPage<SpTemporaryStockEntity> voPages = new Page<>(); IPage<SpTemporaryStockEntity> voPages = new Page<>();
List<WtSpWarehouseEntity> warehouseList = wtSpWarehouseService.list(Wrappers.<WtSpWarehouseEntity>query().lambda(). List<WtSpWarehouseEntity> warehouseList = wtSpWarehouseService.list(Wrappers.<WtSpWarehouseEntity>query().lambda().
in(WtSpWarehouseEntity::getAffiliatedUnit,Func.toLongList(String.valueOf(waterPlantId)))); in(WtSpWarehouseEntity::getAffiliatedUnit, Func.toLongList(String.valueOf(waterPlantId))));
List<Long> longList = new ArrayList<>(); List<Long> longList = new ArrayList<>();
for (int i = 0; i < warehouseList.size(); i++) { for (int i = 0; i < warehouseList.size(); i++) {
longList.add(warehouseList.get(i).getId()); longList.add(warehouseList.get(i).getId());
@ -310,14 +334,14 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
for (int i = 0; i < pages.getRecords().size(); i++) { for (int i = 0; i < pages.getRecords().size(); i++) {
WtSpBasicEntity basicEntity = pages.getRecords().get(i); WtSpBasicEntity basicEntity = pages.getRecords().get(i);
//查询库存数量 //查询库存数量
if(longList.size() >0){ if (longList.size() > 0) {
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda() List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda()
.eq(WtSpTotalEntity::getSpBasicId,basicEntity.getId()) .eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())
.in(WtSpTotalEntity::getWarehouseId,longList)); .in(WtSpTotalEntity::getWarehouseId, longList));
if(totalList.size() >0){ if (totalList.size() > 0) {
SpTemporaryStockEntity stockEntity = new SpTemporaryStockEntity(); SpTemporaryStockEntity stockEntity = new SpTemporaryStockEntity();
WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId());
if(null!=managementEntity){ if (null != managementEntity) {
stockEntity.setManagementId(managementEntity.getId()); stockEntity.setManagementId(managementEntity.getId());
stockEntity.setSparePartsName(managementEntity.getName()); stockEntity.setSparePartsName(managementEntity.getName());
} }
@ -328,20 +352,20 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
stockEntity.setUnit(basicEntity.getUnit()); stockEntity.setUnit(basicEntity.getUnit());
stockEntity.setWaterPlantId(basicEntity.getCreateDept()); stockEntity.setWaterPlantId(basicEntity.getCreateDept());
R<Dept> deptR = sysClient.getDept(basicEntity.getCreateDept()); R<Dept> deptR = sysClient.getDept(basicEntity.getCreateDept());
if(Func.isNotEmpty(deptR.getData())){ if (Func.isNotEmpty(deptR.getData())) {
stockEntity.setWaterPlantName(deptR.getData().getDeptName()); stockEntity.setWaterPlantName(deptR.getData().getDeptName());
} }
stockEntity.setQuantity(totalList.get(0).getStock().intValue()); stockEntity.setQuantity(totalList.get(0).getStock().intValue());
stockEntity.setWarehouseId(totalList.get(0).getWarehouseId()); stockEntity.setWarehouseId(totalList.get(0).getWarehouseId());
WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.getById(totalList.get(0).getWarehouseId()); WtSpWarehouseEntity wtSpWarehouseEntity = wtSpWarehouseService.getById(totalList.get(0).getWarehouseId());
if(null != wtSpWarehouseEntity){ if (null != wtSpWarehouseEntity) {
stockEntity.setWarehouseName(wtSpWarehouseEntity.getName()); stockEntity.setWarehouseName(wtSpWarehouseEntity.getName());
} }
//查询出库数量 //查询出库数量
Integer deliveryQuantity = totalMapper.getListByBasicId(basicEntity.getId()); Integer deliveryQuantity = totalMapper.getListByBasicId(basicEntity.getId());
if(null !=deliveryQuantity){ if (null != deliveryQuantity) {
stockEntity.setDeliveryQuantity(deliveryQuantity); stockEntity.setDeliveryQuantity(deliveryQuantity);
}else{ } else {
stockEntity.setDeliveryQuantity(0); stockEntity.setDeliveryQuantity(0);
} }
//查询工单消耗数量 //查询工单消耗数量
@ -357,12 +381,12 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
// } // }
//查询归还数量 //查询归还数量
Integer returnedQuantity = warehouseInMapper.selectByType(basicEntity.getId(), WarehouseInType.BACK.getType()); Integer returnedQuantity = warehouseInMapper.selectByType(basicEntity.getId(), WarehouseInType.BACK.getType());
if(null!=returnedQuantity){ if (null != returnedQuantity) {
stockEntity.setReturnedQuantity(returnedQuantity); stockEntity.setReturnedQuantity(returnedQuantity);
}else{ } else {
stockEntity.setReturnedQuantity(0); stockEntity.setReturnedQuantity(0);
} }
stockEntity.setStockQuantity(stockEntity.getDeliveryQuantity()-stockEntity.getReturnedQuantity()-stockEntity.getConsumedQuantity()); stockEntity.setStockQuantity(stockEntity.getDeliveryQuantity() - stockEntity.getReturnedQuantity() - stockEntity.getConsumedQuantity());
voList.add(stockEntity); voList.add(stockEntity);
} }
} }
@ -424,6 +448,205 @@ public class WtSpBasicServiceImpl extends BaseServiceImpl<WtSpBasicMapper, WtSpB
return list; return list;
} }
/**
* 库存填写模板导出
*
* @param response
*/
@Override
public void writeTemplateDownload(HttpServletResponse response) {
try {
WtSpBasicEntity wtSpBasicEntity = new WtSpBasicEntity();
List<WtSpBasicEntity> data = new ArrayList<>();
data.add(wtSpBasicEntity);
List<WtSpManagementeExcelEntity> 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<String> excludeColumnFiledNames = new HashSet<String>();
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<String, String> 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<WtSpManagementeExcelEntity> list = wtSpManagementMapper.findAll(AuthUtil.getTenantId());
List<String> codeList = list.stream().map(s -> s.getOneCode()).collect(Collectors.toList());
List<String> 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<WtSpBasicEntity> 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<WtSpBasicEntity> data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params);
// List<WtSpBasicEntity> data = ExcelImportUtil.importExcel(file.getInputStream(), WtSpBasicEntity.class, params);
try {
for (WtSpBasicEntity libraryExcel : data) {
Integer counter = 2;
//数据校验
R<String> 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<String> list, Integer counter) {
List<String> errors = new ArrayList<>();
//数据库操作
List<WtSpBasicEntity> wtSpBasicEntityList = this.list(Wrappers.<WtSpBasicEntity>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<WtSpManagementEntity>() {{
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 // @Override
// public String getTaskUser(Long deptId, String role, String tenantId) { // public String getTaskUser(Long deptId, String role, String tenantId) {
// R<List<User>> userR = userClient.userByDeptAndRole(deptId, role, tenantId); // R<List<User>> userR = userClient.userByDeptAndRole(deptId, role, tenantId);

33
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<Object> 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));
}
}

347
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<Map<Integer, String>> syncRead(String filePath){
return EasyExcelFactory.read(filePath).sheet().doReadSync();
}
/**
* 同步无模型读默认表头占一行从第2行开始读
* @param filePath
* @param sheetNo sheet页号从0开始
* @return
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<List<String>> head, List<List<Object>> 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<List<String>> head, List<List<Object>> 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<String> 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<String> excludeCols, Integer sheetNo, String sheetName){
EasyExcel.write(filePath, headClazz).excludeColumnFiledNames(excludeCols).sheet(sheetNo, sheetName).doWrite(data);
}
}

77
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<Integer,String[]> mapDropDown=new HashMap<>();
// 变量类型 单选 多选 日期 时间 日期时间 数值 字符 字符数值 字符日期 字符时间 长字符
List<Dict> spareUnit = DictCache.getList("spare_unit");
List<String> 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<Integer,String[]> 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);
}
}
}

33
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/ThreadTask.java

@ -66,22 +66,23 @@ public class ThreadTask {
} }
} }
//诊断 //20230426 此接口弃用
public static void fdpTaskNew(FdpTaskDTO taskDTO, FdpFaultEntity fdpFaultEntity, FdpRealTimeAndHisDataVo vo, String key) { // //诊断
try { // public static void fdpTaskNew(FdpTaskDTO taskDTO, FdpFaultEntity fdpFaultEntity, FdpRealTimeAndHisDataVo vo, String key) {
Runnable runnable = new Runnable() { // try {
@Override // Runnable runnable = new Runnable() {
public void run() { // @Override
//异步任务 // public void run() {
updateFaultStateNew(taskDTO, fdpFaultEntity, vo, key); // //异步任务
} // updateFaultStateNew(taskDTO, fdpFaultEntity, vo, key);
}; // }
Thread thread = new Thread(runnable); // };
thread.start(); // Thread thread = new Thread(runnable);
} catch (Exception e) { // thread.start();
log.error(e.getMessage(), e.toString()); // } catch (Exception e) {
} // log.error(e.getMessage(), e.toString());
} // }
// }
// 声明对象 // 声明对象
public static ThreadTask threadTask; public static ThreadTask threadTask;

40
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/scheduled/TrainPredictModelSchedule.java

@ -1,12 +1,8 @@
package com.hnac.hzims.fdp.scheduled; package com.hnac.hzims.fdp.scheduled;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hnac.hzims.fdp.config.FdpUrlConfiguration; 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.IDiagnoseService;
import com.hnac.hzims.fdp.service.IFdpFaultService; import com.hnac.hzims.fdp.service.IFdpFaultService;
import com.hnac.hzims.fdp.service.IFdpMonitorService; 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.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List; 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.TRAIN_PREDICT_MODEL;
import static com.hnac.hzims.fdp.constants.ScheduledConstant.MONITOR_BANDING_PUSH;
/** /**
* @author hx * @author hx
@ -53,20 +46,21 @@ public class TrainPredictModelSchedule {
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
@XxlJob(MONITOR_BANDING_PUSH) //20230426 此接口弃用
public ReturnT<String> monitorBandingPush(String params) { // @XxlJob(MONITOR_BANDING_PUSH)
XxlJobLogger.log("===============监测点绑定关系推送开始==============="); // public ReturnT<String> monitorBandingPush(String params) {
List<MonitorBandingReq> monitorBandingReqList = monitorService.getMonitorBanding(); // XxlJobLogger.log("===============监测点绑定关系推送开始===============");
Map<String,Object> body = new HashMap(1){{ // List<MonitorBandingReq> monitorBandingReqList = monitorService.getMonitorBanding();
put("data", monitorBandingReqList); // Map<String,Object> 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(); // String result = HttpUtil.createPost(urlConfigure.getSetDataLink()).contentType("application/json")
JSONObject resultJson = JSONObject.parseObject(result); // .body(JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)).execute().body();
if(200 != resultJson.getIntValue("code")) { // JSONObject resultJson = JSONObject.parseObject(result);
XxlJobLogger.log("推送失败,错误信息为:"+result + "推送内容为:"+JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT)); // if(200 != resultJson.getIntValue("code")) {
} // XxlJobLogger.log("推送失败,错误信息为:"+result + "推送内容为:"+JSONObject.toJSONStringWithDateFormat(body, JSON.DEFFAULT_DATE_FORMAT));
XxlJobLogger.log("===============监测点绑定关系推送结束==============="); // }
return ReturnT.SUCCESS; // XxlJobLogger.log("===============监测点绑定关系推送结束===============");
} // return ReturnT.SUCCESS;
// }
} }

10
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java

@ -454,18 +454,16 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
if (ObjectUtil.isEmpty(fdpFaultEntity)) { if (ObjectUtil.isEmpty(fdpFaultEntity)) {
throw new ServiceException("获取对应故障对象失败"); throw new ServiceException("获取对应故障对象失败");
} }
/**获取实时、历史数据**/ // /**获取实时、历史数据**/
FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept()); // FdpRealTimeAndHisDataVo pushResp = this.dataPushByPartition(fdpFaultEntity.getFdpPartition(), fdpFaultEntity.getCreateDept());
//String key = UUID.randomUUID().toString(); //String key = UUID.randomUUID().toString();
boolean flag = fdpTaskService.save(taskDTO); boolean flag = fdpTaskService.save(taskDTO);
if (!flag) { if (!flag) {
return R.fail("诊断任务保存失败"); return R.fail("诊断任务保存失败");
} }
String key = taskDTO.getId().toString(); String key = taskDTO.getId().toString();
//异步处理 // //异步处理 20230426 此接口弃用
ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, pushResp, key); // ThreadTask.fdpTaskNew(taskDTO, fdpFaultEntity, pushResp, key);
//获取数据成功-》 告知前端 //获取数据成功-》 告知前端
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("id", key); map.put("id", key);

2
pom.xml

@ -37,7 +37,7 @@
<docker.namespace>blade</docker.namespace> <docker.namespace>blade</docker.namespace>
<docker.plugin.version>1.4.13</docker.plugin.version> <docker.plugin.version>1.4.13</docker.plugin.version>
<poi.version>3.15</poi.version> <poi.version>3.17</poi.version>
<!-- SonarQube代码走查 --> <!-- SonarQube代码走查 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Loading…
Cancel
Save