1、监视升级过程RTU集合以地址排序;
2、实现升级结果查询与导出。
| | |
| | | package com.dy.pipIrrGlobal.voUg; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnore; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.alibaba.excel.annotation.write.style.ColumnWidth; |
| | | import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
| | | import com.alibaba.excel.annotation.write.style.ContentStyle; |
| | | import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
| | | import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; |
| | | import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; |
| | | import com.alibaba.fastjson2.annotation.JSONField; |
| | | import com.alibaba.fastjson2.writer.ObjectWriterImplToString; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | |
| | | */ |
| | | |
| | | @Data |
| | | @JsonPropertyOrder({ "id", "rtuAddr", "intakeName", "isOver", "isOverStr", "ugState", "ugStateStr", "overDt"}) |
| | | @HeadRowHeight(26) |
| | | @ContentRowHeight(22) |
| | | @JsonPropertyOrder({ "id", "intakeNum", "rtuAddr", "isOverStr", "ugStateStr", "overDt"}) |
| | | public class VoUgResult { |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @Schema(description = "主键" ) |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ExcelIgnore() |
| | | public Long id; |
| | | |
| | | /** |
| | | * 控制器地址 |
| | | */ |
| | | @Schema(description = "控制器地址" ) |
| | | @ExcelProperty("控制器地址") |
| | | @ColumnWidth(20) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | public String rtuAddr; |
| | | |
| | | /** |
| | | * 取水编号 |
| | | */ |
| | | @Schema(description = "取水口编号") |
| | | @ExcelProperty("取水编号") |
| | | @ColumnWidth(20) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | private String intakeNum; |
| | | |
| | | /** |
| | | * 升级是否结束 |
| | | */ |
| | | @Schema(description = "升级是否结束" ) |
| | | @JSONField(serialize = false) |
| | | @ExcelIgnore() |
| | | public Byte isOver; |
| | | |
| | | /** |
| | | * 升级是否结束 |
| | | */ |
| | | @Schema(description = "升级是否结束" ) |
| | | @TableField(exist = false) |
| | | @ExcelProperty("升级结束") |
| | | @ColumnWidth(10) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | public String isOverStr; |
| | | |
| | | /** |
| | | * 升级状态 |
| | | */ |
| | | @Schema(description = "升级状态" ) |
| | | @JSONField(serialize = false) |
| | | @ExcelIgnore() |
| | | public Integer ugState; |
| | | |
| | | /** |
| | | * 升级状态 |
| | | */ |
| | | @Schema(description = "升级状态" ) |
| | | @ExcelProperty("升级结果") |
| | | @ColumnWidth(16) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | public String ugStateStr; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Schema(description = "升级结束时间" ) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:SS") |
| | | public Integer overDt; |
| | | @ExcelProperty("结束时间") |
| | | @ColumnWidth(30) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | public Date overDt; |
| | | |
| | | /** |
| | | * 无参数据构造方法 |
| | |
| | | |
| | | @ExcelProperty("升级结果") |
| | | @ColumnWidth(30) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) |
| | | public String result; |
| | | } |
| | |
| | | <!--@mbg.generated--> |
| | | select |
| | | count(*) |
| | | from ug_rtu_controller |
| | | from ug_rtu_controller ugCon |
| | | inner join pr_intake inta ON inta.id = ugCon.task_id |
| | | <where> |
| | | <if test="taskId != null"> |
| | | AND task_id = #{taskId,jdbcType=BIGINT} |
| | | AND ugCon.task_id = #{taskId,jdbcType=BIGINT} |
| | | </if> |
| | | <if test="intakeNum != null"> |
| | | AND inta.name = #{intakeNum,jdbcType=VARCHAR} |
| | | </if> |
| | | <if test="rtuAddr != null"> |
| | | AND ugCon.rtu_addr = #{rtuAddr,jdbcType=VARCHAR} |
| | | </if> |
| | | <if test="state != null and state == 1"> |
| | | AND ugCon.ug_state = 1 |
| | | </if> |
| | | <if test="state != null and state == 0"> |
| | | AND ugCon.ug_state != 1 |
| | | </if> |
| | | <if test="fail != null"> |
| | | AND ugCon.ug_state = #{fail,jdbcType=INTEGER} |
| | | </if> |
| | | </where> |
| | | </select> |
| | |
| | | <select id="selectControllerUpgradeResults" resultType="com.dy.pipIrrGlobal.voUg.VoUgResult"> |
| | | <!--@mbg.generated--> |
| | | select |
| | | ctb.id as id, |
| | | inTb.name as intakeNum, |
| | | ctb.rtu_addr as rtuAddr, |
| | | ctb.is_over as isOver, |
| | | ctb.ug_state as ugState, |
| | | ctb.over_dt as overDt |
| | | from ug_rtu_controller ctb |
| | | inner join pr_intake inTb on ctb.task_id = inTb.id |
| | | ugCon.id as id, |
| | | inta.name as intakeNum, |
| | | ugCon.rtu_addr as rtuAddr, |
| | | ugCon.is_over as isOver, |
| | | ugCon.ug_state as ugState, |
| | | ugCon.over_dt as overDt |
| | | from ug_rtu_controller ugCon |
| | | inner join pr_intake inta on ugCon.task_id = inta.id |
| | | <where> |
| | | <if test="taskId != null"> |
| | | AND ctb.task_id = #{taskId,jdbcType=BIGINT} |
| | | AND ugCon.task_id = #{taskId,jdbcType=BIGINT} |
| | | </if> |
| | | <if test="intakeNum != null"> |
| | | AND inta.name = #{intakeNum,jdbcType=VARCHAR} |
| | | </if> |
| | | <if test="rtuAddr != null"> |
| | | AND ugCon.rtu_addr = #{rtuAddr,jdbcType=VARCHAR} |
| | | </if> |
| | | <if test="state != null and state == 1"> |
| | | AND ugCon.ug_state = 1 |
| | | </if> |
| | | <if test="state != null and state == 0"> |
| | | AND ugCon.ug_state != 1 |
| | | </if> |
| | | <if test="fail != null"> |
| | | AND ugCon.ug_state = #{fail,jdbcType=INTEGER} |
| | | </if> |
| | | </where> |
| | | ORDER BY ctb.id ASC |
| | | ORDER BY ugCon.id ASC |
| | | <trim prefix="limit " > |
| | | <if test="start != null and count != null"> |
| | | #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER} |
| | |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | @Builder |
| | | @Schema(name = "查询升级任务RTU升级情况的条件") |
| | | @Schema(name = "查询升级任务RTU升级结果的条件") |
| | | public class QueryUgResultVo extends QueryConditionVo { |
| | | |
| | | @Schema(description = "升级任务id") |
| | |
| | | @Schema(description = "控制器地址") |
| | | public String rtuAddr; |
| | | |
| | | @Schema(description = "升级结果:1升级成功,0升级失败") |
| | | public Integer state; |
| | | |
| | | @Schema(description = "失败类型:3一包死失败,4多包死失败,5离线失败") |
| | | public Integer fail; |
| | | |
| | | } |
| | |
| | | package com.dy.pipIrrBase.rtuUpgrade.task; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.dy.common.aop.SsoAop; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | |
| | | import com.dy.common.webUtil.ResultCodeMsg; |
| | | import com.dy.pipIrrGlobal.pojoUg.UgRtuTask; |
| | | import com.dy.pipIrrGlobal.voUg.VoUgResult; |
| | | import com.dy.pipIrrGlobal.voUg.VoUgRtuResult; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.media.Content; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| | | import io.swagger.v3.oas.annotations.responses.ApiResponses; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | if (vo.taskId == null) { |
| | | return BaseResponseUtils.buildErrorMsg("升级任务id不能为空"); |
| | | } |
| | | try { |
| | | if(vo.state != null && vo.state == 1){ |
| | | //查询升级成功的 |
| | | vo.fail = null ; |
| | | } |
| | | if(vo.state == null && vo.fail != null){ |
| | | //查询升级失败的 |
| | | vo.state = 0 ; |
| | | } |
| | | QueryResultVo<List<VoUgResult>> res = this.sv.selectSome(vo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询RTU升级任务异常", e); |
| | | return BaseResponseUtils.buildErrorMsg(e.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 导出升级结果RTU列表 |
| | | * @param response |
| | | */ |
| | | @RequestMapping(value = "/exportAll", method = RequestMethod.GET) |
| | | public void exportUgFail(HttpServletResponse response, QueryUgResultVo vo) throws Exception { |
| | | if(vo.state != null && vo.state == 1){ |
| | | //查询升级成功的 |
| | | vo.fail = null ; |
| | | } |
| | | if(vo.state == null && vo.fail != null){ |
| | | //查询升级失败的 |
| | | vo.state = 0 ; |
| | | } |
| | | setExcelRespProp(response, "升级结果列表"); |
| | | List<VoUgResult> rsList = this.sv.selectAll(vo); |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head(VoUgRtuResult.class) |
| | | .excelType(ExcelTypeEnum.XLSX) |
| | | .sheet("升级结果列表") |
| | | .doWrite(rsList); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置excel下载响应头属性 |
| | | */ |
| | | private void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | } |
| | | } |
| | |
| | | private UgRtuControllerMapper dao ; |
| | | |
| | | /** |
| | | * 分页查询一个升级任务中所有控制器升级结查 |
| | | * 分页查询一个升级任务中一些控制器升级结查 |
| | | * @return 控制器升级结查 |
| | | */ |
| | | public QueryResultVo<List<VoUgResult>> selectSome(QueryUgResultVo queryVo){ |
| | |
| | | |
| | | return rsVo ; |
| | | } |
| | | |
| | | /** |
| | | * 分页查询一个升级任务中所有控制器升级结查 |
| | | * @return 控制器升级结查 |
| | | */ |
| | | public List<VoUgResult> selectAll(QueryUgResultVo queryVo){ |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo) ; |
| | | List<VoUgResult> list = this.dao.selectControllerUpgradeResults(params) ; |
| | | if(list != null && list.size() > 0){ |
| | | for(VoUgResult vo : list){ |
| | | if(vo.isOver != null && vo.isOver.byteValue() == 1){ |
| | | vo.isOverStr = "是" ; |
| | | }else{ |
| | | vo.isOverStr = "否" ; |
| | | } |
| | | if(vo.ugState != null){ |
| | | vo.ugStateStr = UpgradeRtu.getStateName(vo.ugState) ; |
| | | } |
| | | } |
| | | } |
| | | return list ; |
| | | } |
| | | } |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | //此时保证两个集合都不为null |
| | | this.save2Db(info.ugTaskId, info.ugRtuStateList, cache.ugRtuStateList); |
| | | } |
| | | if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){ |
| | | //此时保证两个集合都不为null |
| | | info.ugRtuStateList.stream().sorted(Comparator.comparing(UpgradeRtu::getRtuAddr, Comparator.naturalOrder())).collect(Collectors.toList()); |
| | | } |
| | | //cache赋值必须放在上面处理的后面,否则上面的比较不成功 |
| | | cache = info; |
| | | } |
| | |
| | | */ |
| | | private void save2Db(String taskId, List<UpgradeRtu> newList, List<UpgradeRtu> oldList){ |
| | | List<UpgradeRtu> newOverList = newList.stream().filter(vo -> vo.isOver).collect(Collectors.toList()) ; |
| | | List<UpgradeRtu> oldNoOverList = newList.stream().filter(vo -> !vo.isOver).collect(Collectors.toList()) ; |
| | | for(UpgradeRtu nvo : newOverList){ |
| | | if(nvo != null) { |
| | | if(oldList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr) && vo.isOver == false)){ |
| | | if(oldNoOverList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr))){ |
| | | //上次没有升级结束,而当前升级结束了 |
| | | this.sv.saveRtuUpgradeState(Long.parseLong(taskId), nvo); |
| | | } |