Commit 19afc5aa authored by chenzhao's avatar chenzhao

登记表生成 模版文件样式调整及增加注释

parent 6e1d0159
...@@ -104,6 +104,8 @@ import java.net.URLEncoder; ...@@ -104,6 +104,8 @@ 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.text.ParseException; import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -2225,9 +2227,22 @@ public class CommonServiceImpl implements ICommonService { ...@@ -2225,9 +2227,22 @@ public class CommonServiceImpl implements ICommonService {
public JSONObject buildFile (String manageType, JSONObject jsonObject){ public JSONObject buildFile (String manageType, JSONObject jsonObject){
JSONObject formData = new JSONObject(); JSONObject formData = new JSONObject();
formData.putAll(jsonObject); formData.putAll(jsonObject);
//去除值为null的key
formData.entrySet().removeIf(entry -> entry.getValue() == null); formData.entrySet().removeIf(entry -> entry.getValue() == null);
// 定义日期格式 若传进来的时间包含时分秒 则进行格式化
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Pattern timePattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}");
for (String key : formData.keySet()) {
if (key.contains("Date") && timePattern.matcher(formData.getString(key)).matches()){
// 解析原始日期时间字符串
LocalDateTime dateTime = LocalDateTime.parse(formData.getString(key), inputFormatter);
// 格式化为仅包含年月日的字符串
String formattedDate = dateTime.format(outputFormatter);
formData.put(key,formattedDate);
}
}
//管理员赋值 台套/单位模版 //管理员赋值 台套/单位模版
if (formData.containsKey("safetyManager") && formData.getString("safetyManager").contains("_")){ if (formData.containsKey("safetyManager") && formData.getString("safetyManager").contains("_")){
formData.put("safetyManagerName",formData.getString("safetyManager").split("_")[1]); formData.put("safetyManagerName",formData.getString("safetyManager").split("_")[1]);
...@@ -2264,30 +2279,25 @@ public class CommonServiceImpl implements ICommonService { ...@@ -2264,30 +2279,25 @@ public class CommonServiceImpl implements ICommonService {
if (formData.containsKey("projectContraption") ){ if (formData.containsKey("projectContraption") ){
formData.put("productName", formData.getString("projectContraption")); formData.put("productName", formData.getString("projectContraption"));
} }
//单位模版 部分字段需从设备列表中获取
if (formData.containsKey("equipmentLists") && manageType.equals(UNIT) ){ if (formData.containsKey("equipmentLists") && manageType.equals(UNIT) ){
JSONArray equipmentLists = formData.getJSONArray("equipmentLists"); JSONArray equipmentLists = formData.getJSONArray("equipmentLists");
formData.put("equNum",equipmentLists.size());
List<Map<String, Object>> equips = equipmentLists.stream() List<Map<String, Object>> equips = equipmentLists.stream()
.filter(obj -> obj instanceof Map) .filter(obj -> obj instanceof Map)
.map(obj -> (Map<String, Object>) obj).collect(Collectors.toList()); .map(obj -> (Map<String, Object>) obj).collect(Collectors.toList());
if (manageType.equals(UNIT) && !CollectionUtils.isEmpty(equips)){
formData.put("equDefine",equips.get(0).get("equDefineName")); //设备数量
formData.put("equNum",equipmentLists.size());
} //设备品种
if (formData.containsKey("equipmentLists") && manageType.equals(VEHICLE) ){ formData.put("equDefine",equips.get(0).get("equDefineName"));
formData.put("equipBasicInfoList",formData.get("equipmentLists")); }else if (manageType.equals(UNIT) && !CollectionUtils.isEmpty(equips)){
JSONArray equipmentLists = formData.getJSONArray("equipmentLists"); //气瓶数量
formData.put("equNum", equipmentLists.size());
List<Map<String, Object>> equips = equipmentLists.stream()
.filter(obj -> obj instanceof Map)
.map(obj -> (Map<String, Object>) obj).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(equips)){
formData.put("gasNum",equips.size()); formData.put("gasNum",equips.size());
//设备品种
formData.put("equDefineName",equips.get(0).get("equDefineName")); formData.put("equDefineName",equips.get(0).get("equDefineName"));
formData.put("workPressure", equips.stream().mapToDouble(e -> Objects.isNull(e.get("nominalWorkingPressure"))? 0 : Double.valueOf(e.get("nominalWorkingPressure").toString())).sum()); //气瓶压力及容积求和
formData.put("volume", equips.stream().mapToDouble(e -> Objects.isNull(e.get("singleBottleVolume"))? 0 : Double.valueOf(e.get("singleBottleVolume").toString())).sum()); formData.put("workPressure", equips.stream().mapToDouble(e -> Optional.ofNullable(e.get("nominalWorkingPressure")).map(v -> Double.valueOf(v.toString())).orElse(0.0)).sum());
formData.put("volume", equips.stream().mapToDouble(e -> Optional.ofNullable(e.get("singleBottleVolume")).map(v -> Double.valueOf(v.toString())).orElse(0.0)).sum());
Set<String> chargingMedium = equips.stream().map(e -> String.valueOf(e.get("chargingMedium"))).collect(Collectors.toSet()); Set<String> chargingMedium = equips.stream().map(e -> String.valueOf(e.get("chargingMedium"))).collect(Collectors.toSet());
if (chargingMedium.size()>1){ if (chargingMedium.size()>1){
throw new BadRequest("充装介质仅可选择同一类型"); throw new BadRequest("充装介质仅可选择同一类型");
...@@ -2295,7 +2305,9 @@ public class CommonServiceImpl implements ICommonService { ...@@ -2295,7 +2305,9 @@ public class CommonServiceImpl implements ICommonService {
formData.put("chargingMedium",equips.get(0).get("chargingMedium")); formData.put("chargingMedium",equips.get(0).get("chargingMedium"));
} }
} }
} }
//设备类型 台套模版 //设备类型 台套模版
if (formData.containsKey("equDefine") && !manageType.equals(UNIT) ){ if (formData.containsKey("equDefine") && !manageType.equals(UNIT) ){
EquipmentCategory define = equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>() EquipmentCategory define = equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>()
......
...@@ -1429,8 +1429,7 @@ ...@@ -1429,8 +1429,7 @@
</w:pPr> </w:pPr>
<w:r> <w:r>
<w:rPr> <w:rPr>
<w:rFonts w:ascii="Calibri" w:h-ansi="Calibri" w:fareast="宋体" <w:rFonts w:ascii="宋体" w:hint="fareast"/>
w:cs="Times New Roman" w:hint="default"/>
<w:kern w:val="0"/> <w:kern w:val="0"/>
<w:lang w:val="EN-US" w:fareast="ZH-CN" w:bidi="AR-SA"/> <w:lang w:val="EN-US" w:fareast="ZH-CN" w:bidi="AR-SA"/>
</w:rPr> </w:rPr>
......
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