Commit 2a1ec889 authored by hezhuozhi's avatar hezhuozhi

修复电站导出时间格式化

parent 8247db38
...@@ -189,6 +189,30 @@ public class DateUtils { ...@@ -189,6 +189,30 @@ public class DateUtils {
} }
/** /**
* 时间格式字符串化成标准字符串 2024-05-23T14:19:05.432 => 2024-05-23 14:19:05
*
* @param dateString Date
* @return
* @throws ParseException
*/
public static Object dateStringFormat(Object dateString){
if(Objects.isNull(dateString)){
return null;
}
try {
// 转换为 LocalDateTime
LocalDateTime localDateTime = LocalDateTime.parse(String.valueOf(dateString));
// 转换为 Date
Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_PATTERN);
return sdf.format(date);
}catch (Exception e){
return dateString;
}
}
/**
* 暂时不操作原生截取做下转换 * 暂时不操作原生截取做下转换
* *
* @param str * @param str
......
...@@ -49,17 +49,33 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -49,17 +49,33 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
public void exportStationExcelByField(StationFieldDto stationFieldDto, HttpServletResponse response) { public void exportStationExcelByField(StationFieldDto stationFieldDto, HttpServletResponse response) {
dealInitData(stationFieldDto); dealInitData(stationFieldDto);
List<String> fields = getHeaderFields(stationFieldDto); List<String> fields = getHeaderFields(stationFieldDto);
List<String> fieldsFlag = getFieldsFlag(stationFieldDto);
List<Map<String, Object>> data = getExcelData(stationFieldDto); List<Map<String, Object>> data = getExcelData(stationFieldDto);
exportFieldExcel(fields, data, response); exportFieldExcel(fields, fieldsFlag, data, response);
}
/**
* 获取字段标识
* @param stationFieldDto
* @return
*/
private List<String> getFieldsFlag(StationFieldDto stationFieldDto) {
List<String> fieldsFlag = new ArrayList<>();
List<HygfBusinessField> businessFieldList = stationFieldDto.getBusinessFieldList();
for (HygfBusinessField businessField : businessFieldList) {
fieldsFlag.add(businessField.getFieldName() + "_" + businessField.getBusinessName());
}
return fieldsFlag;
} }
/** /**
* 导出动态字段Excel * 导出动态字段Excel
* @param fields * @param fields
* @param fieldsFlag
* @param data * @param data
* @param response * @param response
*/ */
private void exportFieldExcel(List<String> fields, List<Map<String, Object>> data, HttpServletResponse response) { private void exportFieldExcel(List<String> fields, List<String> fieldsFlag, List<Map<String, Object>> data, HttpServletResponse response) {
// 创建工作簿和工作表 // 创建工作簿和工作表
Workbook workbook = new XSSFWorkbook(); Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("电站统计"); Sheet sheet = workbook.createSheet("电站统计");
...@@ -95,8 +111,8 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -95,8 +111,8 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
// 填充数据 // 填充数据
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
Row row = sheet.createRow(i + 1); Row row = sheet.createRow(i + 1);
for (int j = 0; j < fields.size(); j++) { for (int j = 0; j < fieldsFlag.size(); j++) {
Object value = data.get(i).get(fields.get(j)); Object value = data.get(i).get(fieldsFlag.get(j));
if (Objects.nonNull(value) && value.toString().length() >= 32767) { if (Objects.nonNull(value) && value.toString().length() >= 32767) {
value = value.toString().substring(0, 32766); value = value.toString().substring(0, 32766);
} }
...@@ -104,7 +120,7 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -104,7 +120,7 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
} }
} }
try { try {
String fileName = "电站统计" + DateUtils.dateFormat(new Date(), "YYYY-MM-dd-HH-mm") + ".xlsx"; String fileName = "电站详情统计" + DateUtils.dateFormat(new Date(), "YYYY-MM-dd-HH-mm") + ".xlsx";
downLoadExcel(fileName, response, workbook); downLoadExcel(fileName, response, workbook);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
...@@ -258,6 +274,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -258,6 +274,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
List<Map<String, Object>> dataMap = businessFieldMapper.getEngineeringInformation(stationIdList); List<Map<String, Object>> dataMap = businessFieldMapper.getEngineeringInformation(stationIdList);
if (CollectionUtil.isNotEmpty(dataMap)) { if (CollectionUtil.isNotEmpty(dataMap)) {
for (Map<String, Object> item : dataMap) { for (Map<String, Object> item : dataMap) {
if (Objects.nonNull(item.get("completion_date"))) {
item.put("completion_date", DateUtils.dateStringFormat(item.get("completion_date")));
}
//处理组件序列号 //处理组件序列号
dealConstructionComponentInfo(item); dealConstructionComponentInfo(item);
//处理逆变器序列号 //处理逆变器序列号
...@@ -408,7 +427,48 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -408,7 +427,48 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
* @return * @return
*/ */
private Map<String, Map<String, Object>> getExtendedInformation(List<String> stationIdList, List<HygfBusinessField> fields) { private Map<String, Map<String, Object>> getExtendedInformation(List<String> stationIdList, List<HygfBusinessField> fields) {
return dealFields(businessFieldMapper.getExtendedInformation(stationIdList), fields); List<Map<String, Object>> dataMap = businessFieldMapper.getExtendedInformation(stationIdList);
if (CollectionUtil.isNotEmpty(dataMap)) {
for (Map<String, Object> item : dataMap) {
//处理联系人
dealContacts(item);
}
}
return dealFields(dataMap, fields);
}
/**
* 处理联系人
* @param item
*/
private void dealContacts(Map<String, Object> item) {
if (Objects.nonNull(item.get("contacts"))) {
JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("contacts")));
StringBuilder stringBuilder = new StringBuilder();
int index = 0;
for (Object o : jsonArray) {
if (o instanceof JSONObject) {
index++;
JSONObject jsonObject = (JSONObject) o;
stringBuilder.append("序号:");
stringBuilder.append(index);
stringBuilder.append("姓名:");
stringBuilder.append(jsonObject.get("userName") == null ? "" : jsonObject.get("userName"));
stringBuilder.append("关系:");
stringBuilder.append(jsonObject.get("relation") == null ? "" : jsonObject.get("relation"));
stringBuilder.append("联系电话:");
stringBuilder.append(jsonObject.get("telephone") == null ? "" : jsonObject.get("telephone"));
stringBuilder.append("电子邮箱:");
stringBuilder.append(jsonObject.get("mailbox") == null ? "" : jsonObject.get("mailbox"));
stringBuilder.append("QQ:");
stringBuilder.append(jsonObject.get("qq") == null ? "" : jsonObject.get("qq"));
stringBuilder.append("微信:");
stringBuilder.append(jsonObject.get("wechat") == null ? "" : jsonObject.get("wechat"));
stringBuilder.append("\n");
}
}
item.put("contacts", stringBuilder.toString());
}
} }
/** /**
...@@ -619,6 +679,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -619,6 +679,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
if (Objects.nonNull(item.get("meter_position"))) { if (Objects.nonNull(item.get("meter_position"))) {
item.put("meter_position", CommonEnum.getNameByCode(String.valueOf(item.get("meter_position")))); item.put("meter_position", CommonEnum.getNameByCode(String.valueOf(item.get("meter_position"))));
} }
if (Objects.nonNull(item.get("surveyor_time"))) {
item.put("surveyor_time", DateUtils.dateStringFormat(item.get("surveyor_time")));
}
if (Objects.nonNull(item.get("roofway"))) { if (Objects.nonNull(item.get("roofway"))) {
JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("roofway"))); JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("roofway")));
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
...@@ -643,6 +706,14 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -643,6 +706,14 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
} }
item.put("screen", CommonEnum.getNameByCodeList(list)); item.put("screen", CommonEnum.getNameByCodeList(list));
} }
if (Objects.nonNull(item.get("house_type"))) {
JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("house_type")));
List<String> list = new ArrayList<>();
for (Object o : jsonArray) {
list.add(String.valueOf(o));
}
item.put("house_type", CommonEnum.getNameByCodeList(list));
}
if (Objects.nonNull(item.get("solution_measures"))) { if (Objects.nonNull(item.get("solution_measures"))) {
JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("solution_measures"))); JSONArray jsonArray = JSONArray.parseArray(String.valueOf(item.get("solution_measures")));
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
...@@ -673,6 +744,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -673,6 +744,9 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
if (Objects.nonNull(item.get("owner_type"))) { if (Objects.nonNull(item.get("owner_type"))) {
item.put("owner_type", CommonEnum.getNameByCode(String.valueOf(item.get("owner_type")))); item.put("owner_type", CommonEnum.getNameByCode(String.valueOf(item.get("owner_type"))));
} }
if (Objects.nonNull(item.get("creator_time"))) {
item.put("creator_time", DateUtils.dateStringFormat(item.get("creator_time")));
}
} }
} }
return dealFields(basicInformation, fields); return dealFields(basicInformation, fields);
...@@ -690,7 +764,7 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf ...@@ -690,7 +764,7 @@ public class BusinessFieldServiceImpl extends BaseService<BusinessFieldDto, Hygf
for (Map<String, Object> stringObjectMap : selectMapList) { for (Map<String, Object> stringObjectMap : selectMapList) {
Map<String, Object> fieldMap = new HashMap<>(); Map<String, Object> fieldMap = new HashMap<>();
for (HygfBusinessField field : fields) { for (HygfBusinessField field : fields) {
fieldMap.put(field.getFieldName(), stringObjectMap.get(field.getFieldFlag())); fieldMap.put(field.getFieldName() + "_" + field.getBusinessName(), stringObjectMap.get(field.getFieldFlag()));
} }
result.put(String.valueOf(stringObjectMap.get("stationId")), fieldMap); result.put(String.valueOf(stringObjectMap.get("stationId")), fieldMap);
} }
......
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