Commit f2dbade8a0eba35cf6005634fb34d942dffdc28c

Authored by 王通
1 parent 3be16063

1.针对已有人员被停用,人事系统重新启用之后,调度未启用的情况调整逻辑

src/main/java/com/bsth/StartCommand.java
... ... @@ -6,12 +6,23 @@ import com.bsth.util.DateUtils;
6 6  
7 7 import org.springframework.beans.factory.annotation.Autowired;
8 8 import org.springframework.boot.CommandLineRunner;
  9 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  10 +import org.springframework.jdbc.core.JdbcTemplate;
9 11 import org.springframework.stereotype.Component;
10 12 import org.slf4j.Logger;
11 13 import org.slf4j.LoggerFactory;
12 14  
  15 +import java.io.BufferedReader;
  16 +import java.io.File;
  17 +import java.io.FileReader;
  18 +import java.io.IOException;
  19 +import java.sql.PreparedStatement;
  20 +import java.sql.SQLException;
  21 +import java.util.ArrayList;
  22 +import java.util.List;
13 23 import java.util.concurrent.Executors;
14 24 import java.util.concurrent.ScheduledExecutorService;
  25 +import java.util.regex.Pattern;
15 26  
16 27 /**
17 28 * 随应用启动运行
... ... @@ -28,6 +39,9 @@ public class StartCommand implements CommandLineRunner{
28 39  
29 40 @Autowired
30 41 PersonnelUpdateThread personnelUpdateThread;
  42 +
  43 + @Autowired
  44 + private JdbcTemplate jdbcTemplate;
31 45  
32 46 static {
33 47 // 中午12:00
... ... @@ -41,8 +55,106 @@ public class StartCommand implements CommandLineRunner{
41 55 log.info("在:"+timeDiff / 1000 / 60 + "分钟后开始同步数据");
42 56 personnelUpdateThread.run();
43 57 //mainServices.scheduleAtFixedRate(personnelUpdateThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);//timeDiff / 1000
  58 + //analyzeInterface();
44 59 } catch (Exception e) {
45 60 e.printStackTrace();
46 61 }
47 62 }
  63 +
  64 + private Pattern pattern = Pattern.compile("");
  65 +
  66 + private static class InterfaceRequest {
  67 +
  68 + private String ip;
  69 +
  70 + private String password;
  71 +
  72 + private String agent;
  73 +
  74 + private String uri;
  75 +
  76 + private int time;
  77 +
  78 + public InterfaceRequest(String ip, String password, String agent, String uri, int time) {
  79 + this.ip = ip;
  80 + this.password = password;
  81 + this.agent = agent;
  82 + this.uri = uri;
  83 + this.time = time;
  84 + }
  85 +
  86 + public String getIp() {
  87 + return ip;
  88 + }
  89 +
  90 + public void setIp(String ip) {
  91 + this.ip = ip;
  92 + }
  93 +
  94 + public String getPassword() {
  95 + return password;
  96 + }
  97 +
  98 + public void setPassword(String password) {
  99 + this.password = password;
  100 + }
  101 +
  102 + public String getAgent() {
  103 + return agent;
  104 + }
  105 +
  106 + public void setAgent(String agent) {
  107 + this.agent = agent;
  108 + }
  109 +
  110 + public String getUri() {
  111 + return uri;
  112 + }
  113 +
  114 + public void setUri(String uri) {
  115 + this.uri = uri;
  116 + }
  117 +
  118 + public int getTime() {
  119 + return time;
  120 + }
  121 +
  122 + public void setTime(int time) {
  123 + this.time = time;
  124 + }
  125 + }
  126 +
  127 + public void analyzeInterface () throws IOException {
  128 + //String line = "INFO -[][180.167.126.126][Apache-HttpClient/4.5.5 (Java/1.8.0_241)][/webservice/rest/schedule_real/execs][{\"password\":[\"e126853c7f6f43b4857fa8dfe3b28b5d90be9e68\"],\"timestamp\":[\"1686192455081\"],\"nonce\":[\"2mycf6\"],\"sign\":[\"d945f2d522db4d458694a435e46a81c5ff9ee73f\"]}]<time:9462>";
  129 + final List<InterfaceRequest> requests = new ArrayList<>();
  130 + String path = "C:\\Users\\Hill\\Downloads\\main1.log";
  131 + BufferedReader reader = new BufferedReader(new FileReader(new File(path)));
  132 + String line = null;
  133 + while ((line = reader.readLine()) != null) {
  134 + int idx = line.indexOf("<time:"), idxPwdStart = line.indexOf("password\":[\""), idxPwdEnd = line.indexOf("\"]", idxPwdStart);
  135 + if (idx > 0) {
  136 + String[] array = line.split("\\]\\[");
  137 + String ip = array[1], agent = array[2], uri = array[3], time = line.substring(idx + 6, line.length() - 1), password = line.substring(idxPwdStart, idxPwdEnd);
  138 + InterfaceRequest request = new InterfaceRequest(ip, password, agent, uri, Integer.parseInt(time));
  139 + requests.add(request);
  140 + }
  141 + }
  142 + jdbcTemplate.batchUpdate("insert into bsth_c_interface_request (ip, password, agent, uri, `time`) values (?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() {
  143 + @Override
  144 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  145 + InterfaceRequest request = requests.get(i);
  146 +
  147 + ps.setString(1, request.getIp());
  148 + ps.setString(2, request.getPassword());
  149 + ps.setString(3, request.getAgent());
  150 + ps.setString(4, request.getUri());
  151 + ps.setInt(5, request.getTime());
  152 + }
  153 +
  154 + @Override
  155 + public int getBatchSize() {
  156 + return requests.size();
  157 + }
  158 + });
  159 + }
48 160 }
... ...
src/main/java/com/bsth/handler/PersonnelUpdateHandler.java
... ... @@ -134,15 +134,21 @@ public class PersonnelUpdateHandler {
134 134 });
135 135 }
136 136 // 根据工号关联更新姓名、公司、工种、身份证号
137   - int rows = jdbcTemplate.update("update bsth_c_personnel a inner join bsth_c_employee b on a.job_code = b.job_code1 set a.personnel_name = b.employee_name,a.personnel_type = b.job_type,a.company = b.company_name,a.company_code = b.company_code,a.card = b.id_card,a.branche_company_code = b.branche_company_code,a.branche_company = b.branche_company,a.jd_codeori = b.job_code,a.job_codeori = b.job_code2 where a.destroy = 0 and a.locked = 0");
  137 + int rows = jdbcTemplate.update("update bsth_c_personnel a inner join bsth_c_employee b on a.job_code = b.job_code1 set a.destroy = 0, a.personnel_name = b.employee_name,a.personnel_type = b.job_type,a.company = b.company_name,a.company_code = b.company_code,a.card = b.id_card,a.branche_company_code = b.branche_company_code,a.branche_company = b.branche_company,a.jd_codeori = b.job_code,a.job_codeori = b.job_code2 where a.locked = 0");
138 138 logger.info(String.format("根据工号关联更新姓名、公司、工种、身份证号,记录数%d",rows));
139 139 // 未匹配上工号的数据 用身份证号关联更新工号、姓名、公司、工种
140   - rows = jdbcTemplate.update("update bsth_c_personnel a inner join bsth_c_employee b on a.card = b.id_card set a.job_code = b.job_code1,a.personnel_name = b.employee_name,a.personnel_type = b.job_type,a.company = b.company_name,a.company_code = b.company_code,a.branche_company_code = b.branche_company_code,a.branche_company = b.branche_company,a.jd_codeori = b.job_code,a.job_codeori = b.job_code2 where a.destroy = 0 and a.job_code <> b.job_code1 and a.locked = 0");
  140 + rows = jdbcTemplate.update("update bsth_c_personnel a inner join bsth_c_employee b on a.card = b.id_card set a.destroy = 0, a.job_code = b.job_code1,a.personnel_name = b.employee_name,a.personnel_type = b.job_type,a.company = b.company_name,a.company_code = b.company_code,a.branche_company_code = b.branche_company_code,a.branche_company = b.branche_company,a.jd_codeori = b.job_code,a.job_codeori = b.job_code2 where a.job_code <> b.job_code1 and a.locked = 0");
141 141 logger.info(String.format("根据身份证号关联更新工号、姓名、公司、工种,记录数%d",rows));
142 142 // 可能会出现数据异常情况 如一个是最新的工号无身份证号,一个是老的工号有身份证号,最后更新的结果会造成工号和身份证号重复
  143 + // 将更晚创建的人员信息destroy更新为2
  144 + rows = jdbcTemplate.update("update bsth_c_personnel x INNER JOIN (select card,max(id) id from bsth_c_personnel a where destroy = 0 and LENGTH(a.card) > 1 and a.locked = 0) y on x.id = y.id set x.destroy = 2");
  145 + logger.info(String.format("同一个人,临时将更晚创建的人员destroy更新为2,记录数%d",rows));
143 146 // 将更早创建的人员信息更新为停用
144   - rows = jdbcTemplate.update("update bsth_c_personnel x INNER JOIN (select card,min(id) id from bsth_c_personnel a where destroy = 0 and LENGTH(a.card) > 1 and a.locked = 0 GROUP BY card having count(*) > 1) y on x.id = y.id set destroy = 1");
  147 + rows = jdbcTemplate.update("update bsth_c_personnel set destroy = 1 where destroy = 0");
145 148 logger.info(String.format("同一个人,将更早创建的人员停用,记录数%d",rows));
  149 + // 将更晚创建的人员信息更新为启用
  150 + rows = jdbcTemplate.update("update bsth_c_personnel set destroy = 0 where destroy = 2");
  151 + logger.info(String.format("同一个人,将更晚创建的人员启用,记录数%d",rows));
146 152 // 仍未匹配上的调度数据作为停用人员
147 153 rows = jdbcTemplate.update("update bsth_c_personnel a left join bsth_c_employee b on a.job_code = b.job_code1 set a.destroy = 1 where a.destroy = 0 and b.job_code1 is null and a.locked = 0");
148 154 logger.info(String.format("调度系统未匹配数据标记为停用,记录数%d",rows));
... ...
src/main/resources/application.properties
1   -spring.profiles: dev,prod
2   -spring.profiles.active: prod
  1 +spring.profiles.active= prod
3 2  
4 3 spring.view.suffix=.html
5 4 server.session-timeout=-1
... ...