diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/EmInfoEntity.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/EmInfoEntity.java index f9b0dbc..6263434 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/EmInfoEntity.java +++ b/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 infoChildren; @ApiModelProperty("最后下发时间") + @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) + @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) private LocalDateTime lastDistributeTime; @ApiModelProperty("机组类别") diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamServiceImpl.java index 12fced6..ffbdb7f 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/emParam/service/impl/ParamServiceImpl.java +++ b/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 signageList = paramDeviceAttrR.getData().stream().filter(o->StringUtil.isNotBlank(o.getSignage()) && StringUtil.isNotBlank(o.getFacDeviceAttrId())).map(DeviceInstanceAttrVO::getSignage).collect(Collectors.toList()); + List signageList = paramDeviceAttrR.getData().stream() + .filter(o->StringUtil.isNotBlank(o.getSignage()) && StringUtil.isNotBlank(o.getFacDeviceAttrId())) + .map(DeviceInstanceAttrVO::getSignage).collect(Collectors.toList()); Result realDataR = deviceDataClient.getDeviceRealDataByCode(emCode, signageList); Assert.isTrue(realDataR.isSuccess(),() -> { throw new ServiceException("参数召回获取实时数据失败"); }); - Map> 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> 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); diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java index bef9dfc..71b375f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java +++ b/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 param, HttpServletResponse response) { + rehearsalRecordService.exportRehearsalData(param, response); } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java new file mode 100644 index 0000000..5b69652 --- /dev/null +++ b/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 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 list = rehearsalRecordService.getWaitingRehearsalInTimeRange(yesterday, today); + list.forEach(x -> { + x.setRehearsalStatus(RehearsalStatusEnum.UNFINISHED.getValue()); + }); + // 将状态置为未完成 + boolean flag = rehearsalRecordService.updateBatchById(list); + return flag ? ReturnT.SUCCESS : ReturnT.FAIL; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java index 0cb3e1f..2ee8bbf 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java +++ b/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 * @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 param, HttpServletResponse response); + + /** + * 查询时间范围内未开始的演练数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 演练数据 + */ + List getWaitingRehearsalInTimeRange(String startTime, String endTime); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index 007f7ec..0d8d844 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/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 implements IRehearsalRecordService { /** @@ -127,7 +137,7 @@ public class RehearsalRecordServiceImpl extends ServiceImpl 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 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 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 getRehearsalByUnitAndDate(String unit, String startTime, String endTime) { + LambdaQueryWrapper 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 getWaitingRehearsalInTimeRange(String startTime, String endTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(RehearsalRecordEntity::getRehearsalStatus, RehearsalStatusEnum.WAITING.getValue()) + .ge(RehearsalRecordEntity::getScheduledEndTime, startTime) + .lt(RehearsalRecordEntity::getScheduledEndTime, endTime); + return this.list(queryWrapper); } + }