中扬CRM客户关系管理系统
LSH
2023-10-07 c6e9227208dc46f2f46f046fea0b21bea398a16c
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package com.zy.crm.manager.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.crm.common.model.SettleDto;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.entity.BusinessTripOther;
import com.zy.crm.manager.service.BusinessTripOtherService;
import com.zy.crm.manager.utils.CarNumberUtils;
import com.zy.crm.manager.utils.TimeCalculatorUtils;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
public class BusinessTripOtherController extends BaseController {
 
    @Autowired
    private BusinessTripOtherService businessTripOtherService;
    @Autowired
    private UserService userService;
 
    @RequestMapping(value = "/businessTripOther/{id}/auth2")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        BusinessTripOther businessTripOther = businessTripOtherService.selectById(String.valueOf(id));
        assert businessTripOther != null;
        JSONObject resultObj = JSON.parseObject(JSON.toJSONString(businessTripOther));
        // 步骤条相关
        resultObj.put("step", businessTripOther.getSettle() == 3 ? 0 : businessTripOther.getSettle() + 1);
        return R.ok().add(resultObj);
    }
 
    @RequestMapping(value = "/businessTripOther/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<BusinessTripOther> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
//        wrapper.or().eq("member_id",getUserId());
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(businessTripOtherService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        Long deptId = getDeptId();
        boolean signUserId = false;
        boolean signDeptId = false;
        boolean signHostId = false;
        for (Map.Entry<String, Object> entry : map.entrySet()){
            if (entry.getKey().equals("dept_id")){
                signDeptId = true;
                if (String.valueOf(entry.getValue()).equals("19")){
                    signHostId = true;
                }
            }
        }
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else if (entry.getKey().equals("dept_id")){
                if (!val.equals("19")){
                    wrapper.eq(entry.getKey(), val);
                }
            } else if (entry.getKey().equals("user_id") && !signDeptId){
                signUserId = true;
                wrapper.eq(entry.getKey(), val);
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
        if (!signUserId && !signDeptId){
            wrapper.eq("user_id", getUserId());
        }
        if (signHostId){
            wrapper.or().eq("host_id",1);
        }
    }
 
    @RequestMapping(value = "/businessTripOther/add/auth")
    @ManagerAuth(memo = "添加出差申请")
    public R add(BusinessTripOther businessTripOther) {
        if (Cools.isEmpty(businessTripOther)){
            return R.error();
        }
        Date now = new Date();
        businessTripOther.setCarNumber("无");
        businessTripOther.setKilometers("无");
        businessTripOther.setBusinessPeersId(System.currentTimeMillis());
 
        businessTripOther.setBusinessDuration(0.0);
        businessTripOther.setBusinessTripDays(0);
        businessTripOther.setUserId(getUserId());
        businessTripOther.setDeptId(getDeptId());
        businessTripOther.setCreateTime(now);
        businessTripOther.setUserId(getUserId());
        businessTripOther.setUpdateTime(now);
        businessTripOther.setUpdateId(getUserId());
        businessTripOther.setStatus(0);
        businessTripOther.setSettle(1);
 
        User manager = new User();
        try{
            manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        }catch (Exception e){
            manager = getUser();
        }
        businessTripOther.setSettleMsg(JSON.toJSONString(SettleDto.initBusiness(manager,getUser())));
 
        businessTripOtherService.insert(businessTripOther);
        return R.ok();
    }
 
    @RequestMapping(value = "/businessTripOther/update/auth")
    @ManagerAuth(memo = "更新出差申请")
    public R update(BusinessTripOther businessTripOther){
        if (Cools.isEmpty(businessTripOther) || null==businessTripOther.getId()){
            return R.error();
        }
        Date now = new Date();
        businessTripOther.setUpdateTime(now);
        businessTripOther.setUpdateId(getUserId());
        businessTripOtherService.updateById(businessTripOther);
        return R.ok();
    }
 
    @RequestMapping(value = "/businessTripOther/delete/auth")
    @ManagerAuth(memo = "删除出差申请")
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
             businessTripOtherService.deleteById(id);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/businessTripOther/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<BusinessTripOther> wrapper = new EntityWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("businessTrip"));
        convert(map, wrapper);
        List<BusinessTripOther> list = businessTripOtherService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/businessTripOtherQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<BusinessTripOther> wrapper = new EntityWrapper<>();
        wrapper.like("id", condition);
        Page<BusinessTripOther> page = businessTripOtherService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (BusinessTripOther businessTripOther : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", businessTripOther.getId());
            map.put("value", businessTripOther.getId());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/businessTripOther/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<BusinessTripOther> wrapper = new EntityWrapper<BusinessTripOther>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != businessTripOtherService.selectOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(BusinessTripOther.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
    @PostMapping(value = "/businessTripOther/approval/auth")
    @ManagerAuth
    public R approvalBusinessTrip(@RequestParam Long planId,
                                     @RequestParam(required = false) Long plannerId){
        BusinessTripOther businessTripOther = businessTripOtherService.selectById(planId);
        assert businessTripOther != null;
        Date now = new Date();
        switch (businessTripOther.getSettle()) {
            case 1:
                // 本部门经理审核
                User user = userService.selectById(businessTripOther.getUserId());
                User manager = new User();
                try{
                    manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
                }catch (Exception e){
                    manager = user;
                }
                if (manager.getId().equals(getUserId())) {
 
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(businessTripOther.getSettleMsg(), SettleDto.class);
                    for (SettleDto dto : list) {
                        switch (dto.getStep()) {
                            case 1:
                                dto.setCurr(Boolean.FALSE);
                                break;
                            case 2:
                                dto.setCurr(Boolean.TRUE);
                                dto.setMsg("部门经理" + manager.getNickname() + "审批通过");
                                dto.setTime(DateUtils.convert(now));
                                break;
                            default:
                                break;
                        }
                    }
                    businessTripOther.setSettleMsg(JSON.toJSONString(list));
 
                    // 修改规划单状态
                    businessTripOther.setSettle(2);  // 申请通过
                    businessTripOther.setStatus(1);
                    businessTripOther.setUpdateId(getUserId());
                    businessTripOther.setUpdateTime(now);
                    if (!businessTripOtherService.updateById(businessTripOther)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有批准的权限!!!");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
 
}