Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 11 months ago
parent
commit
80ae73770c
  1. 3
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/EmInfoEntity.java
  2. 27
      hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamServiceImpl.java
  3. 21
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java
  4. 43
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java
  5. 24
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java
  6. 154
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

3
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/EmInfoEntity.java

@ -13,6 +13,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import org.springblade.core.tenant.mp.TenantEntity;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
@ -251,6 +252,8 @@ public class EmInfoEntity extends TenantEntity {
private List<EmInfoEntity> infoChildren;
@ApiModelProperty("最后下发时间")
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
private LocalDateTime lastDistributeTime;
@ApiModelProperty("机组类别")

27
hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamServiceImpl.java

@ -40,6 +40,9 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@ -75,24 +78,32 @@ public class ParamServiceImpl implements IParamService {
throw new ServiceException("获取设备实例物模型属性失败!");
});
// 获取实时数据
List<String> signageList = paramDeviceAttrR.getData().stream().filter(o->StringUtil.isNotBlank(o.getSignage()) && StringUtil.isNotBlank(o.getFacDeviceAttrId())).map(DeviceInstanceAttrVO::getSignage).collect(Collectors.toList());
List<String> signageList = paramDeviceAttrR.getData().stream()
.filter(o->StringUtil.isNotBlank(o.getSignage()) && StringUtil.isNotBlank(o.getFacDeviceAttrId()))
.map(DeviceInstanceAttrVO::getSignage).collect(Collectors.toList());
Result<DeviceDataDTO> realDataR = deviceDataClient.getDeviceRealDataByCode(emCode, signageList);
Assert.isTrue(realDataR.isSuccess(),() -> {
throw new ServiceException("参数召回获取实时数据失败");
});
Map<ParamGroupVO, List<ParamVO>> paramGroupVOListMap = paramDeviceAttrR.getData().stream().filter(o->StringUtil.isNotBlank(o.getFacDeviceAttrId())).map(this::convert).collect(Collectors.groupingBy(p -> {
ParamGroupVO paramGroupVO = new ParamGroupVO();
paramGroupVO.setGroupId(String.valueOf(p.getModelClassifyId()));
paramGroupVO.setGroupName(p.getModelClassifyName());
return paramGroupVO;
}));
Map<ParamGroupVO, List<ParamVO>> paramGroupVOListMap = paramDeviceAttrR.getData().stream()
.filter(o->StringUtil.isNotBlank(o.getFacDeviceAttrId()) && o.getIsParam() == 1)
.map(this::convert).collect(Collectors.groupingBy(p -> {
ParamGroupVO paramGroupVO = new ParamGroupVO();
paramGroupVO.setGroupId(String.valueOf(p.getModelClassifyId()));
paramGroupVO.setGroupName(p.getModelClassifyName());
return paramGroupVO;
}));
paramGroupVOListMap.forEach((groupVO,list) -> {
ParamTreeVO paramTreeVO = new ParamTreeVO();
paramTreeVO.setParamGroup(groupVO);
list.stream().filter(p -> realDataR.getData().getDataMap().containsKey(p.getSignage())).forEach(p -> {
String realData = JSON.toJSONString(realDataR.getData().getDataMap().get(p.getSignage()));
if("0".equals(JSONObject.parseObject(realData).getString("q"))) {
p.setValue(JSONObject.parseObject(realData).getString("v"));
String value = JSONObject.parseObject(realData).getString("v");
if(StringUtil.isNotBlank(p.getDbType()) && "double".equals(p.getDbType())) {
value = String.valueOf(new BigDecimal(value).setScale(p.getKeepFigures(), RoundingMode.HALF_UP).doubleValue());
}
p.setValue(value);
}
});
paramTreeVO.setParamList(list);

21
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java

@ -3,7 +3,6 @@ package com.hnac.hzims.safeproduct.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.common.utils.Condition;
import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.service.IRehearsalRecordService;
import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO;
@ -19,6 +18,7 @@ import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;
@ -39,14 +39,14 @@ public class RehearsalRecordController extends BladeController {
@PostMapping("/save")
@ApiOperation(value = "新增")
@ApiOperationSupport(order = 1)
public R save(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) {
public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) {
return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord));
}
@PostMapping("/update")
@ApiOperation(value = "修改")
@ApiOperationSupport(order = 2)
public R update(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) {
public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) {
return R.status(rehearsalRecordService.updateRehearsal(rehearsalRecord));
}
@ -67,8 +67,8 @@ public class RehearsalRecordController extends BladeController {
@GetMapping("/page")
@ApiImplicitParams({
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualStartTime", value = "实际开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualEndTime", value = "实际结束时间", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
})
@ApiOperation(value = "分页")
@ApiOperationSupport(order = 5)
@ -95,9 +95,14 @@ public class RehearsalRecordController extends BladeController {
}
@GetMapping("/exportRehearsalData")
@ApiOperation(value = "导出演练页数据")
@ApiImplicitParams({
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
})
@ApiOperation(value = "演练数据导出")
@ApiOperationSupport(order = 8)
public void exportRehearsalData() {
public void exportRehearsalData(@ApiIgnore @RequestParam Map<String, Object> param, HttpServletResponse response) {
rehearsalRecordService.exportRehearsalData(param, response);
}
}

43
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java

@ -0,0 +1,43 @@
package com.hnac.hzims.safeproduct.jobs;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum;
import com.hnac.hzims.safeproduct.service.IRehearsalRecordService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
* 演练模块定时任务
*
* @author liwen
* @date 2023-12-15
*/
@Component
public class RehearsalJob {
@Autowired
IRehearsalRecordService rehearsalRecordService;
@XxlJob("autoChangeRehearsalStatus")
public ReturnT<String> autoChangeRehearsalStatus(String param) {
// 获取时间范围
Date current = DateUtil.now();
Date before = DateUtil.minusDays(current, 1);
String today = DateUtil.format(current, "yyyy-mm-dd hh:MM:ss");
String yesterday = DateUtil.format(before, "yyyy-mm-dd hh:MM:ss");
// 查询前一天的超时未完成演练记录
List<RehearsalRecordEntity> list = rehearsalRecordService.getWaitingRehearsalInTimeRange(yesterday, today);
list.forEach(x -> {
x.setRehearsalStatus(RehearsalStatusEnum.UNFINISHED.getValue());
});
// 将状态置为未完成
boolean flag = rehearsalRecordService.updateBatchById(list);
return flag ? ReturnT.SUCCESS : ReturnT.FAIL;
}
}

24
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java

@ -2,12 +2,15 @@ package com.hnac.hzims.safeproduct.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO;
import com.hnac.hzims.safeproduct.vo.RehearsalYearVO;
import org.springblade.core.mp.support.Query;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 演练记录服务类
*
@ -37,12 +40,27 @@ public interface IRehearsalRecordService extends IService<RehearsalRecordEntity>
* @param rehearsalRecord 演练记录DTO类
* @return 新增是否成功
*/
boolean saveRehearsal(RehearsalRecordDTO rehearsalRecord);
boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord);
/**
* 修改演练
* @param rehearsalRecord 演练记录DTO类
* @return 更新是否成功
*/
boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord);
boolean updateRehearsal(RehearsalRecordEntity rehearsalRecord);
/**
* 演练数据导出
* @param param 入参
* @param response 响应类
*/
void exportRehearsalData(Map<String, Object> param, HttpServletResponse response);
/**
* 查询时间范围内未开始的演练数据
* @param startTime 开始时间
* @param endTime 结束时间
* @return 演练数据
*/
List<RehearsalRecordEntity> getWaitingRehearsalInTimeRange(String startTime, String endTime);
}

154
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

@ -1,29 +1,38 @@
package com.hnac.hzims.safeproduct.service.impl;
import cn.hutool.core.date.DatePattern;
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.util.CollectionUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
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.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.safeproduct.dto.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum;
import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper;
import com.hnac.hzims.safeproduct.service.IRehearsalRecordService;
import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO;
import com.hnac.hzims.safeproduct.vo.RehearsalYearVO;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -33,6 +42,7 @@ import java.util.stream.Collectors;
* @date 2023-12-13
*/
@Service
@Slf4j
public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMapper, RehearsalRecordEntity> implements IRehearsalRecordService {
/**
@ -127,7 +137,7 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
* 新增演练
*/
@Override
public boolean saveRehearsal(RehearsalRecordDTO rehearsalRecord) {
public boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord) {
// 获取当月时间(yyyymm)
String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date());
// 查询是否存在同月编号
@ -149,19 +159,90 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
}
}
rehearsalRecord.setCode(code);
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = getStandardRehearsal(rehearsalRecord);
return this.save(rehearsalRecordEntity);
// 参演人数
String peopleName = rehearsalRecord.getPeopleName();
if (StringUtils.isNotEmpty(peopleName)) {
int peopleNum = peopleName.split(",").length;
rehearsalRecord.setPeopleNum(peopleNum);
}
return this.save(rehearsalRecord);
}
/**
* 修改演练
*/
@Override
public boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord) {
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = getStandardRehearsal(rehearsalRecord);
return this.updateById(rehearsalRecordEntity);
public boolean updateRehearsal(RehearsalRecordEntity rehearsalRecord) {
// 参演人数
String peopleName = rehearsalRecord.getPeopleName();
if (StringUtils.isNotEmpty(peopleName)) {
int peopleNum = peopleName.split(",").length;
rehearsalRecord.setPeopleNum(peopleNum);
}
return this.updateById(rehearsalRecord);
}
/**
* 演练数据导出
*/
@Override
public void exportRehearsalData(Map<String, Object> param, HttpServletResponse response) {
ServletOutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
String unit = String.valueOf(param.get("unit"));
String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf(param.get("scheduledEndTime"));
List<RehearsalRecordEntity> rehearsalRecordList = getRehearsalByUnitAndDate(unit, startTime, endTime);
// 设置响应头
// URLEncoder.encode防止中文乱码
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<>();
excludeColumnFiledNames.add("peopleName");
excludeColumnFiledNames.add("commander");
excludeColumnFiledNames.add("record");
excludeColumnFiledNames.add("comment");
excludeColumnFiledNames.add("rehearsalMethod");
excludeColumnFiledNames.add("imgPath");
excludeColumnFiledNames.add("filePath");
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(RehearsalRecordEntity.class)
.excludeColumnFiledNames(excludeColumnFiledNames)
.build();
excelWriter.write(rehearsalRecordList, writeSheet);
excelWriter.finish();
} catch (Exception e) {
// 重置response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
throw new ServiceException("演练数据导出异常: " + e.getMessage());
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
log.error("演练导出响应头输出流关闭异常: " + e.getMessage());
}
}
}
}
/**
@ -191,20 +272,37 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
}
/**
* 获取标准演练实体类
* @param rehearsalRecord 演练记录DTO类
* @return 演练实体类
* 根据单位和计划时间查询演练记录
* @param unit 单位
* @param startTime 计划开始时间
* @param endTime 计划结束时间
* @return 演练记录列表
*/
private RehearsalRecordEntity getStandardRehearsal(RehearsalRecordDTO rehearsalRecord) {
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = new RehearsalRecordEntity();
BeanUtils.copyProperties(rehearsalRecord, rehearsalRecordEntity);
// 参演人数
rehearsalRecordEntity.setPeopleNum(rehearsalRecord.getPeople().length);
// 数组转字符串
rehearsalRecordEntity.setPeopleName(Arrays.toString(rehearsalRecord.getPeople()));
rehearsalRecordEntity.setImgPath(Arrays.toString(rehearsalRecord.getImages()));
rehearsalRecordEntity.setFilePath(Arrays.toString(rehearsalRecord.getFiles()));
return rehearsalRecordEntity;
public List<RehearsalRecordEntity> getRehearsalByUnitAndDate(String unit, String startTime, String endTime) {
LambdaQueryWrapper<RehearsalRecordEntity> queryWrapper = new LambdaQueryWrapper<>();
if (!unit.equals("null")) {
queryWrapper.eq(RehearsalRecordEntity::getUnit, unit);
}
if (!startTime.equals("null")) {
queryWrapper.ge(RehearsalRecordEntity::getScheduledStartTime, startTime);
}
if (!endTime.equals("null")) {
queryWrapper.le(RehearsalRecordEntity::getScheduledEndTime, endTime);
}
queryWrapper.orderByDesc(RehearsalRecordEntity::getScheduledEndTime);
return this.list(queryWrapper);
}
/**
* 查询时间范围内未开始的演练数据
*/
@Override
public List<RehearsalRecordEntity> getWaitingRehearsalInTimeRange(String startTime, String endTime) {
QueryWrapper<RehearsalRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(RehearsalRecordEntity::getRehearsalStatus, RehearsalStatusEnum.WAITING.getValue())
.ge(RehearsalRecordEntity::getScheduledEndTime, startTime)
.lt(RehearsalRecordEntity::getScheduledEndTime, endTime);
return this.list(queryWrapper);
}
}

Loading…
Cancel
Save