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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package com.java110.fee.api;
 
import com.alibaba.fastjson.JSONObject;
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;
 
/**
 * 公告时间范围(公共收益金)接口
 * 适配 announcement_time_range 表 Mapper 实现
 */
@RestController
@RequestMapping(value = "/announcementTimeRange")
public class AnnouncementTimeRangeApi {
 
    @Autowired
    protected SqlSessionTemplate sqlSessionTemplate;
 
    /**
     * 保存公告时间范围信息
     *
     * @param reqJson 请求参数
     * @return 响应结果
     * @serviceCode /announcementTimeRange/saveAnnouncementTimeRangeInfo
     * @path /app/announcementTimeRange/saveAnnouncementTimeRangeInfo
     */
    @RequestMapping(value = "/saveAnnouncementTimeRangeInfo", method = RequestMethod.POST)
    public ResponseEntity<String> saveAnnouncementTimeRangeInfo(@RequestBody JSONObject reqJson) {
        // 核心业务参数校验(匹配表字段)
        Assert.hasKeyAndValue(reqJson, "mpId", "请求报文中未包含外键编号mpId");
 
        // 转换为POJO并补充默认值(可选)
        AnnouncementTimeRangePo po = BeanConvertUtil.covertBean(reqJson, AnnouncementTimeRangePo.class);
 
        // 调用Mapper的保存方法(匹配Mapper的namespace和id)
        int insert = sqlSessionTemplate.insert("announcementTimeRangeServiceDaoImpl.saveAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(po));
 
        // 构造返回结果(标准JSON格式)
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "保存成功");
        resJson.put("count", insert);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
 
    public void saveAnnouncementTimeRangeInfo(AnnouncementTimeRangePo po) {
 
        // 调用Mapper的保存方法(匹配Mapper的namespace和id)
        int insert = sqlSessionTemplate.insert("announcementTimeRangeServiceDaoImpl.saveAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(po));
    }
 
 
    /**
     * 批量保存公告时间范围信息
     *
     * @param reqJson 请求参数(包含announcementTimeRangeList数组)
     * @return 响应结果
     * @serviceCode /announcementTimeRange/saveAnnouncementTimeRanges
     * @path /app/announcementTimeRange/saveAnnouncementTimeRanges
     */
    @RequestMapping(value = "/saveAnnouncementTimeRanges", method = RequestMethod.POST)
    public ResponseEntity<String> saveAnnouncementTimeRanges(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "announcementTimeRangeList", "请求报文中未包含批量数据列表");
 
        List<AnnouncementTimeRangePo> poList = BeanConvertUtil.covertBeanList(
                reqJson.getJSONArray("announcementTimeRangeList"), AnnouncementTimeRangePo.class);
 
        Map<String, Object> param = BeanConvertUtil.beanCovertMap(reqJson);
        param.put("announcementTimeRangeList", poList);
 
        int insert = sqlSessionTemplate.insert("announcementTimeRangeServiceDaoImpl.saveAnnouncementTimeRanges", param);
 
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "批量保存成功");
        resJson.put("count", insert);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 修改公告时间范围信息
     *
     * @param reqJson 请求参数
     * @return 响应结果
     * @serviceCode /announcementTimeRange/updateAnnouncementTimeRangeInfo
     * @path /app/announcementTimeRange/updateAnnouncementTimeRangeInfo
     */
    @RequestMapping(value = "/updateAnnouncementTimeRangeInfo", method = RequestMethod.POST)
    public ResponseEntity<String> updateAnnouncementTimeRangeInfo(@RequestBody JSONObject reqJson) {
        // 主键校验(修改必须传id)
        Assert.hasKeyAndValue(reqJson, "id", "请求报文中未包含主键ID");
//        Assert.isNumeric(reqJson.getString("id"), "主键ID必须为数字");
 
        AnnouncementTimeRangePo po = BeanConvertUtil.covertBean(reqJson, AnnouncementTimeRangePo.class);
 
        int update = sqlSessionTemplate.update("announcementTimeRangeServiceDaoImpl.updateAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(po));
 
        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 reqJson 请求参数
     * @return 响应结果
     * @serviceCode /announcementTimeRange/deleteAnnouncementTimeRangeInfo
     * @path /app/announcementTimeRange/deleteAnnouncementTimeRangeInfo
     */
    @RequestMapping(value = "/deleteAnnouncementTimeRangeInfo", method = RequestMethod.POST)
    public ResponseEntity<String> deleteAnnouncementTimeRangeInfo(@RequestBody JSONObject reqJson) {
        // 必要参数校验
        Assert.hasKeyAndValue(reqJson, "id", "主键ID不能为空");
//        Assert.isNumeric(reqJson.getString("id"), "主键ID必须为数字");
 
        AnnouncementTimeRangePo po = BeanConvertUtil.covertBean(reqJson, AnnouncementTimeRangePo.class);
 
        int delete = sqlSessionTemplate.delete("announcementTimeRangeServiceDaoImpl.deleteAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(po));
 
        JSONObject resJson = new JSONObject();
        if (delete > 0) {
            resJson.put("code", "0000");
            resJson.put("msg", "删除成功");
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "删除失败,未找到对应记录");
        }
        resJson.put("count", delete);
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 分页查询公告时间范围信息列表
     *
     * @param mpId            外键编号(必传)
     * @param page            页码(默认1)
     * @param row             每页条数(默认10)
     * @param id              主键ID(可选)
     * @param plannedStart    拟公布起始年月(可选)
     * @param publishedStart  已公布起始年月(可选)
     * @return 响应结果
     * @serviceCode /announcementTimeRange/queryAnnouncementTimeRangeInfo
     * @path /app/announcementTimeRange/queryAnnouncementTimeRangeInfo
     */
    @RequestMapping(value = "/queryAnnouncementTimeRangeInfo", method = RequestMethod.GET)
    public ResponseEntity<String> queryAnnouncementTimeRangeInfo(
            @RequestParam(value = "mpId") Long mpId,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "row", defaultValue = "10") int row,
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "plannedAnnouncementStart", required = false) String plannedStart,
            @RequestParam(value = "publishedAnnouncementStart", required = false) String publishedStart) {
 
        // 封装查询参数(适配Mapper的查询条件)
        AnnouncementTimeRangePo queryPo = new AnnouncementTimeRangePo();
        queryPo.setMpId(mpId);
        queryPo.setPage((page - 1) * row); // 转换为MySQL分页偏移量
        queryPo.setRow(row);
 
        if (id != null && !id.isEmpty()) {
            queryPo.setId(Long.parseLong(id));
        }
        if (plannedStart != null && !plannedStart.isEmpty()) {
            queryPo.setPlannedAnnouncementStart(plannedStart);
        }
        if (publishedStart != null && !publishedStart.isEmpty()) {
            queryPo.setPublishedAnnouncementStart(publishedStart);
        }
 
        // 查询列表
        List<Map<String, Object>> list = sqlSessionTemplate.selectList(
                "announcementTimeRangeServiceDaoImpl.getAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(queryPo));
        List<AnnouncementTimeRangePo> poList =  BeanConvertUtil.covertBeanList(list, AnnouncementTimeRangePo.class);
 
        // 查询总数
        Object total = ((HashMap)sqlSessionTemplate.selectOne(
                "announcementTimeRangeServiceDaoImpl.queryAnnouncementTimeRangeCount",
                BeanConvertUtil.beanCovertMap(queryPo))).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", poList);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据ID查询单条公告时间范围信息
     *
     * @param id 主键ID
     * @return 响应结果
     * @serviceCode /announcementTimeRange/getAnnouncementTimeRangeById
     * @path /app/announcementTimeRange/getAnnouncementTimeRangeById
     */
    @RequestMapping(value = "/getAnnouncementTimeRangeById", method = RequestMethod.GET)
    public ResponseEntity<String> getAnnouncementTimeRangeById(@RequestParam(value = "id") Long id) {
        // 主键校验
        Assert.notNull(id, "主键ID不能为空");
 
        AnnouncementTimeRangePo queryPo = new AnnouncementTimeRangePo();
        queryPo.setId(id);
 
        Map<String, Object> result = sqlSessionTemplate.selectOne(
                "announcementTimeRangeServiceDaoImpl.getAnnouncementTimeRangeInfo",
                BeanConvertUtil.beanCovertMap(queryPo));
 
        JSONObject resJson = new JSONObject();
        if (result != null) {
            resJson.put("code", "0000");
            resJson.put("msg", "查询成功");
            resJson.put("data", result);
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "未找到对应记录");
        }
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 查询公告时间范围统计信息
     *
     * @param mpId            外键编号(可选)
     * @param startCreateTime 开始创建时间(可选,格式:yyyy-MM-dd HH:mm:ss)
     * @param endCreateTime   结束创建时间(可选)
     * @return 响应结果
     * @serviceCode /announcementTimeRange/queryAnnouncementTimeRangeStatistics
     * @path /app/announcementTimeRange/queryAnnouncementTimeRangeStatistics
     */
    @RequestMapping(value = "/queryAnnouncementTimeRangeStatistics", method = RequestMethod.GET)
    public ResponseEntity<String> queryAnnouncementTimeRangeStatistics(
            @RequestParam(value = "mpId", required = false) Integer mpId,
            @RequestParam(value = "startCreateTime", required = false) String startCreateTime,
            @RequestParam(value = "endCreateTime", required = false) String endCreateTime) {
 
        AnnouncementTimeRangePo queryPo = new AnnouncementTimeRangePo();
        queryPo.setMpId(Long.valueOf(mpId));
        queryPo.setStartCreateTime(startCreateTime);
        queryPo.setEndCreateTime(endCreateTime);
 
        Map<String, Object> statistics = sqlSessionTemplate.selectOne(
                "announcementTimeRangeServiceDaoImpl.queryAnnouncementTimeRangeStatistics",
                BeanConvertUtil.beanCovertMap(queryPo));
 
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "统计成功");
        resJson.put("data", statistics);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 按月份分组统计公告时间范围信息
     *
     * @param mpId            外键编号(可选)
     * @param startCreateTime 开始创建时间(可选)
     * @param endCreateTime   结束创建时间(可选)
     * @return 响应结果
     * @serviceCode /announcementTimeRange/queryAnnouncementTimeRangeByMonth
     * @path /app/announcementTimeRange/queryAnnouncementTimeRangeByMonth
     */
    @RequestMapping(value = "/queryAnnouncementTimeRangeByMonth", method = RequestMethod.GET)
    public ResponseEntity<String> queryAnnouncementTimeRangeByMonth(
            @RequestParam(value = "mpId", required = false) Long mpId,
            @RequestParam(value = "startCreateTime", required = false) String startCreateTime,
            @RequestParam(value = "endCreateTime", required = false) String endCreateTime) {
 
        AnnouncementTimeRangePo queryPo = new AnnouncementTimeRangePo();
        queryPo.setMpId(mpId);
        queryPo.setStartCreateTime(startCreateTime);
        queryPo.setEndCreateTime(endCreateTime);
 
        List<Map<String, Object>> list = sqlSessionTemplate.selectList(
                "announcementTimeRangeServiceDaoImpl.queryAnnouncementTimeRangeByMonth",
                BeanConvertUtil.beanCovertMap(queryPo));
 
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "统计成功");
        resJson.put("data", list);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据mpId查询最新的公告时间范围信息
     *
     * @param mpId 外键编号
     * @return 响应结果
     * @serviceCode /announcementTimeRange/getLatestAnnouncementTimeRangeByMpId
     * @path /app/announcementTimeRange/getLatestAnnouncementTimeRangeByMpId
     */
    @RequestMapping(value = "/getLatestAnnouncementTimeRangeByMpId", method = RequestMethod.GET)
    public ResponseEntity<String> getLatestAnnouncementTimeRangeByMpId(@RequestParam(value = "mpId") Long mpId) {
        Assert.notNull(mpId, "外键编号mpId不能为空");
 
        AnnouncementTimeRangePo queryPo = new AnnouncementTimeRangePo();
        queryPo.setMpId(mpId);
 
        Map<String, Object> result = sqlSessionTemplate.selectOne(
                "announcementTimeRangeServiceDaoImpl.getLatestAnnouncementTimeRangeByMpId",
                BeanConvertUtil.beanCovertMap(queryPo));
 
        JSONObject resJson = new JSONObject();
        if (result != null) {
            resJson.put("code", "0000");
            resJson.put("msg", "查询成功");
            resJson.put("data", result);
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "未找到对应记录");
        }
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
}