新增更新铭牌字体接口

This commit is contained in:
liaozetao
2023-12-14 15:16:11 +08:00
parent 84cde89378
commit 4adc8458a1
3 changed files with 114 additions and 58 deletions

View File

@@ -45,6 +45,7 @@ import com.accompany.core.vo.user.UserNameplateVo;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
@@ -107,7 +108,7 @@ public class NameplateAdminService extends BaseService {
@Autowired
private SysConfService sysConfService;
public HashMap<String, Object> getPageList(NameplateDto dto){
public HashMap<String, Object> getPageList(NameplateDto dto) {
HashMap<String, Object> result = new HashMap<>();
String limit = String.format("%d,%d", (dto.getPageNumber() - 1) * dto.getPageSize(), dto.getPageSize());
// 数量
@@ -119,7 +120,7 @@ public class NameplateAdminService extends BaseService {
}
List<Integer> configValue = sysConfService.getJsonValueById(Constant.SysConfId.HEARTBEAT_NAMEPLATE, new TypeReference<List<Integer>>() {
});
List<NameplateVo> nameplateVos = nameplateMapper.getNameplateList(dto.getName(), dto.getNameplateType(), dto.getStatus(), dto.getType(),limit);
List<NameplateVo> nameplateVos = nameplateMapper.getNameplateList(dto.getName(), dto.getNameplateType(), dto.getStatus(), dto.getType(), limit);
List<NameplateAdminVo> data = new ArrayList<>();
for (NameplateVo nameplateVo : nameplateVos) {
NameplateAdminVo vo = BeanMapper.map(nameplateVo, NameplateAdminVo.class);
@@ -138,7 +139,7 @@ public class NameplateAdminService extends BaseService {
typeStr = floor + "~" + (upper - 1) + "收到";
} else if (NameplateStyleTypeEnum.PROMOTION_PLATE_SEND.getValue().equals(type)) {
typeStr = upper + "+送出";
} else if(NameplateStyleTypeEnum.PROMOTION_PLATE_RECIVE.getValue().equals(type)) {
} else if (NameplateStyleTypeEnum.PROMOTION_PLATE_RECIVE.getValue().equals(type)) {
typeStr = upper + "+收到";
}
vo.setTypeStr(typeStr);
@@ -154,7 +155,7 @@ public class NameplateAdminService extends BaseService {
//获取操作人信息
AdminUser adminUser = adminUserService.getAdminUserById(adminId);
String adminUserName = "";
if (adminUser != null){
if (adminUser != null) {
adminUserName = adminUser.getUsername();
}
return adminUserName;
@@ -162,11 +163,12 @@ public class NameplateAdminService extends BaseService {
/**
* 保存铭牌数据
*
* @param dto
* @param adminId
* @return
*/
public Boolean save(NameplateDto dto, Integer adminId){
public Boolean save(NameplateDto dto, Integer adminId) {
Nameplate nameplate = BeanMapper.map(dto, Nameplate.class);
nameplate.setUpdateTime(new Date());
nameplate.setUpdateBy(getUpdateBy(adminId));
@@ -182,10 +184,10 @@ public class NameplateAdminService extends BaseService {
nameplate.setFixedWord(StringUtils.isEmpty(nameplate.getFixedWord()) ? " " : nameplate.getFixedWord());
}
// 保存到数据库
if (dto.getId() != null){
if (dto.getId() != null) {
Nameplate nameplateDB = nameplateMapper.selectById(nameplate.getId());
// 自定义铭牌文案设置
if(NameplateTypeEnum.CUSTOMIZE.getValue().toString().equals(nameplateDB.getNameplateType()) && StringUtils.isNotBlank(nameplate.getName())){
if (NameplateTypeEnum.CUSTOMIZE.getValue().toString().equals(nameplateDB.getNameplateType()) && StringUtils.isNotBlank(nameplate.getName())) {
nameplate.setName(nameplate.getFixedWord());
}
nameplateMapper.updateById(nameplate);
@@ -197,7 +199,7 @@ public class NameplateAdminService extends BaseService {
return true;
}
public Nameplate getOneById(Long id){
public Nameplate getOneById(Long id) {
return nameplateMapper.selectById(id);
}
@@ -230,7 +232,7 @@ public class NameplateAdminService extends BaseService {
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
Long targetUid = users.getUid();
userNameplateService.officialSendNameplateSingle(nameplateId, targetUid, days, remark, updateBy, null,null);
userNameplateService.officialSendNameplateSingle(nameplateId, targetUid, days, remark, updateBy, null, null);
if (isSendMsg) {
// 赠送铭牌时需要发送小助手通知
this.sendNameplateSecretaryMessage(targetUid, "小秘書贈送給你銘牌 - [" + nameplate.getName() + "] 有效期" + days
@@ -296,9 +298,9 @@ public class NameplateAdminService extends BaseService {
return new BusiResult(BusiStatus.SUCCESS, data);
}
public List<Nameplate> getTotalNameplateList(){
public List<Nameplate> getTotalNameplateList() {
QueryWrapper<Nameplate> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(Nameplate::getStatus,1)
wrapper.lambda().eq(Nameplate::getStatus, 1)
.orderByDesc(Nameplate::getCreateTime);
return nameplateMapper.selectList(wrapper);
}
@@ -344,14 +346,14 @@ public class NameplateAdminService extends BaseService {
return;
}
try{
try {
// 粉丝团铭牌更新
if (NameplateStyleTypeEnum.ANCHOR_FANS_MP_SEND.getValue().equals(nameplate.getType())) {
generateAndUpdateUserNameplateWithLevelAndWord(nameplate);
} else {
// 更新基础铭牌数据
generateAndUpdateUserNameplatePicByNameplateId(nameplate);
Map<String, String> result = jedisService.hgetAll(RedisKey.user_using_nameplate.getKey());
Map<String, String> result = jedisService.hgetAll(RedisKey.user_using_nameplate.getKey());
// key为uid
for (String key : result.keySet()) {
UserNameplateVo vo = gson.fromJson(result.get(key), UserNameplateVo.class);
@@ -366,8 +368,8 @@ public class NameplateAdminService extends BaseService {
}
}
} catch (Exception e){
logger.error("铭牌同步数据失败, 铭牌id{}",nameplate.getId(), e);
} catch (Exception e) {
logger.error("铭牌同步数据失败, 铭牌id{}", nameplate.getId(), e);
}
}
@@ -375,6 +377,7 @@ public class NameplateAdminService extends BaseService {
/**
* 生成铭牌图片
* 并更新关联的铭牌数据 => 粉丝团铭牌 拥有等级和文案
*
* @param nameplate
*/
public void generateAndUpdateUserNameplateWithLevelAndWord(Nameplate nameplate) throws IOException {
@@ -384,11 +387,11 @@ public class NameplateAdminService extends BaseService {
// 批量更新使用该铭牌特权的粉丝团铭牌图片 => 目前粉丝铭牌只有一种固定类型
// 批量更新使用该铭牌特权的粉丝团成员铭牌图片
if (nameplateId.equals(config.getNormalId())) {
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.narmal,config.getId(),nameplateId);
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.narmal, config.getId(), nameplateId);
} else if (nameplateId.equals(config.getActiveId())) {
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.active,config.getId(),null);
} else if(nameplateId.equals(config.getNegativeId())) {
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.negative,config.getId(),null);
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.active, config.getId(), null);
} else if (nameplateId.equals(config.getNegativeId())) {
anchorFansTeamService.generateAllAnchorFansTeamMpPicAndMemberPic(Constant.AnchorFansMemberMpStatus.negative, config.getId(), null);
}
}
}
@@ -396,6 +399,7 @@ public class NameplateAdminService extends BaseService {
/**
* 生成铭牌图片
* 并更新关联的铭牌数据
*
* @param nameplate
* @throws IOException
*/
@@ -409,17 +413,17 @@ public class NameplateAdminService extends BaseService {
// 固定文案修改需要修改用户铭牌文案及图片信息
String mpPic = nameplate.getIconPic();
if (!nameplate.getIsCustomWord()) {
if (StringUtils.isNotBlank(nameplate.getFixedWord())){
try{
if (StringUtils.isNotBlank(nameplate.getFixedWord())) {
try {
mpPic = userNameplateService.generateUserNameplatePic(nameplate.getIconPic(), nameplate.getFixedWord());
} catch (Exception e){
} catch (Exception e) {
logger.error("生成对应铭牌图片异常, 异常铭牌id:{}", nameplate.getId(), e);
}
}
userNameplateMapper.batchUpdateByNameplateId(nameplateId, nameplate.getFixedWord(),mpPic);
userNameplateMapper.batchUpdateByNameplateId(nameplateId, nameplate.getFixedWord(), mpPic);
} else {
// 自定义铭牌
List<UserNameplate> userNameplates = userNameplateMapper.getUserNameplateListByNameplateId(nameplate.getId());
List<UserNameplate> userNameplates = userNameplateMapper.getUserNameplateListByNameplateId(nameplate.getId());
List<UserNameplate> updateUserNameplates = new ArrayList<>();
for (UserNameplate userNameplate : userNameplates) {
InputStream uploadStream = null;
@@ -436,19 +440,18 @@ public class NameplateAdminService extends BaseService {
upadteNameplate.setId(userNameplate.getId());
upadteNameplate.setUpdateTime(date);
upadteNameplate.setNameplateImage(mpPicUrl);
if(NameplateTypeEnum.CUSTOMIZE.getValue().toString().equals(nameplate.getNameplateType())){
if (NameplateTypeEnum.CUSTOMIZE.getValue().toString().equals(nameplate.getNameplateType())) {
upadteNameplate.setWord(nameplate.getFixedWord());
}
updateUserNameplates.add(upadteNameplate);
} catch (Exception e) {
logger.error("自定义铭牌生成异常:{}", e.getMessage());
e.printStackTrace();
logger.error("自定义铭牌生成异常:{}", e.getMessage(), e);
} finally {
if (uploadStream != null) uploadStream.close();
}
}
if ( !CollectionUtils.isEmpty(updateUserNameplates) ){
if (!CollectionUtils.isEmpty(updateUserNameplates)) {
userNameplateMapper.batchUpdateUserNameplateList(updateUserNameplates);
}
@@ -465,21 +468,45 @@ public class NameplateAdminService extends BaseService {
Font font = null;
ClassPathResource resource = new ClassPathResource("fonts/SourceHanSansCN-Regular.otf");
InputStream inputStream = resource.getInputStream();
//InputStream inputStream2 = this.getClass().getClassLoader().getResourceAsStream("fonts/simsun.ttc");
try {
font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
} catch (Exception e) {
logger.error(e.getMessage(), e);
e.printStackTrace();
}
try {
if (inputStream != null) inputStream.close();
inputStream.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
assert font != null;
return font.deriveFont(22f);
}
public void updateFont() {
Date now = new Date();
List<UserNameplate> userNameplates = userNameplateMapper.selectList(Wrappers.<UserNameplate>lambdaQuery()
.isNotNull(UserNameplate::getWord)
.gt(UserNameplate::getExpireTime, now));
if (CollectionUtil.isEmpty(userNameplates)) {
logger.info("userNameplates is null");
return;
}
for (UserNameplate userNameplate : userNameplates) {
try {
Long nameplateId = userNameplate.getNameplateId();
Nameplate nameplate = nameplateMapper.selectById(nameplateId);
if (nameplate == null) {
continue;
}
String iconPic = nameplate.getIconPic();
String word = userNameplate.getWord();
logger.info("updateFont uid : {}, iconPic : {}, word : {}", userNameplate.getUid(), iconPic, word);
String nameplateImage = userNameplateService.generateUserNameplatePic(iconPic, word);
userNameplate.setNameplateImage(nameplateImage);
userNameplateMapper.updateById(userNameplate);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}

View File

@@ -8,12 +8,10 @@ import com.accompany.admin.dto.NameplateDto;
import com.accompany.admin.service.nameplate.NameplateAdminService;
import com.accompany.core.exception.ServiceException;
import com.accompany.business.model.Nameplate;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
@@ -31,7 +29,7 @@ public class NameplateAdminController extends BaseController {
private NameplateAdminService nameplateAdminService;
@RequestMapping("/list")
public Object list(NameplateDto dto){
public Object list(NameplateDto dto) {
if (dto.getPageNumber() < 1) {
return new BusiResult(BusiStatus.PARAMETERILLEGAL);
}
@@ -39,17 +37,17 @@ public class NameplateAdminController extends BaseController {
}
@PostMapping("/save")
public void save(NameplateDto dto){
try{
public void save(NameplateDto dto) {
try {
nameplateAdminService.save(dto, getAdminId());
writeJson(true, "保存成功");
} catch (ServiceException e){
} catch (ServiceException e) {
writeJson(false, e.getBusiStatus().getMessage());
}
}
@RequestMapping("/get")
public Nameplate getOne(Long id){
public Nameplate getOne(Long id) {
return nameplateAdminService.getOneById(id);
}
@@ -63,7 +61,7 @@ public class NameplateAdminController extends BaseController {
retMap = nameplateAdminService.officialDonateNameplate(nameplateId, erbanNoList, days, sendDesc, true, getAdminId());
if (null != retMap) {
List<String> failCount = (List<String>) retMap.get("failErbanNo");
if (failCount!=null&&failCount.size()> 0) {
if (failCount != null && failCount.size() > 0) {
retMap.put("code", "200");// 部分成功
retMap.put("erban", retMap.get("failErbanNo").toString());
retMap.put("message", retMap.get("failReason").toString());
@@ -83,21 +81,21 @@ public class NameplateAdminController extends BaseController {
* 铭牌赠送记录
*/
@RequestMapping("recordList")
public Object recordList(Integer page, Integer pageSize, Long erbanNo){
public Object recordList(Integer page, Integer pageSize, Long erbanNo) {
if (null == page || null == pageSize || page < 1 || pageSize < 1) {
return new BusiResult(BusiStatus.PARAMETERILLEGAL);
}
return nameplateAdminService.recordList(page, pageSize, erbanNo);
}
@RequestMapping(value = "/total/list",method = RequestMethod.GET)
public BusiResult getTotalNameplateList(){
@RequestMapping(value = "/total/list", method = RequestMethod.GET)
public BusiResult getTotalNameplateList() {
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
try{
try {
List<Nameplate> list = this.nameplateAdminService.getTotalNameplateList();
busiResult.setData(list);
return busiResult;
}catch (Exception e){
} catch (Exception e) {
return new BusiResult(BusiStatus.BUSIERROR);
}
}
@@ -106,7 +104,7 @@ public class NameplateAdminController extends BaseController {
* 取消赠送铭牌
*/
@RequestMapping("recall")
public BusiResult recallUserNameplate(Long id){
public BusiResult recallUserNameplate(Long id) {
nameplateAdminService.recallUserNameplate(id);
return new BusiResult(BusiStatus.SUCCESS);
}
@@ -115,9 +113,21 @@ public class NameplateAdminController extends BaseController {
* 同步铭牌
*/
@RequestMapping("sync")
public BusiResult syncNameplate(Long id){
public BusiResult syncNameplate(Long id) {
nameplateAdminService.syncNameplate(id);
return new BusiResult(BusiStatus.SUCCESS);
}
/**
* 更新字体
*
* @return
*/
@ApiOperation("更新字体")
@GetMapping("updateFont")
public BusiResult<Void> updateFont() {
nameplateAdminService.updateFont();
return BusiResult.success();
}
}

View File

@@ -1,5 +1,7 @@
package com.accompany.business.service.nameplate;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.accompany.business.constant.nameplate.NameplateStyleTypeEnum;
import com.accompany.business.model.*;
import com.accompany.business.mybatismapper.NameplateAuditRecordMapper;
@@ -32,10 +34,12 @@ import com.accompany.core.vo.user.UserNameplateVo;
import com.accompany.payment.model.UserVipInfo;
import com.accompany.payment.service.UserVipInfoService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.ClassPathResource;
@@ -175,19 +179,34 @@ public class UserNameplateService extends BaseService {
}
public UserNameplateVo getUserUsingNameplateVo(Long uid) {
String str = this.jedisService.hget(RedisKey.user_using_nameplate.getKey(), uid.toString());
if (ApplicationConstant.NULL_JSON_OBJECT.equalsIgnoreCase(str) || StringUtils.isEmpty(str)) {
String json = this.jedisService.hget(RedisKey.user_using_nameplate.getKey(), uid.toString());
if (ApplicationConstant.NULL_JSON_OBJECT.equalsIgnoreCase(json)) {
return null;
}
UserNameplateVo userNameplate = null;
if (StrUtil.isNotEmpty(json)) {
logger.info("userNameplate from redis: {}", json);
userNameplate = GsonUtil.getDefGson().fromJson(json, UserNameplateVo.class);
}
if (userNameplate == null) {
List<UserNameplate> userNameplates = userNameplateMapper.selectList(Wrappers.<UserNameplate>lambdaQuery()
.eq(UserNameplate::getUid, uid)
.gt(UserNameplate::getExpireTime, new Date()));
if (CollectionUtil.isNotEmpty(userNameplates)) {
UserNameplate nameplate = userNameplates.get(0);
userNameplate = userNameplateMapper.userNameplateById(nameplate.getId());
jedisService.hset(RedisKey.user_using_nameplate.getKey(), String.valueOf(uid), GsonUtil.getDefGson().toJson(userNameplate));
}
}
if (userNameplate == null) {
return null;
}
logger.info("userNameplateVo from redis: {}", str);
UserNameplateVo vo = this.gson.fromJson(str, UserNameplateVo.class);
// 检查是否过期
if (vo.getExpireTime().getTime() <= System.currentTimeMillis()) {
this.jedisService.hdel(RedisKey.user_using_nameplate.getKey(), uid.toString());
if (userNameplate.getExpireTime().getTime() <= System.currentTimeMillis()) {
jedisService.hdel(RedisKey.user_using_nameplate.getKey(), String.valueOf(uid));
return null;
}
return vo;
return userNameplate;
}
public Map<Long, UserNameplateVo> getBatchUserUsingNameplateVo(List<String> uids) throws Exception {