Browse Source

修改

dev^2
2 weeks ago
parent
commit
4cf5d44757
  1. 105
      application-tenant/tenant-admin/src/main/java/apelet/tenantadmin/upms/controller/DocxTemplateController.java
  2. 59
      common/common-association/src/main/java/apelet/association/controller/AssociationActivitiesController.java
  3. 12
      common/common-association/src/main/java/apelet/association/plugin/active/ActivityInfoDetailsPlugin.java
  4. 15
      common/common-association/src/main/java/apelet/association/plugin/active/ActivitySignConfigPlugin.java
  5. 23
      zz-resource/quotation_template.docx

105
application-tenant/tenant-admin/src/main/java/apelet/tenantadmin/upms/controller/DocxTemplateController.java

@ -1,11 +1,17 @@
package apelet.tenantadmin.upms.controller; package apelet.tenantadmin.upms.controller;
import apelet.common.core.exception.MyRuntimeException; import apelet.common.core.exception.MyRuntimeException;
import apelet.common.core.object.ObjectCollection;
import apelet.common.core.object.ObjectValue; import apelet.common.core.object.ObjectValue;
import apelet.common.core.object.TokenData; import apelet.common.core.object.ResponseResult;
import apelet.common.generator.utils.OrmGenDataSourceUtil; import apelet.common.generator.utils.OrmGenDataSourceUtil;
import apelet.common.online.service.OnlineDictService; import apelet.common.online.service.OnlineDictService;
import apelet.common.orm.impl.Filter;
import apelet.common.orm.impl.Selector;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -14,9 +20,12 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*; import org.apache.poi.xwpf.usermodel.*;
import org.docx4j.Docx4J; import org.docx4j.Docx4J;
import org.docx4j.fonts.IdentityPlusMapper;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
@ -25,11 +34,10 @@ import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/api/template") @RequestMapping("/api/template")
@ -76,7 +84,7 @@ public class DocxTemplateController {
hashMap.put("name", objectValue.getString("name")); hashMap.put("name", objectValue.getString("name"));
hashMap.put("type", dictMap.get(String.valueOf(objectValue.get("type", "")))); hashMap.put("type", dictMap.get(String.valueOf(objectValue.get("type", ""))));
hashMap.put("number", objectValue.getString("number")); hashMap.put("number", objectValue.getString("number"));
hashMap.put("create_time", objectValue.getString("create_time")); hashMap.put("create_time", objectValue.getString("create_time").substring(0, 10));
hashMap.put("qty", objectValue.getString("qty")); hashMap.put("qty", objectValue.getString("qty"));
String signatureImage = user.getString("signature_image"); String signatureImage = user.getString("signature_image");
@ -108,6 +116,8 @@ public class DocxTemplateController {
docxOut.close(); docxOut.close();
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new ByteArrayInputStream(docxBytes)); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new ByteArrayInputStream(docxBytes));
PhysicalFonts.discoverPhysicalFonts();
wordMLPackage.setFontMapper(new IdentityPlusMapper());
pdfOut = new ByteArrayOutputStream(); pdfOut = new ByteArrayOutputStream();
Docx4J.toPDF(wordMLPackage, pdfOut); Docx4J.toPDF(wordMLPackage, pdfOut);
byte[] pdfBytes = pdfOut.toByteArray(); byte[] pdfBytes = pdfOut.toByteArray();
@ -208,7 +218,6 @@ public class DocxTemplateController {
} }
private void replaceImageInParagraphs(XWPFDocument document, String placeholderKey, byte[] imageBytes, int width, int height) throws IOException, InvalidFormatException { private void replaceImageInParagraphs(XWPFDocument document, String placeholderKey, byte[] imageBytes, int width, int height) throws IOException, InvalidFormatException {
String placeholder = "#{" + placeholderKey + "}"; String placeholder = "#{" + placeholderKey + "}";
for (XWPFParagraph paragraph : document.getParagraphs()) { for (XWPFParagraph paragraph : document.getParagraphs()) {
@ -257,4 +266,88 @@ public class DocxTemplateController {
} }
} }
private static final Map<String, String> HEADER_MAP = new LinkedHashMap<>();
static {
HEADER_MAP.put("名称", "name");
HEADER_MAP.put("性别", "gender");
HEADER_MAP.put("手机号码", "phone");
HEADER_MAP.put("出生年月", "birth_date");
HEADER_MAP.put("学历", "education");
HEADER_MAP.put("民族", "nation");
HEADER_MAP.put("政治面貌", "political_status");
HEADER_MAP.put("身份证号码", "id_card");
HEADER_MAP.put("毕业院校", "graduate_school");
HEADER_MAP.put("所属专业", "major");
HEADER_MAP.put("常住地", "permanent_address");
}
@PostMapping("/expertImport")
public ResponseResult<?> expertImport(@RequestParam("file") MultipartFile file) {
List<Map<String, Object>> dataList = new ArrayList<>();
try (InputStream is = file.getInputStream()) {
ExcelReader reader = ExcelUtil.getReader(is);
// 第一行作为表头,key 为表头名称,自动兼容 xls/xlsx
List<Map<String, Object>> rawList = reader.readAll();
//学历
Map<String, String> educationDictMap = onlineDictService.getDictMap(2054094099727781888L);
educationDictMap = educationDictMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
//政治面貌
Map<String, String> politicalDictMap = onlineDictService.getDictMap(2054098587905691648L);
politicalDictMap = politicalDictMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
for (Map<String, Object> row : rawList) {
Map<String, Object> dataMap = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : row.entrySet()) {
String header = entry.getKey() == null ? "" : entry.getKey().trim();
// 中文表头转英文,映射中没有的表头保留原值
String key = HEADER_MAP.getOrDefault(header, header);
Object value = entry.getValue();
dataMap.put(key, value);
if (key.equals("gender")) {
dataMap.put("gender", value.equals("男") ? "1" : "0");
}
if (key.equals("education")) {
dataMap.put("education", educationDictMap.get(value.toString()));
}
if (key.equals("political_status")) {
dataMap.put("political_status", politicalDictMap.get(value.toString()));
}
if ("birth_date".equals(key)) {
if (value instanceof Date) {
value = DateUtil.formatDateTime((Date) value);
} else if (value instanceof String && StringUtils.isNotBlank((String) value)) {
value = DateUtil.formatDateTime(DateUtil.parse((String) value));
}
dataMap.put(key, value);
}
}
dataMap.put("billstatus", "A");
dataMap.put("apply_time", DateUtil.formatDateTime(new Date()));
dataList.add(dataMap);
}
ObjectCollection expertManage = ormGenDataSourceUtil.query("expert_manage", new Filter(), new Selector());
dataList.forEach(dataMap -> {
long count = expertManage.stream().filter(f -> f.get("id_card").equals(dataMap.get("id_card"))).count();
if (count > 0) {
return;
}
ObjectValue value = new ObjectValue("expert_manage");
value.setValues(dataMap);
try {
ormGenDataSourceUtil.addNew("expert_manage", value);
} catch (Exception e) {
e.printStackTrace();
}
});
} catch (IOException e) {
throw new MyRuntimeException("文件解析失败: " + e.getMessage());
}
return ResponseResult.success("导入成功");
}
} }

59
common/common-association/src/main/java/apelet/association/controller/AssociationActivitiesController.java

@ -54,50 +54,51 @@ public class AssociationActivitiesController {
} }
Integer type = jsonObject.getInteger("type"); Integer type = jsonObject.getInteger("type");
Filter filter = new Filter(); // Filter filter = new Filter();
filter.add(new FilterItem("unit_name", FilterItem.equals, signInUnit)); // filter.add(new FilterItem("unit_name", FilterItem.equals, signInUnit));
ObjectCollection collection = ormGenDataSourceUtil.query("membership_apply", filter, new Selector()); // ObjectCollection collection = ormGenDataSourceUtil.query("membership_apply", filter, new Selector());
//
if (collection == null || collection.isEmpty()) { // if (collection == null || collection.isEmpty()) {
return ResponseResult.error("500", "签到单位不存在, 请检查签到单位!!!"); // return ResponseResult.error("500", "签到单位不存在, 请检查签到单位!!!");
} // }
//
ObjectCollection managerCollection = ormGenDataSourceUtil.query("membership_manager", new Filter(), new Selector()); // ObjectCollection managerCollection = ormGenDataSourceUtil.query("membership_manager", new Filter(), new Selector());
List<Map<String, Object>> managerList = DataTransformationUtil.objectCollectionToList(managerCollection); // List<Map<String, Object>> managerList = DataTransformationUtil.objectCollectionToList(managerCollection);
Map<String, Map<String, Object>> mapMap = managerList.stream().collect(Collectors.toMap(map -> String.valueOf(map.get("id")), map -> map, (oldValue, newValue) -> oldValue)); // Map<String, Map<String, Object>> mapMap = managerList.stream().collect(Collectors.toMap(map -> String.valueOf(map.get("id")), map -> map, (oldValue, newValue) -> oldValue));
//
ObjectValue member = null; // ObjectValue member = null;
for (int i = 0; i < collection.size(); i++) { // for (int i = 0; i < collection.size(); i++) {
ObjectValue object = collection.getObject(i); // ObjectValue object = collection.getObject(i);
ObjectValue manger = object.getObjectValue("membership_manger_id"); // ObjectValue manger = object.getObjectValue("membership_manger_id");
Map<String, Object> map = mapMap.get(manger != null && manger.get("id") != null ? manger.get("id") : ""); // Map<String, Object> map = mapMap.get(manger != null && manger.get("id") != null ? manger.get("id") : "");
Object phone = map.get("phone"); // Object phone = map.get("phone");
if (ObjectUtil.equal(phone, phoneNumber)) { // if (ObjectUtil.equal(phone, phoneNumber)) {
member = object; // member = object;
} // }
} // }
if (member == null) { // if (member == null) {
return ResponseResult.error("500", signInUnit + " 签到单位下签到人不存在!!!"); // return ResponseResult.error("500", signInUnit + " 签到单位下签到人不存在!!!");
} // }
if (type == 1) { if (type == 1) {
//签到 //签到
ObjectValue value = new ObjectValue("check_in_out"); ObjectValue value = new ObjectValue("check_in_out");
value.put("name", signInPerson); value.put("name", signInPerson);
value.put("phone", phoneNumber); value.put("phone", phoneNumber);
value.put("membership_id", member); // value.put("membership_id", member);
value.put("create_time", new Date()); value.put("create_time", new Date());
value.put("create_time", new Date()); value.put("create_time", new Date());
value.put("parent_id", activityId); value.put("parent_id", activityId);
value.put("check_in", 1); value.put("check_in", 1);
ormGenDataSourceUtil.addNew(value.getTableName(), value); ormGenDataSourceUtil.addNew(value.getTableName(), value);
} }
if (type == 2) { if (type == 2) {
//签退 //签退
filter = new Filter(); Filter filter = new Filter();
filter.add(new FilterItem("membership_id", FilterItem.equals, member.get("id"))); // filter.add(new FilterItem("membership_id", FilterItem.equals, member.get("id")));
filter.add(new FilterItem("parent_id", FilterItem.equals, activityId)); filter.add(new FilterItem("parent_id", FilterItem.equals, activityId));
filter.add(new FilterItem("check_in", FilterItem.equals, 1)); filter.add(new FilterItem("check_in", FilterItem.equals, 1));
collection = ormGenDataSourceUtil.query("check_in_out", filter, new Selector()); ObjectCollection collection = ormGenDataSourceUtil.query("check_in_out", filter, new Selector());
if (collection != null && !collection.isEmpty()) { if (collection != null && !collection.isEmpty()) {
ObjectValue object = collection.getObject(0); ObjectValue object = collection.getObject(0);
object.put("check_out", 1); object.put("check_out", 1);

12
common/common-association/src/main/java/apelet/association/plugin/active/ActivityInfoDetailsPlugin.java

@ -130,10 +130,10 @@ public class ActivityInfoDetailsPlugin extends ListPlugin {
// 生成报名二维码 // 生成报名二维码
if (widgetVariableName.equals("button1786587153460")) { if (widgetVariableName.equals("button1786587153460")) {
String registrationQr = objectValue.getString("registration_qr"); String registrationQr = objectValue.getString("registration_qr");
if (StringUtils.isNotEmpty(registrationQr)) { // if (StringUtils.isNotEmpty(registrationQr)) {
this.showErrorMessage("当前已存在报名二维码, 请勿重复生成!!!"); // this.showErrorMessage("当前已存在报名二维码, 请勿重复生成!!!");
return; // return;
} // }
OnlineEventPluginExecuteDto dto = getDto(); OnlineEventPluginExecuteDto dto = getDto();
String savePath = System.getProperty("user.dir") + "\\zz-resource\\qrcode"; String savePath = System.getProperty("user.dir") + "\\zz-resource\\qrcode";
File QRFile = null; File QRFile = null;
@ -146,9 +146,9 @@ public class ActivityInfoDetailsPlugin extends ListPlugin {
String url = "http://58.48.135.5:8069" + "/#/?" + String url = "http://58.48.135.5:8069" + "/#/?" +
"loginName=" + "admin" + "loginName=" + "admin" +
"&password=" + "123456" + "&password=" + "123456" +
"&entryId=" + "2087710350152568832" + "&entryId=" + "2087413611113746432" +
"&bindType=" + "1" + "&bindType=" + "1" +
"&onlineFormId=" + "2048951917157027840" + "&onlineFormId=" + "2087385700075835392" +
"&activeId=" + id; "&activeId=" + id;
byte[] checkInQr = qrCodeUtil.generateQrCode(url, 350, 350); byte[] checkInQr = qrCodeUtil.generateQrCode(url, 350, 350);

15
common/common-association/src/main/java/apelet/association/plugin/active/ActivitySignConfigPlugin.java

@ -27,6 +27,8 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
/** /**
@ -113,20 +115,23 @@ public class ActivitySignConfigPlugin extends ListPlugin {
File checkOutFile = null; File checkOutFile = null;
File checkInFile = null; File checkInFile = null;
try { try {
Object activityId = objectValue.get("id"); Map parentParams = getDto().getParentParams();
Object activityName = objectValue.get("name"); Object activityId = parentParams.get("id");
ObjectValue value = ormGenDataSourceUtil.queryOne("association_activity", activityId);
String name = value.getString("name");
OnlineDatasource onlineDatasource = onlineDatasourceService.getById(model.getDatasourceId()); OnlineDatasource onlineDatasource = onlineDatasourceService.getById(model.getDatasourceId());
OnlineTable table = onlineTableService.getOnlineTableFromCache(onlineDatasource.getMasterTableId()); OnlineTable table = onlineTableService.getOnlineTableFromCache(onlineDatasource.getMasterTableId());
// 中文活动名称做 URL 编码,保证扫码 URL 为纯 ASCII;前端 decodeURIComponent 后仍是原中文
String checkIn = url + "/#/pages/login/routerHdView?activityId=" + activityId + "&activityName=" + activityName + "&type=" + 1; String encodedName = URLEncoder.encode(name, StandardCharsets.UTF_8.name());
String checkIn = url + "/#/pages/login/routerHdView?activityId=" + activityId + "&activityName=" + encodedName + "&type=1";
byte[] checkInQr = qrCodeUtil.generateQrCode(checkIn, 350, 350); byte[] checkInQr = qrCodeUtil.generateQrCode(checkIn, 350, 350);
checkInFile = MyFileUtil.writeToFile(checkInQr, savePath, "qrcode-" + System.currentTimeMillis() + ".png"); checkInFile = MyFileUtil.writeToFile(checkInQr, savePath, "qrcode-" + System.currentTimeMillis() + ".png");
MultipartFile checkInMultipart = MyFileUtil.readFileAsMultipartFile(checkInFile, "image/png"); MultipartFile checkInMultipart = MyFileUtil.readFileAsMultipartFile(checkInFile, "image/png");
UploadResponseInfo checkInUpload = myFileUtil.uploadMyFile(table, "sign_in_code", true, checkInMultipart); UploadResponseInfo checkInUpload = myFileUtil.uploadMyFile(table, "sign_in_code", true, checkInMultipart);
this.setWidgetAttribute("signInCode", AttributeEnum.VALUE_CHANGE, checkInUpload); this.setWidgetAttribute("signInCode", AttributeEnum.VALUE_CHANGE, checkInUpload);
String checkOut = url + "#/pages/login/routerHdView?activityId=" + activityId + "&activityName=" + activityName + "&type=" + 2; String checkOut = url + "/#/pages/login/routerHdView?activityId=" + activityId + "&activityName=" + encodedName + "&type=2";
byte[] checkOutQr = qrCodeUtil.generateQrCode(checkOut, 300, 300); byte[] checkOutQr = qrCodeUtil.generateQrCode(checkOut, 300, 300);
checkOutFile = MyFileUtil.writeToFile(checkOutQr, savePath, "qrcode-" + System.currentTimeMillis() + ".png"); checkOutFile = MyFileUtil.writeToFile(checkOutQr, savePath, "qrcode-" + System.currentTimeMillis() + ".png");
MultipartFile checkOutMultipart = MyFileUtil.readFileAsMultipartFile(checkOutFile, "image/png"); MultipartFile checkOutMultipart = MyFileUtil.readFileAsMultipartFile(checkOutFile, "image/png");

23
zz-resource/quotation_template.docx

@ -0,0 +1,23 @@
线下报价单
报价内容
#{name}
项目类型
#{type}
报价负责人
#{managerperson}
总报价(元)
#{qty}
报价日期
#{create_time}
报价编号
#{number}
负责人签字:
#{personimage}
Loading…
Cancel
Save