|
@@ -1,35 +1,253 @@
|
|
|
package com.palatform.yijia;
|
|
|
+import com.platform.yijia.YijiaApplication;
|
|
|
+import com.platform.yijia.pojo.*;
|
|
|
+import com.platform.yijia.service.CustomerPointsRecordService;
|
|
|
+import com.platform.yijia.service.CustomerPointsService;
|
|
|
+import com.platform.yijia.service.IntegralRuleService;
|
|
|
+import com.platform.yijia.service.StationService;
|
|
|
import com.platform.yijia.utils.weixinapp.WxPushUtil;
|
|
|
+import javafx.application.Application;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.mybatis.spring.annotation.MapperScan;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
-import javax.swing.plaf.IconUIResource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-class YijiaApplicationTests {
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- boolean b= false;
|
|
|
- for (int i=0; i<=10; i++){
|
|
|
- switch (i){
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- System.out.println("3333333");
|
|
|
- b=true;
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- System.out.println("4444444");
|
|
|
- break;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = YijiaApplication.class)
|
|
|
+public class YijiaApplicationTests {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IntegralRuleService integralRuleService;
|
|
|
+ @Resource
|
|
|
+ private CustomerPointsService customerPointsService;
|
|
|
+ @Resource
|
|
|
+ private CustomerPointsRecordService customerPointsRecordService;
|
|
|
+ @Resource
|
|
|
+ private StationService stationService;
|
|
|
+ @Resource
|
|
|
+ private WxPushUtil wxPushUtil;
|
|
|
+// @Resource
|
|
|
+// private CustomerManage customerManage;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testIntegral() {
|
|
|
+
|
|
|
+ /*//================================================================================================================================
|
|
|
+ CustomerManage customerManage = new CustomerManage();
|
|
|
+ //customerManage.setGrade("铜牌");
|
|
|
+ String discountPlanType ="1";
|
|
|
+ Map infoMap = new HashMap();
|
|
|
+ infoMap.put("stationId", 1);
|
|
|
+ infoMap.put("oilName", "92#");
|
|
|
+ infoMap.put("consumer", "M");
|
|
|
+ infoMap.put("mobilePhone", "18654585051");
|
|
|
+ infoMap.put("userType", "2");
|
|
|
+ infoMap.put("amt", "200");
|
|
|
+ infoMap.put("receivableAmt", "300");
|
|
|
+ infoMap.put("orderLiters", "55");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //客户积分
|
|
|
+ IntegralRule integralRule =new IntegralRule();
|
|
|
+ integralRule.setStationId(Integer.valueOf(infoMap.get("stationId").toString()));
|
|
|
+ integralRule.setOilName(infoMap.get("oilName").toString());
|
|
|
+ //获取该油站的积分规则
|
|
|
+ List<IntegralRule> rule = integralRuleService.getIntegralRule(integralRule);
|
|
|
+ if(rule !=null && rule.size() > 0 && rule.get(0).getEmptyDate().compareTo(new Date()) ==1){
|
|
|
+ CustomerPoints customerPoints = new CustomerPoints(); //客户积分实体表
|
|
|
+ CustomerPointsRecord customerPointsRecord = new CustomerPointsRecord(); //客户积分记录实体表
|
|
|
+ if(infoMap.containsKey("unionId")){
|
|
|
+ customerPoints.setUnionId(infoMap.get("unionId").toString());
|
|
|
+ customerPointsRecord.setUnionId(infoMap.get("unionId").toString());
|
|
|
}
|
|
|
- if(b){
|
|
|
- break;
|
|
|
+ customerPoints.setCustomerName(infoMap.get("consumer").toString());
|
|
|
+ customerPoints.setMobilePhone(infoMap.get("mobilePhone").toString()); //存入手机号
|
|
|
+
|
|
|
+ customerPointsRecord.setCustomerName(infoMap.get("consumer").toString()); //客户名称
|
|
|
+ customerPointsRecord.setRecordType("+"); // "+"表示增加积分
|
|
|
+ customerPointsRecord.setStationId(Integer.valueOf(infoMap.get("stationId").toString()));
|
|
|
+ customerPointsRecord.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if(infoMap.containsKey("userType") && infoMap.get("userType") !=null){
|
|
|
+ switch (infoMap.get("userType").toString()){
|
|
|
+ case "1":
|
|
|
+ customerPoints.setBlogOpenId(infoMap.get("blogOpenid").toString());
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ customerPoints.setMinaOpenId(infoMap.get("minaOpenid").toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ //获取该用户积分信息
|
|
|
+ CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfo(customerPoints);
|
|
|
+ if(customerPointsInfo !=null){
|
|
|
+ //String ruleType = rule.get(0).getRuleType(); //获取积分规则类型
|
|
|
+ String[] datePicker={}; //积分比例时间
|
|
|
+ if(rule.get(0).getDatePicker() != null && rule.get(0).getDatePicker() !=""){
|
|
|
+ datePicker = rule.get(0).getDatePicker().split(",");
|
|
|
+ }
|
|
|
+ String currentTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前时间
|
|
|
+ List<IntegralRuleDetail> integralRuleDetailList = rule.get(0).getIntegralRuleDetailList(); //积分规则详细计算信息
|
|
|
+ if(integralRuleDetailList !=null && integralRuleDetailList.size() > 0){
|
|
|
+ BigDecimal realAmt = new BigDecimal(infoMap.get("amt").toString()); //本次消费实收金额
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(infoMap.get("receivableAmt").toString()); //本次消费实收金额
|
|
|
+ BigDecimal orderLiters = new BigDecimal(infoMap.get("orderLiters").toString()); //本次加油升数
|
|
|
+ //循环规则明细
|
|
|
+ for(IntegralRuleDetail integralRuleDetail : integralRuleDetailList){
|
|
|
+ //规则类型
|
|
|
+ String ruleType = integralRuleDetail.getRuleType();
|
|
|
+ if(ruleType !=null && ruleType.equals("1") && realAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ //以实收金额为准时
|
|
|
+ if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = realAmt.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ //如果当前时间在改日期比例时间内
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() != null){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = realAmt.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() != null){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else if(ruleType !=null && ruleType.equals("2") && receivableAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ //应收金额为准时
|
|
|
+ if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = receivableAmt.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() != null){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = receivableAmt.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() != null){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else if(ruleType !=null && ruleType.equals("3") && orderLiters.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ //加油升数为准时
|
|
|
+ if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = orderLiters.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() !=null ){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ //计算积分并取整
|
|
|
+ BigDecimal integral = orderLiters.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ //设置积分多倍时间时
|
|
|
+ if(datePicker !=null){
|
|
|
+ for(String str: datePicker){
|
|
|
+ if (str.contains(currentTime) && rule.get(0).getIntegralProportion() !=null ){
|
|
|
+ integral=integral.multiply(new BigDecimal(rule.get(0).getIntegralProportion()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints() + Integer.valueOf(integral.toString()));
|
|
|
+ customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新客户余额积分
|
|
|
+ customerPointsService.updateCustomerPointsInfo(customerPoints);
|
|
|
+ //插入客户积分记录表
|
|
|
+ customerPointsRecordService.insertCustomerPointsInfo(customerPointsRecord);
|
|
|
+
|
|
|
+ //客户公众号积分增加通知
|
|
|
+ String gzhAppId ="";
|
|
|
+ String gzhAppSecret ="";
|
|
|
+ String stationName = ""; //油站名称
|
|
|
+ Map<String, String> m = stationService.getStationAppIdAndAppSecret(Integer.valueOf(infoMap.get("stationId").toString()));
|
|
|
+ if(m !=null && m.containsKey("stationName") && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
|
|
|
+ stationName = m.get("stationName");
|
|
|
+ gzhAppId = m.get("gzhAppId");
|
|
|
+ gzhAppSecret = m.get("gzhAppSecret");
|
|
|
+ }
|
|
|
+ List<WxMpTemplateData> wxMpTemplate = new ArrayList<>();
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("first","尊敬的"+infoMap.get("consumer").toString()+",您好:\n" + "您在"+stationName+"的积分最新交易信息如下"));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("time", new SimpleDateFormat("yyyy年MM月dd日HH时mm分").format(new Date())));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("type", "增加"));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("Point", customerPointsRecord.getIntegral().toString()));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("From", stationName));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("remark",
|
|
|
+ "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的可用积分为 "+customerPoints.getPoints().toString()+" 分"));
|
|
|
+ String templateId = "G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc"; //积分兑换成功通知模板
|
|
|
+ wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, "oJR5R6r4EJhaORFcPap70r_mtFZo", wxMpTemplate);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+*///========================================================================================================================================================//
|
|
|
+
|
|
|
|
|
|
|
|
|
|