You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

332 lines
12 KiB

  1. package com.simple.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.simple.common.ErrorCode;
  5. import com.simple.common.Result;
  6. import com.simple.common.ResultData;
  7. import com.simple.domain.po.*;
  8. import com.simple.enums.EnumCarCmd;
  9. import com.simple.enums.EnumCarVendor;
  10. import com.simple.enums.EnumETCPCode;
  11. import com.simple.service.WxCUserCarService;
  12. import com.simple.service.WxCarCmdLogService;
  13. import com.simple.service.WxMerchantService;
  14. import com.simple.service.WxParkService;
  15. import com.simple.utils.ETCPUtil;
  16. import com.simple.utils.TJDCarUtil;
  17. import io.swagger.annotations.ApiOperation;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.apache.log4j.Logger;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. @RestController
  26. @RequestMapping("/carCallback")
  27. public class WxCarCallBackController extends BaseController
  28. {
  29. private Logger logger = Logger.getLogger(WxCarCallBackController.class);
  30. ETCPUtil etcp = new ETCPUtil();
  31. TJDCarUtil tjd = new TJDCarUtil();
  32. @Autowired
  33. WxParkService wxParkService;
  34. @Autowired
  35. WxCUserCarService wxCUserCarService;
  36. @Autowired
  37. WxMerchantService wxMerchantService;
  38. @Autowired
  39. WxCarCmdLogService wxCarCmdLogService;
  40. /**
  41. * ETCP 车辆入场通知
  42. * {
  43. * "synId": "4ebd80ff-cfcf-462a-94cb-727e9fa9547c",
  44. * "plateNumber": "渝 ATX061",
  45. * "parkName": "ETCP 智慧停车场",
  46. * "parkId": "1",
  47. * "entranceTime": "2017-08-20 12:59:54",
  48. * "userType": "76",
  49. * "pushTime": "2017-08-20 12:59:57",
  50. * "fixParkingId": "U7",
  51. * "remainingDays": "11"
  52. * }
  53. */
  54. @PostMapping(value = "/etcpParkInCallback")
  55. public Result etcpParkInCallback(@RequestBody Map<String,String> paramMap) {
  56. logger.info("etcpParkInCallback: " + paramMap.toString());
  57. Date currentDate = new Date();
  58. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  59. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  60. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode());
  61. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  62. wxCarCmdLog.setCreateDate(currentDate);
  63. wxCarCmdLog.setUpdateDate(currentDate);
  64. String etcpParkId = paramMap.get("parkId");
  65. WxPark parkQ = new WxPark();
  66. parkQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  67. parkQ.setParkId(etcpParkId);
  68. WxPark park = wxParkService.getByObj(parkQ);
  69. if (park == null) {
  70. logger.error("etcpParkInCallback: ETCP车场未找到"+ etcpParkId);
  71. //return new Result(ErrorCode.CAR_PARK_NOT_FOUND.getCode(), "ETCP车场未找到"+ etcpParkId);
  72. } else {
  73. wxCarCmdLog.setTenantId(park.getTenantId());
  74. }
  75. try {
  76. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  77. } catch (Exception e) {
  78. logger.error("etcpParkInCallback: 入库错误 "+ paramMap.toString());
  79. return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
  80. }
  81. // TODO 发起 营销 -- 短信
  82. return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
  83. }
  84. /**
  85. * ETCP 车辆出场通知
  86. * {
  87. * "synId": "fd92f645-880e-4c2a-9d7d-7081a2488181",
  88. * "plateNumber": "渝 ATX061",
  89. * "parkName": "ETCP 智慧停车场",
  90. * "parkId": "1",
  91. * "entranceTime": "2017-08-17 18:44:19",
  92. * "userType": "76",
  93. * "pushTime": "2017-08-20 11:57:51",
  94. * "exitTime": "2017-08-19 12:07:19",
  95. * "stayedTime": 148980,
  96. * "receivableFee": 0,
  97. * "paidServiceFee": 0,
  98. * "fixParkingId": "U7",
  99. * "remainingDays": "12"
  100. * }
  101. */
  102. @PostMapping(value = "/etcpParkOutCallback")
  103. public Result etcpParkOutCallback(@RequestBody Map<String,String> paramMap) {
  104. logger.info("etcpParkOutCallback: " + paramMap.toString());
  105. Date currentDate = new Date();
  106. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  107. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  108. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode());
  109. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  110. wxCarCmdLog.setCreateDate(currentDate);
  111. wxCarCmdLog.setUpdateDate(currentDate);
  112. String etcpParkId = paramMap.get("parkId");
  113. WxPark parkQ = new WxPark();
  114. parkQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  115. parkQ.setParkId(etcpParkId);
  116. WxPark park = wxParkService.getByObj(parkQ);
  117. if (park == null) {
  118. logger.error("etcpParkOutCallback: ETCP车场未找到 "+ etcpParkId);
  119. //return new Result(ErrorCode.CAR_PARK_NOT_FOUND.getCode(), "ETCP车场未找到"+ etcpParkId);
  120. } else {
  121. wxCarCmdLog.setTenantId(park.getTenantId());
  122. }
  123. try {
  124. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  125. } catch (Exception e) {
  126. logger.error("etcpParkOutCallback: 入库错误 "+ paramMap.toString());
  127. return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
  128. }
  129. // TODO 如果此车关联了停车优免券,自动把优免券设为已使用
  130. return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
  131. }
  132. /**
  133. * ETCP 车辆解绑通知
  134. * {
  135. * "plateNumber": "渝 ATX061",
  136. * "time": "2017-08-20 11:57:51"
  137. * }
  138. */
  139. @PostMapping(value = "/etcpUnbindCarCallBack")
  140. public Result etcpUnbindCarCallBack(@RequestBody Map<String,String> paramMap) {
  141. logger.info("etcpUnbindCarCallBack: " + paramMap.toString());
  142. String carNumber = paramMap.get("plateNumber");
  143. // TODO how to get the parkId
  144. Date currentDate = new Date();
  145. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  146. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  147. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_UNBIND.getCode());
  148. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  149. wxCarCmdLog.setCreateDate(currentDate);
  150. wxCarCmdLog.setUpdateDate(currentDate);
  151. try {
  152. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  153. } catch (Exception e) {
  154. logger.error("etcpUnbindCarCallBack: 入库错误 "+ paramMap.toString());
  155. return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
  156. }
  157. WxCUserCar userCarQ = new WxCUserCar();
  158. userCarQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  159. userCarQ.setCarNumber(carNumber);
  160. // 数据库里删除,保持同步
  161. try {
  162. wxCUserCarService.deleteByObj(userCarQ);
  163. } catch (Exception e) {
  164. logger.error(e.getMessage());
  165. }
  166. // 营销 - 短信
  167. return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
  168. }
  169. /**
  170. * ETCP 主动支付结果通知
  171. * {
  172. * "plateNumber": "渝 ATX061",
  173. * "orderId": "fd92f645-880e-4c2a-9d7d-7081a2488181",
  174. * "fee": 7.65,
  175. * "paidServiceFee": 0.07,
  176. * "coupon": 0,
  177. * "time": "2017-08-20 11:57:51"
  178. * }
  179. */
  180. @PostMapping(value = "/etcpPaidCallback")
  181. public Result etcpPaidCallback(@RequestBody Map<String,String> paramMap) {
  182. logger.info("etcpPaidCallback: " + paramMap.toString());
  183. String carNumber = paramMap.get("plateNumber");
  184. // TODO how to get the parkId
  185. Date currentDate = new Date();
  186. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  187. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  188. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode());
  189. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  190. wxCarCmdLog.setCreateDate(currentDate);
  191. wxCarCmdLog.setUpdateDate(currentDate);
  192. try {
  193. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  194. } catch (Exception e) {
  195. logger.error("etcpPaidCallback: 入库错误 "+ paramMap.toString());
  196. return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
  197. }
  198. // 营销 - 短信
  199. return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
  200. }
  201. /**
  202. * TJD 车辆入场通知
  203. * {
  204. * "tradeId": "5836b8b52ada463ebc6199579f029565",
  205. * "outCarId": "45454545454",
  206. * "carNum": "京A45413",
  207. * "carNumColor ": "blue",
  208. * "inDt": "20170319202020",
  209. * "parkName": "测试停车场",
  210. * "parkId": "5836b8b52ada463ebc6199579f029561",
  211. * "lon": "74.000272",
  212. * "lat": "159.768703",
  213. * "wLon": "123.523032",
  214. * "wLat": "35.430735",
  215. * "payUrl": "http://prep.tingjiandan.com/tcweixin/letter/prePay/payInPark.html?prePayType=16&channel=10001",
  216. * "canFindCar": "0"
  217. * }
  218. */
  219. @RequestMapping(value = "/tjdParkInCallback")
  220. public Map tjdParkInCallback(@RequestBody Map<String,String> paramMap) {
  221. logger.info("tjdParkInCallback: " + paramMap.toString());
  222. Map map = new HashMap();
  223. String tjdParkId = paramMap.get("parkId");
  224. WxPark parkQ = new WxPark();
  225. parkQ.setVendorType(EnumCarVendor.CAR_TJD.getCode());
  226. parkQ.setParkId(tjdParkId);
  227. WxPark park = wxParkService.getByObj(parkQ);
  228. if (park == null) {
  229. logger.error("tjdParkInCallback: 停简单车场未找到"+ tjdParkId);
  230. map.put("isSuccess", "0");
  231. map.put("errorMsg", "停简单车场未找到"+ tjdParkId);
  232. return map;
  233. }
  234. Date currentDate = new Date();
  235. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  236. wxCarCmdLog.setTenantId(park.getTenantId());
  237. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode());
  238. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode());
  239. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  240. wxCarCmdLog.setCreateDate(currentDate);
  241. wxCarCmdLog.setUpdateDate(currentDate);
  242. try {
  243. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  244. } catch (Exception e) {
  245. logger.error("tjdParkInCallback: 入库错误"+ paramMap.toString());
  246. map.put("isSuccess", "0");
  247. map.put("errorMsg", "入库错误"+ paramMap.toString());
  248. return map;
  249. }
  250. map.put("isSuccess", "0");
  251. map.put("errorMsg", "");
  252. return map;
  253. }
  254. /**
  255. * TJD 车辆出场通知
  256. * {
  257. * "tradeId": "5836b8b52ada463ebc6199579f029565",
  258. * "outDt": "20170319232020",
  259. * "lon": "74.000272",
  260. * "lat": "159.768703",
  261. * "wLon": "123.523032",
  262. * "wLat": "35.430735",
  263. * "parkAmount": "5.20"
  264. * }
  265. */
  266. @RequestMapping(value = "/tjdParkoutCallback")
  267. public Map tjdParkOutCallback(@RequestBody Map<String,String> paramMap) {
  268. logger.info("tjdParkoutCallback: " + paramMap.toString());
  269. Map map = new HashMap();
  270. String tradeId = paramMap.get("tradeId");
  271. Date currentDate = new Date();
  272. WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
  273. wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
  274. wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode());
  275. wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
  276. wxCarCmdLog.setCreateDate(currentDate);
  277. wxCarCmdLog.setUpdateDate(currentDate);
  278. try {
  279. wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
  280. } catch (Exception e) {
  281. logger.error("tjdParkoutCallback: 入库错误"+ paramMap.toString());
  282. map.put("isSuccess", "0");
  283. map.put("errorMsg", "入库错误"+ paramMap.toString());
  284. return map;
  285. }
  286. map.put("isSuccess", "0");
  287. map.put("errorMsg", "");
  288. return map;
  289. }
  290. }