中扬CRM客户关系管理系统
LSH
2023-08-24 7cced07216f9be95eb6d5c26b74c2e736cda3594
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
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.domain.KeyValueVo;
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.*;
import com.zy.crm.manager.entity.param.ReimburseOnlineDomainParam;
import com.zy.crm.manager.service.*;
import com.zy.crm.manager.utils.RuleUtils;
import com.zy.crm.system.entity.User;
import com.zy.crm.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
 
@RestController
public class ReimburseOnlineController extends BaseController {
 
    @Autowired
    private ReimburseOnlineService reimburseOnlineService;
 
    @Autowired
    private ReimburseService reimburseService;
 
    @Autowired
    private PlanService planService;
 
    @Autowired
    private ReimburseOnlineDetlService reimburseOnlineDetlService;
 
    @Autowired
    private RuleService ruleService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private ProcessPermissionsService processPermissionsService;
 
    @RequestMapping(value = "/reimburseOnline/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(String.valueOf(id));
        assert reimburseOnline != null;
        JSONObject resultObj = JSON.parseObject(JSON.toJSONString(reimburseOnline));
        if (!Cools.isEmpty(reimburseOnline.getForm())) {
            JSONObject formObj = JSON.parseObject(reimburseOnline.getForm());
            formObj.forEach(resultObj::putIfAbsent);
        }
 
        // 步骤条相关
        resultObj.put("step", reimburseOnline.getSettle() == 6 ? 0 : reimburseOnline.getSettle() + 1);
 
        return R.ok().add(resultObj);
    }
 
    @RequestMapping(value = "/reimburseOnline/viewCheck/{id}/auth")
    @ManagerAuth
    public R viewCheck(@PathVariable("id") String id) {
        ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(String.valueOf(id));
        if (Cools.isEmpty(reimburseOnline.getCheckData())) {
            return R.error("请先上传询价");
        }
        return R.ok(reimburseOnline);
    }
 
    @RequestMapping(value = "/reimburseOnline/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(required = false)String condition,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<ReimburseOnline> wrapper = new EntityWrapper<>();
        wrapper.setSqlSelect("id,settle,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId");
//        wrapper.in("member_id", getUserRoleBelongsToUserId());
        wrapper.andNew();
        excludeTrash(param);
        convert(param, wrapper);
        allLike(ReimburseOnline.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        wrapper.or().eq("member_id",getUserId());
        return R.ok(reimburseOnlineService.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 = "/reimburseOnline/from/add/auth")
    @ManagerAuth(memo = "添加报销单")
    @Transactional
    public R formAdd(@RequestBody ReimburseOnlineDomainParam param){
        long planId = 0;
        if (!param.getTemplateName().equals("非项目型报销")){
            if (Cools.isEmpty(param.getOrderNo())){
                return R.error("添加失败!"+param.getTemplateName()+"需要关联项目号");
            }
            String[] split = param.getOrderNo().split("---");
            planId = Long.parseLong(split[1]);
        }
        Date now = new Date();
        Rule rule = ruleService.selectById(1);
        ReimburseOnline reimburseOnline = new ReimburseOnline(planId,RuleUtils.rule(rule),now,getUser());
        reimburseOnline.setCheckData(param.getCheckData());
        reimburseOnline.setTemplateName(param.getTemplateName());
 
        reimburseOnline.setSettle(0);  // 0.创建
        User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
 
        ProcessPermissions processPermissions3 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", param.getCheckData().equals("否")? "3-1" : "3-2"));//3:报销流程
        User president3 = userService.selectById(processPermissions3.getUserId());       // 获取报价流程节点3确认人
 
        ProcessPermissions processPermissions4 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "4-1"));//3:报销流程
        User president4 = userService.selectById(processPermissions4.getUserId());       // 获取报价流程节点4确认人
 
        ProcessPermissions processPermissions5 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "5-1"));//3:报销流程
        User president5 = userService.selectById(processPermissions5.getUserId());       // 获取报价流程节点5确认人
 
        ProcessPermissions processPermissions6 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "6-1"));//3:报销流程
        User president6 = userService.selectById(processPermissions6.getUserId());       // 获取报价流程节点6确认人
 
        reimburseOnline.setSettleMsg(JSON.toJSONString(SettleDto.initPriQuote(reimburseOnline, manager,president3,president4,president5,president6,getUser())));
        Map<String, Object> map = new HashMap<>();
        map.put("title","非项目型报销");
        map.put("reimburseId",reimburseOnline.getPlanId$());
        map.put("docType",param.getDocType());
        map.put("orderNo",param.getOrderNo());
        map.put("templateName",param.getTemplateName());
        map.put("checkData",param.getCheckData());
        reimburseOnline.setForm(JSON.toJSONString(map));
        reimburseOnline.setMemberId(getUser().getId());
 
        if (!reimburseOnlineService.insert(reimburseOnline)){
            return R.error("添加报销主档失败");
        }
        for (ReimburseOnlineDetl reimburseOnlineDetl:param.getReimburseOnlineDetls()){
            reimburseOnlineDetl.setOrderId(reimburseOnline.getId());
            reimburseOnlineDetlService.insert(reimburseOnlineDetl);
        }
 
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/from/modify/auth")
    @ManagerAuth(memo = "修改报销单")
    @Transactional
    public R formModify(@RequestBody ReimburseOnlineDomainParam param){
 
        long planId = 0;
        if (!param.getTemplateName().equals("非项目型报销")){
            if (Cools.isEmpty(param.getOrderNo())){
                return R.error("修改失败!"+param.getTemplateName()+"需要关联项目号");
            }
            String[] split = param.getOrderNo().split("---");
            planId = Long.parseLong(split[1]);
        }
        Date now = new Date();
        ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(param.getReimburseId());
 
        if (!reimburseOnline.getSettle().equals(0)){
            return R.error("修改失败!提交之后禁止修改!");
        }
        if (!reimburseOnline.getUserId().equals(getUserId())){
            return R.error("非创建人员禁止修改!");
        }
 
 
        reimburseOnline.setCheckData(param.getCheckData());
        reimburseOnline.setTemplateName(param.getTemplateName());
        reimburseOnline.setItemId(planId);
        reimburseOnline.setUpdateTime(new Date());
 
        Map<String, Object> map = new HashMap<>();
        map.put("title",reimburseOnline.getPlanId$());
        map.put("reimburseId",param.getReimburseId());
        map.put("docType",param.getDocType());
        map.put("orderNo",param.getOrderNo());
        map.put("templateName",param.getTemplateName());
        map.put("checkData",param.getCheckData());
        reimburseOnline.setForm(JSON.toJSONString(map));
 
        if (!reimburseOnlineService.updateById(reimburseOnline)){
            return R.error("更新报销主档失败");
        }
 
        reimburseOnlineDetlService.delete(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id",reimburseOnline.getId()));
 
        for (ReimburseOnlineDetl reimburseOnlineDetl:param.getReimburseOnlineDetls()){
            reimburseOnlineDetl.setOrderId(reimburseOnline.getId());
            reimburseOnlineDetlService.insert(reimburseOnlineDetl);
        }
 
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/detl/all/auth")
    @Transactional
    public R head(@RequestParam Integer reimburseId){
        List<ReimburseOnlineDetl> reimburseOnlineDetls = reimburseOnlineDetlService.selectList(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id", reimburseId));
        return R.ok().add(reimburseOnlineDetls);
    }
 
    @RequestMapping(value = "/reimburseOnline/add/auth")
    @ManagerAuth
    public R add(@RequestBody Map<String,Object> map) {
        //获取模板名称
        Reimburse reimburse = reimburseService.selectById(Integer.parseInt(map.get("priId").toString()));
        if (reimburse.getStatus() == 0) {
            return R.error("该模板已被禁用");
        }
 
        ReimburseOnline reimburseOnline = new ReimburseOnline();
        reimburseOnline.setCreateTime(new Date());
        reimburseOnline.setTitle(map.get("title").toString());
        reimburseOnline.setTemplateName(reimburse.getTitle());
        reimburseOnline.setSheetData(map.get("sheetData").toString());
        reimburseOnline.setItemId(Long.parseLong(map.get("itemId").toString()));
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        reimburseOnline.setOrderNum(format.format(new Date()));
        //创建人员
        reimburseOnline.setUserId(getUserId());
        //创建人员部门
        reimburseOnline.setDeptId(getDeptId());
        //更新时间
        reimburseOnline.setUpdateTime(new Date());
        //更新人员
        reimburseOnline.setUpdateUserId(getUserId());
        //状态,未完成
        reimburseOnline.setStatus(0);
        //业务员
//        Item item = itemService.selectById(priOnline.getItemId());
        Plan plan = planService.selectById(reimburseOnline.getItemId());
        reimburseOnline.setMemberId(plan.getUserId());
 
 
        //设置项目流程
        plan.setStep(2);
        planService.updateById(plan);
 
        reimburseOnlineService.insert(reimburseOnline);
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/addOther/auth")
    @ManagerAuth
    public R addOther(@RequestBody Map<String,Object> map) {
        ReimburseOnline online = reimburseOnlineService.selectById(Long.parseLong(map.get("id").toString()));
 
        ReimburseOnline reimburseOnline = new ReimburseOnline();
        reimburseOnline.setCreateTime(new Date());
        reimburseOnline.setTitle(map.get("title").toString());
        reimburseOnline.setTemplateName(online.getTemplateName());
        reimburseOnline.setSheetData(map.get("sheetData").toString());
        reimburseOnline.setItemId(online.getItemId());
 
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        reimburseOnline.setOrderNum(format.format(new Date()));
        //创建人员
        reimburseOnline.setUserId(getUserId());
        //更新时间
        reimburseOnline.setUpdateTime(new Date());
        //更新人员
        reimburseOnline.setUpdateUserId(getUserId());
        //状态,未完成
        reimburseOnline.setStatus(0);
        reimburseOnline.setDeptId(getDeptId());
        //业务员
//        Item item = itemService.selectById(priOnline.getItemId());
        Plan plan = planService.selectById(reimburseOnline.getItemId());
        reimburseOnline.setMemberId(plan.getUserId());
 
        reimburseOnlineService.insert(reimburseOnline);
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/update/auth")
    @ManagerAuth
    public R update(@RequestBody Map<String,Object> map){
        ReimburseOnline priOnline = reimburseOnlineService.selectById(Long.parseLong(map.get("id").toString()));
        if (priOnline.getStatus() == 1) {
            return R.error("核价已完成,禁止保存");
        }
        priOnline.setTitle(map.get("title").toString());
        priOnline.setSheetData(map.get("sheetData").toString());
        //更新人员
        priOnline.setUpdateUserId(getUserId());
        //更新时间
        priOnline.setUpdateTime(new Date());
        reimburseOnlineService.updateById(priOnline);
        return R.ok();
    }
 
    //更新状态
    @RequestMapping(value = "/reimburseOnline/updateForm/auth")
    @ManagerAuth
    public R updateForm(Long id,Integer status,String title,String templateName){
        ReimburseOnline priOnline = reimburseOnlineService.selectById(id);
        priOnline.setStatus(status);
        priOnline.setUpdateTime(new Date());
        priOnline.setTitle(title);
        priOnline.setTemplateName(templateName);
        reimburseOnlineService.updateById(priOnline);
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/uploadCheck/auth")
    @ManagerAuth
    public R uploadCheck(@RequestParam("id") Integer id,
                         @RequestParam("checkData") String checkData,
                         @RequestParam("file") MultipartFile[] files){
        ReimburseOnline priOnline = reimburseOnlineService.selectById(id);
        if (priOnline.getStatus() == 1) {
            return R.error("核价已完成,禁止上传");
        }
        priOnline.setCheckData(checkData);
 
 
        MultipartFile file = files[0];
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
        String path =  ClassUtils.getDefaultClassLoader().getResource("excel/uploadCheckData").getPath();
        //文件后缀名
        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        //上传文件名
        String filename = format.format(new Date()) + suffix;
        //最终文件路径
        String filepath = path + "/" + filename;
 
 
        //服务器端保存的文件对象
        File serverFile = new File(filepath);
        if(!serverFile.exists()) {
            try {
                //创建文件
                serverFile.createNewFile();
                //将上传的文件写入到服务器端文件内
                file.transferTo(serverFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
 
        //保存文件名
        priOnline.setCheckDataFile(filename);
        reimburseOnlineService.updateById(priOnline);
        return R.ok();
    }
 
    @GetMapping("/reimburseOnline/checkDataDownload/{filename}")
    public void download(@PathVariable String filename, HttpServletResponse response) {
        try {
            ClassPathResource pathResource = new ClassPathResource("excel/uploadCheckData/" + filename);
            File file = pathResource.getFile();
            InputStream inputStream = pathResource.getInputStream();
            //输出文件
            InputStream fis = new BufferedInputStream(inputStream);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            response.reset();
 
            //获取文件的名字再浏览器下载页面
            String name = file.getName();
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
            response.addHeader("Content-Length", "" + file.length());
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            out.write(buffer);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @RequestMapping(value = "/reimburseOnline/delete/auth")
    @ManagerAuth
    public R delete(Long[] ids){
        if (Cools.isEmpty(ids)){
            return R.error();
        }
        reimburseOnlineService.deleteBatchIds(Arrays.asList(ids));
        for (Long id : ids){
            reimburseOnlineDetlService.delete(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id",id));
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/reimburseOnline/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<ReimburseOnline> wrapper = new EntityWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("priOnline"));
        convert(map, wrapper);
        List<ReimburseOnline> list = reimburseOnlineService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/reimburseOnlineQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<ReimburseOnline> wrapper = new EntityWrapper<>();
        wrapper.like("order_num", condition);
        wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
        Page<ReimburseOnline> page = reimburseOnlineService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (ReimburseOnline priOnline : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", priOnline.getId());
            map.put("value", priOnline.getOrderNum() + "/" + priOnline.getPlanId$() + "/" + priOnline.getMemberId$());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/reimburseOnline/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<ReimburseOnline> wrapper = new EntityWrapper<ReimburseOnline>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != reimburseOnlineService.selectOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(ReimburseOnline.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
    @RequestMapping("/reimburseOnline/all/get/kv")
    @ManagerAuth
    public R getDataKV(@RequestParam(required = false) String condition) {
        List<KeyValueVo> vos = new ArrayList<>();
        Wrapper<ReimburseOnline> wrapper = new EntityWrapper<ReimburseOnline>().andNew().like("id", condition).orderBy("create_time", false);
        reimburseOnlineService.selectPage(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId())));
        return R.ok().add(vos);
    }
 
    @PostMapping(value = "/reimburseOnline/approval2/auth")
    @ManagerAuth
    public R approvalReimburseOnline(@RequestParam Long planId,
                              @RequestParam(required = false) Long plannerId){
        ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(planId);
        assert reimburseOnline != null;
        Integer settle = reimburseOnline.getSettle();
        String process="";
        Date now = new Date();
        switch (reimburseOnline.getSettle()) {
            case 0:
                User user2 = userService.selectById(reimburseOnline.getUserId());
                User manager1 = userService.getDeptManager(getHostId(), user2.getDeptId());
 
                if (Cools.isEmpty(getUser())) {
                    return R.error("抱歉,您没有提交的权限");
                }
                if (!getUserId().equals(getUser().getId())) {
                    return R.error("抱歉,您没有提交的权限");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list1 = JSON.parseArray(reimburseOnline.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list1) {
                    switch (dto.getStep()) {
                        case 0:
                            dto.setCurr(Boolean.FALSE);
                            break;
                        case 1:
                            dto.setCurr(Boolean.TRUE);
                            dto.setMsg(getUser().getNickname() + "提交完成");
                            dto.setTime(DateUtils.convert(now));
                            break;
                        default:
                            break;
                    }
                }
                reimburseOnline.setSettleMsg(JSON.toJSONString(list1));
                // 修改规划单状态
                reimburseOnline.setSettle(1);
                reimburseOnline.setUpdateUserId(getUserId());
                reimburseOnline.setUpdateTime(now);
                reimburseOnline.setMemberId(manager1.getId());
 
                if (!reimburseOnlineService.updateById(reimburseOnline)) {
                    throw new CoolException("审核失败,请联系管理员");
                }
                break;
            case 1:
                // 本部门经理审核
                User user = userService.selectById(reimburseOnline.getUserId());
                User manager = userService.getDeptManager(getHostId(), user.getDeptId());
                if (manager.getId().equals(getUserId())) {
 
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(reimburseOnline.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;
                        }
                    }
                    reimburseOnline.setSettleMsg(JSON.toJSONString(list));
 
                    // 修改规划单状态
                    reimburseOnline.setSettle(2);  // 总裁办待审
                    reimburseOnline.setUpdateUserId(getUserId());
                    reimburseOnline.setUpdateTime(now);
                    ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", reimburseOnline.getCheckData().equals("否") ? "3-1" : "3-2"));//3:报销流程
                    reimburseOnline.setMemberId(processPermissions.getUserId());
 
                    if (!reimburseOnlineService.updateById(reimburseOnline)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
 
                } else {
                    return R.error("抱歉,您没有审核的权限");
                }
                break;
            case 2:
                if (reimburseOnline.getCheckData().equals("否")){
                    process="3-1";
                }else {
                    process="3-2";
                }
            case 3:
                if (Cools.isEmpty(process) || process.equals("")){
                    process="4-1";
                }
            case 4:
                if (Cools.isEmpty(process) || process.equals("")){
                    process="5-1";
                }
            case 5:
                if (Cools.isEmpty(process) || process.equals("")){
                    process="6-1";
                }
                ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", process));//3:报销流程
                User planLeader = userService.selectById(processPermissions.getUserId());       // 获取报价流程节点确认人
 
                if (Cools.isEmpty(planLeader)) {
                    throw new CoolException("未查找到报价流程节点"+process+"确认人,请联系在审批权限添加确认人!");
                }
                if (!getUserId().equals(planLeader.getId())) {
                    return R.error("抱歉,您没有审核的权限");
                }
                // 修改 settle 步骤数据
                List<SettleDto> list = JSON.parseArray(reimburseOnline.getSettleMsg(), SettleDto.class);
                for (SettleDto dto : list) {
                    if (dto.getStep().equals(settle)){
                        dto.setCurr(Boolean.FALSE);
                    }else if (dto.getStep().equals(settle+1)){
                        dto.setCurr(Boolean.TRUE);
                        dto.setMsg("报价流程节点"+process+"确认人:"+planLeader.getNickname() + "审批通过");
                        dto.setTime(DateUtils.convert(now));
                    }
                }
                reimburseOnline.setSettleMsg(JSON.toJSONString(list));
                // 修改规划单状态
                reimburseOnline.setSettle(settle+1);
                reimburseOnline.setUpdateUserId(getUserId());
                reimburseOnline.setUpdateTime(now);
                String[] split = process.split("-");
                if (settle!=5){
                    settle=settle+2;
                }else {
                    settle++;
                    reimburseOnline.setStatus(1);
                }
                ProcessPermissions processPermissions2 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", settle+"-"+split[1]));//3:报销流程
                reimburseOnline.setMemberId(processPermissions2.getUserId());
 
                if (!reimburseOnlineService.updateById(reimburseOnline)) {
                    throw new CoolException("审核失败,请联系管理员");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
 
}