chengf
2026-01-27 b6184e2ddf3db37a94f7efb3b619bbc64642a292
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package com.java110.fee.api;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.po.meter.PhoneBillFlow;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 话费流水信息接口
 * 适配 phone_bill_flow 表
 * @author dev
 * @date 2025-12-24
 */
@RestController
@RequestMapping(value = "/phoneBillFlowInfo")
public class PhoneBillFlowInfoApi {
 
    @Autowired
    protected SqlSessionTemplate sqlSessionTemplate;
 
    /**
     * 保存话费流水信息
     *
     * @param reqJson 请求参数
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/savePhoneBillFlowInfo
     * @path /app/phoneBillFlowInfo/savePhoneBillFlowInfo
     */
    @RequestMapping(value = "/savePhoneBillFlowInfo", method = RequestMethod.POST)
    public ResponseEntity<String> savePhoneBillFlowInfo(@RequestBody JSONObject reqJson) {
        // 核心参数校验
        Assert.hasKeyAndValue(reqJson, "id", "请求报文中未包含主键ID");
        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区ID");
 
        // 转换为DTO
        PhoneBillFlow dto = BeanConvertUtil.covertBean(reqJson, PhoneBillFlow.class);
 
        // 调用Mapper保存方法
        int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.savePhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(dto));
 
        // 构造响应结果
        JSONObject resJson = new JSONObject();
        if (insert > 0) {
            resJson.put("code", "0000");
            resJson.put("msg", "保存话费流水信息成功");
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "保存话费流水信息失败");
        }
        resJson.put("count", insert);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 重载方法-保存话费流水信息
     *
     * @param dto 话费流水DTO
     * @return 响应结果
     */
    public ResponseEntity<String> savePhoneBillFlowInfo(PhoneBillFlow dto) {
        int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.savePhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(dto));
 
        // 构造响应结果
        JSONObject resJson = new JSONObject();
        if (insert > 0) {
            resJson.put("code", "0000");
            resJson.put("msg", "保存话费流水信息成功");
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "保存话费流水信息失败");
        }
        resJson.put("count", insert);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 批量插入话费流水信息
     *
     * @param reqJson 请求参数(包含phoneBillFlowList列表)
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/insertPhoneBillFlows
     * @path /app/phoneBillFlowInfo/insertPhoneBillFlows
     */
    @RequestMapping(value = "/insertPhoneBillFlows", method = RequestMethod.POST)
    public ResponseEntity<String> insertPhoneBillFlows(@RequestBody JSONObject reqJson) {
        // 校验列表参数
        Assert.hasKey(reqJson, "phoneBillFlowList", "请求报文中未包含话费流水列表");
        Assert.notEmpty(reqJson.getJSONArray("phoneBillFlowList"), "话费流水列表不能为空");
 
        // 转换为Map(适配批量插入的参数格式)
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("phoneBillFlowList", reqJson.getJSONArray("phoneBillFlowList"));
 
        // 调用Mapper批量插入方法
        int insert = sqlSessionTemplate.insert("phoneBillFlowServiceDaoImpl.insertPhoneBillFlows", paramMap);
 
        // 构造响应结果
        JSONObject resJson = new JSONObject();
        if (insert > 0) {
            resJson.put("code", "0000");
            resJson.put("msg", "批量插入话费流水信息成功");
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "批量插入话费流水信息失败");
        }
        resJson.put("count", insert);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 修改话费流水信息
     *
     * @param reqJson 请求参数
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/updatePhoneBillFlowInfo
     * @path /app/phoneBillFlowInfo/updatePhoneBillFlowInfo
     */
    @RequestMapping(value = "/updatePhoneBillFlowInfo", method = RequestMethod.POST)
    public ResponseEntity<String> updatePhoneBillFlowInfo(@RequestBody JSONObject reqJson) {
        // 主键校验
        Assert.hasKey(reqJson, "id", "请求报文中未包含主键ID");
 
        PhoneBillFlow dto = BeanConvertUtil.covertBean(reqJson, PhoneBillFlow.class);
 
        // 调用Mapper修改方法
        int update = sqlSessionTemplate.update("phoneBillFlowServiceDaoImpl.updatePhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(dto));
 
        JSONObject resJson = new JSONObject();
        if (update > 0) {
            resJson.put("code", "0000");
            resJson.put("msg", "修改话费流水信息成功");
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "修改话费流水信息失败,未找到对应记录");
        }
        resJson.put("count", update);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 分页查询话费流水信息列表
     *
     * @param id                主键ID(可选)
     * @param communityId       小区ID(可选)
     * @param roomId            房间ID(可选)
     * @param deviceNumber      设备号(可选)
     * @param year              年份(可选)
     * @param month             月份(可选)
     * @param page              页码(默认1)
     * @param row               每页条数(默认10)
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/queryPhoneBillFlowInfo
     * @path /app/phoneBillFlowInfo/queryPhoneBillFlowInfo
     */
    @RequestMapping(value = "/queryPhoneBillFlowInfo", method = RequestMethod.GET)
    public ResponseEntity<String> queryPhoneBillFlowInfo(
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "communityId", required = false) String communityId,
            @RequestParam(value = "roomId", required = false) String roomId,
            @RequestParam(value = "deviceNumber", required = false) String deviceNumber,
            @RequestParam(value = "year", required = false) String year,
            @RequestParam(value = "month", required = false) String month,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "row", defaultValue = "10") int row) {
 
        // 封装查询参数
        PhoneBillFlow queryDto = new PhoneBillFlow();
        queryDto.setId(id);
        queryDto.setCommunityId(communityId);
        queryDto.setRoomId(roomId);
        queryDto.setDeviceNumber(deviceNumber);
        queryDto.setYear(year);
        queryDto.setMonth(month);
        queryDto.setPage((page - 1) * row); // 计算分页起始位置
        queryDto.setRow(row);
 
        // 查询列表数据
        List<Map<String, Object>> list = sqlSessionTemplate.selectList(
                "phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(queryDto));
 
        List<PhoneBillFlow> phoneBillFlows = BeanConvertUtil.covertBeanList(list, PhoneBillFlow.class);
 
        // 查询总数
        Object total = ((HashMap) sqlSessionTemplate.selectOne(
                "phoneBillFlowServiceDaoImpl.queryPhoneBillFlowsCount",
                BeanConvertUtil.beanCovertMap(queryDto))).get("count");
 
        // 构造分页响应
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "查询话费流水信息成功");
        resJson.put("page", page);
        resJson.put("row", row);
        resJson.put("total", total);
        resJson.put("data", phoneBillFlows);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据ID查询单条话费流水信息
     *
     * @param id 主键ID
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/getPhoneBillFlowInfoById
     * @path /app/phoneBillFlowInfo/getPhoneBillFlowInfoById
     */
    @RequestMapping(value = "/getPhoneBillFlowInfoById", method = RequestMethod.GET)
    public ResponseEntity<String> getPhoneBillFlowInfoById(@RequestParam(value = "id") String id) {
        // 主键校验
        Assert.hasLength(id, "主键ID不能为空");
 
        PhoneBillFlow queryDto = new PhoneBillFlow();
        queryDto.setId(id);
 
        // 查询单条数据
        Map<String, Object> result = sqlSessionTemplate.selectOne(
                "phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(queryDto));
 
 
        JSONObject resJson = new JSONObject();
        if (result != null) {
            PhoneBillFlow phoneBillFlow = BeanConvertUtil.covertBean(result, PhoneBillFlow.class);
            resJson.put("code", "0000");
            resJson.put("msg", "查询话费流水信息成功");
            resJson.put("data", phoneBillFlow);
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "未找到对应话费流水记录");
        }
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据设备号查询话费流水信息
     *
     * @param deviceNumber 设备号
     * @return 响应结果
     * @serviceCode /phoneBillFlowInfo/getPhoneBillFlowInfoByDeviceNumber
     * @path /app/phoneBillFlowInfo/getPhoneBillFlowInfoByDeviceNumber
     */
    @RequestMapping(value = "/getPhoneBillFlowInfoByDeviceNumber", method = RequestMethod.GET)
    public ResponseEntity<String> getPhoneBillFlowInfoByDeviceNumber(@RequestParam(value = "deviceNumber") String deviceNumber) {
        Assert.hasLength(deviceNumber, "设备号不能为空");
 
        PhoneBillFlow queryDto = new PhoneBillFlow();
        queryDto.setDeviceNumber(deviceNumber);
 
        List<Map<String, Object>> result = sqlSessionTemplate.selectList(
                "phoneBillFlowServiceDaoImpl.getPhoneBillFlowInfo",
                BeanConvertUtil.beanCovertMap(queryDto));
 
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "查询话费流水信息成功");
        resJson.put("data", result);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
}