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 wrapper = new LambdaQueryWrapper(); wrapper.eq(UserCertificate::getUserId, ShiroUtils.getUId()); return R.ok().put("certificateList",userCertificateService.list(wrapper)); } //生成证书(管理员) @RequestMapping("/generateCertificateAdmin") public R generateCertificateAdmin(@RequestBody Map 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 params) { MPJLambdaWrapper 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 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 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 params) { userCertificateService.removeById(params.get("id").toString()); return R.ok(); } }