wuxw
2024-02-26 4356029f74f35f4df426f223e1c774f4912984a6
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
package com.java110.fee.api;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.base.controller.BaseController;
import com.java110.core.context.BusinessServiceDataFlow;
import com.java110.core.factory.DataTransactionFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.fee.FeeAttrDto;
import com.java110.dto.fee.FeeDto;
import com.java110.fee.bmo.*;
import com.java110.fee.smo.IFeeServiceSMO;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.InitConfigDataException;
import com.java110.utils.exception.InitDataFlowContextException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 用户服务类
 * Created by wuxw on 2018/5/14.
 */
@RestController
@RequestMapping(value = "/feeApi")
public class FeeApi extends BaseController {
    private final static Logger logger = LoggerFactory.getLogger(FeeApi.class);
 
    @Autowired
    IFeeServiceSMO feeServiceSMOImpl;
 
    @Autowired
    private IQueryFeeByAttr queryFeeByAttrImpl;
 
    @Autowired
    private IQueryParkspaceFee queryParkspaceFeeImpl;
 
    @Autowired
    private IQueryOweFee queryOweFeeImpl;
 
    @Autowired
    private IPayOweFee payOweFeeImpl;
 
    @Autowired
    private IImportRoomFee importRoomFeeImpl;
 
    @RequestMapping(path = "/service", method = RequestMethod.GET)
    public String serviceGet(HttpServletRequest request) {
        return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR, "不支持Get方法请求").toJSONString();
    }
 
    /**
     * 用户服务统一处理接口
     *
     * @param orderInfo
     * @param request
     * @return
     */
    @RequestMapping(path = "/service", method = RequestMethod.POST)
    public String servicePost(@RequestBody String orderInfo, HttpServletRequest request) {
        BusinessServiceDataFlow businessServiceDataFlow = null;
        JSONObject responseJson = null;
        try {
            Map<String, String> headers = new HashMap<String, String>();
            getRequestInfo(request, headers);
            //预校验
            preValiateOrderInfo(orderInfo);
            businessServiceDataFlow = this.writeDataToDataFlowContext(orderInfo, headers);
            responseJson = feeServiceSMOImpl.service(businessServiceDataFlow);
        } catch (InitDataFlowContextException e) {
            logger.error("请求报文错误,初始化 BusinessServiceDataFlow失败" + orderInfo, e);
            responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
        } catch (InitConfigDataException e) {
            logger.error("请求报文错误,加载配置信息失败" + orderInfo, e);
            responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
        } catch (Exception e) {
            logger.error("请求订单异常", e);
            responseJson = DataTransactionFactory.createBusinessResponseJson(businessServiceDataFlow, ResponseConstant.RESULT_CODE_ERROR, e.getMessage() + e,
                    null);
        } finally {
        }
        return responseJson.toJSONString();
    }
 
    /**
     * 这里预校验,请求报文中不能有 dataFlowId
     *
     * @param orderInfo
     */
    private void preValiateOrderInfo(String orderInfo) {
       /* if(JSONObject.parseObject(orderInfo).getJSONObject("orders").containsKey("dataFlowId")){
            throw new BusinessException(ResponseConstant.RESULT_CODE_ERROR,"报文中不能存在dataFlowId节点");
        }*/
    }
 
    /**
     * 获取请求信息
     *
     * @param request
     * @param headers
     * @throws RuntimeException
     */
    private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
        try {
            super.initHeadParam(request, headers);
            super.initUrlParam(request, headers);
        } catch (Exception e) {
            logger.error("加载头信息失败", e);
            throw new InitConfigDataException(ResponseConstant.RESULT_PARAM_ERROR, "加载头信息失败");
        }
    }
 
    public IFeeServiceSMO getFeeServiceSMOImpl() {
        return feeServiceSMOImpl;
    }
 
    public void setFeeServiceSMOImpl(IFeeServiceSMO feeServiceSMOImpl) {
        this.feeServiceSMOImpl = feeServiceSMOImpl;
    }
 
 
    /**
     * 停车费查询
     *
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/parkSpaceFee", method = RequestMethod.POST)
    public ResponseEntity<String> parkSpaceFee(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "code", "未包含小区编码");
        return queryParkspaceFeeImpl.query(reqJson);
    }
 
    /**
     * 根据属性查询费用
     *
     * @param communityId
     * @return
     * @path /app/feeApi/listFeeByAttr
     */
    @RequestMapping(value = "/listFeeByAttr", method = RequestMethod.GET)
    public ResponseEntity<String> listFeeByAttr(@RequestParam(value = "communityId") String communityId,
                                                @RequestParam(value = "feeId", required = false) String feeId,
                                                @RequestParam(value = "specCd") String specCd,
                                                @RequestParam(value = "value") String value,
                                                @RequestParam(value = "row") int row,
                                                @RequestParam(value = "page") int page) {
 
        FeeAttrDto feeAttrDto = new FeeAttrDto();
        feeAttrDto.setCommunityId(communityId);
        feeAttrDto.setSpecCd(specCd);
        feeAttrDto.setValue(value);
        feeAttrDto.setFeeId(feeId);
        feeAttrDto.setRow(row);
        feeAttrDto.setPage(page);
        return queryFeeByAttrImpl.query(feeAttrDto);
    }
 
    /**
     * 查询欠费费用
     *
     * @param payObjId    付费方ID
     * @param communityId 小区ID
     * @return
     * @path /app/feeApi/listOweFees
     */
    @RequestMapping(value = "/listOweFees", method = RequestMethod.GET)
    public ResponseEntity<String> listOweFees(@RequestParam(value = "payObjId", required = false) String payObjId,
                                              @RequestParam(value = "payObjType", required = false) String payObjType,
                                              @RequestParam(value = "ownerId", required = false) String ownerId,
                                              @RequestParam(value = "targetEndTime", required = false) String targetEndTime,
                                              @RequestParam(value = "communityId") String communityId) {
        if (StringUtil.isEmpty(payObjId) && StringUtil.isEmpty(ownerId)) {
            throw new IllegalArgumentException("费用对象或者业主不能都为空");
        }
        FeeDto feeDto = new FeeDto();
        if(!StringUtil.isEmpty(payObjId)) {
            if (payObjId.contains(",")) {
                feeDto.setPayerObjIds(payObjId.split(","));
            } else {
                feeDto.setPayerObjId(payObjId);
            }
        }
        if(!StringUtil.isEmpty(targetEndTime)){
            targetEndTime = DateUtil.getAddDayStringB(DateUtil.getDateFromStringB(targetEndTime),1);
            feeDto.setTargetEndTime(targetEndTime);
        }
        feeDto.setPayerObjType(payObjType);
        feeDto.setOwnerId(ownerId);
        feeDto.setCommunityId(communityId);
        return queryOweFeeImpl.query(feeDto);
    }
 
    /**
     * 查询欠费费用
     *
     * @param roomId      房屋ID
     * @param communityId 小区ID
     * @return
     * @path /app/feeApi/listAllRoomOweFees
     */
    @RequestMapping(value = "/listAllRoomOweFees", method = RequestMethod.GET)
    public ResponseEntity<String> listAllRoomOweFees(
            @RequestParam(value = "roomId", required = false) String roomId,
            @RequestParam(value = "communityId") String communityId) {
        FeeDto feeDto = new FeeDto();
        feeDto.setPayerObjId(roomId);
        feeDto.setPayerObjType(FeeDto.PAYER_OBJ_TYPE_ROOM);
        feeDto.setCommunityId(communityId);
        return queryOweFeeImpl.querys(feeDto);
    }
 
 
    /**
     * 查询欠费费用(批量查询)
     *
     * @param num         停车位或房屋编号
     * @param communityId 小区ID
     * @return
     * @path /app/feeApi/getOweFees
     */
    @RequestMapping(value = "/getOweFees", method = RequestMethod.GET)
    public ResponseEntity<String> getOweFees(
            @RequestParam(value = "payObjType") String payObjType,
            @RequestParam(value = "communityId") String communityId,
            @RequestParam(value = "billType") String billType,
            @RequestParam(value = "row") int row,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "num", required = false) String num
    ) {
        FeeDto feeDto = new FeeDto();
        feeDto.setPayerObjId(num);
        feeDto.setPayerObjType(payObjType);
        feeDto.setCommunityId(communityId);
        feeDto.setBillType(billType);
        feeDto.setRow(row);
        feeDto.setPage(page);
        return queryOweFeeImpl.queryAllOwneFee(feeDto);
    }
 
    /**
     * 欠费批量缴费
     *
     * @param reqJson {
     *                "communityId":"",
     *                "fees":[
     *                {
     *                "feeId":"123123",
     *                "feePrice":10.00,
     *                <p>
     *                }
     *                <p>
     *                ]
     *                }
     * @return
     * @path /app/feeApi/payOweFee
     */
    @RequestMapping(value = "/payOweFee", method = RequestMethod.POST)
    public ResponseEntity<String> payOweFee(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
 
        Assert.hasKey(reqJson, "fees", "未包含缴费项目");
 
        return payOweFeeImpl.pay(reqJson);
    }
 
    /**
     * 费用导入
     *
     * @param reqString
     * @return
     */
    @RequestMapping(value = "/importRoomFees", method = RequestMethod.POST)
    public ResponseEntity<String> importRoomFees(@RequestBody String reqString) {
 
        JSONObject reqJson = JSONObject.parseObject(reqString);
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
        Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
        Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
        Assert.hasKeyAndValue(reqJson, "batchId", "未包含用户信息");
 
        return importRoomFeeImpl.importFee(reqJson);
    }
 
    /**
     * 车辆费用导入
     * /feeApi/importCarFees
     * path /app/feeApi/importCarFees
     *
     * @param reqString
     * @return
     */
    @RequestMapping(value = "/importCarFees", method = RequestMethod.POST)
    public ResponseEntity<String> importCarFees(@RequestBody String reqString) {
 
        JSONObject reqJson = JSONObject.parseObject(reqString);
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
        Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
        Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
        Assert.hasKeyAndValue(reqJson, "batchId", "未包含批次信息");
 
        return importRoomFeeImpl.importCarFee(reqJson);
    }
 
    /**
     * 合同费用导入
     * /feeApi/importContractFees
     * path /app/feeApi/importContractFees
     *
     * @param reqString
     * @return
     */
    @RequestMapping(value = "/importContractFees", method = RequestMethod.POST)
    public ResponseEntity<String> importContractFees(@RequestBody String reqString) {
 
        JSONObject reqJson = JSONObject.parseObject(reqString);
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
        Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
        Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
        Assert.hasKeyAndValue(reqJson, "batchId", "未包含批次信息");
 
        return importRoomFeeImpl.importContractFees(reqJson);
    }
 
}