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);
|
}
|
}
|