| package com.matrix.system.hiveErp.action; | 
|   | 
| import cn.hutool.core.date.DateTime; | 
| import cn.hutool.json.JSONUtil; | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.core.metadata.IPage; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.BasePageQueryDto; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.core.tools.WebUtil; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.common.dao.SysUsersDao; | 
| import com.matrix.system.hive.action.util.QueryUtil; | 
| import com.matrix.system.hive.bean.AchieveRule; | 
| import com.matrix.system.hive.dao.AchieveRuleDao; | 
| import com.matrix.system.hiveErp.pojo.AchieveRuleItem; | 
| import lombok.AllArgsConstructor; | 
| import org.springframework.validation.annotation.Validated; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| /** | 
|  * 业绩规则Api | 
|  * | 
|  * @author jiangyouyao | 
|  * @date 2021-06-03 | 
|  **/ | 
| @RestController | 
| @AllArgsConstructor | 
| @RequestMapping(value = "/admin/achieveRule") | 
| public class AchieveRuleAction { | 
|   | 
|     private AchieveRuleDao achieveRuleDao; | 
|   | 
|   | 
|     private SysUsersDao sysUsersDao; | 
|   | 
|   | 
|     /** | 
|      * 新增业绩规则 | 
|      * @param achieveRule | 
|      * @return | 
|      */ | 
|     @PostMapping("/add") | 
|     public AjaxResult add(@RequestBody @Validated AchieveRule achieveRule) { | 
|   | 
|   | 
|   | 
|         String rules = JSONUtil.toJsonStr(achieveRule.getRuleItemList()); | 
|         achieveRule.setRules(rules); | 
|   | 
|         QueryUtil.setQueryLimitCom(achieveRule); | 
|         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         achieveRule.setCreateTime(DateTime.now()); | 
|         achieveRule.setUpdateTime(DateTime.now()); | 
|         achieveRule.setCreateBy(user.getSuName()); | 
|         achieveRule.setUpdateBy(user.getSuName()); | 
|         achieveRuleDao.insert(achieveRule); | 
|         return AjaxResult.buildSuccessInstance("新增成功"); | 
|     } | 
|   | 
|     /** | 
|      * 修改业绩规则 | 
|      * | 
|      * @param achieveRule | 
|      * @return | 
|      */ | 
|     @PostMapping("/update") | 
|     public AjaxResult update(@RequestBody @Validated AchieveRule achieveRule) { | 
|   | 
|         if (achieveRule.getId() == null) { | 
|             return AjaxResult.buildFailInstance("id不能为空"); | 
|         } | 
|   | 
|         String rules = JSONUtil.toJsonStr(achieveRule.getRuleItemList()); | 
|         achieveRule.setRules(rules); | 
|   | 
|         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         achieveRule.setUpdateBy(user.getSuName()); | 
|         achieveRule.setUpdateTime(DateTime.now()); | 
|         achieveRuleDao.updateById(achieveRule); | 
|         return AjaxResult.buildSuccessInstance("修改成功"); | 
|     } | 
|   | 
|     /** | 
|      * 删除id | 
|      * | 
|      * @param id | 
|      * @return | 
|      */ | 
|     @GetMapping("/removeById/{id}") | 
|     public AjaxResult removeById(@PathVariable Long id) { | 
|         achieveRuleDao.deleteById(id); | 
|         return AjaxResult.buildSuccessInstance("删除成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 分页查询规则 | 
|      * | 
|      * @param pageDto | 
|      * @return | 
|      */ | 
|     @PostMapping("/selectList") | 
|     public AjaxResult selectList(@RequestBody BasePageQueryDto pageDto) { | 
|   | 
|         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         Page<AchieveRule> page = new Page<>(pageDto.getPageNum(), pageDto.getPageSize()); | 
|         LambdaQueryWrapper<AchieveRule> lambdaQueryWrapper = new LambdaQueryWrapper<AchieveRule>() | 
|                 .eq(AchieveRule::getCompanyId, user.getCompanyId()); | 
|         if (StringUtils.isNotBlank(pageDto.getKeywords())) { | 
|             lambdaQueryWrapper.like(AchieveRule::getName, pageDto.getKeywords()); | 
|         } | 
|         IPage<AchieveRule> achieveRuleIPage = achieveRuleDao.selectPage(page, lambdaQueryWrapper); | 
|         achieveRuleIPage.getRecords().stream().forEach(item->{ | 
|             item.setRuleItemList(JSONUtil.toList(JSONUtil.parseArray(item.getRules()), AchieveRuleItem.class)); | 
|             item.setRules(null); | 
|         }); | 
|   | 
|         AjaxResult result = AjaxResult.buildSuccessInstance(achieveRuleIPage.getRecords(), achieveRuleIPage.getTotal()); | 
|         return result; | 
|     } | 
|   | 
|     @PostMapping("/selectListForm") | 
|     public AjaxResult selectListForm(BasePageQueryDto pageDto) { | 
|         return selectList(pageDto); | 
|     } | 
| } |