FeeApi.java 9.7 KB

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