Commit 51d88801 authored by 刘林's avatar 刘林

fix(JG):添加套打功能

parent 056413ad
......@@ -78,5 +78,5 @@ public interface IJgChangeRegistrationReformService {
* @param sequenceNbr
* @param response
*/
void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response);
void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response, String printType);
}
......@@ -35,6 +35,7 @@ public interface IJgChangeRegistrationTransferService extends IService<JgChangeR
void revocation(String instanceId);
void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response);
void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response, String printType);
Map<String, Object> getDetailFieldCamelCase(String record);
}
......@@ -121,10 +121,17 @@ public class JgChangeRegistrationReformController extends BaseController {
return ResponseHelper.buildResponse(map);
}
/**
* 改造登记-导出使用登记证
* @param response 返回
* @param sequenceNbr 主键
* @param printType 打印类型,0-正常打印,1-套打(默认0)
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/export")
@ApiOperation(httpMethod = "GET", value = "改造登记-导出使用登记证", notes = "改造登记-导出使用登记证")
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr){
jgChangeRegistrationReformServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response);
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr,
@RequestParam(value = "printType", defaultValue = "0") String printType){
jgChangeRegistrationReformServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response, printType);
}
}
......@@ -157,11 +157,18 @@ public class JgChangeRegistrationTransferController extends BaseController {
return ResponseHelper.buildResponse(jgChangeRegistrationTransferService.queryListForPage(page,params, type));
}
/**
* 导出使用登记证
* @param response 返回
* @param sequenceNbr 主键
* @param printType 打印类型,0-正常打印,1-套打(默认0)
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/export")
@ApiOperation(httpMethod = "GET", value = "导出使用登记证", notes = "导出使用登记证")
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr){
jgChangeRegistrationTransferService.exportUseRegistrationCertificate(sequenceNbr, response);
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr,
@RequestParam(value = "printType", defaultValue = "0") String printType){
jgChangeRegistrationTransferService.exportUseRegistrationCertificate(sequenceNbr, response, printType);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping (value = "/detailFieldCamelCase")
......
......@@ -199,11 +199,18 @@ public class JgChangeRegistrationUnitController extends BaseController {
}
/**
* 导出使用登记证
* @param response 返回
* @param sequenceNbr 主键
* @param printType 打印类型,0-正常打印,1-套打(默认0)
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/export")
@ApiOperation(httpMethod = "GET", value = "导出使用登记证", notes = "导出使用登记证")
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr) throws IOException {
jgChangeRegistrationUnitServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response);
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr,
@RequestParam(value = "printType", defaultValue = "0") String printType) {
jgChangeRegistrationUnitServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response, printType);
}
}
......@@ -22,11 +22,8 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.File;
import java.util.*;
/**
......@@ -195,4 +192,25 @@ public class JgTransferNoticeController extends BaseController {
map.put("supervisoryCode", "YZGZ20231225001"); // 监管二维码
commonService.generateCertificateReport(map, response);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "(测试使用)特种设备登记证套打", notes = "(测试使用)特种设备登记证套打")
@GetMapping(value = "/generate/pdf/print")
public void printing(HttpServletResponse response) {
Map<String, Object> map = new HashMap<>();
map.put("useRegistrationCode", "梯10 陕B00005(24)");
map.put("useUnitName", "西安市高科物业服务有限公司");
map.put("fullAddress", "西安市曲江新区春临东街南湖意境1单元2号楼");
map.put("equList", "场(厂)内专用机动车辆");
map.put("equDefine", "特种气瓶(内装填料气瓶、纤维缠绕气瓶、低温绝热气瓶)");
map.put("equCode", "31006102002024010001");
map.put("equCategory", "非公路用旅游观光车辆");
map.put("useInnerCode", "NBBH-1231231231");
map.put("factoryNum", "CCBH-2312312312");
map.put("giveOutYear", "2024");
map.put("giveOutMonth", "12");
map.put("giveOutDay", "26");
map.put("supervisoryCode", "YZGZ20231225001");
commonService.generatePdfPrint(map, response);
}
}
......@@ -145,8 +145,9 @@ public class JgUseRegistrationController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/export")
@ApiOperation(httpMethod = "GET", value = "导出使用登记证", notes = "导出使用登记证")
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr) {
jgUseRegistrationServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response);
public void exportImageZip(HttpServletResponse response, @RequestParam("sequenceNbr") String sequenceNbr,
@RequestParam(value = "printType", defaultValue = "0") String printType) {
jgUseRegistrationServiceImpl.exportUseRegistrationCertificate(sequenceNbr, response, printType);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
......
......@@ -38,6 +38,8 @@ public interface ICommonService {
void generateCertificateReport(Map<String, Object> map, HttpServletResponse response);
void generatePdfPrint(Map<String, Object> map, HttpServletResponse response);
List<LinkedHashMap> creatApproveTree();
List<Map<String, Object>> superviseBusinessCategory(String type);
......
......@@ -2,10 +2,16 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aspose.words.SaveFormat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
......@@ -42,7 +48,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
......@@ -51,11 +59,8 @@ import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URLEncoder;
......@@ -556,6 +561,89 @@ public class CommonServiceImpl implements ICommonService {
}
}
/**
* 返回附件
* @param map 参数
* @param response 响应
*/
@Override
public void generatePdfPrint(Map<String, Object> map, HttpServletResponse response) {
String[] DEFAULT_KEYS = {
"useRegistrationCode", "useUnitName", "fullAddress", "equList", "equipDefine",
"equipCode", "equipCategory", "useInnerCode", "factoryNum", "giveOutYear",
"giveOutMonth", "giveOutDay"
};
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException("参数不能为空");
}
// 设置默认值
Arrays.stream(DEFAULT_KEYS)
.forEach(key -> map.computeIfAbsent(key, k -> ""));
// 生成二维码
String qrCode = ImageUtils.generateQRCode((String) map.getOrDefault("supervisoryCode", ""), 100, 100);
map.put("supervisoryCode", qrCode); // 监管二维码 代码优化
// 读取资源文件夹下的模板
ClassPathResource resource = new ClassPathResource("templates/use-registration-model.pdf");
PdfReader reader = null;
ByteArrayOutputStream bos = null;
try {
InputStream inputStream = resource.getInputStream();
reader = new PdfReader(inputStream);
bos = new ByteArrayOutputStream();
PdfStamper pdfStamper = new PdfStamper(reader, bos);
AcroFields acroFields = pdfStamper.getAcroFields();
// 中文字体
BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
for (Map.Entry<String, Object> param : map.entrySet()) {
// 设置文本域的字体为中文字体
acroFields.setFieldProperty(param.getKey(), "textfont", font,null);
// 设置字体大小
acroFields.setFieldProperty(param.getKey(), "textsize", 12.0f, null);
// 将 map 中的值写到 pdf 模板对应的文本域中
acroFields.setField(param.getKey(), param.getValue()+"");
}
// 如果为false那么生成的PDF文件还能编辑,所以一定要设为true
pdfStamper.setFormFlattening(true);
pdfStamper.close();
// 返回文件
//FileExporter.exportFile(FileExporter.FileType.valueOf("pdf"), "套打使用登记证", bos.toByteArray(), response);
this.writeAttachment(response, bos.toByteArray());
} catch (IOException | DocumentException e) {
e.printStackTrace();
} finally {
try {
assert bos != null;
bos.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 返回附件
*
* @param response 响应
* @param content 附件内容
*/
private void writeAttachment(HttpServletResponse response, byte[] content) throws IOException {
// 设置 header 和 contentType
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("套打使用登记证.pdf", "UTF-8"));
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
// 输出附件
IoUtil.write(response.getOutputStream(), false, content);
}
/**
* word 转 pdf
......
......@@ -675,7 +675,7 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
}
@Override
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response) {
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response, String printType) {
Map<String, Object> exportParamsMap = new HashMap<>();
//查询移装变更详情
JgChangeRegistrationReform jgChangeRegistrationReform = this.getById(sequenceNbr);
......@@ -787,8 +787,13 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
}
exportParamsMap.put("factoryNum", factoryInfo.getFactoryNum());
}
//调用生成使用登记证
commonServiceImpl.generateCertificateReport(exportParamsMap, response);
if ("0".equals(printType)) {
//调用生成使用登记证
commonServiceImpl.generateCertificateReport(exportParamsMap, response);
}else{
//套打
commonServiceImpl.generatePdfPrint(exportParamsMap, response);
}
}
/**
......
......@@ -897,7 +897,7 @@ public class JgChangeRegistrationUnitServiceImpl extends BaseService<JgChangeReg
*
* @param sequenceNbr
*/
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response) {
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response, String printType) {
Map<String, Object> exportParamsMap = new HashMap<>();
//查询移装变更详情
JgChangeRegistrationUnit transfer = this.getById(sequenceNbr);
......@@ -975,7 +975,13 @@ public class JgChangeRegistrationUnitServiceImpl extends BaseService<JgChangeReg
//调用生成使用登记证
exportParamsMap.put("excelType","变更登记");
exportParamsMap.put("tableName","特种设备单位变更登记");
commonService.generateCertificateReport(exportParamsMap, response);
if ("0".equals(printType)) {
//调用生成使用登记证
commonService.generateCertificateReport(exportParamsMap, response);
}else{
commonService.generatePdfPrint(exportParamsMap, response);
}
}
......
......@@ -47,7 +47,6 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.time.LocalDate;
......@@ -650,7 +649,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
return null;
}
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response) {
public void exportUseRegistrationCertificate(String sequenceNbr, HttpServletResponse response, String printType) {
Map<String, Object> exportParamsMap = new HashMap<>();
//查询使用登记详情
JgUseRegistration useRegistration = this.getById(sequenceNbr);
......@@ -760,8 +759,13 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
}
exportParamsMap.put("factoryNum", factoryInfo.getFactoryNum());
}
//调用生成使用登记证
commonService.generateCertificateReport(exportParamsMap, response);
if ("0".equals(printType)) {
//调用生成使用登记证
commonService.generateCertificateReport(exportParamsMap, response);
}else{
//套打
commonService.generatePdfPrint(exportParamsMap, response);
}
}
/**
......
......@@ -33,7 +33,7 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
private static final String LOCK_KEY_SUPERVISORY = "sequence_lock_supervisory";
private static final String SEQUENCE_TYPE_UR = "%05d";
private static final String SEQUENCE_TYPE = "%07d";
private static final long LOCK_EXPIRATION_SECONDS = 60;
private static final long LOCK_EXPIRATION_SECONDS = 600;
private final RedisTemplate<String, String> redisTemplate;
private final StringRedisTemplate stringRedisTemplate;
private final CategoryOtherInfoMapper categoryOtherInfoMapper;
......@@ -165,7 +165,7 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
* @param batchSize 批量生成个数
* @return List
*/
public synchronized List<String> generateBatchSequence(String sequenceKey, int batchSize) {
public List<String> generateBatchSequence(String sequenceKey, int batchSize) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = obtainLock(LOCK_KEY_AF);
if (Boolean.TRUE.equals(lockAcquired)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment