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.
 
 
 
 
 

353 lines
13 KiB

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