package com.simple.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; 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.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.List; import java.util.Map; @RestController @RequestMapping("/car") public class WxCarController extends BaseController { private Logger logger = Logger.getLogger(WxCarController.class); ETCPUtil etcp = new ETCPUtil(); TJDCarUtil tjd = new TJDCarUtil(); @Autowired WxParkService wxParkService; @Autowired WxCUserCarService wxCUserCarService; @Autowired WxMerchantService wxMerchantService; @Autowired WxCarCmdLogService wxCarCmdLogService; private WxPark getCurrentPark(MallUserInfo user) { WxPark parkQ = new WxPark(); parkQ.setTenantId(user.getTenantId()); WxPark wxPark = wxParkService.getByObj(parkQ); // 1, get mall's park // future use redis to optimize return wxPark; } @ApiOperation(value = "获取车场支持的厂家",notes="{}") @GetMapping("/getVendor") public ResultData getVendor() { MallUserInfo user = getUser(); // 1, get mall's park WxPark park = getCurrentPark(user); Map map = new HashMap(); map.put("vendor", park.getVendorType()); return new ResultData(map); } // 优免券模板 /* { "id": 4974, //优免券模板 ID "parkId": "fbqXUlfVvfc=", //车场标识 "businessId": "ZcWQ26TeJuQ=", //商家标识 title -- "businessName": "天洋广场", //商家名称 subtitle -- "name": "商家 1 小时优免券", //优免券名称 "category": "1", //优免券类型 1:小时优惠券,2:金额优惠券,3:折扣优惠券,4:免费券 price -- "categoryValue": "1.00", //优免券价值 total -- "amount": 100000, //优免券数量 valid_start_date -- "effectiveStart": "2018-02-01", //生效开始时间 valid_end_date -- "effectiveEnd": "2028-02-01",//生效结束时间 -"couponType": "0",//优惠券类型 number 库存 -- "avaliavleNum": 99993 //可用优惠券 }, */ @ApiOperation(value = "优免券模板", notes = "{\"merchantId\":\"商户ID\"}\n输出\n" + "{\n" + "\"data\":{" + "\"count\": 4," + "\"couponPlatformModels\": [\n" + " {\n" + " \"id\": 4974, //优免券模板 ID\n" + " \"parkId\": \"fbqXUlfVvfc=\", //车场标识" + " \"businessId\": \"ZcWQ26TeJuQ=\", //商家标识" + " \"businessName\": \"天洋广场\", //商家名称" + " \"name\": \"商家 1 小时优免券\", //优免券名称" + " \"category\": \"1\", //优免券类型\n 1:小时优惠券,2:金额优惠券,3:折扣优惠券,4:免费券" + " \"categoryValue\": \"1.00\", //优免券价值\n" + " \"amount\": 100000, //优免券数量\n" + " \"effectiveStart\": \"2018-02-01\", //生效开始时间\n" + " \"effectiveEnd\": \"2028-02-01\",//生效结束时间\n" + " \"couponType\": \"0\",//优惠券类型\n" + " \"avaliavleNum\": 99993 //可用优惠券\n" + " },\n" + " {...},\n" + " {...}\n" + " ]}}\n") @PostMapping("/quanTemplate") public ResultData quanTemplate(Map paramMap) { logger.info("quanTemplate: " + paramMap.toString()); MallUserInfo user = getUser(); /// 1, get mall's park WxPark park = getCurrentPark(user); if (park.getVendorType() == EnumCarVendor.CAR_ETCP.getCode()) { String merchantIdStr = paramMap.get("merchantId"); if (StringUtils.isBlank(merchantIdStr)) { // 优先从从商户表里取 logger.error("quanTemplate failed, merchantId为空"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantId为空"); } String params = park.getVendorParams(); JSONObject objParams = JSON.parseObject(params); String url = objParams.getString("url"); String merchantNo = objParams.getString("merchantNo"); String merchantKey = objParams.getString("merchantKey"); String version = objParams.getString("version"); String parkId = park.getParkId(); // bussinessId from 参数信息 String businessId = ""; // 优先从从商户表里取 businessId = getETCPBusinessID(merchantIdStr); if (StringUtils.isBlank(businessId)) { // 1期只有一个虚拟商户,可以写在商场配置里 businessId = objParams.getString("businessId"); } String ret = etcp.getBCouponList(url, merchantNo, merchantKey, version, parkId, businessId); JSONObject retObj = JSON.parseObject(ret); if (retObj.getIntValue("code") == 0) { return new ResultData(retObj.getJSONObject("data")); } else { logger.error("quanTemplate failed, 优免券模板未发现"); return new ResultData(ErrorCode.ETCP_QUAN_TEMP_FAIL.getCode(), "优免券模板未发现"); } } return new ResultData(ErrorCode.CAR_VENDOR_NOT_SUPPORT.getCode(), "优免券模板失败"); } private String getETCPBusinessID(String merchantIdStr) { String businessId; Long merchantId = 0L; try { merchantId = Long.valueOf(merchantIdStr); } catch (NumberFormatException e) { logger.error(e.getMessage()); } WxMerchant wxMerchant = wxMerchantService.getById(merchantId); String carParams = wxMerchant.getCarParams(); JSONObject objParams1 = JSON.parseObject(carParams); businessId = objParams1.getString("businessId"); return businessId; } }