src/main/java/com/lunhan/water/entity/request/alarmhistory/ReqCreateAlarmHistory.java
对比新文件 @@ -0,0 +1,53 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.entity.request.alarmhistory; import lombok.Data; /** * 历史报警表 * @author lin.liu */ @Data public class ReqCreateAlarmHistory { /** * 设备id */ private Long facilityId; /** * 报警参数 */ private String code; /** * 描述 */ private String description; /** * 备注 */ private String comment; /** * 是否处理 */ private Integer isSolve; } src/main/java/com/lunhan/water/entity/request/alarmhistory/ReqModifyAlarmHistory.java
对比新文件 @@ -0,0 +1,57 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.entity.request.alarmhistory; import lombok.Data; /** * 历史报警表 * @author lin.liu */ @Data public class ReqModifyAlarmHistory { /** * 自增id */ private Long id; /** * 设备id */ private Long facilityId; /** * 报警参数 */ private String code; /** * 描述 */ private String description; /** * 备注 */ private String comment; /** * 是否处理 */ private Integer isSolve; } src/main/java/com/lunhan/water/entity/search/SearchAlarmHistory.java
对比新文件 @@ -0,0 +1,14 @@ package com.lunhan.water.entity.search; import lombok.Data; import com.lunhan.water.entity.dto.SearchBasicDTO; /** * 历史报警表 * @author lin.liu */ @Data public class SearchAlarmHistory extends SearchBasicDTO { } src/main/java/com/lunhan/water/host/controller/AlarmHistoryController.java
对比新文件 @@ -0,0 +1,113 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.host.controller; import com.lunhan.water.common.ExecutedResult; import com.lunhan.water.common.PagerResult; import com.lunhan.water.common.util.ParameterUtil; import com.lunhan.water.common.validator.ParameterValidateResult; import com.lunhan.water.common.validator.ParameterValidator; import com.lunhan.water.entity.request.ReqListId; import com.lunhan.water.host.BasicController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; import com.lunhan.water.service.AlarmHistoryService; import com.lunhan.water.entity.request.alarmhistory.ReqCreateAlarmHistory; import com.lunhan.water.entity.request.alarmhistory.ReqModifyAlarmHistory; import com.lunhan.water.entity.search.SearchAlarmHistory; import com.lunhan.water.repository.vo.AlarmHistoryVO; /** * 9000.历史报警表 * @author lin.liu * @order 9000 */ @RestController @RequestMapping(value = "alarmHistory") public class AlarmHistoryController extends BasicController { @Autowired private AlarmHistoryService service; /** * 创建[历史报警表] * @author lin.liu */ @PostMapping(value = "create") public ExecutedResult<Long> create(@RequestBody ReqCreateAlarmHistory request) { //#region 参数验证 ParameterValidator validator = new ParameterValidator() // 非空 //.addNotNullOrEmpty(ParameterUtil.named("名称"), request.getName()) // 限制最大长度 //.addLengthMax(ParameterUtil.named("名称"), request.getName(), ConstantFactory.LENGTH_MAX50) ; ParameterValidateResult result = validator.validate(); if (result.getIsFiled()) { return failed(result.getErrorMsg()); } //#endregion return service.create(request); } /** * 编辑[历史报警表] * @author lin.liu */ @PostMapping(value = "modify") public ExecutedResult<String> modify(@RequestBody ReqModifyAlarmHistory request) { //#region 参数验证 ParameterValidator validator = new ParameterValidator() // 必须大于0 .addGreater(ParameterUtil.named("[历史报警表]id"), request.getId(), 0L) // 非空 //.addNotNullOrEmpty(ParameterUtil.named("名称"), request.getName()) // 限制最大长度 //.addLengthMax(ParameterUtil.named("名称"), request.getName(), ConstantFactory.LENGTH_MAX50) ; ParameterValidateResult result = validator.validate(); if (result.getIsFiled()) { return failed(result.getErrorMsg()); } //#endregion return service.modify(request); } /** * 获取[历史报警表] * @author lin.liu */ @GetMapping(value = "get/{id}") public ExecutedResult<AlarmHistoryVO> get(@PathVariable Long id) { return service.get(id); } /** * 查询[历史报警表] * @author lin.liu */ @PostMapping(value = "search") public ExecutedResult<PagerResult<AlarmHistoryVO>> search(@RequestBody SearchAlarmHistory request) { return service.search(request); } } src/main/java/com/lunhan/water/repository/impl/AlarmHistoryMapperImpl.java
对比新文件 @@ -0,0 +1,147 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.repository.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.lunhan.water.common.PagerResult; import com.lunhan.water.common.enums.EYesOrNo; import com.lunhan.water.common.util.*; import com.lunhan.water.entity.dto.*; import com.lunhan.water.entity.enums.*; import com.lunhan.water.repository.BasicMapperImpl; import org.springframework.stereotype.Repository; import java.util.List; import com.lunhan.water.entity.search.SearchAlarmHistory; import com.lunhan.water.repository.mapper.AlarmHistoryMapper; import com.lunhan.water.repository.po.AlarmHistoryPO; /** * 历史报警表 * @author lin.liu */ @Repository public class AlarmHistoryMapperImpl extends BasicMapperImpl<AlarmHistoryPO, AlarmHistoryMapper> { AlarmHistoryMapperImpl(AlarmHistoryMapper mapper) { super(mapper); } @Override public PagerResult<AlarmHistoryPO> search(SearchBasicDTO request) { // 还原查询条件真实类型 SearchAlarmHistory search = (SearchAlarmHistory)request; // 查询条件 LambdaQueryWrapper<AlarmHistoryPO> queryWrapper = this.query(); // 非逻辑删除 queryWrapper.eq(AlarmHistoryPO::getIsDelete, EYesOrNo.NO.getValue()); // 状态 //queryWrapper.eq(NumericUtil.tryParseInt(search.getStatus()).compareTo(0) > 0, AlarmHistoryPO::getStatus, search.getStatus()); // 状态列表 //queryWrapper.in(ListUtil.isNotNullOrEmpty(search.getListStatus()), AlarmHistoryPO::getStatus, search.getListStatus()); // 数据创建时间-起始 queryWrapper.ge(NumericUtil.tryParseLong(search.getCreateTimeStart()).compareTo(0L) > 0, AlarmHistoryPO::getCreateTime, search.getCreateTimeStart()); // 数据创建时间-截止 queryWrapper.le(NumericUtil.tryParseLong(search.getCreateTimeEnd()).compareTo(0L) > 0, AlarmHistoryPO::getCreateTime, search.getCreateTimeEnd()); // 关键字 //if (StringUtil.isNotNullOrEmpty(search.getKeywords())) { // queryWrapper.and(q -> // q.like(AlarmHistoryPO::getName, search.getKeywords()) // .or().like(AlarmHistoryPO::getPhone, search.getKeywords()) // ); //} // 排序处理 if (ListUtil.isNotNullOrEmpty(search.getOrderBy())) { for (OrderByDTO item : search.getOrderBy()) { EOrderBy orderBy = EOrderBy.getByValue(item.getOrderBy()); // 顺序排序 if (item.getIsAsc()) { switch (orderBy) { // 主键 case ID: queryWrapper.orderByAsc(AlarmHistoryPO::getId); break; // 数据创建时间 case CREATE_TIME: queryWrapper.orderByAsc(AlarmHistoryPO::getCreateTime); break; // 最后更新时间 case UPDATE_TIME: queryWrapper.orderByAsc(AlarmHistoryPO::getUpdateTime); break; } } else { // 倒叙排序 switch (orderBy) { // 主键 case ID: queryWrapper.orderByDesc(AlarmHistoryPO::getId); break; // 数据创建时间 case CREATE_TIME: queryWrapper.orderByDesc(AlarmHistoryPO::getCreateTime); break; // 最后更新时间 case UPDATE_TIME: queryWrapper.orderByDesc(AlarmHistoryPO::getUpdateTime); break; } } } } else { queryWrapper.orderByDesc(AlarmHistoryPO::getId); } Page<AlarmHistoryPO> pageResult = super.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper); return new PagerResult<>(pageResult.getSize(), pageResult.getCurrent(), pageResult.getTotal(), pageResult.getRecords()); } public Boolean add(AlarmHistoryPO item) { int rowCount = super.insert(item); return rowCount == 1; } public Boolean addNotIncrement(AlarmHistoryPO item) { int rowCount = super.insert(item); return rowCount == 1; } public AlarmHistoryPO getById(Long id) { return super.get(id); } public AlarmHistoryPO getByCode(Long facilityId,String code) { LambdaQueryWrapper<AlarmHistoryPO> queryWrapper = this.query(); queryWrapper.eq(AlarmHistoryPO::getFacilityId,facilityId); queryWrapper.eq(AlarmHistoryPO::getCode,code); return super.selectOne(queryWrapper); } public Integer deleteByFacilityId(Long facilityId) { return DB.deleteByFacilityId(facilityId); } public List<AlarmHistoryPO> getListById(List<Long> listId) { return super.getList(listId); } } src/main/java/com/lunhan/water/repository/mapper/AlarmHistoryMapper.java
对比新文件 @@ -0,0 +1,14 @@ package com.lunhan.water.repository.mapper; import com.lunhan.water.repository.BasicMapper; import com.lunhan.water.repository.po.AlarmHistoryPO; import org.apache.ibatis.annotations.Delete; /** * 历史报警表 mapper * @author lin.liu */ public interface AlarmHistoryMapper extends BasicMapper<AlarmHistoryPO> { @Delete("delete from alarm_history where is_delete=0 and facility_id=#{facilityId}") Integer deleteByFacilityId(Long facilityId); } src/main/java/com/lunhan/water/repository/po/AlarmHistoryPO.java
对比新文件 @@ -0,0 +1,84 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.repository.po; import lombok.Data; import com.baomidou.mybatisplus.annotation.*; import java.io.Serializable; import java.sql.Timestamp; /** * 历史报警表 * @author lin.liu */ @Data @TableName("alarm_history") public class AlarmHistoryPO implements Serializable { /** * 自增id */ private Long id; /** * 设备id */ @TableField(value = "facility_id") private Long facilityId; /** * 报警参数 */ @TableField(value = "code") private String code; /** * 描述 */ @TableField(value = "description") private String description; /** * 备注 */ @TableField(value = "last_time") private String lastTime; /** * 创建时间 */ @TableField(value = "create_time") private Long createTime; /** * 数据最后更新时间 */ @TableField(value = "update_time") private Timestamp updateTime; /** * 是否删除(逻辑删除) */ @TableLogic @TableField(value = "is_delete") private Integer isDelete; /** * 是否处理 */ @TableField(value = "count") private Integer count; } src/main/java/com/lunhan/water/repository/vo/AlarmHistoryVO.java
对比新文件 @@ -0,0 +1,54 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.repository.vo; import lombok.Data; import com.lunhan.water.common.util.LocalDateTimeUtil; import com.lunhan.water.common.util.NumericUtil; import java.util.Objects; import com.lunhan.water.repository.po.AlarmHistoryPO; /** * 历史报警表 * @author lin.liu */ @Data public class AlarmHistoryVO extends AlarmHistoryPO implements BasicVO { @Override public String getCreateTimeView() { if (NumericUtil.tryParseLong(this.getCreateTime()).compareTo(0L) > 0) { return LocalDateTimeUtil.toFormatString(this.getCreateTime()); } return ""; } @Override public String getUpdateTimeView() { if (Objects.isNull(this.getUpdateTime())) { return ""; } return LocalDateTimeUtil.toFormatFullString(this.getUpdateTime()); } } src/main/java/com/lunhan/water/service/AlarmHistoryService.java
对比新文件 @@ -0,0 +1,244 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.service; import com.lunhan.water.common.*; import com.lunhan.water.common.enums.*; import com.lunhan.water.common.model.Tuple; import com.lunhan.water.common.util.*; import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; import com.lunhan.water.repository.impl.AlarmHistoryMapperImpl; import com.lunhan.water.repository.po.AlarmHistoryPO; import com.lunhan.water.entity.request.alarmhistory.ReqCreateAlarmHistory; import com.lunhan.water.entity.request.alarmhistory.ReqModifyAlarmHistory; import com.lunhan.water.entity.search.SearchAlarmHistory; import com.lunhan.water.repository.vo.AlarmHistoryVO; import com.lunhan.water.service.convert.AlarmHistoryConvert; /** * 历史报警表 * @author lin.liu */ @Service public class AlarmHistoryService extends BaseService { @Autowired private AlarmHistoryMapperImpl mapper; public ExecutedResult<Long> create(ReqCreateAlarmHistory request) { // 转换po AlarmHistoryPO item = AlarmHistoryConvert.INSTANCE.toCreate(request); // 设置状态 //item.setStatus(EState.NORMAL.getValue()); // 设置记录创建时间 item.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); // 是否删除(逻辑删除)初始值 item.setIsDelete(EYesOrNo.NO.getValue()); int rowCount = mapper.insert(item); if (rowCount != 1) { return ExecutedResult.failed("创建[历史报警表]失败。"); } return ExecutedResult.success(item.getId()); } public ExecutedResult<String> modify(ReqModifyAlarmHistory request) { // 验证记录是否存在 ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(request.getId()); if (checkExists.isFailed()) { return ExecutedResult.failed(checkExists.getMsg()); } // 转换po AlarmHistoryPO item = AlarmHistoryConvert.INSTANCE.toModify(request); int rowCount = mapper.updateById(item); if (rowCount != 1) { return ExecutedResult.failed("编辑[历史报警表]失败。"); } return ExecutedResult.success(); } public ExecutedResult<AlarmHistoryVO> get(Long id) { AlarmHistoryVO result = new AlarmHistoryVO(); AlarmHistoryPO find = mapper.get(id); if (null != find) { // 转换vo result = AlarmHistoryConvert.INSTANCE.toVo(find); } return ExecutedResult.success(result); } // public ExecutedResult<String> stop(Long id) { // // 验证记录是否存在 // ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(id); // if (checkExists.isFailed()) { // return ExecutedResult.failed(checkExists.getMsg()); // } // AlarmHistoryPO item = new AlarmHistoryPO(); // item.setId(id); // item.setStatus(EState.DISABLED.getValue()); // // int rowCount = mapper.updateById(item); // if (rowCount != 1) { // return ExecutedResult.failed("停用[历史报警表]失败。"); // } // return ExecutedResult.success(); // } // // public ExecutedResult<String> enable(Long id) { // // 验证记录是否存在 // ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(id); // if (checkExists.isFailed()) { // return ExecutedResult.failed(checkExists.getMsg()); // } // AlarmHistoryPO item = new AlarmHistoryPO(); // item.setId(id); // item.setStatus(EState.NORMAL.getValue()); // // int rowCount = mapper.updateById(item); // if (rowCount != 1) { // return ExecutedResult.failed("启用[历史报警表]失败。"); // } // return ExecutedResult.success(); // } // // public ExecutedResult<String> setSort(ReqSetSort request) { // // 验证记录是否存在 // ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(request.getId()); // if (checkExists.isFailed()) { // return ExecutedResult.failed(checkExists.getMsg()); // } // AlarmHistoryPO item = new AlarmHistoryPO(); // item.setId(request.getId()); // item.setSort(request.getSort()); // // int rowCount = mapper.updateById(item); // if (rowCount != 1) { // return ExecutedResult.failed("设置[历史报警表]排序值失败。"); // } // return ExecutedResult.success(); // } // // public ExecutedResult<String> listSetSort(ReqListSetSort request) { // // id列表 // List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList()); // // 验证记录是否存在 // ExecutedResult<List<AlarmHistoryPO>> checkExists = this.check4Id(listId); // if (checkExists.isFailed()) { // return ExecutedResult.failed(checkExists.getMsg()); // } // // List<AlarmHistoryPO> listUpdate = request.getList().stream() // .map(c -> { // AlarmHistoryPO item = new AlarmHistoryPO(); // item.setId(c.getId()); // item.setSort(c.getSort()); // return item; // }) // .collect(Collectors.toList()); // Boolean result = mapper.modifyList(listUpdate); // if (result) { // return ExecutedResult.success(); // } // return ExecutedResult.failed("[历史报警表]设置排序值失败"); // } // // public ExecutedResult<String> remove(Long id) { // Boolean result = mapper.deleteLogic(id); // if (BooleanUtils.isFalse(result)) { // return ExecutedResult.failed("删除[历史报警表]失败。"); // } // return ExecutedResult.success(); // } // // public ExecutedResult<String> removeList(List<Long> ids) { // Boolean result = mapper.deleteLogic(ids); // if (BooleanUtils.isFalse(result)) { // return ExecutedResult.failed("删除[历史报警表]失败。"); // } // return ExecutedResult.success(); // } public ExecutedResult<List<AlarmHistoryVO>> getList(List<Long> listId) { List<AlarmHistoryVO> result = new ArrayList<>(); List<AlarmHistoryPO> list = mapper.getList(listId); if (ListUtil.isNotNullOrEmpty(list)) { // 转换vo result = AlarmHistoryConvert.INSTANCE.toVo(list); } return ExecutedResult.success(result); } public ExecutedResult<PagerResult<AlarmHistoryVO>> search(SearchAlarmHistory search) { // 处理创建时间范围-查询参数 Tuple<String, String> createTimeRange = ParameterUtil.getTimeRange(search.getCreateTimeRange()); if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem1())) { search.setCreateTimeStart(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem1()).getTime()); } if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem2())) { search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime()); } PagerResult<AlarmHistoryPO> pageList = mapper.search(search); List<AlarmHistoryVO> listVo = new ArrayList<>(); List<AlarmHistoryPO> list = pageList.getList(); if (ListUtil.isNotNullOrEmpty(list)) { pageList.setLastId(list.get(list.size() - 1).getId()); // 转换vo listVo = AlarmHistoryConvert.INSTANCE.toVo(list); } PagerResult<AlarmHistoryVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo); result.setLastId(pageList.getLastId()); return ExecutedResult.success(result); } protected ExecutedResult<AlarmHistoryPO> check4Id(Long id) { AlarmHistoryPO exists = mapper.get(id); if (Objects.isNull(exists)) { return ExecutedResult.failed("[历史报警表]不存在:" + id); } return ExecutedResult.success(exists); } protected ExecutedResult<List<AlarmHistoryPO>> check4Id(List<Long> listId) { // 从数据库查找历史报警表 List<AlarmHistoryPO> list = mapper.getList(listId); if (ListUtil.isNullOrEmpty(list)) { return ExecutedResult.failed("[历史报警表]不存在." + listId); } // 数据库找到的id列表 List<Long> listIdFind = list.stream().map(AlarmHistoryPO::getId).collect(Collectors.toList()); // 数量不一致 if (listId.size() != listIdFind.size()) { // 筛选数据库不存在的历史报警表 List<Long> listIdNotFound = listId.stream().filter(c -> !listIdFind.contains(c)).collect(Collectors.toList()); if (ListUtil.isNullOrEmpty(list)) { return ExecutedResult.failed("[历史报警表]不存在." + listIdNotFound); } } return ExecutedResult.success(list); }} src/main/java/com/lunhan/water/service/PaymentRecordsService.java
@@ -80,6 +80,8 @@ private FacilityAlarmRecordMapperImpl facilityAlarmRecordMapper; @Autowired private WaterFacilityRecordsMapperImpl waterFacilityRecordsMapper; @Autowired private AlarmHistoryMapperImpl alarmHistoryMapper; public ExecutedResult<Long> create(ReqCreatePaymentRecords request) { // 转换po @@ -310,23 +312,6 @@ DEBUG_LOGGER.error("设备数据未找到!"); return; } // 数据上报格式: // 主题格式:zundong/QS001/data // 数据格式:{"Data": // [ // {"name":"QS001_state","value":1}, //状态 // {"name":"QS001_fault","value":0}, //是否故障 // {"name":"QS001_count","value":10000} //总水量 // ],"time":"2025-07-02 15:19:17" // } // 心跳上报格式: // 主题格式:zundong/QS001/state // 数据格式:{"Data": // [ // {"name":"QS001_heartbeat","value":1} //心跳 // ],"time":"2025-07-02 15:19:17" // } //消息解析 Gson gson = new Gson(); JsonObject object = gson.fromJson(msg, JsonObject.class); @@ -350,6 +335,8 @@ CountVO stateVo = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_state1")).findFirst().orElse(null); CountVO heartbeat = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_heartbeat")).findFirst().orElse(null); CountVO countVO = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_count1")).findFirst().orElse(null); AlarmHistoryPO alarmHistoryPO=new AlarmHistoryPO(); alarmHistoryPO.setFacilityId(facilityPO.getId()); switch (stateVo.getValue()) { case "0"://取水完成 BigDecimal divide = new BigDecimal(countVO.getValue()).setScale(2,RoundingMode.DOWN); @@ -370,11 +357,48 @@ } break; case "1"://运行 facilityPO.setState(1); waterFacilityMapper.updateById(facilityPO); break; case "2"://停止 facilityPO.setState(2); waterFacilityMapper.updateById(facilityPO); break; case "3"://故障 case "10"://故障 alarmHistoryPO.setCode("500"); alarmHistoryPO.setDescription("管道缺水"); break; case "11"://故障 alarmHistoryPO.setCode("501"); alarmHistoryPO.setDescription("流量计故障"); break; case "12"://故障 alarmHistoryPO.setCode("502"); alarmHistoryPO.setDescription("阀门故障"); break; case "13"://故障 alarmHistoryPO.setCode("503"); alarmHistoryPO.setDescription("柜内温度过低"); break; case "14"://故障 alarmHistoryPO.setCode("504"); alarmHistoryPO.setDescription("柜内温度过高"); break; } if(StringUtil.isNotNullOrEmpty(alarmHistoryPO.getCode())){ AlarmHistoryPO historyPO = alarmHistoryMapper.getByCode(facilityPO.getId(), alarmHistoryPO.getCode()); if(Objects.nonNull(historyPO)){ historyPO.setLastTime(LocalDateTimeUtil.nowDateTimeStr()); historyPO.setCount(historyPO.getCount()+1); alarmHistoryMapper.updateById(historyPO); }else { alarmHistoryPO.setLastTime(LocalDateTimeUtil.nowDateTimeStr()); alarmHistoryPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); alarmHistoryMapper.insert(alarmHistoryPO); } }else { alarmHistoryMapper.deleteByFacilityId(facilityPO.getId()); } HeartbeatDataPO heartbeatDataPO = heartbeatDataMapper.getByKey(facilityPO.getFacilityCode()); if(Objects.nonNull(heartbeatDataPO)){ src/main/java/com/lunhan/water/service/convert/AlarmHistoryConvert.java
对比新文件 @@ -0,0 +1,48 @@ /** # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 永无BUG! */ package com.lunhan.water.service.convert; import com.lunhan.water.entity.request.alarmhistory.ReqCreateAlarmHistory; import com.lunhan.water.entity.request.alarmhistory.ReqModifyAlarmHistory; import com.lunhan.water.repository.po.AlarmHistoryPO; import com.lunhan.water.repository.vo.AlarmHistoryVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; /** * 历史报警表 * @author {#=author} */ @Mapper public interface AlarmHistoryConvert { AlarmHistoryConvert INSTANCE = Mappers.getMapper(AlarmHistoryConvert.class); AlarmHistoryPO toCreate(ReqCreateAlarmHistory request); AlarmHistoryPO toModify(ReqModifyAlarmHistory request); AlarmHistoryVO toVo(AlarmHistoryPO item); List<AlarmHistoryVO> toVo(List<AlarmHistoryPO> list); } src/test/java/com/lunhan/water/GenCodeGauss.java
@@ -243,7 +243,7 @@ * 只生成以下配置的表 */ private static final List<String> ONLY_TABLES = Arrays.asList( "water_facility_records" "alarm_history" ); public static void main(String[] args) {