244 lines
11 KiB
Java
244 lines
11 KiB
Java
package com.peanut.modules.master.controller;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||
import com.peanut.common.utils.R;
|
||
import com.peanut.modules.common.entity.*;
|
||
import com.peanut.modules.common.service.*;
|
||
import com.peanut.modules.master.service.CourseMedicalService;
|
||
import com.peanut.modules.master.service.CourseService;
|
||
import com.peanut.modules.master.service.CourseToMedicalService;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* 证书管理
|
||
*/
|
||
@Slf4j
|
||
@RestController("masterUserCertificate")
|
||
@RequestMapping("master/userCertificate")
|
||
public class UserCertificateController {
|
||
|
||
@Autowired
|
||
private UserCertificateService userCertificateService;
|
||
@Autowired
|
||
private UserCertificateLabelService userCertificateLabelService;
|
||
@Autowired
|
||
private MyUserService myUserService;
|
||
@Autowired
|
||
private CourseService courseService;
|
||
@Autowired
|
||
private CourseMedicalService courseMedicalService;
|
||
@Autowired
|
||
private CourseToMedicalService courseToMedicalService;
|
||
|
||
//小班自考证书列表
|
||
@RequestMapping("/userClassAndZKCertificateList")
|
||
public R userClassAndZKCertificateList(@RequestBody Map<String,Object> params) {
|
||
List list = new ArrayList<>();
|
||
//查询顶级标签下子标签
|
||
if ("13".equals(params.get("labelId").toString())) {
|
||
bottomLabel(1,list);
|
||
}else {
|
||
bottomLabel(2,list);
|
||
}
|
||
//标签下课程
|
||
List<Integer> bixiuList = courseToMedicalService.list(new LambdaQueryWrapper<CourseToMedicine>()
|
||
.eq(CourseToMedicine::getSelective,1)
|
||
.in(CourseToMedicine::getMedicalId,list)).stream().map(CourseToMedicine::getCourseId).collect(Collectors.toList());
|
||
List<Integer> xuanxiuList = courseToMedicalService.list(new LambdaQueryWrapper<CourseToMedicine>()
|
||
.eq(CourseToMedicine::getSelective,2)
|
||
.in(CourseToMedicine::getMedicalId,list)).stream().map(CourseToMedicine::getCourseId).collect(Collectors.toList());
|
||
//拥有小班证书的人
|
||
MPJLambdaWrapper<MyUserEntity> wrapper = new MPJLambdaWrapper();
|
||
wrapper.rightJoin(UserCertificate.class,UserCertificate::getUserId,MyUserEntity::getId);
|
||
wrapper.in(UserCertificate::getLabelId,5,8);
|
||
wrapper.and(t->t.in(UserCertificate::getCourseId,bixiuList)
|
||
.or().in(UserCertificate::getCourseId,xuanxiuList));
|
||
//过滤获得国际中医师证和国际针灸师证得人
|
||
wrapper.notExists("select 1 from user_certificate where label_id = "+params.get("labelId")+" and user_id = t.id ");
|
||
wrapper.select("count(1) as count,user_id userId,name,tel,email");
|
||
wrapper.groupBy(UserCertificate::getUserId);
|
||
wrapper.orderByDesc("count");
|
||
List<Map<String,Object>> certificateMaps = myUserService.listMaps(wrapper);
|
||
List<Map<String,Object>> resList = new ArrayList<>();
|
||
for (Map<String,Object> map:certificateMaps){
|
||
if ((long)map.get("count")>0){
|
||
//用户获取得证书
|
||
List<UserCertificate> certificateList = userCertificateService.list(new LambdaQueryWrapper<UserCertificate>()
|
||
.eq(UserCertificate::getUserId,map.get("userId"))
|
||
.in(UserCertificate::getLabelId,5,8)
|
||
.and(t->t.in(UserCertificate::getCourseId,bixiuList)
|
||
.or().in(UserCertificate::getCourseId,xuanxiuList)));
|
||
map.put("msg","");
|
||
if (certificateList.size()>0){
|
||
int bACount=0,bBCount=0,bZKCount=0,xCount=0;
|
||
for (UserCertificate uc : certificateList) {
|
||
if (bixiuList.contains(uc.getCourseId())){
|
||
uc.setSelective("必修");
|
||
if (uc.getCertificateNo().contains("ZK0")){
|
||
bZKCount++;
|
||
}else {
|
||
if (uc.getCertificateNo().contains("-B")){
|
||
bBCount++;
|
||
}else {
|
||
bACount++;
|
||
}
|
||
}
|
||
}else if (xuanxiuList.contains(uc.getCourseId())){
|
||
uc.setSelective("选修");
|
||
xCount++;
|
||
}
|
||
}
|
||
map.put("msg","A证:"+bACount+",B证:"+bBCount+",自考:"+bZKCount+",选修:"+xCount);
|
||
}
|
||
map.put("certificate",certificateList);
|
||
resList.add(map);
|
||
}
|
||
}
|
||
resList = resList.stream().sorted((map1,map2)->{
|
||
return Long.compare(((List)map2.get("certificate")).size(),((List)map1.get("certificate")).size());
|
||
}).collect(Collectors.toList());
|
||
Page<Map<String,Object>> page = new Page();
|
||
page.setRecords(resList);
|
||
page.setTotal(resList.size());
|
||
page.setCurrent((int)params.get("current"));
|
||
page.setSize((int)params.get("limit"));
|
||
return R.ok().put("certificateList", page);
|
||
}
|
||
|
||
//查询顶级标签下子标签
|
||
public void bottomLabel(int labelId,List list) {
|
||
CourseMedicine cm = courseMedicalService.getById(labelId);
|
||
if (cm != null) {
|
||
if (cm.getIsLast()==1){
|
||
list.add(cm.getId());
|
||
}else {
|
||
List<CourseMedicine> cms = courseMedicalService.list(new LambdaQueryWrapper<CourseMedicine>()
|
||
.eq(CourseMedicine::getPid,cm.getId()));
|
||
for (CourseMedicine ccm:cms){
|
||
bottomLabel(ccm.getId(),list);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//新增证书
|
||
@RequestMapping("/addCertificate")
|
||
public R addCertificate(@RequestBody UserCertificate userCertificate) {
|
||
CourseEntity courseEntity = courseService.getById(userCertificate.getCourseId());
|
||
if (courseEntity != null) {
|
||
userCertificate.setTitle(courseEntity.getTitle());
|
||
}
|
||
userCertificateService.save(userCertificate);
|
||
return R.ok();
|
||
}
|
||
|
||
//编辑证书
|
||
@RequestMapping("/editCertificate")
|
||
public R editCertificate(@RequestBody UserCertificate userCertificate) {
|
||
userCertificateService.updateById(userCertificate);
|
||
return R.ok();
|
||
}
|
||
|
||
//删除证书
|
||
@RequestMapping("/delCertificate")
|
||
public R delCertificate(@RequestBody UserCertificate userCertificate) {
|
||
userCertificateService.removeById(userCertificate.getId());
|
||
return R.ok();
|
||
}
|
||
|
||
//标签列表
|
||
@RequestMapping("/userCertificateLabelList")
|
||
public R userCertificateLabelList() {
|
||
List<UserCertificateLabel> labelList = userCertificateLabelService.userCertificateLabelList();
|
||
return R.ok().put("labelList", labelList);
|
||
}
|
||
|
||
//证书列表
|
||
@RequestMapping("/userCertificateList")
|
||
public R userCertificateList(@RequestBody Map<String,Object> params) {
|
||
MPJLambdaWrapper<UserCertificate> wrapper = new MPJLambdaWrapper();
|
||
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserCertificate::getUserId);
|
||
wrapper.selectAll(UserCertificate.class);
|
||
if (params.containsKey("labelId")&&StringUtils.isNotBlank(params.get("labelId").toString())) {
|
||
wrapper.eq(UserCertificate::getLabelId,params.get("labelId"));
|
||
}
|
||
if (params.containsKey("userId")&&StringUtils.isNotBlank(params.get("userId").toString())) {
|
||
wrapper.eq(MyUserEntity::getId,params.get("userId"));
|
||
}
|
||
if (params.containsKey("tel")&&StringUtils.isNotBlank(params.get("tel").toString())) {
|
||
wrapper.like(MyUserEntity::getTel,params.get("tel"));
|
||
}
|
||
if (params.containsKey("title")&&StringUtils.isNotBlank(params.get("title").toString())) {
|
||
wrapper.like(UserCertificate::getTitle,params.get("title"));
|
||
}
|
||
wrapper.orderByDesc(UserCertificate::getCreateTime);
|
||
Page<UserCertificate> certificatePage = userCertificateService.page(new Page<>(
|
||
Long.parseLong(params.get("current").toString()),Long.parseLong(params.get("limit").toString())),wrapper);
|
||
for (UserCertificate certificate:certificatePage.getRecords()){
|
||
certificate.setUser(myUserService.getById(certificate.getUserId()));
|
||
}
|
||
return R.ok().put("certificateList", certificatePage);
|
||
}
|
||
|
||
//新增标签
|
||
@RequestMapping("/saveUserCertificateLabel")
|
||
public R saveUserCertificate(@RequestBody UserCertificateLabel label) {
|
||
userCertificateLabelService.save(label);
|
||
return R.ok().put("labelId",label.getId());
|
||
}
|
||
|
||
//修改标签
|
||
@RequestMapping("/editUserCertificateLabel")
|
||
public R editUserCertificateLabel(@RequestBody UserCertificateLabel label) {
|
||
UserCertificateLabel oldLabel = userCertificateLabelService.getById(label.getId());
|
||
if(oldLabel.getIsLast()==0&& label.getIsLast()==1){
|
||
List<UserCertificateLabel> childrens = userCertificateLabelService.list(new LambdaQueryWrapper<UserCertificateLabel>()
|
||
.eq(UserCertificateLabel::getPid, label.getId()));
|
||
if(childrens.size()>0){
|
||
return R.error("更新失败,请先清空此项的下级标签,才能将此标签变成终极标签");
|
||
}
|
||
}
|
||
if(oldLabel.getIsLast()==1&& label.getIsLast()==0){
|
||
Long integer = userCertificateService.count(new LambdaQueryWrapper<UserCertificate>()
|
||
.eq(UserCertificate::getLabelId, label.getId()));
|
||
if(integer>0){
|
||
return R.error("更新失败,标签下存在证书");
|
||
}
|
||
}
|
||
userCertificateLabelService.updateById(label);
|
||
return R.ok().put("labelId",label.getId());
|
||
}
|
||
|
||
//删除标签
|
||
@RequestMapping("/delUserCertificateLabel")
|
||
public R delUserCertificateLabel(@RequestBody Map<String,Object> params) {
|
||
//查看下一级是否存在
|
||
Long count = userCertificateLabelService.count(new LambdaQueryWrapper<UserCertificateLabel>()
|
||
.eq(UserCertificateLabel::getPid, params.get("id")));
|
||
if(count>0){
|
||
return R.error("删除失败,请先删除子项目后再尝试");
|
||
}
|
||
//查看绑定关系是否存在
|
||
Long integer = userCertificateService.count(new LambdaQueryWrapper<UserCertificate>()
|
||
.eq(UserCertificate::getLabelId, params.get("id")));
|
||
if(integer>0){
|
||
return R.error("删除失败,标签下存在证书");
|
||
}
|
||
userCertificateLabelService.removeById((int)params.get("id"));
|
||
return R.ok();
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|