|
@@ -5,6 +5,15 @@ import com.platform.yijia.pojo.*;
|
|
import com.platform.yijia.service.*;
|
|
import com.platform.yijia.service.*;
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
import com.platform.yijia.utils.ResultData;
|
|
import com.platform.yijia.utils.ResultData;
|
|
|
|
+import com.platform.yijia.utils.redis.RedisCacheUtil;
|
|
|
|
+import com.platform.yijia.utils.weixinapp.WeiXinUserUtil;
|
|
|
|
+import com.platform.yijia.utils.weixinapp.WxPushUtil;
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
+import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
|
|
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
+import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
|
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
|
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -14,10 +23,9 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Random;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/*
|
|
/*
|
|
* <Title> IntegralShoppingMallController </Title>
|
|
* <Title> IntegralShoppingMallController </Title>
|
|
@@ -39,6 +47,10 @@ public class IntegralShoppingMallController {
|
|
private StationService stationService;
|
|
private StationService stationService;
|
|
@Resource
|
|
@Resource
|
|
private CustomerPointsRecordService customerPointsRecordService;
|
|
private CustomerPointsRecordService customerPointsRecordService;
|
|
|
|
+ @Resource
|
|
|
|
+ private RedisCacheUtil redisCacheUtil;
|
|
|
|
+ @Resource
|
|
|
|
+ private WxPushUtil wxPushUtil;
|
|
|
|
|
|
//获取油站积分商品信息
|
|
//获取油站积分商品信息
|
|
@RequestMapping(value = "/getIntegralWaresInfoList", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/getIntegralWaresInfoList", method = RequestMethod.GET)
|
|
@@ -107,15 +119,18 @@ public class IntegralShoppingMallController {
|
|
for(int i=0; i<6; i++){
|
|
for(int i=0; i<6; i++){
|
|
str+=random.nextInt(10);
|
|
str+=random.nextInt(10);
|
|
}
|
|
}
|
|
- integralOrder.setIntegralOrderNo(System.nanoTime()+str);
|
|
|
|
|
|
+ String integralOrderNo = System.nanoTime()+str;
|
|
|
|
+ integralOrder.setIntegralOrderNo(integralOrderNo);
|
|
integralOrder.setExchangeTime(new Date());
|
|
integralOrder.setExchangeTime(new Date());
|
|
|
|
|
|
//更新用户积分
|
|
//更新用户积分
|
|
|
|
+ String surplusPoints =""; //剩余积分
|
|
CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfo(customerPoints);
|
|
CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfo(customerPoints);
|
|
if(customerPointsInfo !=null){
|
|
if(customerPointsInfo !=null){
|
|
//用户剩余积分
|
|
//用户剩余积分
|
|
BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
|
|
BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
|
|
- customerPoints.setPoints(Integer.valueOf(points.toString()));
|
|
|
|
|
|
+ surplusPoints = points.toString();
|
|
|
|
+ customerPoints.setPoints(Integer.valueOf(surplusPoints));
|
|
//用户已消费积分累积
|
|
//用户已消费积分累积
|
|
BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
|
|
BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
|
|
customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
|
|
customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
|
|
@@ -123,10 +138,16 @@ public class IntegralShoppingMallController {
|
|
}
|
|
}
|
|
|
|
|
|
//油站名称
|
|
//油站名称
|
|
|
|
+ String gzhAppId ="";
|
|
|
|
+ String gzhAppSecret ="";
|
|
|
|
+ String stationName = "";
|
|
Map<String, String> m = stationService.getStationAppIdAndAppSecret(request.getStationId());
|
|
Map<String, String> m = stationService.getStationAppIdAndAppSecret(request.getStationId());
|
|
- if(m !=null && m.containsKey("stationName")){
|
|
|
|
- integralOrder.setStationName(m.get("stationName"));
|
|
|
|
- customerPointsRecord.setStationName(m.get("stationName"));
|
|
|
|
|
|
+ if(m !=null && m.containsKey("stationName") && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
|
|
|
|
+ stationName = m.get("stationName");
|
|
|
|
+ gzhAppId = m.get("gzhAppId");
|
|
|
|
+ gzhAppSecret = m.get("gzhAppSecret");
|
|
|
|
+ integralOrder.setStationName(stationName);
|
|
|
|
+ customerPointsRecord.setStationName(stationName);
|
|
}
|
|
}
|
|
|
|
|
|
List<IntegralWares> integralWaresInfoList = integralWaresService.getIntegralWaresInfoList(integralWares);
|
|
List<IntegralWares> integralWaresInfoList = integralWaresService.getIntegralWaresInfoList(integralWares);
|
|
@@ -142,9 +163,20 @@ public class IntegralShoppingMallController {
|
|
customerPointsRecord.setCreateTime(new Date());
|
|
customerPointsRecord.setCreateTime(new Date());
|
|
customerPointsRecordService.insertCustomerPointsInfo(customerPointsRecord);
|
|
customerPointsRecordService.insertCustomerPointsInfo(customerPointsRecord);
|
|
|
|
|
|
-
|
|
|
|
boolean b = integralOrderService.insertIntegralOrder(integralOrder);
|
|
boolean b = integralOrderService.insertIntegralOrder(integralOrder);
|
|
if (b){
|
|
if (b){
|
|
|
|
+ //公众号积分消耗消息推送
|
|
|
|
+ List<WxMpTemplateData> wxMpTemplate = new ArrayList<>();
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("first","您好!您已成功在"+stationName+"完成积分商品兑换:"));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("keyword1", request.getCustomerName()));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("keyword2", integralOrderNo));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("keyword3", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("keyword4", request.getWaresName()));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("keyword5", request.getIntegral().toString()));
|
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("remark",
|
|
|
|
+ "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的当前积分值还剩余 "+surplusPoints+" 分."));
|
|
|
|
+ String templateId = "9EWrreI-P8r4xDgoOcczC4jHt1v0HEjKzkgVRDzoNXA"; //积分兑换成功通知
|
|
|
|
+ wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, request.getOpenId(), wxMpTemplate);
|
|
resultData=ResultData.success(CodeMsg.SUCCESS);
|
|
resultData=ResultData.success(CodeMsg.SUCCESS);
|
|
}else {
|
|
}else {
|
|
resultData=ResultData.success(CodeMsg.REQUEST_FAIL);
|
|
resultData=ResultData.success(CodeMsg.REQUEST_FAIL);
|
|
@@ -152,6 +184,23 @@ public class IntegralShoppingMallController {
|
|
return gson.toJson(resultData);
|
|
return gson.toJson(resultData);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //测试redis缓存
|
|
|
|
+ @RequestMapping(value = "/redisCacheUtil", method = RequestMethod.GET)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public String redisCacheUtil(@RequestParam String unionId){
|
|
|
|
+ Gson gson =new Gson();
|
|
|
|
+ //返回结果集
|
|
|
|
+ ResultData resultData = null;
|
|
|
|
+ if(unionId !=null){
|
|
|
|
+ redisCacheUtil.setCacheObject("unionId", unionId);
|
|
|
|
+ String cacheObject = redisCacheUtil.getCacheObject("unionId");
|
|
|
|
+ resultData=ResultData.success(cacheObject);
|
|
|
|
+ }else {
|
|
|
|
+ resultData=ResultData.success(CodeMsg.REQUEST_FAIL);
|
|
|
|
+ }
|
|
|
|
+ return gson.toJson(resultData);
|
|
|
|
+ }
|
|
|
|
+
|
|
//获取用户积分订单列表
|
|
//获取用户积分订单列表
|
|
@RequestMapping(value = "/getUserIntegralOrderList", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/getUserIntegralOrderList", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -208,4 +257,5 @@ public class IntegralShoppingMallController {
|
|
}
|
|
}
|
|
return gson.toJson(resultData);
|
|
return gson.toJson(resultData);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|