Commit 65b8f734 authored by 王果's avatar 王果

36671 子 【一张图替换站端系统】-自动化数据处理 / 数据同步:消防及运维人员

parent 83b10d74
...@@ -69,4 +69,10 @@ public class AdpterController { ...@@ -69,4 +69,10 @@ public class AdpterController {
public void systemExcel(HttpServletResponse response, String gatewayId) throws IOException { public void systemExcel(HttpServletResponse response, String gatewayId) throws IOException {
adpterService.buildingExcel(response, gatewayId); adpterService.buildingExcel(response, gatewayId);
} }
@ApiOperation(value = "人员信息")
@RequestMapping(value = "/personExcel", method = RequestMethod.POST)
public void personExcel(HttpServletResponse response) throws IOException {
adpterService.personExcel(response);
}
} }
\ No newline at end of file
package com.yeejoin.amos.adpter.model;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class PersonExcelModel {
@ExcelProperty(value = "编号", index = 0)
private String code;
@ExcelProperty(value = "上级编号", index = 1)
private String parentCode;
@ExcelProperty(value = "对象类型", index = 2)
private String objType;
@ExcelProperty(value = "网关名称", index = 3)
private String gatewayName;
@ExcelProperty(value = "类型", index = 4)
private String type;
@ExcelProperty(value = "消防岗位", index = 5)
private String firePost;
@ExcelProperty(value = "姓名", index = 6)
private String name;
@ExcelProperty(value = "岗位", index = 7)
private String post;
@ExcelProperty(value = "电话", index = 8)
private String phone;
@ExcelProperty(value = "员工编号", index = 9)
private String num;
@ExcelProperty(value = "性别", index = 10)
private String gender;
@ExcelProperty(value = "证件类型", index = 11)
private String idType;
@ExcelProperty(value = "证件号码", index = 12)
private String idNum;
@ExcelProperty(value = "出生日期", index = 13)
private String birth;
@ExcelProperty(value = "岗位资质", index = 14)
private String qualification;
@ExcelProperty(value = "资质到期日期", index = 15)
private String qualificationExpDate;
@ExcelProperty(value = "是否进行安全培训", index = 16)
private String safetyTraining;
@ExcelProperty(value = "是否准入(外围人员)", index = 17)
private String admitted;
}
...@@ -5,6 +5,7 @@ import com.alibaba.excel.ExcelWriter; ...@@ -5,6 +5,7 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.yeejoin.amos.adpter.model.AreaExcelModel; import com.yeejoin.amos.adpter.model.AreaExcelModel;
import com.yeejoin.amos.adpter.model.DeviceExcelModel; import com.yeejoin.amos.adpter.model.DeviceExcelModel;
import com.yeejoin.amos.adpter.model.PersonExcelModel;
import com.yeejoin.amos.adpter.model.SystemExcelModel; import com.yeejoin.amos.adpter.model.SystemExcelModel;
import org.apache.ibatis.io.Resources; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.RuntimeSqlException; import org.apache.ibatis.jdbc.RuntimeSqlException;
...@@ -29,6 +30,7 @@ import java.sql.*; ...@@ -29,6 +30,7 @@ import java.sql.*;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Service @Service
public class AdpterService { public class AdpterService {
...@@ -65,6 +67,8 @@ public class AdpterService { ...@@ -65,6 +67,8 @@ public class AdpterService {
@Value("${goal.jdbc.ip.dlbuss}") @Value("${goal.jdbc.ip.dlbuss}")
String dlBuss; String dlBuss;
@Value("${goal.jdbc.ip.dlcom}")
String dlCom;
String driver = "com.mysql.cj.jdbc.Driver"; String driver = "com.mysql.cj.jdbc.Driver";
@Value("${yeejoin.user}") @Value("${yeejoin.user}")
...@@ -152,10 +156,10 @@ public class AdpterService { ...@@ -152,10 +156,10 @@ public class AdpterService {
in = new FileInputStream(filePath); in = new FileInputStream(filePath);
ServletOutputStream os = response.getOutputStream(); ServletOutputStream os = response.getOutputStream();
//缓冲区 //缓冲区
int len =1; int len = 1;
byte[] b = new byte[1024]; byte[] b = new byte[1024];
while ((len = in.read(b))!=-1){ while ((len = in.read(b)) != -1) {
os.write(b,0,len); os.write(b, 0, len);
in.close(); in.close();
os.close(); os.close();
} }
...@@ -481,18 +485,14 @@ public class AdpterService { ...@@ -481,18 +485,14 @@ public class AdpterService {
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = "连接数据库失败,请检查数据库连接信息是否有误!"; String errorMsg = "连接数据库失败,请检查数据库连接信息是否有误!";
if (printWriter.checkError()) { if (printWriter.checkError()) {
try try {
{
File logFile = new File("output.txt"); File logFile = new File("output.txt");
printWriter = new PrintWriter(logFile, "UTF-8"); printWriter = new PrintWriter(logFile, "UTF-8");
printWriter.write(errorMsg); printWriter.write(errorMsg);
if (printWriter.checkError()) if (printWriter.checkError()) {
{
log.error("文件写入异常:" + errorMsg); log.error("文件写入异常:" + errorMsg);
} }
} } catch (Exception exception) {
catch (Exception exception)
{
log.error("日志写入异常!" + errorMsg, exception); log.error("日志写入异常!" + errorMsg, exception);
} }
} else { } else {
...@@ -505,7 +505,7 @@ public class AdpterService { ...@@ -505,7 +505,7 @@ public class AdpterService {
} }
} }
public static boolean deleteFile(String path) { public static boolean deleteFile(String path) {
boolean flag = false; boolean flag = false;
try { try {
File file = new File(path); File file = new File(path);
...@@ -514,7 +514,7 @@ public class AdpterService { ...@@ -514,7 +514,7 @@ public class AdpterService {
file.delete(); file.delete();
flag = true; flag = true;
} }
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return flag; return flag;
...@@ -693,6 +693,7 @@ public class AdpterService { ...@@ -693,6 +693,7 @@ public class AdpterService {
setData(emergencyList, deviceExcelModels); setData(emergencyList, deviceExcelModels);
return deviceExcelModels; return deviceExcelModels;
} }
public ArrayList<SystemExcelModel> systemInfo() throws IOException { public ArrayList<SystemExcelModel> systemInfo() throws IOException {
Resource resource = new ClassPathResource("sql/systemInfo.sql"); Resource resource = new ClassPathResource("sql/systemInfo.sql");
String sql = new String(Files.readAllBytes(resource.getFile().toPath())); String sql = new String(Files.readAllBytes(resource.getFile().toPath()));
...@@ -721,7 +722,7 @@ public class AdpterService { ...@@ -721,7 +722,7 @@ public class AdpterService {
return deviceExcelModels; return deviceExcelModels;
} }
public void setData(List<Map<String, Object>> list, List<DeviceExcelModel> models){ public void setData(List<Map<String, Object>> list, List<DeviceExcelModel> models) {
list.forEach(a -> { list.forEach(a -> {
DeviceExcelModel model = new DeviceExcelModel(); DeviceExcelModel model = new DeviceExcelModel();
model.setGatewayDevice(ObjectUtils.isEmpty(a.get("gatewayDevice")) ? "" : String.valueOf(a.get("gatewayDevice"))); model.setGatewayDevice(ObjectUtils.isEmpty(a.get("gatewayDevice")) ? "" : String.valueOf(a.get("gatewayDevice")));
...@@ -750,4 +751,102 @@ public class AdpterService { ...@@ -750,4 +751,102 @@ public class AdpterService {
models.add(model); models.add(model);
}); });
} }
public void personExcel(HttpServletResponse response) throws IOException {
String sql1 = "select * from cb_org_usr where biz_org_type ='PERSON'";
List<Map<String, Object>> list1 = query(dlBuss, sql1);
String sql2 = "SELECT * FROM cb_dynamic_form_instance WHERE instance_id in (";
if (ObjectUtils.isEmpty(list1)) {
return;
}
List<String> arrayList = new ArrayList<>();
for (Map<String, Object> map : list1) {
arrayList.add(map.get("sequence_nbr").toString());
}
if (ObjectUtils.isEmpty(arrayList)) {
return;
}
sql2 = sql2 + String.join(",", arrayList) + ") and field_value is not NULL and field_value !=''";
List<Map<String, Object>> list2 = query(dlCom, sql2);
ArrayList<PersonExcelModel> models = new ArrayList<>();
String sql3 = "select * from cb_firefighters_post where org_usr_id in ("+ String.join(",", arrayList) + ")";
List<Map<String, Object>> list3 = query(dlCom, sql3);
String sql4 = "select CONCAT(b.name,'-',a.name) as name from cb_data_dictionary a " +
"left join cb_data_dictionary b on a.parent = b.sequence_nbr " +
"where a.`type` ='GWZZ' and a.parent is not null";
List<Map<String, Object>> list4 = query(dlCom, sql4);
for (Map<String, Object> map : list1) {
PersonExcelModel model = new PersonExcelModel();
model.setName(ObjectUtils.isEmpty(map.get("biz_org_name")) ? "" : String.valueOf(map.get("biz_org_name")));
// list2 = list2.stream().filter(v->v.containsKey("field_value")&&!ObjectUtils.isEmpty(v.get("field_value"))).collect(Collectors.toList());
for (Map<String, Object> objectMap : list2) {
if (map.get("sequence_nbr").toString().equals(objectMap.get("instance_id").toString())) {
if (objectMap.get("field_code").equals("personNumber") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setCode(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
model.setNum(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("peopleType") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setType(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
// if (objectMap.get("field_code").equals("positionType") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
// model.setFirePost(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
// }
// if (objectMap.get("field_code").equals("fireManagementPostCode") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
// model.setPost(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
// }
if (objectMap.get("field_code").equals("telephone") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setPhone(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("gender") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setGender(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("certificatesTypeCode") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setIdType(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("certificatesNumber") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setIdNum(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("birthdayTime") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setBirth(objectMap.get("field_value").toString().substring(0, 10));
}
// if (objectMap.get("field_code").equals("birthdayTime") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
// model.setQualification(ObjectUtils.isEmpty(objectMap.get("field_value_label"))?objectMap.get("field_value").toString():objectMap.get("field_value_label").toString());
// }
if (objectMap.get("field_code").equals("safetyTraining") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setSafetyTraining(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
if (objectMap.get("field_code").equals("safetyTraining") && !ObjectUtils.isEmpty(objectMap.get("field_value"))) {
model.setAdmitted(ObjectUtils.isEmpty(objectMap.get("field_value_label")) ? objectMap.get("field_value").toString() : objectMap.get("field_value_label").toString());
}
}
}
for (Map<String, Object> objectMap : list3) {
if (map.get("sequence_nbr").toString().equals(objectMap.get("org_usr_id").toString())) {
if(!ObjectUtils.isEmpty(objectMap.get("post_qualification"))){
String qualification = objectMap.get("post_qualification").toString();
List<Map<String, Object>> maps = list4.stream().filter(v -> v.get("name").toString().contains(qualification)).collect(Collectors.toList());
if(!ObjectUtils.isEmpty(maps)){
model.setQualification(maps.get(0).get("name").toString());
}
}
if(!ObjectUtils.isEmpty(objectMap.get("qualification_certificate"))){
model.setFirePost(objectMap.get("qualification_certificate").toString());
}
if(!ObjectUtils.isEmpty(objectMap.get("job_title"))){
model.setPost(objectMap.get("job_title").toString());
}
}
}
model.setObjType("人员");
models.add(model);
}
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("人员信息", "UTF-8") + ".xlsx");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
try (ServletOutputStream outputStream = response.getOutputStream()) {
EasyExcel.write(outputStream).head(PersonExcelModel.class).sheet("Sheet1").doWrite(models);
} catch (IOException e) {
log.error("dynamicExportSPTemplateExcel error:", e);
}
}
} }
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