UpdateMeterWaterCmd.java
8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Copyright 2017-2020 吴学文 and java110 team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.java110.fee.cmd.meterWater;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.room.RoomDto;
import com.java110.dto.meter.MeterWaterDto;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.fee.IMeterWaterInnerServiceSMO;
import com.java110.intf.fee.IMeterWaterV1InnerServiceSMO;
import com.java110.intf.fee.IPayFeeV1InnerServiceSMO;
import com.java110.po.fee.PayFeePo;
import com.java110.po.meter.MeterWaterPo;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 类表述:更新水表抄表记录命令类
* 服务编码:meterWater.updateMeterWater
* 请求路劲:/app/meterWater.UpdateMeterWater
* 功能描述:该类负责处理水表抄表记录的更新操作,包括数据验证、业务逻辑处理和数据库更新
* 主要功能:
* 1. 验证更新抄表记录的必填参数
* 2. 根据项目是否在黑名单中决定是否生成费用记录
* 3. 更新抄表记录和相关的费用信息
* add by 吴学文 at 2022-07-21 09:17:10 mail: 928255095@qq.com
* open source address: https://gitee.com/wuxw7/MicroCommunity
* 官网:http://www.homecommunity.cn
* 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
* // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
*/
@Java110Cmd(serviceCode = "meterWater.updateMeterWater")
public class UpdateMeterWaterCmd extends Cmd {
private static Logger logger = LoggerFactory.getLogger(UpdateMeterWaterCmd.class);
/**
* 抄表记录V1版本服务接口
*/
@Autowired
private IMeterWaterV1InnerServiceSMO meterWaterV1InnerServiceSMOImpl;
/**
* 抄表记录服务接口
*/
@Autowired
private IMeterWaterInnerServiceSMO meterWaterInnerServiceSMOImpl;
/**
* 房屋信息服务接口
*/
@Autowired
private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
/**
* 费用服务接口
*/
@Autowired
private IPayFeeV1InnerServiceSMO payFeeV1InnerServiceSMOImpl;
/**
* 公共配置域
*/
public static final String DOMAIN_COMMON = "DOMAIN.COMMON";
/**
* 水费黑名单配置键
*/
public static final String WATER_BLACK_LIST = "WATER_BLACK_LIST";
/**
* 电费黑名单配置键
*/
public static final String ELECTRIC_BLACK_LIST = "ELECTRIC_BLACK_LIST";
/**
* 验证请求参数
*
* @param event 命令事件
* @param cmdDataFlowContext 命令数据流上下文
* @param reqJson 请求参数JSON对象
* 功能描述:验证更新抄表记录所需的必填参数是否完整
* 验证参数包括:waterId, preDegrees, curDegrees, preReadingTime, curReadingTime, communityId
*/
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
Assert.hasKeyAndValue(reqJson, "waterId", "waterId不能为空");
Assert.hasKeyAndValue(reqJson, "preDegrees", "请求报文中未包含preDegrees");
Assert.hasKeyAndValue(reqJson, "curDegrees", "请求报文中未包含curDegrees");
Assert.hasKeyAndValue(reqJson, "preReadingTime", "请求报文中未包含preReadingTime");
Assert.hasKeyAndValue(reqJson, "curReadingTime", "请求报文中未包含curReadingTime");
Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
}
/**
* 执行抄表记录更新命令
*
* @param event 命令事件
* @param cmdDataFlowContext 命令数据流上下文
* @param reqJson 请求参数JSON对象
* @throws CmdException 命令执行异常
* 功能描述:处理抄表记录的更新逻辑,包括:
* 1. 查询抄表记录和房屋信息
* 2. 根据项目黑名单配置决定是否生成费用
* 3. 更新抄表记录和费用信息
*/
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
// 根据waterId查询抄表记录
MeterWaterDto meterWaterDto = new MeterWaterDto();
meterWaterDto.setWaterId(reqJson.getString("waterId"));
meterWaterDto.setCommunityId(reqJson.getString("communityId"));
List<MeterWaterDto> meterWaterDtos = meterWaterInnerServiceSMOImpl.queryMeterWaters(meterWaterDto);
// 验证查询结果唯一性
Assert.listOnlyOne(meterWaterDtos, "数据异常未找到费用信息");
// 查询房屋信息
RoomDto roomDto = new RoomDto();
roomDto.setRoomId(meterWaterDtos.get(0).getObjId());
List<RoomDto> roomList = roomInnerServiceSMOImpl.queryRooms(roomDto);
Assert.listOnlyOne(roomList, "查询房屋信息错误!");
// 获取抄表对象所属项目id
String communityId = roomList.get(0).getCommunityId();
// 获取抄表类型
String meterType = meterWaterDtos.get(0).getMeterType();
// 取出开关映射的备注值(水费黑名单)
String waterRemark = MappingCache.getRemark(DOMAIN_COMMON, WATER_BLACK_LIST);
List<String> waterRemarkList = new ArrayList<>();
if (!StringUtil.isEmpty(waterRemark)) {
String[] waterSplit = waterRemark.split(",");
// 将数组转成list集合(水费黑名单集合)
waterRemarkList = Arrays.asList(waterSplit);
}
// 取出开关映射的备注值(电费黑名单)
String electricRemark = MappingCache.getRemark(DOMAIN_COMMON, ELECTRIC_BLACK_LIST);
List<String> electricRemarkList = new ArrayList<>();
if (!StringUtil.isEmpty(electricRemark)) {
String[] electricSplit = electricRemark.split(",");
// 将数组转成list集合(电费黑名单集合)
electricRemarkList = Arrays.asList(electricSplit);
}
// 业务逻辑处理:根据黑名单配置决定是否生成费用
// 如果是水费,且在水费黑名单就直接生成水费记录,不生成费用
if (waterRemarkList.contains(communityId) && meterType.equals("2020")) {
updateMeterWater(reqJson);
} else if (electricRemarkList.contains(communityId) && meterType.equals("1010")) {
updateMeterWater(reqJson);
} else {
// 正常流程:更新费用信息
PayFeePo payFeePo = new PayFeePo();
payFeePo.setFeeId(meterWaterDtos.get(0).getFeeId());
payFeePo.setCommunityId(meterWaterDtos.get(0).getCommunityId());
payFeePo.setStartTime(reqJson.getString("preReadingTime"));
//payFeePo.setEndTime(reqJson.getString("curReadingTime"));
int flag = payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
if (flag < 1) {
throw new CmdException("更新数据失败");
}
updateMeterWater(reqJson);
}
cmdDataFlowContext.setResponseEntity(ResultVo.success());
}
/**
* 更新抄表记录信息
*
* @param paramInJson 接口调用方传入入参
* 功能描述:将JSON参数转换为抄表记录PO对象并执行更新操作
* 如果更新失败则抛出CmdException异常
*/
public void updateMeterWater(JSONObject paramInJson) {
// 将JSON对象转换为抄表记录PO对象
MeterWaterPo meterWaterPo = BeanConvertUtil.covertBean(paramInJson, MeterWaterPo.class);
// 执行更新操作
int flag = meterWaterV1InnerServiceSMOImpl.updateMeterWater(meterWaterPo);
if (flag < 1) {
throw new CmdException("更新数据失败");
}
}
}