| 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);  | 
|     }  | 
|   | 
| }  |