Files
nuttyreading-java/src/main/java/com/peanut/modules/common/controller/UserCertificateController.java
2024-09-14 16:14:48 +08:00

118 lines
5.4 KiB
Java

package com.peanut.modules.common.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.common.utils.ShiroUtils;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserCertificate;
import com.peanut.modules.common.service.UserCertificateService;
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 javax.imageio.ImageIO;
import java.net.URL;
import java.util.List;
import java.util.Map;
/**
* 用户证书
*/
@Slf4j
@RestController("commonUserCertificate")
@RequestMapping("common/userCertificate")
public class UserCertificateController {
@Autowired
private UserCertificateService userCertificateService;
//获取证书列表
@RequestMapping("/getUserCertificateList")
public R getUserCertificateList() {
LambdaQueryWrapper<UserCertificate> wrapper = new LambdaQueryWrapper();
wrapper.eq(UserCertificate::getUserId, ShiroUtils.getUId());
return R.ok().put("certificateList",userCertificateService.list(wrapper));
}
//生成证书(管理员)
@RequestMapping("/generateCertificateAdmin")
public R generateCertificateAdmin(@RequestBody Map<String,Object> params) {
if (StringUtils.isBlank(params.get("type").toString())||StringUtils.isBlank(params.get("certificateNo").toString())||
StringUtils.isBlank(params.get("iconUrl").toString())||StringUtils.isBlank(params.get("realName").toString())||
StringUtils.isBlank(params.get("description").toString())||StringUtils.isBlank(params.get("edes").toString())||
StringUtils.isBlank(params.get("endYear").toString())|| StringUtils.isBlank(params.get("endMonth").toString())||
StringUtils.isBlank(params.get("endDay").toString())){
return R.error("数据不能为空");
}
try {
ImageIO.read(new URL(params.get("iconUrl").toString()));
}catch (Exception e) {
return R.error("照片链接错误");
}
String type = params.get("type").toString();
String certificateNo = params.get("certificateNo").toString();
String iconUrl = params.get("iconUrl").toString();
String realName = params.get("realName").toString();
String description = params.get("description").toString();
String edes = params.get("edes").toString();
String endYear = params.get("endYear").toString();
String endMonth = params.get("endMonth").toString();
String endDay = params.get("endDay").toString();
String url = userCertificateService.generateCertificate(type,certificateNo,iconUrl,realName, description, edes, endYear,endMonth,endDay);
return R.ok().put("url",url);
}
//证书列表
@RequestMapping("/getCertificateList")
public R getCertificateList(@RequestBody Map<String,Object> params) {
MPJLambdaWrapper<UserCertificate> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserCertificate::getUserId);
wrapper.selectAll(UserCertificate.class);
wrapper.select(MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getTel,MyUserEntity::getEmail);
if (StringUtils.isNotBlank(params.get("userWords").toString())){
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userWords")).or().like(MyUserEntity::getNickname,params.get("userWords"))
.or().like(MyUserEntity::getEmail,params.get("userWords")).or().like(MyUserEntity::getTel,params.get("userWords")));
}
if (StringUtils.isNotBlank(params.get("title").toString())){
wrapper.like(UserCertificate::getTitle,params.get("title"));
}
if (StringUtils.isNotBlank(params.get("certificateNo").toString())){
wrapper.like(UserCertificate::getCertificateNo,params.get("certificateNo"));
}
Page<UserCertificate> page = userCertificateService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
return R.ok().put("certificate",page);
}
@RequestMapping("/getCertificateById")
public R getCertificateById(@RequestBody Map<String,Object> params) {
UserCertificate userCertificate = userCertificateService.getById(params.get("id").toString());
return R.ok().put("userCertificate",userCertificate);
}
@RequestMapping("/addCertificate")
public R addCertificate(@RequestBody UserCertificate userCertificate) {
userCertificateService.save(userCertificate);
return R.ok();
}
@RequestMapping("/updateCertificate")
public R updateCertificate(@RequestBody UserCertificate userCertificate) {
userCertificateService.updateById(userCertificate);
return R.ok();
}
@RequestMapping("/delCertificate")
public R delCertificate(@RequestBody Map<String,Object> params) {
userCertificateService.removeById(params.get("id").toString());
return R.ok();
}
}