|
- package com.simple.controller;
-
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.simple.common.ErrorCode;
- import com.simple.common.Result;
- import com.simple.common.ResultData;
- import com.simple.domain.po.*;
- import com.simple.enums.EnumCarCmd;
- import com.simple.enums.EnumCarVendor;
- import com.simple.enums.EnumETCPCode;
- import com.simple.service.WxCUserCarService;
- import com.simple.service.WxCarCmdLogService;
- import com.simple.service.WxMerchantService;
- import com.simple.service.WxParkService;
- import com.simple.utils.ETCPUtil;
- import com.simple.utils.TJDCarUtil;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
-
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
-
- @RestController
- @RequestMapping("/carCallback")
- public class WxCarCallBackController extends BaseController
- {
- private Logger logger = Logger.getLogger(WxCarCallBackController.class);
-
- ETCPUtil etcp = new ETCPUtil();
-
- TJDCarUtil tjd = new TJDCarUtil();
-
- @Autowired
- WxParkService wxParkService;
-
- @Autowired
- WxCUserCarService wxCUserCarService;
-
- @Autowired
- WxMerchantService wxMerchantService;
-
- @Autowired
- WxCarCmdLogService wxCarCmdLogService;
-
- /**
- * ETCP 车辆入场通知
- * {
- * "synId": "4ebd80ff-cfcf-462a-94cb-727e9fa9547c",
- * "plateNumber": "渝 ATX061",
- * "parkName": "ETCP 智慧停车场",
- * "parkId": "1",
- * "entranceTime": "2017-08-20 12:59:54",
- * "userType": "76",
- * "pushTime": "2017-08-20 12:59:57",
- * "fixParkingId": "U7",
- * "remainingDays": "11"
- * }
- */
- @PostMapping(value = "/etcpParkInCallback")
- public Result etcpParkInCallback(@RequestBody Map<String,String> paramMap) {
- logger.info("etcpParkInCallback: " + paramMap.toString());
- Date currentDate = new Date();
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
-
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
-
- String etcpParkId = paramMap.get("parkId");
- WxPark parkQ = new WxPark();
- parkQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- parkQ.setParkId(etcpParkId);
- WxPark park = wxParkService.getByObj(parkQ);
- if (park == null) {
- logger.error("etcpParkInCallback: ETCP车场未找到"+ etcpParkId);
- //return new Result(ErrorCode.CAR_PARK_NOT_FOUND.getCode(), "ETCP车场未找到"+ etcpParkId);
- } else {
- wxCarCmdLog.setTenantId(park.getTenantId());
- }
-
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("etcpParkInCallback: 入库错误 "+ paramMap.toString());
- return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
- }
-
- // TODO 发起 营销 -- 短信
- return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
- }
-
- /**
- * ETCP 车辆出场通知
- * {
- * "synId": "fd92f645-880e-4c2a-9d7d-7081a2488181",
- * "plateNumber": "渝 ATX061",
- * "parkName": "ETCP 智慧停车场",
- * "parkId": "1",
- * "entranceTime": "2017-08-17 18:44:19",
- * "userType": "76",
- * "pushTime": "2017-08-20 11:57:51",
- * "exitTime": "2017-08-19 12:07:19",
- * "stayedTime": 148980,
- * "receivableFee": 0,
- * "paidServiceFee": 0,
- * "fixParkingId": "U7",
- * "remainingDays": "12"
- * }
- */
- @PostMapping(value = "/etcpParkOutCallback")
- public Result etcpParkOutCallback(@RequestBody Map<String,String> paramMap) {
- logger.info("etcpParkOutCallback: " + paramMap.toString());
- Date currentDate = new Date();
-
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
-
- String etcpParkId = paramMap.get("parkId");
- WxPark parkQ = new WxPark();
- parkQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- parkQ.setParkId(etcpParkId);
- WxPark park = wxParkService.getByObj(parkQ);
- if (park == null) {
- logger.error("etcpParkOutCallback: ETCP车场未找到 "+ etcpParkId);
- //return new Result(ErrorCode.CAR_PARK_NOT_FOUND.getCode(), "ETCP车场未找到"+ etcpParkId);
- } else {
- wxCarCmdLog.setTenantId(park.getTenantId());
- }
-
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("etcpParkOutCallback: 入库错误 "+ paramMap.toString());
- return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
- }
-
- // TODO 如果此车关联了停车优免券,自动把优免券设为已使用
-
- return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
- }
-
- /**
- * ETCP 车辆解绑通知
- * {
- * "plateNumber": "渝 ATX061",
- * "time": "2017-08-20 11:57:51"
- * }
- */
- @PostMapping(value = "/etcpUnbindCarCallBack")
- public Result etcpUnbindCarCallBack(@RequestBody Map<String,String> paramMap) {
- logger.info("etcpUnbindCarCallBack: " + paramMap.toString());
- String carNumber = paramMap.get("plateNumber");
-
- // TODO how to get the parkId
-
- Date currentDate = new Date();
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_UNBIND.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("etcpUnbindCarCallBack: 入库错误 "+ paramMap.toString());
- return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
- }
-
- WxCUserCar userCarQ = new WxCUserCar();
- userCarQ.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- userCarQ.setCarNumber(carNumber);
- // 数据库里删除,保持同步
- try {
- wxCUserCarService.deleteByObj(userCarQ);
- } catch (Exception e) {
- logger.error(e.getMessage());
- }
- // 营销 - 短信
- return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
- }
-
- /**
- * ETCP 主动支付结果通知
- * {
- * "plateNumber": "渝 ATX061",
- * "orderId": "fd92f645-880e-4c2a-9d7d-7081a2488181",
- * "fee": 7.65,
- * "paidServiceFee": 0.07,
- * "coupon": 0,
- * "time": "2017-08-20 11:57:51"
- * }
- */
- @PostMapping(value = "/etcpPaidCallback")
- public Result etcpPaidCallback(@RequestBody Map<String,String> paramMap) {
- logger.info("etcpPaidCallback: " + paramMap.toString());
- String carNumber = paramMap.get("plateNumber");
-
- // TODO how to get the parkId
-
- Date currentDate = new Date();
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("etcpPaidCallback: 入库错误 "+ paramMap.toString());
- return new Result(ErrorCode.DB_FAIL.getCode(), "入库错误"+paramMap.toString());
- }
-
- // 营销 - 短信
- return new Result(EnumETCPCode.SUCCESS.getCode(), EnumETCPCode.SUCCESS.getMessage());
- }
-
-
- /**
- * TJD 车辆入场通知
- * {
- * "tradeId": "5836b8b52ada463ebc6199579f029565",
- * "outCarId": "45454545454",
- * "carNum": "京A45413",
- * "carNumColor ": "blue",
- * "inDt": "20170319202020",
- * "parkName": "测试停车场",
- * "parkId": "5836b8b52ada463ebc6199579f029561",
- * "lon": "74.000272",
- * "lat": "159.768703",
- * "wLon": "123.523032",
- * "wLat": "35.430735",
- * "payUrl": "http://prep.tingjiandan.com/tcweixin/letter/prePay/payInPark.html?prePayType=16&channel=10001",
- * "canFindCar": "0"
- * }
- */
- @RequestMapping(value = "/tjdParkInCallback")
- public Map tjdParkInCallback(@RequestBody Map<String,String> paramMap) {
- logger.info("tjdParkInCallback: " + paramMap.toString());
- Map map = new HashMap();
-
-
- String tjdParkId = paramMap.get("parkId");
-
- WxPark parkQ = new WxPark();
- parkQ.setVendorType(EnumCarVendor.CAR_TJD.getCode());
- parkQ.setParkId(tjdParkId);
- WxPark park = wxParkService.getByObj(parkQ);
- if (park == null) {
- logger.error("tjdParkInCallback: 停简单车场未找到"+ tjdParkId);
- map.put("isSuccess", "0");
- map.put("errorMsg", "停简单车场未找到"+ tjdParkId);
- return map;
- }
-
- Date currentDate = new Date();
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
- wxCarCmdLog.setTenantId(park.getTenantId());
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("tjdParkInCallback: 入库错误"+ paramMap.toString());
- map.put("isSuccess", "0");
- map.put("errorMsg", "入库错误"+ paramMap.toString());
- return map;
- }
-
- map.put("isSuccess", "0");
- map.put("errorMsg", "");
- return map;
- }
-
- /**
- * TJD 车辆出场通知
- * {
- * "tradeId": "5836b8b52ada463ebc6199579f029565",
- * "outDt": "20170319232020",
- * "lon": "74.000272",
- * "lat": "159.768703",
- * "wLon": "123.523032",
- * "wLat": "35.430735",
- * "parkAmount": "5.20"
- * }
- */
- @RequestMapping(value = "/tjdParkoutCallback")
- public Map tjdParkOutCallback(@RequestBody Map<String,String> paramMap) {
- logger.info("tjdParkoutCallback: " + paramMap.toString());
- Map map = new HashMap();
-
-
- String tradeId = paramMap.get("tradeId");
-
- Date currentDate = new Date();
- WxCarCmdLog wxCarCmdLog = new WxCarCmdLog();
- wxCarCmdLog.setVendorType(EnumCarVendor.CAR_ETCP.getCode());
- wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode());
- wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap));
- wxCarCmdLog.setCreateDate(currentDate);
- wxCarCmdLog.setUpdateDate(currentDate);
- try {
- wxCarCmdLogService.saveOrUpdate(wxCarCmdLog);
- } catch (Exception e) {
- logger.error("tjdParkoutCallback: 入库错误"+ paramMap.toString());
- map.put("isSuccess", "0");
- map.put("errorMsg", "入库错误"+ paramMap.toString());
- return map;
- }
-
- map.put("isSuccess", "0");
- map.put("errorMsg", "");
- return map;
- }
-
- }
|