| package com.matrix.system.fenxiao.action; | 
|   | 
| import com.matrix.biz.dao.BizUserDao; | 
| 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.fenxiao.constant.FenxiaoSettingConstant; | 
| import com.matrix.system.fenxiao.service.FenXiaoSettingService; | 
| import com.matrix.system.fenxiao.vo.FenXiaoSettingVo; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.Arrays; | 
| import java.util.List; | 
|   | 
| import com.matrix.system.hive.bean.ShoppingGoods; | 
| import com.matrix.system.hive.dao.ShoppingGoodsDao; | 
|   | 
| import cn.hutool.core.collection.CollUtil; | 
| import cn.hutool.core.util.StrUtil; | 
|   | 
| import org.apache.commons.collections.CollectionUtils; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.PostMapping; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
| import org.springframework.web.bind.annotation.RestController; | 
|   | 
| @RestController | 
| @RequestMapping(value = "/fenXiao/ruleSetting") | 
| public class FenXiaoSettingAction { | 
|      | 
|     @Autowired | 
|     private FenXiaoSettingService fenXiaoSettingService; | 
|   | 
|     @Autowired | 
|     private BusParameterSettingsDao busParameterSettingsDao; | 
|   | 
|     @Autowired | 
|     private ShoppingGoodsDao shoppingGoodsDao; | 
|      | 
|     @Autowired | 
|     private BizUserDao bizUserDao; | 
|      | 
|     /** | 
|      *查询分销配置 | 
|      */ | 
|     @RequestMapping(value = "/selectFenXiaoSetting") | 
|     public AjaxResult selectFenXiaoSetting() { | 
|   | 
|        AjaxResult result= AjaxResult.buildSuccessInstance("查询成功"); | 
|        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|        Long companyId = user.getCompanyId(); | 
|         | 
|        //分销开关 | 
|        String[] FXKGCode={FenxiaoSettingConstant.FX_SWITCH}; | 
|        String[] FXKGName={"分销开关"}; | 
|        List<FenXiaoSettingVo> fxkgRuleSettingsVo = getRuleSettingsVo(FXKGCode,FXKGName,companyId); | 
|        result.putInMap("fxkg", fxkgRuleSettingsVo); | 
|        //分销模式 | 
|        String[] FXMSCode={FenxiaoSettingConstant.FX_MODEL}; | 
|        String[] FXMSName={"分销模式"}; | 
|        List<FenXiaoSettingVo> fxmsRuleSettingsVo = getRuleSettingsVo(FXMSCode,FXMSName,companyId); | 
|        result.putInMap("fxms", fxmsRuleSettingsVo); | 
|        //申请方式 | 
|        String[] sqfsCode={FenxiaoSettingConstant.FX_APPLY_WAY}; | 
|        String[] sqfsName={"申请方式"}; | 
|        List<FenXiaoSettingVo> sqfsRuleSettingsVo = getRuleSettingsVo(sqfsCode,sqfsName,companyId); | 
|        result.putInMap("sqfs", sqfsRuleSettingsVo); | 
|        //审核方式 | 
|        String[] shfsCode={FenxiaoSettingConstant.FX_AUDIT_METHOD}; | 
|        String[] shfsName={"审核方式"}; | 
|        List<FenXiaoSettingVo> shfsRuleSettingsVo = getRuleSettingsVo(shfsCode,shfsName,companyId); | 
|        result.putInMap("shfs", shfsRuleSettingsVo); | 
|        //申请条件 | 
|        String[] sqtjCode={FenxiaoSettingConstant.FX_APPLY_CONDITION}; | 
|        String[] sqtjName={"申请条件"}; | 
|        List<FenXiaoSettingVo> sqtjRuleSettingsVo = getRuleSettingsVo(sqtjCode,sqtjName,companyId); | 
|        result.putInMap("sqtj", sqtjRuleSettingsVo); | 
|        if(CollUtil.isNotEmpty(sqtjRuleSettingsVo)){ | 
|            for(FenXiaoSettingVo fenXiaoSettingVo : sqtjRuleSettingsVo) { | 
|                //选择申请条件条件3时,获得选中产品集合 | 
|                if("3".equals(fenXiaoSettingVo.getParamValue())) { | 
|                    String paramValue1 = fenXiaoSettingVo.getParamValue1(); | 
|                    if(StrUtil.isNotEmpty(paramValue1)) { | 
|                        List<Integer> idsList = new ArrayList<>(); | 
|                        List<String> idsStringList = Arrays.asList(paramValue1.split(",")); | 
|                        if(CollUtil.isNotEmpty(idsStringList)){ | 
|                            for(String string : idsStringList) { | 
|                                Integer parseInt = Integer.parseInt(string); | 
|                                idsList.add(parseInt); | 
|                            } | 
|                        } | 
|                        List<ShoppingGoods> list = shoppingGoodsDao.selectByIds(idsList); | 
|                        result.putInMap("order", list); | 
|                    } | 
|                } | 
|            } | 
|        } | 
|        return result; | 
|     } | 
|      | 
|     /** | 
|      *获取对应的规则设置数据 | 
|      * @param ArrayCode | 
|      * @param ArrayName | 
|      * @param companyId | 
|      * @return | 
|      */ | 
|     private List<FenXiaoSettingVo> getRuleSettingsVo(String[] ArrayCode,String[] ArrayName,Long companyId){ | 
|         List<BusParameterSettings> dataList = busParameterSettingsDao.selectByCodesAndCompanyId(Arrays.asList(ArrayCode), companyId); | 
|         List<FenXiaoSettingVo> scoreRuleSettingsVos=new ArrayList<FenXiaoSettingVo>(); | 
|         int index=0; | 
|         for (BusParameterSettings item:dataList){ | 
|             FenXiaoSettingVo paramVo=new FenXiaoSettingVo(); | 
|             BeanUtils.copyProperties(item,paramVo); | 
|             paramVo.setParamName(ArrayName[index]); | 
|             scoreRuleSettingsVos.add(paramVo); | 
|             index++; | 
|         } | 
|         return scoreRuleSettingsVos; | 
|     } | 
|      | 
|     /** | 
|      * 修改公司维度的分销规则 | 
|      */ | 
|     @PostMapping(value = "/updateFenXiaoSetting") | 
|     public @ResponseBody | 
|     AjaxResult updateFenXiaoSetting(@RequestBody List<BusParameterSettings> busParameterSettings) { | 
|         return fenXiaoSettingService.updateFenXiaoSettingByCompanyId(busParameterSettings); | 
|     } | 
|   | 
| } |