935090232@qq.com
2021-03-19 81a3369395a7cccceb7cd36f5238cc6fe2aa88e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.matrix.system.score.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.score.constant.ScoreSettingConstant;
import com.matrix.system.score.service.ScoreRuleSettingService;
import com.matrix.system.score.vo.ScoreRuleSettingsVo;
 
import cn.hutool.core.util.StrUtil;
 
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * @author wzy
 * @date 2021-02-22
 **/
@RestController
@RequestMapping(value = "/score/ruleSetting")
public class ScoreRuleSettingAction {
 
    @Autowired
    private ScoreRuleSettingService scoreRuleSettingService;
    @Autowired
    private BusParameterSettingsDao busParameterSettingsDao;
 
 
    @GetMapping(value = "/testApi")
    public AjaxResult testApi() {
        scoreRuleSettingService.testMethod();
        return AjaxResult.buildSuccessInstance("success");
    }
 
    /**
     *查询积分规则配置
     */
    @RequestMapping(value = "/selectScoreRule")
    public AjaxResult selectScoreRule() {
 
       AjaxResult result= AjaxResult.buildSuccessInstance("查询成功");
       SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
       Long companyId = user.getCompanyId();
       
       //积分有效期
       String[] jfyxqArrayCode={ScoreSettingConstant.VALID_PERIOD_POINTS};
       String[] jfyxqArrayName={"积分有效期:从获得开始 到"};
       List<ScoreRuleSettingsVo> jfyxqRuleSettingsVo = getRuleSettingsVo(jfyxqArrayCode,jfyxqArrayName,companyId);
       result.putInMap("jfyxq", jfyxqRuleSettingsVo);
       //积分抵扣现金
       String[] jfdxjArrayCode={ScoreSettingConstant.CREDIT_POINTS_CASH};
       String[] jfdxjArrayName={"积分抵扣现金"};
       List<BusParameterSettings> dataList = busParameterSettingsDao.selectByCodesAndCompanyId(Arrays.asList(jfdxjArrayCode), companyId);
       List<ScoreRuleSettingsVo> jfdxjRuleSettingsVo=new ArrayList<ScoreRuleSettingsVo>();
       int index=0;
       for (BusParameterSettings item:dataList){
           ScoreRuleSettingsVo paramVo=new ScoreRuleSettingsVo();
            BeanUtils.copyProperties(item,paramVo);
            paramVo.setParamName(jfdxjArrayName[index]);
            String paramValue = paramVo.getParamValue();
            if(StrUtil.isNotEmpty(paramValue)) {
                paramVo.setParamSwitch(Boolean.TRUE);
            }else {
                paramVo.setParamSwitch(Boolean.FALSE);
            }
            jfdxjRuleSettingsVo.add(paramVo);
            index++;
       }
       result.putInMap("jfdxj", jfdxjRuleSettingsVo);
       //门店积分规则
       String[] mdjfArrayCode={
               ScoreSettingConstant.CASH_CONSUMPTION,
               ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION,
               ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION,
               ScoreSettingConstant.PRINCIPAL_CONSUMPTION,
               ScoreSettingConstant.GIVE_CONSUMPTION,
               ScoreSettingConstant.REFERRALS_CONSUMPTION};
       String[] mdjfArrayName={
               "现金消费",
               "本金余额消费",
               "赠金余额消费",
               "本金消耗",
               "赠送消耗",
               "转介客户"};
       List<ScoreRuleSettingsVo> mdjfRuleSettingsVo = getRuleSettingsVo(mdjfArrayCode,mdjfArrayName,companyId);
       result.putInMap("mdjf", mdjfRuleSettingsVo);
       //商城积分规则
       String[] scjfArrayCode={
               ScoreSettingConstant.CASH_CONSUMPTION_SHOP,
               ScoreSettingConstant.RESERVATION_SERVICE_SHOP,
               ScoreSettingConstant.EVALUATUIN_ORDER_SHOP,
               ScoreSettingConstant.SIGN_SHOP};
       String[] scjfArrayName={
               "现金消费",
               "预约服务",
               "评价订单",
               "签到"};
       List<ScoreRuleSettingsVo> scjfRuleSettingsVo =getRuleSettingsVo(scjfArrayCode,scjfArrayName,companyId);
       result.putInMap("scjf", scjfRuleSettingsVo);
       return result;
    }
 
    /**
     *获取对应的积分规则设置数据
     * @param ArrayCode
     * @param ArrayName
     * @param companyId
     * @return
     */
    private List<ScoreRuleSettingsVo> getRuleSettingsVo(String[] ArrayCode,String[] ArrayName,Long companyId){
        List<BusParameterSettings> dataList = busParameterSettingsDao.selectByCodesAndCompanyId(Arrays.asList(ArrayCode), companyId);
        List<ScoreRuleSettingsVo> scoreRuleSettingsVos=new ArrayList<ScoreRuleSettingsVo>();
        int index=0;
        for (BusParameterSettings item:dataList){
            ScoreRuleSettingsVo paramVo=new ScoreRuleSettingsVo();
             BeanUtils.copyProperties(item,paramVo);
             paramVo.setParamName(ArrayName[index]);
             scoreRuleSettingsVos.add(paramVo);
             index++;
        }
        return scoreRuleSettingsVos;
    }
 
    /**
     * 修改公司维度的积分规则
     */
    @PostMapping(value = "/updateScoreRule")
    public @ResponseBody
    AjaxResult updateScoreRule(@RequestBody List<BusParameterSettings> busParameterSettings) {
        return scoreRuleSettingService.updateScoreRuleByCompanyId(busParameterSettings);
    }
 
}