运行不起来了

This commit is contained in:
2025-08-09 17:18:30 +08:00
parent c93eeaa5e3
commit 8ef39e573b
58 changed files with 4028 additions and 598 deletions

View File

@@ -0,0 +1,50 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxBm;
import com.gxwebsoft.bszx.param.BszxBmParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 百色中学-报名记录Service
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
public interface BszxBmService extends IService<BszxBm> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxBm>
*/
PageResult<BszxBm> pageRel(BszxBmParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxBm>
*/
List<BszxBm> listRel(BszxBmParam param);
/**
* 根据id查询
*
* @param id 自增ID
* @return BszxBm
*/
BszxBm getByIdRel(Integer id);
/**
* 生成海报
*/
String generatePoster(BszxBm bm) throws Exception;
BszxBm getByUserId(Integer userId);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxBranch;
import com.gxwebsoft.bszx.param.BszxBranchParam;
import java.util.List;
/**
* 百色中学-分部Service
*
* @author 科技小王子
* @since 2025-03-17 17:18:22
*/
public interface BszxBranchService extends IService<BszxBranch> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxBranch>
*/
PageResult<BszxBranch> pageRel(BszxBranchParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxBranch>
*/
List<BszxBranch> listRel(BszxBranchParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxBranch
*/
BszxBranch getByIdRel(Integer id);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxClass;
import com.gxwebsoft.bszx.param.BszxClassParam;
import java.util.List;
/**
* 百色中学-班级Service
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
public interface BszxClassService extends IService<BszxClass> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxClass>
*/
PageResult<BszxClass> pageRel(BszxClassParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxClass>
*/
List<BszxClass> listRel(BszxClassParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxClass
*/
BszxClass getByIdRel(Integer id);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxEra;
import com.gxwebsoft.bszx.param.BszxEraParam;
import java.util.List;
/**
* 百色中学-年代Service
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
public interface BszxEraService extends IService<BszxEra> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxEra>
*/
PageResult<BszxEra> pageRel(BszxEraParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxEra>
*/
List<BszxEra> listRel(BszxEraParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxEra
*/
BszxEra getByIdRel(Integer id);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxGrade;
import com.gxwebsoft.bszx.param.BszxGradeParam;
import java.util.List;
/**
* 百色中学-年级Service
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
public interface BszxGradeService extends IService<BszxGrade> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxGrade>
*/
PageResult<BszxGrade> pageRel(BszxGradeParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxGrade>
*/
List<BszxGrade> listRel(BszxGradeParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxGrade
*/
BszxGrade getByIdRel(Integer id);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxPayRanking;
import com.gxwebsoft.bszx.param.BszxPayRankingParam;
import java.util.List;
/**
* 百色中学-捐款排行Service
*
* @author 科技小王子
* @since 2025-03-25 08:54:09
*/
public interface BszxPayRankingService extends IService<BszxPayRanking> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxPayRanking>
*/
PageResult<BszxPayRanking> pageRel(BszxPayRankingParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxPayRanking>
*/
List<BszxPayRanking> listRel(BszxPayRankingParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxPayRanking
*/
BszxPayRanking getByIdRel(Integer id);
}

View File

@@ -0,0 +1,57 @@
package com.gxwebsoft.bszx.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.bszx.entity.BszxPay;
import com.gxwebsoft.bszx.param.BszxPayParam;
import java.math.BigDecimal;
import java.util.List;
/**
* 百色中学-捐款记录Service
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
public interface BszxPayService extends IService<BszxPay> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<BszxPay>
*/
PageResult<BszxPay> pageRel(BszxPayParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<BszxPay>
*/
List<BszxPay> listRel(BszxPayParam param);
/**
* 根据id查询
*
* @param id ID
* @return BszxPay
*/
BszxPay getByIdRel(Integer id);
/**
* 生成捐款证书
*/
String generatePayCert(Integer id) throws Exception;
BigDecimal sumMoney(LambdaQueryWrapper<BszxPay> between);
/**
* 统计捐款总金额
*
* @return 捐款总金额
*/
BigDecimal total();
}

View File

@@ -0,0 +1,162 @@
package com.gxwebsoft.bszx.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freewayso.image.combiner.ImageCombiner;
import com.freewayso.image.combiner.enums.OutputFormat;
import com.gxwebsoft.bszx.entity.BszxClass;
import com.gxwebsoft.bszx.mapper.BszxBmMapper;
import com.gxwebsoft.bszx.param.BszxClassParam;
import com.gxwebsoft.bszx.service.BszxBmService;
import com.gxwebsoft.bszx.entity.BszxBm;
import com.gxwebsoft.bszx.param.BszxBmParam;
import com.gxwebsoft.bszx.service.BszxClassService;
import com.gxwebsoft.cms.entity.CmsArticle;
import com.gxwebsoft.cms.service.CmsArticleService;
import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.utils.FileServerUtil;
import com.gxwebsoft.common.core.utils.ImageUtil;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
* 百色中学-报名记录Service实现
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
@Service
public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> implements BszxBmService {
@Value("${config.upload-path}")
private String uploadPath;
@Value("${config.file-server}")
private String fileServer;
@Resource
private ConfigProperties config;
@Resource
@Lazy
private CmsArticleService cmsArticleService;
@Resource
private BszxClassService bszxClassService;
@Override
public PageResult<BszxBm> pageRel(BszxBmParam param) {
PageParam<BszxBm, BszxBmParam> page = new PageParam<>(param);
page.setDefaultOrder("id desc");
List<BszxBm> list = baseMapper.selectPageRel(page, param);
list.forEach(d -> {
if(d.getClassId().equals(0)){
final BszxClassParam classParam = new BszxClassParam();
classParam.setGradeName(d.getGradeName());
classParam.setName(d.getClassName());
final List<BszxClass> bszxClasses = bszxClassService.listRel(classParam);
if (!CollectionUtils.isEmpty(bszxClasses)) {
BszxClass bszxClass = bszxClasses.get(0);
System.out.println("bszxClass = " + bszxClass);
d.setClassId(bszxClass.getId());
d.setBranchId(bszxClass.getBranch());
updateById(d);
}
}
});
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxBm> listRel(BszxBmParam param) {
List<BszxBm> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxBm, BszxBmParam> page = new PageParam<>();
page.setDefaultOrder("id desc");
return page.sortRecords(list);
}
@Override
public BszxBm getByIdRel(Integer id) {
BszxBmParam param = new BszxBmParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
/**
* 生成捐款证书 <a href="https://portrait.gitee.com/sGodT/image-combiner">...</a>
*
* @return
* @throws Exception
*/
@Override
public String generatePoster(BszxBm item) throws Exception {
final CmsArticle article = cmsArticleService.getById(7859);
if (ObjectUtil.isEmpty(article)) {
return null;
}
if (ObjectUtil.isNotEmpty(item)) {
// Font font = new Font("阿里巴巴普惠体", Font.PLAIN, 40);
//合成器(指定背景图和输出格式,整个图片的宽高和相关计算依赖于背景图,所以背景图的大小是个基准)
ImageCombiner combiner = new ImageCombiner(article.getAddress(), OutputFormat.JPG);
//加文本元素:姓名
// if (item.getType().equals(0)) {
// combiner.addTextElement(item.getName().concat(" 校友"), 40, 220, 540);
// } else {
// combiner.addTextElement(item.getName(), 40, 220, 540);
// }
// combiner.addTextElement(DateUtil.format(DateUtil.date(), "yyyy年MM月"), 28,650, 1566);
//加图片元素:盖章
// combiner.addImageElement("https://oss.wsdns.cn/20250304/6936b109b09b4919a3498ac5027e728b.png", 600, 1420);
if (item.getType().equals(0)) {
combiner.addTextElement(item.getName().concat(" 校友"), 30, 160, 1008);
} else {
combiner.addTextElement(item.getName(), 30, 160, 1008);
}
// combiner.addTextElement(DateUtil.format(DateUtil.date(), "yyyy年MM月"), 28,650, 1566);
//加图片元素:盖章
// combiner.addImageElement("https://oss.wsdns.cn/20250304/6936b109b09b4919a3498ac5027e728b.png", 600, 1420);
//执行图片合并
combiner.combine();
if (!FileUtil.exist(uploadPath + "/file/poster/" + item.getTenantId() + "/bm")) {
FileUtil.mkdir(uploadPath + "/file/poster/" + item.getTenantId() + "/bm");
}
String basePath = "/poster/" + item.getTenantId() + "/bm/big-" + item.getId() + ".jpg";
String smallPath = "/poster/" + item.getTenantId() + "/bm/" + item.getId() + ".jpg";
String filename = uploadPath + "/file" + basePath;
String smallFileName = uploadPath + "/file" + smallPath;
combiner.save(filename);
File input = new File(filename);
File output = new File(smallFileName);
ImageUtil.adjustQuality(input, output, 0.8f);
if(input.exists()){
input.delete();
}
return fileServer + smallPath + "?r=" + RandomUtil.randomNumbers(4);
}
return null;
}
@Override
public BszxBm getByUserId(Integer userId) {
return getOne(new LambdaQueryWrapper<BszxBm>().eq(BszxBm::getUserId, userId).last("limit 1"));
}
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.bszx.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.mapper.BszxBranchMapper;
import com.gxwebsoft.bszx.service.BszxBranchService;
import com.gxwebsoft.bszx.entity.BszxBranch;
import com.gxwebsoft.bszx.param.BszxBranchParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 百色中学-分部Service实现
*
* @author 科技小王子
* @since 2025-03-17 17:18:22
*/
@Service
public class BszxBranchServiceImpl extends ServiceImpl<BszxBranchMapper, BszxBranch> implements BszxBranchService {
@Override
public PageResult<BszxBranch> pageRel(BszxBranchParam param) {
PageParam<BszxBranch, BszxBranchParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<BszxBranch> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxBranch> listRel(BszxBranchParam param) {
List<BszxBranch> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxBranch, BszxBranchParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public BszxBranch getByIdRel(Integer id) {
BszxBranchParam param = new BszxBranchParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -0,0 +1,68 @@
package com.gxwebsoft.bszx.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.entity.BszxPay;
import com.gxwebsoft.bszx.mapper.BszxClassMapper;
import com.gxwebsoft.bszx.service.BszxClassService;
import com.gxwebsoft.bszx.entity.BszxClass;
import com.gxwebsoft.bszx.param.BszxClassParam;
import com.gxwebsoft.bszx.service.BszxPayService;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 百色中学-班级Service实现
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
@Service
public class BszxClassServiceImpl extends ServiceImpl<BszxClassMapper, BszxClass> implements BszxClassService {
@Resource
private RedisUtil redisUtil;
@Resource
private BszxPayService bszxPayService;
@Override
public PageResult<BszxClass> pageRel(BszxClassParam param) {
PageParam<BszxClass, BszxClassParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, id asc");
List<BszxClass> list = baseMapper.selectPageRel(page, param);
LambdaQueryWrapper<BszxPay> wrapper = new LambdaQueryWrapper<>();
if (param.getLimit() == null) {
list.forEach(item -> {
wrapper.clear();
// wrapper.eq(BszxPay::getBranchName,item.getBranchName());
wrapper.eq(BszxPay::getGradeName,item.getGradeName());
wrapper.eq(BszxPay::getClassName, item.getName());
item.setTotalMoney(bszxPayService.sumMoney(wrapper));
updateById(item);
});
}
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxClass> listRel(BszxClassParam param) {
List<BszxClass> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxClass, BszxClassParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, id asc");
return page.sortRecords(list);
}
@Override
public BszxClass getByIdRel(Integer id) {
BszxClassParam param = new BszxClassParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.bszx.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.mapper.BszxEraMapper;
import com.gxwebsoft.bszx.service.BszxEraService;
import com.gxwebsoft.bszx.entity.BszxEra;
import com.gxwebsoft.bszx.param.BszxEraParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 百色中学-年代Service实现
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
@Service
public class BszxEraServiceImpl extends ServiceImpl<BszxEraMapper, BszxEra> implements BszxEraService {
@Override
public PageResult<BszxEra> pageRel(BszxEraParam param) {
PageParam<BszxEra, BszxEraParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<BszxEra> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxEra> listRel(BszxEraParam param) {
List<BszxEra> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxEra, BszxEraParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public BszxEra getByIdRel(Integer id) {
BszxEraParam param = new BszxEraParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.bszx.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.mapper.BszxGradeMapper;
import com.gxwebsoft.bszx.service.BszxGradeService;
import com.gxwebsoft.bszx.entity.BszxGrade;
import com.gxwebsoft.bszx.param.BszxGradeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 百色中学-年级Service实现
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
@Service
public class BszxGradeServiceImpl extends ServiceImpl<BszxGradeMapper, BszxGrade> implements BszxGradeService {
@Override
public PageResult<BszxGrade> pageRel(BszxGradeParam param) {
PageParam<BszxGrade, BszxGradeParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, id asc");
List<BszxGrade> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxGrade> listRel(BszxGradeParam param) {
List<BszxGrade> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxGrade, BszxGradeParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, id asc");
return page.sortRecords(list);
}
@Override
public BszxGrade getByIdRel(Integer id) {
BszxGradeParam param = new BszxGradeParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.bszx.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.mapper.BszxPayRankingMapper;
import com.gxwebsoft.bszx.service.BszxPayRankingService;
import com.gxwebsoft.bszx.entity.BszxPayRanking;
import com.gxwebsoft.bszx.param.BszxPayRankingParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 百色中学-捐款排行Service实现
*
* @author 科技小王子
* @since 2025-03-25 08:54:09
*/
@Service
public class BszxPayRankingServiceImpl extends ServiceImpl<BszxPayRankingMapper, BszxPayRanking> implements BszxPayRankingService {
@Override
public PageResult<BszxPayRanking> pageRel(BszxPayRankingParam param) {
PageParam<BszxPayRanking, BszxPayRankingParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<BszxPayRanking> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxPayRanking> listRel(BszxPayRankingParam param) {
List<BszxPayRanking> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxPayRanking, BszxPayRankingParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public BszxPayRanking getByIdRel(Integer id) {
BszxPayRankingParam param = new BszxPayRankingParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -0,0 +1,169 @@
package com.gxwebsoft.bszx.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freewayso.image.combiner.ImageCombiner;
import com.freewayso.image.combiner.enums.OutputFormat;
import com.gxwebsoft.bszx.entity.BszxBm;
import com.gxwebsoft.bszx.mapper.BszxPayMapper;
import com.gxwebsoft.bszx.service.BszxBmService;
import com.gxwebsoft.bszx.service.BszxPayService;
import com.gxwebsoft.bszx.entity.BszxPay;
import com.gxwebsoft.bszx.param.BszxPayParam;
import com.gxwebsoft.cms.entity.CmsArticle;
import com.gxwebsoft.cms.service.CmsArticleService;
import com.gxwebsoft.common.core.utils.ImageUtil;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.util.List;
/**
* 百色中学-捐款记录Service实现
*
* @author 科技小王子
* @since 2025-03-06 22:50:25
*/
@Service
public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> implements BszxPayService {
@Value("${config.upload-path}")
private String uploadPath;
@Value("${config.file-server}")
private String fileServer;
@Resource
private CmsArticleService cmsArticleService;
@Resource
public BszxBmService bszxBmService;
@Resource
private BszxPayService bszxPayService;
@Override
public PageResult<BszxPay> pageRel(BszxPayParam param) {
PageParam<BszxPay, BszxPayParam> page = new PageParam<>(param);
page.setDefaultOrder("price desc, create_time desc");
List<BszxPay> list = baseMapper.selectPageRel(page, param);
list.forEach(item -> {
if(item.getId().equals(2088)){
item.setFormName("捐款用于设立阙里校友奖学金");
}
});
return new PageResult<>(list, page.getTotal());
}
@Override
public List<BszxPay> listRel(BszxPayParam param) {
List<BszxPay> list = baseMapper.selectListRel(param);
// 排序
PageParam<BszxPay, BszxPayParam> page = new PageParam<>();
page.setDefaultOrder("id desc");
return page.sortRecords(list);
}
@Override
public BszxPay getByIdRel(Integer id) {
BszxPayParam param = new BszxPayParam();
param.setId(id);
final BszxPay item = param.getOne(baseMapper.selectListRel(param));
final CmsArticle article = cmsArticleService.getById(item.getFormId());
if (ObjectUtil.isNotEmpty(article)) {
item.setArticle(article);
}
return item;
}
/**
* 生成捐款证书 <a href="https://portrait.gitee.com/sGodT/image-combiner">...</a>
*/
@Override
public String generatePayCert(Integer id) throws Exception {
final BszxPay payCert = getByIdRel(id);
final CmsArticle item = cmsArticleService.getById(payCert.getFormId());
final BszxBm bm = bszxBmService.getOne(new LambdaQueryWrapper<BszxBm>().eq(BszxBm::getUserId, payCert.getUserId()).last("limit 1"));
final BigDecimal totalMoney = bszxPayService.sumMoney(new LambdaQueryWrapper<BszxPay>().eq(BszxPay::getUserId, payCert.getUserId()));
if (StrUtil.isBlank(item.getAddress())) {
return null;
}
if (ObjectUtil.isNotEmpty(payCert)) {
//合成器(指定背景图和输出格式,整个图片的宽高和相关计算依赖于背景图,所以背景图的大小是个基准)
ImageCombiner combiner = new ImageCombiner("https://oss.wsdns.cn/20250420/811a380e8e124097aa0940a7c68a1f72.jpeg", OutputFormat.JPG);
//加图片元素:盖章
// combiner.addImageElement("https://oss.wsdns.cn/20250304/6936b109b09b4919a3498ac5027e728b.png", 550, 926);
//加文本元素:姓名
String str;
if (bm.getType().equals(0)) {
str = bm.getName().concat(" 校友");
combiner.addTextElement(str, 32, 930, 450);
} else {
str = bm.getName();
combiner.addTextElement(str, 22, 880, 450);
}
// combiner.addTextElement(bm.getName(), 32,900, 450);
//加文本元素:捐款证书内容
// combiner.addTextElement(" 承您慷慨解囊,襄助百色市百色中学", 32,200, 650);
// combiner.addTextElement("百廿校庆“" + item.getTitle() + "”项目,捐赠人民币", 32,200, 700);
combiner.addTextElement(totalMoney + "", 32, 1330, 600);
// combiner.addTextElement(" 您对学校的支持,为我们共同教育理", 32,200, 800);
// combiner.addTextElement("想的实现增添了一份动力。", 32,200, 850);
// combiner.addTextElement(" 承蒙惠赠,隆情铭感,特颁此证,以资谢旌!", 32, 200, 900);
// combiner.addTextElement("百色市百色中学", 32,560, 1015);
// final Date createTime = payCert.getCreateTime();
// combiner.addTextElement(DateUtil.format(createTime, "yyyy年MM月"), 28,586, 1060);
// combiner.addTextElement("2025年4月15日", 28,580, 1060);
//执行图片合并
combiner.combine();
if (!FileUtil.exist(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay")) {
FileUtil.mkdir(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay");
}
String basePath = "/poster/" + payCert.getTenantId() + "/pay/big-" + id + ".jpg";
String smallPath = "/poster/" + payCert.getTenantId() + "/pay/" + id + ".jpg";
String filename = uploadPath + "/file" + basePath;
String smallFileName = uploadPath + "/file" + smallPath;
combiner.save(filename);
File input = new File(filename);
File output = new File(smallFileName);
ImageUtil.adjustQuality(input, output, 0.8f);
if (input.exists()) {
input.delete();
}
return fileServer + smallPath + "?r=" + RandomUtil.randomNumbers(4);
}
return null;
}
@Override
public BigDecimal sumMoney(LambdaQueryWrapper<BszxPay> wrapper) {
return baseMapper.selectSumMoney(wrapper);
}
@Override
public BigDecimal total() {
try {
// 使用数据库聚合查询统计捐款总金额,性能更高
LambdaQueryWrapper<BszxPay> wrapper = new LambdaQueryWrapper<>();
BigDecimal total = baseMapper.selectSumMoney(wrapper);
if (total == null) {
total = BigDecimal.ZERO;
}
return total;
} catch (Exception e) {
// 异常时返回0确保接口稳定性
return BigDecimal.ZERO;
}
}
}