zhaowenxuan
2024-10-14 e4de984c46c980d39df745351a2fbd5f97cc354d
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
package com.ltkj.web.controller.system;
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
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.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.hosp.domain.TjCustomer;
import com.ltkj.hosp.domain.TjCustomerBlack;
import com.ltkj.hosp.service.*;
import com.ltkj.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("/hosp/cusBlack")
@Api(tags = "PC端 ----体检黑名单记录接口")
@Slf4j
public class TjCustomerBlackController extends BaseController {
    @Resource
    private ITjCustomerService customerService;
    @Resource
    private TjCustomerBlackService blackService;
    @Resource
    private ITjOrderService tjOrderService;
    @Autowired
    private ISysConfigService configService;
 
    @PostMapping("/addCustomerBlack")
    @ApiOperation(value = "添加黑名单")
    public AjaxResult addCustomerBlack(@RequestBody TjCustomerBlack customerBlack) {
//        TjCustomer customer = customerService.getTjCustomerByCusIdCard(String.valueOf(customerBlack.getCusId()));
        TjCustomer customer = customerService.getById(customerBlack.getCusId());
        if (null != customer) {
            LambdaQueryWrapper<TjCustomerBlack>wq=new LambdaQueryWrapper<>();
            wq.eq(TjCustomerBlack::getCusId,customer.getCusId());
            wq.eq(TjCustomerBlack::getIsExpiration,"N");
           TjCustomerBlack tjCustomerBlack = blackService.getOne(wq);
            if(null !=tjCustomerBlack){
                return AjaxResult.error("该人员已经是黑名单  不可重复加入!");
            }
            customerBlack.setCusId(customer.getCusId());
            String days = customerBlack.getDays();
            if(null ==days){
                days = configService.selectConfigByKey("Blacklist");
                customerBlack.setDays(days);
            }
            DateTime day = DateUtil.offsetDay(new Date(), Integer.parseInt(days));
            customerBlack.setExpirationTime(day);
            customerBlack.setIsExpiration("N");
            customerBlack.setCusName(customer.getCusName());
            customerBlack.setCusPhone(customer.getCusPhone());
            return AjaxResult.success(blackService.save(customerBlack));
        }
        return AjaxResult.success("该人员不存在!");
    }
 
    @PutMapping("/putCustomerBlack")
    @ApiOperation(value = "修改黑名单")
    public AjaxResult putCustomerBlack(@RequestBody TjCustomerBlack customerBlack) {
 
        String days = customerBlack.getDays();
        if(null ==days){
             days = configService.selectConfigByKey("Blacklist");
        }
        DateTime day = DateUtil.offsetDay(new Date(), Integer.parseInt(days));
        customerBlack.setExpirationTime(day);
        if(day.before(new Date())){
            customerBlack.setIsExpiration("Y");
        }else {
            customerBlack.setIsExpiration("N");
        }
        return AjaxResult.success(blackService.updateById(customerBlack));
    }
 
    @DeleteMapping("/delCustomerBlack")
    @ApiOperation(value = "删除黑名单")
    public AjaxResult delCustomerBlack(@RequestBody TjCustomerBlack customerBlack) {
        return AjaxResult.success(blackService.save(customerBlack));
    }
 
 
    @GetMapping("/getCustomerBlack")
    @ApiOperation(value = "查询黑名单列表")
    public AjaxResult getCustomerBlack(@RequestParam(required = false) @ApiParam(value = "客户姓名") String name,
                                       @RequestParam(required = false) @ApiParam(value = "客户手机号") String phone,
                                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码数") Integer page,
                                       @RequestParam(defaultValue = "10") @ApiParam(value = "每页显示条数") Integer pageSize) {
 
        LambdaQueryWrapper<TjCustomerBlack>wq=new LambdaQueryWrapper<>();
        wq.eq(TjCustomerBlack::getIsExpiration,"N");
        if(null !=name)wq.like(TjCustomerBlack::getCusName,name);
        if(null !=phone)wq.like(TjCustomerBlack::getCusPhone,phone);
        IPage<TjCustomerBlack> pages=new Page<>(page,pageSize);
        IPage<TjCustomerBlack> iPage = blackService.page(pages, wq);
        List<TjCustomerBlack> list = iPage.getRecords();
        if(null !=list && list.size()>0){
            for (TjCustomerBlack black : list) {
                TjCustomer customer = customerService.getById(black.getCusId());
                black.setCusName(customer.getCusName());
                black.setCusSex(customer.getCusSex());
                black.setTjCompName(customerService.getCompNameByCusId(String.valueOf(black.getCusId())));
            }
        }
        return AjaxResult.success(iPage);
    }
}