jyy
2021-06-04 1d917e41e6a31a535932fbfde6324fe4bdf6ed8b
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
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);
    }
}