From d36ad7a2138062f891000c13d9712b4706f8627c Mon Sep 17 00:00:00 2001 From: liulin <lin.liu@88.com> Date: 星期二, 08 七月 2025 09:24:46 +0800 Subject: [PATCH] 修改支付接口 --- src/main/java/com/lunhan/water/repository/impl/WaterFacilityRecordsMapperImpl.java | 137 ++++++++ src/main/java/com/lunhan/water/repository/vo/WaterFacilityRecordsVO.java | 54 +++ src/main/java/com/lunhan/water/host/controller/WaterFacilityRecordsController.java | 113 +++++++ src/main/java/com/lunhan/water/entity/search/SearchWaterFacilityRecords.java | 14 src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqModifyWaterFacilityRecords.java | 58 +++ src/main/java/com/lunhan/water/repository/po/WaterFacilityRecordsPO.java | 85 +++++ src/main/java/com/lunhan/water/repository/mapper/WaterFacilityRecordsMapper.java | 10 src/test/java/com/lunhan/water/DateTimeTest.java | 10 src/main/java/com/lunhan/water/service/PaymentRecordsService.java | 124 +++---- src/test/java/com/lunhan/water/GenCodeGauss.java | 2 src/main/java/com/lunhan/water/service/convert/WaterFacilityRecordsConvert.java | 48 +++ src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqCreateWaterFacilityRecords.java | 54 +++ src/main/java/com/lunhan/water/repository/po/WaterFacilityPO.java | 6 src/main/java/com/lunhan/water/service/WaterFacilityRecordsService.java | 244 +++++++++++++++ 14 files changed, 888 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqCreateWaterFacilityRecords.java b/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqCreateWaterFacilityRecords.java new file mode 100644 index 0000000..cfea3e9 --- /dev/null +++ b/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqCreateWaterFacilityRecords.java @@ -0,0 +1,54 @@ +/** +# __----~~~~~~~~~~~------___ +# . . ~~//====...... __--~ ~~ +# -. \_|// |||\\ ~~~~~~::::... /~ +# ___-==_ _-~o~ \/ ||| \\ _/~~- +# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ +# _-~~ .=~ | \\-_ '-~7 /- / || \ / +# .~ .~ | \\ -_ / /- / || \ / +# / ____ / | \\ ~-_/ /|- _/ .|| \ / +# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ +# ' ~-| /| |-~\~~ __--~~ +# |-~~-_/ | | ~\_ _-~ /\ +# / \ \__ \/~ \__ +# _--~ _/ | .-~~____--~-/ ~~==. +# ((->/~ '.|||' -_| ~~-/ , . _|| +# -_ ~\ ~~---l__i__i__i--~~_/ +# _-~-__ ~) \--______________--~~ +# //.-~~~-~_--~- |-------~~~~~~~~ +# //.-~~~--\ +# 神兽保佑 +# 永无BUG! +*/ +package com.lunhan.water.entity.request.waterfacilityrecords; + +import lombok.Data; +import java.math.BigDecimal; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Data +public class ReqCreateWaterFacilityRecords { + /** + * 设备id + */ + private Long facilityId; + /** + * 设备名称 + */ + private String facilityName; + /** + * 本次用水量 + */ + private BigDecimal waterValue; + /** + * 使用日期 + */ + private String useDate; + /** + * 备注 + */ + private String remark; +} diff --git a/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqModifyWaterFacilityRecords.java b/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqModifyWaterFacilityRecords.java new file mode 100644 index 0000000..b90c7e1 --- /dev/null +++ b/src/main/java/com/lunhan/water/entity/request/waterfacilityrecords/ReqModifyWaterFacilityRecords.java @@ -0,0 +1,58 @@ +/** +# __----~~~~~~~~~~~------___ +# . . ~~//====...... __--~ ~~ +# -. \_|// |||\\ ~~~~~~::::... /~ +# ___-==_ _-~o~ \/ ||| \\ _/~~- +# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ +# _-~~ .=~ | \\-_ '-~7 /- / || \ / +# .~ .~ | \\ -_ / /- / || \ / +# / ____ / | \\ ~-_/ /|- _/ .|| \ / +# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ +# ' ~-| /| |-~\~~ __--~~ +# |-~~-_/ | | ~\_ _-~ /\ +# / \ \__ \/~ \__ +# _--~ _/ | .-~~____--~-/ ~~==. +# ((->/~ '.|||' -_| ~~-/ , . _|| +# -_ ~\ ~~---l__i__i__i--~~_/ +# _-~-__ ~) \--______________--~~ +# //.-~~~-~_--~- |-------~~~~~~~~ +# //.-~~~--\ +# 神兽保佑 +# 永无BUG! +*/ +package com.lunhan.water.entity.request.waterfacilityrecords; + +import lombok.Data; +import java.math.BigDecimal; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Data +public class ReqModifyWaterFacilityRecords { + /** + * 主键id + */ + private Long id; + /** + * 设备id + */ + private Long facilityId; + /** + * 设备名称 + */ + private String facilityName; + /** + * 本次用水量 + */ + private BigDecimal waterValue; + /** + * 使用日期 + */ + private String useDate; + /** + * 备注 + */ + private String remark; +} diff --git a/src/main/java/com/lunhan/water/entity/search/SearchWaterFacilityRecords.java b/src/main/java/com/lunhan/water/entity/search/SearchWaterFacilityRecords.java new file mode 100644 index 0000000..06703e6 --- /dev/null +++ b/src/main/java/com/lunhan/water/entity/search/SearchWaterFacilityRecords.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 SearchWaterFacilityRecords extends SearchBasicDTO { + +} diff --git a/src/main/java/com/lunhan/water/host/controller/WaterFacilityRecordsController.java b/src/main/java/com/lunhan/water/host/controller/WaterFacilityRecordsController.java new file mode 100644 index 0000000..b02a6c7 --- /dev/null +++ b/src/main/java/com/lunhan/water/host/controller/WaterFacilityRecordsController.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.WaterFacilityRecordsService; +import com.lunhan.water.entity.request.waterfacilityrecords.ReqCreateWaterFacilityRecords; +import com.lunhan.water.entity.request.waterfacilityrecords.ReqModifyWaterFacilityRecords; +import com.lunhan.water.entity.search.SearchWaterFacilityRecords; +import com.lunhan.water.repository.vo.WaterFacilityRecordsVO; + +/** + * 9000.设备供水记录 + * @author lin.liu + * @order 9000 + */ +@RestController +@RequestMapping(value = "waterFacilityRecords") +public class WaterFacilityRecordsController extends BasicController { + @Autowired + private WaterFacilityRecordsService service; + + /** + * 创建[设备供水记录] + * @author lin.liu + */ + @PostMapping(value = "create") + public ExecutedResult<Long> create(@RequestBody ReqCreateWaterFacilityRecords 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 ReqModifyWaterFacilityRecords 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<WaterFacilityRecordsVO> get(@PathVariable Long id) { + return service.get(id); + } + + /** + * 查询[设备供水记录] + * @author lin.liu + */ + @PostMapping(value = "search") + public ExecutedResult<PagerResult<WaterFacilityRecordsVO>> search(@RequestBody SearchWaterFacilityRecords request) { + return service.search(request); + } +} diff --git a/src/main/java/com/lunhan/water/repository/impl/WaterFacilityRecordsMapperImpl.java b/src/main/java/com/lunhan/water/repository/impl/WaterFacilityRecordsMapperImpl.java new file mode 100644 index 0000000..b5345ea --- /dev/null +++ b/src/main/java/com/lunhan/water/repository/impl/WaterFacilityRecordsMapperImpl.java @@ -0,0 +1,137 @@ +/** +# __----~~~~~~~~~~~------___ +# . . ~~//====...... __--~ ~~ +# -. \_|// |||\\ ~~~~~~::::... /~ +# ___-==_ _-~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.SearchWaterFacilityRecords; +import com.lunhan.water.repository.mapper.WaterFacilityRecordsMapper; +import com.lunhan.water.repository.po.WaterFacilityRecordsPO; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Repository +public class WaterFacilityRecordsMapperImpl extends BasicMapperImpl<WaterFacilityRecordsPO, WaterFacilityRecordsMapper> { + WaterFacilityRecordsMapperImpl(WaterFacilityRecordsMapper mapper) { + super(mapper); + } + + @Override + public PagerResult<WaterFacilityRecordsPO> search(SearchBasicDTO request) { + // 还原查询条件真实类型 + SearchWaterFacilityRecords search = (SearchWaterFacilityRecords)request; + // 查询条件 + LambdaQueryWrapper<WaterFacilityRecordsPO> queryWrapper = this.query(); + // 非逻辑删除 + queryWrapper.eq(WaterFacilityRecordsPO::getIsDelete, EYesOrNo.NO.getValue()); + // 状态 + //queryWrapper.eq(NumericUtil.tryParseInt(search.getStatus()).compareTo(0) > 0, WaterFacilityRecordsPO::getStatus, search.getStatus()); + // 状态列表 + //queryWrapper.in(ListUtil.isNotNullOrEmpty(search.getListStatus()), WaterFacilityRecordsPO::getStatus, search.getListStatus()); + + // 数据创建时间-起始 + queryWrapper.ge(NumericUtil.tryParseLong(search.getCreateTimeStart()).compareTo(0L) > 0, WaterFacilityRecordsPO::getCreateTime, search.getCreateTimeStart()); + // 数据创建时间-截止 + queryWrapper.le(NumericUtil.tryParseLong(search.getCreateTimeEnd()).compareTo(0L) > 0, WaterFacilityRecordsPO::getCreateTime, search.getCreateTimeEnd()); + // 关键字 + //if (StringUtil.isNotNullOrEmpty(search.getKeywords())) { + // queryWrapper.and(q -> + // q.like(WaterFacilityRecordsPO::getName, search.getKeywords()) + // .or().like(WaterFacilityRecordsPO::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(WaterFacilityRecordsPO::getId); + break; + // 数据创建时间 + case CREATE_TIME: + queryWrapper.orderByAsc(WaterFacilityRecordsPO::getCreateTime); + break; + // 最后更新时间 + case UPDATE_TIME: + queryWrapper.orderByAsc(WaterFacilityRecordsPO::getUpdateTime); + break; + } + } else { + // 倒叙排序 + switch (orderBy) { + // 主键 + case ID: + queryWrapper.orderByDesc(WaterFacilityRecordsPO::getId); + break; + // 数据创建时间 + case CREATE_TIME: + queryWrapper.orderByDesc(WaterFacilityRecordsPO::getCreateTime); + break; + // 最后更新时间 + case UPDATE_TIME: + queryWrapper.orderByDesc(WaterFacilityRecordsPO::getUpdateTime); + break; + } + } + } + } else { + queryWrapper.orderByDesc(WaterFacilityRecordsPO::getId); + } + Page<WaterFacilityRecordsPO> pageResult = super.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper); + return new PagerResult<>(pageResult.getSize(), pageResult.getCurrent(), pageResult.getTotal(), pageResult.getRecords()); + } + + public Boolean add(WaterFacilityRecordsPO item) { + int rowCount = super.insert(item); + return rowCount == 1; + } + + public Boolean addNotIncrement(WaterFacilityRecordsPO item) { + int rowCount = super.insert(item); + return rowCount == 1; + } + + public WaterFacilityRecordsPO getById(Long id) { + return super.get(id); + } + + public List<WaterFacilityRecordsPO> getListById(List<Long> listId) { + return super.getList(listId); + } +} diff --git a/src/main/java/com/lunhan/water/repository/mapper/WaterFacilityRecordsMapper.java b/src/main/java/com/lunhan/water/repository/mapper/WaterFacilityRecordsMapper.java new file mode 100644 index 0000000..a34e714 --- /dev/null +++ b/src/main/java/com/lunhan/water/repository/mapper/WaterFacilityRecordsMapper.java @@ -0,0 +1,10 @@ +package com.lunhan.water.repository.mapper; + +import com.lunhan.water.repository.BasicMapper;import com.lunhan.water.repository.po.WaterFacilityRecordsPO; + +/** + * 设备供水记录 mapper + * @author lin.liu + */ +public interface WaterFacilityRecordsMapper extends BasicMapper<WaterFacilityRecordsPO> { +} diff --git a/src/main/java/com/lunhan/water/repository/po/WaterFacilityPO.java b/src/main/java/com/lunhan/water/repository/po/WaterFacilityPO.java index 541f30d..6676351 100644 --- a/src/main/java/com/lunhan/water/repository/po/WaterFacilityPO.java +++ b/src/main/java/com/lunhan/water/repository/po/WaterFacilityPO.java @@ -108,10 +108,10 @@ @TableField(value = "install_date") private String installDate; /** - * 信号值 + * 总用水量 */ - @TableField(value = "signal_value") - private Integer signalValue; + @TableField(value = "water_count") + private BigDecimal waterCount; /** * 设备状态(1正常 2故障) */ diff --git a/src/main/java/com/lunhan/water/repository/po/WaterFacilityRecordsPO.java b/src/main/java/com/lunhan/water/repository/po/WaterFacilityRecordsPO.java new file mode 100644 index 0000000..6e0240d --- /dev/null +++ b/src/main/java/com/lunhan/water/repository/po/WaterFacilityRecordsPO.java @@ -0,0 +1,85 @@ +/** +# __----~~~~~~~~~~~------___ +# . . ~~//====...... __--~ ~~ +# -. \_|// |||\\ ~~~~~~::::... /~ +# ___-==_ _-~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; +import java.math.BigDecimal; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Data +@TableName("water_facility_records") +public class WaterFacilityRecordsPO implements Serializable { + /** + * 主键id + */ + private Long id; + /** + * 设备id + */ + @TableField(value = "facility_id") + private Long facilityId; + /** + * 设备名称 + */ + @TableField(value = "facility_name") + private String facilityName; + /** + * 本次用水量 + */ + @TableField(value = "water_value") + private BigDecimal waterValue; + /** + * 使用日期 + */ + @TableField(value = "use_date") + private String useDate; + /** + * 是否删除 + */ + @TableLogic + @TableField(value = "is_delete") + private Integer isDelete; + /** + * 备注 + */ + @TableField(value = "remark") + private String remark; + /** + * 创建日期 + */ + @TableField(value = "create_time") + private Long createTime; + /** + * 修改日期 + */ + @TableField(value = "update_time") + private Timestamp updateTime; +} diff --git a/src/main/java/com/lunhan/water/repository/vo/WaterFacilityRecordsVO.java b/src/main/java/com/lunhan/water/repository/vo/WaterFacilityRecordsVO.java new file mode 100644 index 0000000..d9928d3 --- /dev/null +++ b/src/main/java/com/lunhan/water/repository/vo/WaterFacilityRecordsVO.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.WaterFacilityRecordsPO; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Data +public class WaterFacilityRecordsVO extends WaterFacilityRecordsPO 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()); + } +} diff --git a/src/main/java/com/lunhan/water/service/PaymentRecordsService.java b/src/main/java/com/lunhan/water/service/PaymentRecordsService.java index 340600f..7d523da 100644 --- a/src/main/java/com/lunhan/water/service/PaymentRecordsService.java +++ b/src/main/java/com/lunhan/water/service/PaymentRecordsService.java @@ -46,6 +46,7 @@ import java.lang.reflect.Type; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -77,6 +78,8 @@ private HeartbeatDataMapperImpl heartbeatDataMapper; @Autowired private FacilityAlarmRecordMapperImpl facilityAlarmRecordMapper; + @Autowired + private WaterFacilityRecordsMapperImpl waterFacilityRecordsMapper; public ExecutedResult<Long> create(ReqCreatePaymentRecords request) { // 转换po @@ -230,11 +233,10 @@ return ExecutedResult.failed("余额水量不足!"); } //发送mqtt取水指令 - String topic = "zundong/" + facilityPO.getFacilityCode() + "/switch"; + String topic = "zundong/" + facilityPO.getFacilityCode() + "/send"; JsonObject data = new JsonObject(); - data.addProperty(facilityPO.getFacilityCode() + "_amount", request.getAmount().multiply(BigDecimal.valueOf(100))); - data.addProperty(facilityPO.getFacilityCode() + "_user", userLoginPO.getUserCode()); - data.addProperty(facilityPO.getFacilityCode() + "_state", 1); + data.addProperty(facilityPO.getFacilityCode() + "_count2", request.getAmount().multiply(BigDecimal.valueOf(100))); + data.addProperty(facilityPO.getFacilityCode() + "_state2", 1); boolean send=false; if (Objects.nonNull(mqttServer)) { send = mqttServer.send(topic, data.toString()); @@ -252,6 +254,35 @@ if(!send){ ExecutedResult.failed("通讯断开!"); } + //扣除余额 + //创建消费记录 + PaymentRecordsPO recordsPO=new PaymentRecordsPO(); + recordsPO.setUserId(userLoginPO.getId()); + recordsPO.setUserName(userLoginPO.getUserName()); + recordsPO.setFacilityCode(facilityPO.getFacilityCode()); + recordsPO.setPaymentAmount(request.getAmount()); + recordsPO.setWaterAmount(request.getAmount()); + recordsPO.setPayTime(LocalDateTimeUtil.nowDateTimeStr()); + recordsPO.setPayStatus(EBillPayStatus.PAID.getValue()); + recordsPO.setComment("取水"); + recordsPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); + mapper.insert(recordsPO); + //修改余额 + BigDecimal beforeMoney=userLoginPO.getBalance(); + BigDecimal subtract = beforeMoney.subtract(request.getAmount()); + userLoginPO.setBalance(subtract); + userLoginMapper.updateById(userLoginPO); + //生成余额变动记录 + UserCapitalChangePO changePO=new UserCapitalChangePO(); + changePO.setUserId(userLoginPO.getId()); + changePO.setBusiness(ECapitalChange.WATER_BILL_COUNTER_PAY.getValue()); + changePO.setBusinessName("取水"); + changePO.setBusinessCode("QS"+SnowFlakeUtil.getId()); + changePO.setChangeMoney(request.getAmount()); + changePO.setBeforeMoney(beforeMoney); + changePO.setAfterMoney(subtract); + changePO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); + userCapitalChangeMapper.insert(changePO); return ExecutedResult.success("请点击设备取水按钮取水"); } @@ -309,50 +340,34 @@ case "data": uploadData(time,facilityPO,listVo); break; - case "state": - uploadState(time,facilityPO,listVo); - break; +// case "state": +// uploadState(time,facilityPO,listVo); +// break; } } public void uploadData(String time,WaterFacilityPO facilityPO, List<CountVO> listVo) { - CountVO stateVo = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_state")).findFirst().orElse(null); - CountVO faultVo = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_fault")).findFirst().orElse(null); - CountVO countVO = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_count")).findFirst().orElse(null); - CountVO userVo = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_user")).findFirst().orElse(null); + 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() + "_count2")).findFirst().orElse(null); switch (stateVo.getValue()) { case "0"://取水完成 - //扣除余额 - UserLoginPO user = userLoginMapper.get4UserCode(userVo.getValue()); - //创建消费记录 - PaymentRecordsPO recordsPO=new PaymentRecordsPO(); - recordsPO.setUserId(user.getId()); - recordsPO.setUserName(user.getUserName()); - recordsPO.setFacilityCode(facilityPO.getFacilityCode()); - BigDecimal bigDecimal = new BigDecimal(countVO.getValue()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_DOWN); - recordsPO.setPaymentAmount(bigDecimal); - recordsPO.setWaterAmount(bigDecimal); - recordsPO.setPayTime(time); - recordsPO.setPayStatus(EBillPayStatus.PAID.getValue()); - recordsPO.setComment("取水"); - recordsPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); - mapper.insert(recordsPO); - //修改余额 - BigDecimal beforeMoney=user.getBalance(); - BigDecimal subtract = beforeMoney.subtract(bigDecimal); - user.setBalance(subtract); - userLoginMapper.updateById(user); - //生成余额变动记录 - UserCapitalChangePO changePO=new UserCapitalChangePO(); - changePO.setUserId(user.getId()); - changePO.setBusiness(ECapitalChange.WATER_BILL_COUNTER_PAY.getValue()); - changePO.setBusinessName("取水"); - changePO.setBusinessCode("QS"+SnowFlakeUtil.getId()); - changePO.setChangeMoney(bigDecimal); - changePO.setBeforeMoney(beforeMoney); - changePO.setAfterMoney(subtract); - changePO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); - userCapitalChangeMapper.insert(changePO); + BigDecimal divide = new BigDecimal(countVO.getValue()).divide(new BigDecimal(100)).setScale(2,RoundingMode.DOWN); + BigDecimal subtract=divide.subtract(facilityPO.getWaterCount()); + if(subtract.compareTo(BigDecimal.ZERO)>0){ + facilityPO.setWaterCount(divide); + int i = waterFacilityMapper.updateById(facilityPO); + if(i>0){ + WaterFacilityRecordsPO recordsPO=new WaterFacilityRecordsPO(); + recordsPO.setFacilityId(facilityPO.getId()); + recordsPO.setFacilityName(facilityPO.getFacilityName()); + recordsPO.setWaterValue(subtract); + recordsPO.setUseDate(time); + recordsPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); + recordsPO.setRemark("设备供水记录"); + waterFacilityRecordsMapper.insert(recordsPO); + } + } break; case "1"://运行 break; @@ -361,40 +376,19 @@ case "3"://故障 break; } - } - public void uploadState(String time,WaterFacilityPO facilityPO, List<CountVO> listVo){ - CountVO heartbeatVO = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_heartbeat")).findFirst().orElse(null); HeartbeatDataPO heartbeatDataPO = heartbeatDataMapper.getByKey(facilityPO.getFacilityCode()); if(Objects.nonNull(heartbeatDataPO)){ - heartbeatDataPO.setDataValue(Integer.valueOf(heartbeatVO.getValue())); + heartbeatDataPO.setDataValue(Integer.valueOf(heartbeat.getValue())); heartbeatDataPO.setSendValue(heartbeatDataPO.getSendValue()==0?1:0); heartbeatDataMapper.updateById(heartbeatDataPO); }else { HeartbeatDataPO dataPO=new HeartbeatDataPO(); dataPO.setDataKey(facilityPO.getFacilityCode()); dataPO.setSendValue(0); - dataPO.setDataValue(Integer.valueOf(heartbeatVO.getValue())); + dataPO.setDataValue(Integer.valueOf(heartbeat.getValue())); dataPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); dataPO.setRemark(LocalDateTimeUtil.nowDateTimeStr()); heartbeatDataMapper.insert(dataPO); - } - //发送心跳数据 - // 发送心跳 - String topic = "zundong/"+facilityPO.getFacilityCode()+"/remotecontrol/"; - JsonObject data = new JsonObject(); - data.addProperty(facilityPO.getFacilityCode()+"_heartbeat", heartbeatDataPO.getSendValue()==0?1:0); - if (Objects.nonNull(mqttServer)) { - mqttServer.send(topic, data.toString()); - } else { - try { - System.out.println("mqttServer bean尚未初始化..."); - mqttServer = SpringUtil.getBean(MQTTServer.class); - System.out.println("mqttServer 初始化bean成功!"); - } catch (Exception ignored) { - } - if (Objects.nonNull(mqttServer)) { - mqttServer.send(topic, data.toString()); - } } } public ExecutedResult<List<PaymentRecordsVO>> getList(List<Long> listId) { diff --git a/src/main/java/com/lunhan/water/service/WaterFacilityRecordsService.java b/src/main/java/com/lunhan/water/service/WaterFacilityRecordsService.java new file mode 100644 index 0000000..50a22fb --- /dev/null +++ b/src/main/java/com/lunhan/water/service/WaterFacilityRecordsService.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.WaterFacilityRecordsMapperImpl; +import com.lunhan.water.repository.po.WaterFacilityRecordsPO; +import com.lunhan.water.entity.request.waterfacilityrecords.ReqCreateWaterFacilityRecords; +import com.lunhan.water.entity.request.waterfacilityrecords.ReqModifyWaterFacilityRecords; +import com.lunhan.water.entity.search.SearchWaterFacilityRecords; +import com.lunhan.water.repository.vo.WaterFacilityRecordsVO; +import com.lunhan.water.service.convert.WaterFacilityRecordsConvert; + +/** + * 设备供水记录 + * @author lin.liu + */ +@Service +public class WaterFacilityRecordsService extends BaseService { + @Autowired + private WaterFacilityRecordsMapperImpl mapper; + + public ExecutedResult<Long> create(ReqCreateWaterFacilityRecords request) { + // 转换po + WaterFacilityRecordsPO item = WaterFacilityRecordsConvert.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(ReqModifyWaterFacilityRecords request) { + // 验证记录是否存在 + ExecutedResult<WaterFacilityRecordsPO> checkExists = this.check4Id(request.getId()); + if (checkExists.isFailed()) { + return ExecutedResult.failed(checkExists.getMsg()); + } + // 转换po + WaterFacilityRecordsPO item = WaterFacilityRecordsConvert.INSTANCE.toModify(request); + + int rowCount = mapper.updateById(item); + if (rowCount != 1) { + return ExecutedResult.failed("编辑[设备供水记录]失败。"); + } + return ExecutedResult.success(); + } + + public ExecutedResult<WaterFacilityRecordsVO> get(Long id) { + WaterFacilityRecordsVO result = new WaterFacilityRecordsVO(); + + WaterFacilityRecordsPO find = mapper.get(id); + if (null != find) { + // 转换vo + result = WaterFacilityRecordsConvert.INSTANCE.toVo(find); + } + return ExecutedResult.success(result); + } + +// public ExecutedResult<String> stop(Long id) { +// // 验证记录是否存在 +// ExecutedResult<WaterFacilityRecordsPO> checkExists = this.check4Id(id); +// if (checkExists.isFailed()) { +// return ExecutedResult.failed(checkExists.getMsg()); +// } +// WaterFacilityRecordsPO item = new WaterFacilityRecordsPO(); +// 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<WaterFacilityRecordsPO> checkExists = this.check4Id(id); +// if (checkExists.isFailed()) { +// return ExecutedResult.failed(checkExists.getMsg()); +// } +// WaterFacilityRecordsPO item = new WaterFacilityRecordsPO(); +// 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<WaterFacilityRecordsPO> checkExists = this.check4Id(request.getId()); +// if (checkExists.isFailed()) { +// return ExecutedResult.failed(checkExists.getMsg()); +// } +// WaterFacilityRecordsPO item = new WaterFacilityRecordsPO(); +// 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<WaterFacilityRecordsPO>> checkExists = this.check4Id(listId); +// if (checkExists.isFailed()) { +// return ExecutedResult.failed(checkExists.getMsg()); +// } +// +// List<WaterFacilityRecordsPO> listUpdate = request.getList().stream() +// .map(c -> { +// WaterFacilityRecordsPO item = new WaterFacilityRecordsPO(); +// 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<WaterFacilityRecordsVO>> getList(List<Long> listId) { + List<WaterFacilityRecordsVO> result = new ArrayList<>(); + + List<WaterFacilityRecordsPO> list = mapper.getList(listId); + if (ListUtil.isNotNullOrEmpty(list)) { + // 转换vo + result = WaterFacilityRecordsConvert.INSTANCE.toVo(list); + } + return ExecutedResult.success(result); + } + + public ExecutedResult<PagerResult<WaterFacilityRecordsVO>> search(SearchWaterFacilityRecords 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<WaterFacilityRecordsPO> pageList = mapper.search(search); + List<WaterFacilityRecordsVO> listVo = new ArrayList<>(); + List<WaterFacilityRecordsPO> list = pageList.getList(); + if (ListUtil.isNotNullOrEmpty(list)) { + pageList.setLastId(list.get(list.size() - 1).getId()); + // 转换vo + listVo = WaterFacilityRecordsConvert.INSTANCE.toVo(list); + } + PagerResult<WaterFacilityRecordsVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo); + result.setLastId(pageList.getLastId()); + return ExecutedResult.success(result); + } + + protected ExecutedResult<WaterFacilityRecordsPO> check4Id(Long id) { + WaterFacilityRecordsPO exists = mapper.get(id); + if (Objects.isNull(exists)) { + return ExecutedResult.failed("[设备供水记录]不存在:" + id); + } + return ExecutedResult.success(exists); + } + protected ExecutedResult<List<WaterFacilityRecordsPO>> check4Id(List<Long> listId) { + // 从数据库查找设备供水记录 + List<WaterFacilityRecordsPO> list = mapper.getList(listId); + if (ListUtil.isNullOrEmpty(list)) { + return ExecutedResult.failed("[设备供水记录]不存在." + listId); + } + // 数据库找到的id列表 + List<Long> listIdFind = list.stream().map(WaterFacilityRecordsPO::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); + }} diff --git a/src/main/java/com/lunhan/water/service/convert/WaterFacilityRecordsConvert.java b/src/main/java/com/lunhan/water/service/convert/WaterFacilityRecordsConvert.java new file mode 100644 index 0000000..0a965fb --- /dev/null +++ b/src/main/java/com/lunhan/water/service/convert/WaterFacilityRecordsConvert.java @@ -0,0 +1,48 @@ +/** +# __----~~~~~~~~~~~------___ +# . . ~~//====...... __--~ ~~ +# -. \_|// |||\\ ~~~~~~::::... /~ +# ___-==_ _-~o~ \/ ||| \\ _/~~- +# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ +# _-~~ .=~ | \\-_ '-~7 /- / || \ / +# .~ .~ | \\ -_ / /- / || \ / +# / ____ / | \\ ~-_/ /|- _/ .|| \ / +# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ +# ' ~-| /| |-~\~~ __--~~ +# |-~~-_/ | | ~\_ _-~ /\ +# / \ \__ \/~ \__ +# _--~ _/ | .-~~____--~-/ ~~==. +# ((->/~ '.|||' -_| ~~-/ , . _|| +# -_ ~\ ~~---l__i__i__i--~~_/ +# _-~-__ ~) \--______________--~~ +# //.-~~~-~_--~- |-------~~~~~~~~ +# //.-~~~--\ +# 神兽保佑 +# 永无BUG! +*/ +package com.lunhan.water.service.convert; + +import com.lunhan.water.entity.request.waterfacilityrecords.ReqCreateWaterFacilityRecords; +import com.lunhan.water.entity.request.waterfacilityrecords.ReqModifyWaterFacilityRecords; +import com.lunhan.water.repository.po.WaterFacilityRecordsPO; +import com.lunhan.water.repository.vo.WaterFacilityRecordsVO; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 设备供水记录 + * @author {#=author} + */ +@Mapper +public interface WaterFacilityRecordsConvert { + WaterFacilityRecordsConvert INSTANCE = Mappers.getMapper(WaterFacilityRecordsConvert.class); + + WaterFacilityRecordsPO toCreate(ReqCreateWaterFacilityRecords request); + WaterFacilityRecordsPO toModify(ReqModifyWaterFacilityRecords request); + + WaterFacilityRecordsVO toVo(WaterFacilityRecordsPO item); + List<WaterFacilityRecordsVO> toVo(List<WaterFacilityRecordsPO> list); +} diff --git a/src/test/java/com/lunhan/water/DateTimeTest.java b/src/test/java/com/lunhan/water/DateTimeTest.java index 5e7d364..f8d93be 100644 --- a/src/test/java/com/lunhan/water/DateTimeTest.java +++ b/src/test/java/com/lunhan/water/DateTimeTest.java @@ -5,11 +5,17 @@ import org.junit.runner.RunWith; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.math.BigDecimal; + @RunWith(SpringJUnit4ClassRunner.class) public class DateTimeTest { @Test public void time2BCDTest() { - String timeStr = LocalDateTimeUtil.nowTimeBCD("yyMMddHHmmss"); - System.out.println(timeStr); + String c="3"; + BigDecimal a=new BigDecimal(0.1); + BigDecimal b=BigDecimal.ZERO; + BigDecimal bigDecimal = a.multiply(new BigDecimal(c)).setScale(2, BigDecimal.ROUND_DOWN); + + System.out.println(b.add(bigDecimal)); } } diff --git a/src/test/java/com/lunhan/water/GenCodeGauss.java b/src/test/java/com/lunhan/water/GenCodeGauss.java index ab85fce..baed708 100644 --- a/src/test/java/com/lunhan/water/GenCodeGauss.java +++ b/src/test/java/com/lunhan/water/GenCodeGauss.java @@ -243,7 +243,7 @@ * 只生成以下配置的表 */ private static final List<String> ONLY_TABLES = Arrays.asList( - "facility_alarm_record" + "water_facility_records" ); public static void main(String[] args) { -- Gitblit v1.9.3