FeeApi.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package com.java110.fee.api;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.java110.core.base.controller.BaseController;
  4. import com.java110.core.context.BusinessServiceDataFlow;
  5. import com.java110.core.factory.DataTransactionFactory;
  6. import com.java110.core.log.LoggerFactory;
  7. import com.java110.dto.fee.FeeAttrDto;
  8. import com.java110.dto.fee.FeeDto;
  9. import com.java110.fee.bmo.*;
  10. import com.java110.fee.smo.IFeeServiceSMO;
  11. import com.java110.utils.constant.ResponseConstant;
  12. import com.java110.utils.exception.InitConfigDataException;
  13. import com.java110.utils.exception.InitDataFlowContextException;
  14. import com.java110.utils.util.Assert;
  15. import com.java110.utils.util.DateUtil;
  16. import com.java110.utils.util.StringUtil;
  17. import org.slf4j.Logger;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.http.ResponseEntity;
  20. import org.springframework.web.bind.annotation.*;
  21. import javax.servlet.http.HttpServletRequest;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. /**
  25. * 用户服务类
  26. * Created by wuxw on 2018/5/14.
  27. */
  28. @RestController
  29. @RequestMapping(value = "/feeApi")
  30. public class FeeApi extends BaseController {
  31. private final static Logger logger = LoggerFactory.getLogger(FeeApi.class);
  32. @Autowired
  33. IFeeServiceSMO feeServiceSMOImpl;
  34. @Autowired
  35. private IQueryFeeByAttr queryFeeByAttrImpl;
  36. @Autowired
  37. private IQueryParkspaceFee queryParkspaceFeeImpl;
  38. @Autowired
  39. private IQueryOweFee queryOweFeeImpl;
  40. @Autowired
  41. private IPayOweFee payOweFeeImpl;
  42. @Autowired
  43. private IImportRoomFee importRoomFeeImpl;
  44. @RequestMapping(path = "/service", method = RequestMethod.GET)
  45. public String serviceGet(HttpServletRequest request) {
  46. return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR, "不支持Get方法请求").toJSONString();
  47. }
  48. /**
  49. * 用户服务统一处理接口
  50. *
  51. * @param orderInfo
  52. * @param request
  53. * @return
  54. */
  55. @RequestMapping(path = "/service", method = RequestMethod.POST)
  56. public String servicePost(@RequestBody String orderInfo, HttpServletRequest request) {
  57. BusinessServiceDataFlow businessServiceDataFlow = null;
  58. JSONObject responseJson = null;
  59. try {
  60. Map<String, String> headers = new HashMap<String, String>();
  61. getRequestInfo(request, headers);
  62. //预校验
  63. preValiateOrderInfo(orderInfo);
  64. businessServiceDataFlow = this.writeDataToDataFlowContext(orderInfo, headers);
  65. responseJson = feeServiceSMOImpl.service(businessServiceDataFlow);
  66. } catch (InitDataFlowContextException e) {
  67. logger.error("请求报文错误,初始化 BusinessServiceDataFlow失败" + orderInfo, e);
  68. responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
  69. } catch (InitConfigDataException e) {
  70. logger.error("请求报文错误,加载配置信息失败" + orderInfo, e);
  71. responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
  72. } catch (Exception e) {
  73. logger.error("请求订单异常", e);
  74. responseJson = DataTransactionFactory.createBusinessResponseJson(businessServiceDataFlow, ResponseConstant.RESULT_CODE_ERROR, e.getMessage() + e,
  75. null);
  76. } finally {
  77. }
  78. return responseJson.toJSONString();
  79. }
  80. /**
  81. * 这里预校验,请求报文中不能有 dataFlowId
  82. *
  83. * @param orderInfo
  84. */
  85. private void preValiateOrderInfo(String orderInfo) {
  86. /* if(JSONObject.parseObject(orderInfo).getJSONObject("orders").containsKey("dataFlowId")){
  87. throw new BusinessException(ResponseConstant.RESULT_CODE_ERROR,"报文中不能存在dataFlowId节点");
  88. }*/
  89. }
  90. /**
  91. * 获取请求信息
  92. *
  93. * @param request
  94. * @param headers
  95. * @throws RuntimeException
  96. */
  97. private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
  98. try {
  99. super.initHeadParam(request, headers);
  100. super.initUrlParam(request, headers);
  101. } catch (Exception e) {
  102. logger.error("加载头信息失败", e);
  103. throw new InitConfigDataException(ResponseConstant.RESULT_PARAM_ERROR, "加载头信息失败");
  104. }
  105. }
  106. public IFeeServiceSMO getFeeServiceSMOImpl() {
  107. return feeServiceSMOImpl;
  108. }
  109. public void setFeeServiceSMOImpl(IFeeServiceSMO feeServiceSMOImpl) {
  110. this.feeServiceSMOImpl = feeServiceSMOImpl;
  111. }
  112. /**
  113. * 停车费查询
  114. *
  115. * @param reqJson
  116. * @return
  117. */
  118. @RequestMapping(value = "/parkSpaceFee", method = RequestMethod.POST)
  119. public ResponseEntity<String> parkSpaceFee(@RequestBody JSONObject reqJson) {
  120. Assert.hasKeyAndValue(reqJson, "code", "未包含小区编码");
  121. return queryParkspaceFeeImpl.query(reqJson);
  122. }
  123. /**
  124. * 根据属性查询费用
  125. *
  126. * @param communityId
  127. * @return
  128. * @path /app/feeApi/listFeeByAttr
  129. */
  130. @RequestMapping(value = "/listFeeByAttr", method = RequestMethod.GET)
  131. public ResponseEntity<String> listFeeByAttr(@RequestParam(value = "communityId") String communityId,
  132. @RequestParam(value = "feeId", required = false) String feeId,
  133. @RequestParam(value = "specCd") String specCd,
  134. @RequestParam(value = "value") String value,
  135. @RequestParam(value = "row") int row,
  136. @RequestParam(value = "page") int page) {
  137. FeeAttrDto feeAttrDto = new FeeAttrDto();
  138. feeAttrDto.setCommunityId(communityId);
  139. feeAttrDto.setSpecCd(specCd);
  140. feeAttrDto.setValue(value);
  141. feeAttrDto.setFeeId(feeId);
  142. feeAttrDto.setRow(row);
  143. feeAttrDto.setPage(page);
  144. return queryFeeByAttrImpl.query(feeAttrDto);
  145. }
  146. /**
  147. * 查询欠费费用
  148. *
  149. * @param payObjId 付费方ID
  150. * @param communityId 小区ID
  151. * @return
  152. * @path /app/feeApi/listOweFees
  153. */
  154. @RequestMapping(value = "/listOweFees", method = RequestMethod.GET)
  155. public ResponseEntity<String> listOweFees(@RequestParam(value = "payObjId", required = false) String payObjId,
  156. @RequestParam(value = "payObjType", required = false) String payObjType,
  157. @RequestParam(value = "ownerId", required = false) String ownerId,
  158. @RequestParam(value = "targetEndTime", required = false) String targetEndTime,
  159. @RequestParam(value = "communityId") String communityId) {
  160. if (StringUtil.isEmpty(payObjId) && StringUtil.isEmpty(ownerId)) {
  161. throw new IllegalArgumentException("费用对象或者业主不能都为空");
  162. }
  163. FeeDto feeDto = new FeeDto();
  164. if (!StringUtil.isEmpty(payObjId)) {
  165. if (payObjId.contains(",")) {
  166. feeDto.setPayerObjIds(payObjId.split(","));
  167. } else {
  168. feeDto.setPayerObjId(payObjId);
  169. }
  170. }
  171. if (!StringUtil.isEmpty(targetEndTime)) {
  172. targetEndTime = targetEndTime + " 23:59:59";
  173. feeDto.setTargetEndTime(targetEndTime);
  174. }
  175. feeDto.setPayerObjType(payObjType);
  176. feeDto.setOwnerId(ownerId);
  177. feeDto.setCommunityId(communityId);
  178. return queryOweFeeImpl.query(feeDto);
  179. }
  180. /**
  181. * 查询欠费费用
  182. *
  183. * @param roomId 房屋ID
  184. * @param communityId 小区ID
  185. * @return
  186. * @path /app/feeApi/listAllRoomOweFees
  187. */
  188. @RequestMapping(value = "/listAllRoomOweFees", method = RequestMethod.GET)
  189. public ResponseEntity<String> listAllRoomOweFees(
  190. @RequestParam(value = "roomId", required = false) String roomId,
  191. @RequestParam(value = "communityId") String communityId) {
  192. FeeDto feeDto = new FeeDto();
  193. feeDto.setPayerObjId(roomId);
  194. feeDto.setPayerObjType(FeeDto.PAYER_OBJ_TYPE_ROOM);
  195. feeDto.setCommunityId(communityId);
  196. return queryOweFeeImpl.querys(feeDto);
  197. }
  198. /**
  199. * 查询欠费费用(批量查询)
  200. *
  201. * @param num 停车位或房屋编号
  202. * @param communityId 小区ID
  203. * @return
  204. * @path /app/feeApi/getOweFees
  205. */
  206. @RequestMapping(value = "/getOweFees", method = RequestMethod.GET)
  207. public ResponseEntity<String> getOweFees(
  208. @RequestParam(value = "payObjType") String payObjType,
  209. @RequestParam(value = "communityId") String communityId,
  210. @RequestParam(value = "billType") String billType,
  211. @RequestParam(value = "row") int row,
  212. @RequestParam(value = "page") int page,
  213. @RequestParam(value = "num", required = false) String num
  214. ) {
  215. FeeDto feeDto = new FeeDto();
  216. feeDto.setPayerObjId(num);
  217. feeDto.setPayerObjType(payObjType);
  218. feeDto.setCommunityId(communityId);
  219. feeDto.setBillType(billType);
  220. feeDto.setRow(row);
  221. feeDto.setPage(page);
  222. return queryOweFeeImpl.queryAllOwneFee(feeDto);
  223. }
  224. /**
  225. * 欠费批量缴费
  226. *
  227. * @param reqJson {
  228. * "communityId":"",
  229. * "fees":[
  230. * {
  231. * "feeId":"123123",
  232. * "feePrice":10.00,
  233. * <p>
  234. * }
  235. * <p>
  236. * ]
  237. * }
  238. * @return
  239. * @path /app/feeApi/payOweFee
  240. */
  241. @RequestMapping(value = "/payOweFee", method = RequestMethod.POST)
  242. public ResponseEntity<String> payOweFee(@RequestBody JSONObject reqJson) {
  243. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
  244. Assert.hasKey(reqJson, "fees", "未包含缴费项目");
  245. return payOweFeeImpl.pay(reqJson);
  246. }
  247. /**
  248. * 费用导入
  249. *
  250. * @param reqString
  251. * @return
  252. */
  253. @RequestMapping(value = "/importRoomFees", method = RequestMethod.POST)
  254. public ResponseEntity<String> importRoomFees(@RequestBody String reqString) {
  255. JSONObject reqJson = JSONObject.parseObject(reqString);
  256. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
  257. Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
  258. Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
  259. Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
  260. Assert.hasKeyAndValue(reqJson, "batchId", "未包含用户信息");
  261. return importRoomFeeImpl.importFee(reqJson);
  262. }
  263. /**
  264. * 车辆费用导入
  265. * /feeApi/importCarFees
  266. * path /app/feeApi/importCarFees
  267. *
  268. * @param reqString
  269. * @return
  270. */
  271. @RequestMapping(value = "/importCarFees", method = RequestMethod.POST)
  272. public ResponseEntity<String> importCarFees(@RequestBody String reqString) {
  273. JSONObject reqJson = JSONObject.parseObject(reqString);
  274. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
  275. Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
  276. Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
  277. Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
  278. Assert.hasKeyAndValue(reqJson, "batchId", "未包含批次信息");
  279. return importRoomFeeImpl.importCarFee(reqJson);
  280. }
  281. /**
  282. * 合同费用导入
  283. * /feeApi/importContractFees
  284. * path /app/feeApi/importContractFees
  285. *
  286. * @param reqString
  287. * @return
  288. */
  289. @RequestMapping(value = "/importContractFees", method = RequestMethod.POST)
  290. public ResponseEntity<String> importContractFees(@RequestBody String reqString) {
  291. JSONObject reqJson = JSONObject.parseObject(reqString);
  292. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
  293. Assert.hasKeyAndValue(reqJson, "feeTypeCd", "未包含费用类型");
  294. Assert.hasKeyAndValue(reqJson, "storeId", "未包含商户信息");
  295. Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
  296. Assert.hasKeyAndValue(reqJson, "batchId", "未包含批次信息");
  297. return importRoomFeeImpl.importContractFees(reqJson);
  298. }
  299. }