证书标签
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package com.peanut.modules.master.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.UserCertificate;
|
||||
import com.peanut.modules.common.entity.UserCertificateLabel;
|
||||
import com.peanut.modules.common.service.MyUserService;
|
||||
import com.peanut.modules.common.service.UserCertificateLabelService;
|
||||
import com.peanut.modules.common.service.UserCertificateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 证书管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("masterUserCertificate")
|
||||
@RequestMapping("master/userCertificate")
|
||||
public class UserCertificateController {
|
||||
|
||||
@Autowired
|
||||
private UserCertificateService userCertificateService;
|
||||
@Autowired
|
||||
private UserCertificateLabelService userCertificateLabelService;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
|
||||
//标签列表
|
||||
@RequestMapping("/userCertificateLabelList")
|
||||
public R userCertificateLabelList() {
|
||||
List<UserCertificateLabel> labelList = userCertificateLabelService.userCertificateLabelList();
|
||||
return R.ok().put("labelList", labelList);
|
||||
}
|
||||
|
||||
//标签下证书列表
|
||||
@RequestMapping("/userCertificateListByLabel")
|
||||
public R userCertificateListByLabel(@RequestBody Map<String,Object> params) {
|
||||
Page<UserCertificate> certificatePage = userCertificateService.page(new Page<>(
|
||||
Long.parseLong(params.get("current").toString()),
|
||||
Long.parseLong(params.get("limit").toString())),new LambdaQueryWrapper<UserCertificate>()
|
||||
.eq(UserCertificate::getLabelId,params.get("labelId")));
|
||||
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();
|
||||
}
|
||||
|
||||
//修改标签
|
||||
@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){
|
||||
Integer integer = userCertificateService.count(new LambdaQueryWrapper<UserCertificate>()
|
||||
.eq(UserCertificate::getLabelId, label.getId()));
|
||||
if(integer>0){
|
||||
return R.error("更新失败,标签下存在证书");
|
||||
}
|
||||
}
|
||||
userCertificateLabelService.updateById(label);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除标签
|
||||
@RequestMapping("/delUserCertificateLabel")
|
||||
public R delUserCertificateLabel(@RequestBody Map<String,Object> params) {
|
||||
//查看下一级是否存在
|
||||
int count = userCertificateLabelService.count(new LambdaQueryWrapper<UserCertificateLabel>()
|
||||
.eq(UserCertificateLabel::getPid, params.get("id")));
|
||||
if(count>0){
|
||||
return R.error("删除失败,请先删除子项目后再尝试");
|
||||
}
|
||||
//查看绑定关系是否存在
|
||||
Integer 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user