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
package com.java110.fee.api;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.importData.OwnerCollectionDto;
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;
 
/**
 * 业主催缴信息接口
 * 适配 owner_collection 表
 * @author dev
 * @date 2025-12-24
 */
@RestController
@RequestMapping(value = "/ownerCollection")
public class OwnerCollectionApi {
 
    @Autowired
    protected SqlSessionTemplate sqlSessionTemplate;
 
    /**
     * 保存业主催缴信息
     *
     * @param reqJson 请求参数
     * @return 响应结果
     * @serviceCode /ownerCollection/saveOwnerCollection
     * @path /app/ownerCollection/saveOwnerCollection
     */
    @RequestMapping(value = "/saveOwnerCollection", method = RequestMethod.POST)
    public ResponseEntity<String> saveOwnerCollection(@RequestBody JSONObject reqJson) {
        // 核心参数校验(可根据业务补充必要的非空校验)
        Assert.hasKeyAndValue(reqJson, "ownerId", "请求报文中未包含业主ID");
        Assert.hasKeyAndValue(reqJson, "roomId", "请求报文中未包含房间ID");
 
        // 转换为DTO
        OwnerCollectionDto dto = BeanConvertUtil.covertBean(reqJson, OwnerCollectionDto.class);
        // 补充默认时间(可根据业务调整,比如取当前时间)
        if (dto.getCreateTime() == null || dto.getCreateTime().isEmpty()) {
            dto.setCreateTime(String.valueOf(System.currentTimeMillis()));
        }
        dto.setUpdateTime(dto.getCreateTime());
 
        // 调用Mapper保存方法
        int insert = sqlSessionTemplate.insert("ownerV1ServiceDaoImpl.saveOwnerCollection",
                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> saveOwnerCollection(OwnerCollectionDto dto) {
        // 补充默认时间
        if (dto.getCreateTime() == null || dto.getCreateTime().isEmpty()) {
            dto.setCreateTime(String.valueOf(System.currentTimeMillis()));
        }
        dto.setUpdateTime(dto.getCreateTime());
 
        int insert = sqlSessionTemplate.insert("ownerV1ServiceDaoImpl.saveOwnerCollection",
                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 请求参数
     * @return 响应结果
     * @serviceCode /ownerCollection/updateOwnerCollection
     * @path /app/ownerCollection/updateOwnerCollection
     */
    @RequestMapping(value = "/updateOwnerCollection", method = RequestMethod.POST)
    public ResponseEntity<String> updateOwnerCollection(@RequestBody JSONObject reqJson) {
        // 主键校验
        Assert.hasKey(reqJson, "collectionId", "请求报文中未包含催缴信息主键ID");
 
        OwnerCollectionDto dto = BeanConvertUtil.covertBean(reqJson, OwnerCollectionDto.class);
        // 补充更新时间
        dto.setUpdateTime(String.valueOf(System.currentTimeMillis()));
 
        // 调用Mapper修改方法
        int update = sqlSessionTemplate.update("ownerV1ServiceDaoImpl.updateOwnerCollection",
                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 collectionId       催缴信息ID(可选)
     * @param ownerId            业主ID(可选)
     * @param roomId             房间ID(可选)
     * @param collectionStartDate 催缴开始日期(可选)
     * @param collectionEndDate   催缴结束日期(可选)
     * @param page               页码(默认1)
     * @param row                每页条数(默认10)
     * @return 响应结果
     * @serviceCode /ownerCollection/queryOwnerCollection
     * @path /app/ownerCollection/queryOwnerCollection
     */
    @RequestMapping(value = "/queryOwnerCollection", method = RequestMethod.GET)
    public ResponseEntity<String> queryOwnerCollection(
            @RequestParam(value = "collectionId", required = false) String collectionId,
            @RequestParam(value = "ownerId", required = false) String ownerId,
            @RequestParam(value = "roomId", required = false) String roomId,
            @RequestParam(value = "collectionStartDate", required = false) String collectionStartDate,
            @RequestParam(value = "collectionEndDate", required = false) String collectionEndDate,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "row", defaultValue = "10") int row) {
 
        // 封装查询参数
        OwnerCollectionDto queryDto = new OwnerCollectionDto();
        queryDto.setCollectionId(collectionId);
        queryDto.setOwnerId(ownerId);
        queryDto.setRoomId(roomId);
        queryDto.setCollectionStartDate(collectionStartDate);
        queryDto.setCollectionEndDate(collectionEndDate);
        queryDto.setCreateTime(null); // 排除默认时间干扰
        queryDto.setUpdateTime(null);
        queryDto.setPage((page - 1) * row); // 计算分页起始位置
        queryDto.setRow(row);
 
        // 查询列表数据
        List<Map<String, Object>> list = sqlSessionTemplate.selectList(
                "ownerV1ServiceDaoImpl.getOwnerCollection",
                BeanConvertUtil.beanCovertMap(queryDto));
 
        List<OwnerCollectionDto> ownerCollections = BeanConvertUtil.covertBeanList(list, OwnerCollectionDto.class);
 
        // 查询总数
        Object total = ((HashMap) sqlSessionTemplate.selectOne(
                "ownerV1ServiceDaoImpl.queryOwnerCollectionCount",
                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", ownerCollections);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据ID查询单条业主催缴信息
     *
     * @param collectionId 催缴信息主键ID
     * @return 响应结果
     * @serviceCode /ownerCollection/getOwnerCollectionById
     * @path /app/ownerCollection/getOwnerCollectionById
     */
    @RequestMapping(value = "/getOwnerCollectionById", method = RequestMethod.GET)
    public ResponseEntity<String> getOwnerCollectionById(@RequestParam(value = "collectionId") String collectionId) {
        // 主键校验
        Assert.hasLength(collectionId, "催缴信息主键ID不能为空");
 
        OwnerCollectionDto queryDto = new OwnerCollectionDto();
        queryDto.setCollectionId(collectionId);
 
        // 查询单条数据
        Map<String, Object> result = sqlSessionTemplate.selectOne(
                "ownerV1ServiceDaoImpl.getOwnerCollection",
                BeanConvertUtil.beanCovertMap(queryDto));
 
        JSONObject resJson = new JSONObject();
        if (result != null) {
            OwnerCollectionDto ownerCollection = BeanConvertUtil.covertBean(result, OwnerCollectionDto.class);
            resJson.put("code", "0000");
            resJson.put("msg", "查询业主催缴信息成功");
            resJson.put("data", ownerCollection);
        } else {
            resJson.put("code", "0001");
            resJson.put("msg", "未找到对应业主催缴记录");
        }
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
 
    /**
     * 根据业主ID查询业主催缴信息
     *
     * @param ownerId 业主ID
     * @return 响应结果
     * @serviceCode /ownerCollection/getOwnerCollectionByOwnerId
     * @path /app/ownerCollection/getOwnerCollectionByOwnerId
     */
    @RequestMapping(value = "/getOwnerCollectionByOwnerId", method = RequestMethod.GET)
    public ResponseEntity<String> getOwnerCollectionByOwnerId(@RequestParam(value = "ownerId") String ownerId) {
        Assert.hasLength(ownerId, "业主ID不能为空");
 
        OwnerCollectionDto queryDto = new OwnerCollectionDto();
        queryDto.setOwnerId(ownerId);
 
        List<Map<String, Object>> result = sqlSessionTemplate.selectList(
                "ownerV1ServiceDaoImpl.getOwnerCollection",
                BeanConvertUtil.beanCovertMap(queryDto));
 
        JSONObject resJson = new JSONObject();
        resJson.put("code", "0000");
        resJson.put("msg", "查询业主催缴信息成功");
        resJson.put("data", result);
 
        return ResponseEntity.ok(resJson.toJSONString());
    }
}