FeeApi.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.IQueryFeeByAttr;
  9. import com.java110.fee.bmo.IQueryOweFee;
  10. import com.java110.fee.bmo.IQueryParkspaceFee;
  11. import com.java110.fee.smo.IFeeServiceSMO;
  12. import com.java110.utils.constant.ResponseConstant;
  13. import com.java110.utils.exception.InitConfigDataException;
  14. import com.java110.utils.exception.InitDataFlowContextException;
  15. import com.java110.utils.util.Assert;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  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. @RequestMapping(path = "/service", method = RequestMethod.GET)
  41. public String serviceGet(HttpServletRequest request) {
  42. return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR, "不支持Get方法请求").toJSONString();
  43. }
  44. /**
  45. * 用户服务统一处理接口
  46. *
  47. * @param orderInfo
  48. * @param request
  49. * @return
  50. */
  51. @RequestMapping(path = "/service", method = RequestMethod.POST)
  52. public String servicePost(@RequestBody String orderInfo, HttpServletRequest request) {
  53. BusinessServiceDataFlow businessServiceDataFlow = null;
  54. JSONObject responseJson = null;
  55. try {
  56. Map<String, String> headers = new HashMap<String, String>();
  57. getRequestInfo(request, headers);
  58. //预校验
  59. preValiateOrderInfo(orderInfo);
  60. businessServiceDataFlow = this.writeDataToDataFlowContext(orderInfo, headers);
  61. responseJson = feeServiceSMOImpl.service(businessServiceDataFlow);
  62. } catch (InitDataFlowContextException e) {
  63. logger.error("请求报文错误,初始化 BusinessServiceDataFlow失败" + orderInfo, e);
  64. responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
  65. } catch (InitConfigDataException e) {
  66. logger.error("请求报文错误,加载配置信息失败" + orderInfo, e);
  67. responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo, ResponseConstant.RESULT_PARAM_ERROR, e.getMessage(), null);
  68. } catch (Exception e) {
  69. logger.error("请求订单异常", e);
  70. responseJson = DataTransactionFactory.createBusinessResponseJson(businessServiceDataFlow, ResponseConstant.RESULT_CODE_ERROR, e.getMessage() + e,
  71. null);
  72. } finally {
  73. return responseJson.toJSONString();
  74. }
  75. }
  76. /**
  77. * 这里预校验,请求报文中不能有 dataFlowId
  78. *
  79. * @param orderInfo
  80. */
  81. private void preValiateOrderInfo(String orderInfo) {
  82. /* if(JSONObject.parseObject(orderInfo).getJSONObject("orders").containsKey("dataFlowId")){
  83. throw new BusinessException(ResponseConstant.RESULT_CODE_ERROR,"报文中不能存在dataFlowId节点");
  84. }*/
  85. }
  86. /**
  87. * 获取请求信息
  88. *
  89. * @param request
  90. * @param headers
  91. * @throws RuntimeException
  92. */
  93. private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
  94. try {
  95. super.initHeadParam(request, headers);
  96. super.initUrlParam(request, headers);
  97. } catch (Exception e) {
  98. logger.error("加载头信息失败", e);
  99. throw new InitConfigDataException(ResponseConstant.RESULT_PARAM_ERROR, "加载头信息失败");
  100. }
  101. }
  102. public IFeeServiceSMO getFeeServiceSMOImpl() {
  103. return feeServiceSMOImpl;
  104. }
  105. public void setFeeServiceSMOImpl(IFeeServiceSMO feeServiceSMOImpl) {
  106. this.feeServiceSMOImpl = feeServiceSMOImpl;
  107. }
  108. /**
  109. * 停车费查询
  110. *
  111. * @param reqJson
  112. * @return
  113. */
  114. @RequestMapping(value = "/parkSpaceFee", method = RequestMethod.POST)
  115. public ResponseEntity<String> parkSpaceFee(@RequestBody JSONObject reqJson) {
  116. Assert.hasKeyAndValue(reqJson, "code", "未包含小区编码");
  117. return queryParkspaceFeeImpl.query(reqJson);
  118. }
  119. /**
  120. * 根据属性查询费用
  121. *
  122. * @param communityId
  123. * @return
  124. * @path /app/feeApi/listFeeByAttr
  125. */
  126. @RequestMapping(value = "/listFeeByAttr", method = RequestMethod.GET)
  127. public ResponseEntity<String> listFeeByAttr(@RequestParam(value = "communityId") String communityId,
  128. @RequestParam(value = "feeId", required = false) String feeId,
  129. @RequestParam(value = "specCd") String specCd,
  130. @RequestParam(value = "value") String value,
  131. @RequestParam(value = "row") int row,
  132. @RequestParam(value = "page") int page) {
  133. FeeAttrDto feeAttrDto = new FeeAttrDto();
  134. feeAttrDto.setCommunityId(communityId);
  135. feeAttrDto.setSpecCd(specCd);
  136. feeAttrDto.setValue(value);
  137. feeAttrDto.setFeeId(feeId);
  138. feeAttrDto.setRow(row);
  139. feeAttrDto.setPage(page);
  140. return queryFeeByAttrImpl.query(feeAttrDto);
  141. }
  142. /**
  143. * 查询欠费费用
  144. * @path /app/feeApi/listOweFees
  145. * @param payObjId 付费方ID
  146. * @param communityId 小区ID
  147. * @return
  148. */
  149. @RequestMapping(value = "/listOweFees", method = RequestMethod.GET)
  150. public ResponseEntity<String> listOweFees(
  151. @RequestParam(value = "payObjId") String payObjId,
  152. @RequestParam(value = "payObjType") String payObjType,
  153. @RequestParam(value = "communityId") String communityId) {
  154. FeeDto feeDto = new FeeDto();
  155. feeDto.setPayerObjId(payObjId);
  156. feeDto.setPayerObjType(payObjType);
  157. feeDto.setCommunityId(communityId);
  158. return queryOweFeeImpl.query(feeDto);
  159. }
  160. }