Commit 61461b96de8f5017dcf43f9990b29c65c3ca0644
1 parent
104f1118
1.调度人员信息与人事库同步,逻辑变更
Showing
7 changed files
with
108 additions
and
12 deletions
src/main/java/com/bsth/handler/personnelUpdateHandler.java
| ... | ... | @@ -9,14 +9,20 @@ import com.bsth.util.DBUtils_Personnel; |
| 9 | 9 | import com.bsth.util.XmlToJson; |
| 10 | 10 | import com.bsth.wsdl.PJDataSerivce; |
| 11 | 11 | import com.bsth.wsdl.PJDataSerivceSoap; |
| 12 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 12 | 13 | import org.hibernate.collection.internal.PersistentBag; |
| 13 | 14 | import org.joda.time.DateTime; |
| 14 | 15 | import org.slf4j.Logger; |
| 15 | 16 | import org.slf4j.LoggerFactory; |
| 16 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 18 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | |
| 17 | 19 | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
| 18 | 20 | import org.springframework.jdbc.core.JdbcTemplate; |
| 21 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 19 | 22 | import org.springframework.stereotype.Component; |
| 23 | +import org.springframework.transaction.TransactionDefinition; | |
| 24 | +import org.springframework.transaction.TransactionStatus; | |
| 25 | +import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 20 | 26 | |
| 21 | 27 | import javax.xml.namespace.QName; |
| 22 | 28 | import java.net.URL; |
| ... | ... | @@ -47,6 +53,18 @@ public class personnelUpdateHandler { |
| 47 | 53 | |
| 48 | 54 | private static final QName SERVICE_NAME = new QName("http://www.pd-transport.com/", "PJDataSerivce"); |
| 49 | 55 | |
| 56 | + private static Map<String, String> gzname2code = new HashMap<>(); | |
| 57 | + | |
| 58 | + static { | |
| 59 | + gzname2code.put("路线驾驶员","1"); | |
| 60 | + gzname2code.put("团客车驾驶员","1"); | |
| 61 | + gzname2code.put("交通车驾驶员","1"); | |
| 62 | + gzname2code.put("调度员","2"); | |
| 63 | + gzname2code.put("乘务员","3"); | |
| 64 | + gzname2code.put("机务员/质检员","3"); | |
| 65 | + gzname2code.put("其他服务人员","14"); | |
| 66 | + } | |
| 67 | + | |
| 50 | 68 | public void sync() { |
| 51 | 69 | |
| 52 | 70 | URL wsdlURL = PJDataSerivce.WSDL_LOCATION; |
| ... | ... | @@ -80,7 +98,7 @@ public class personnelUpdateHandler { |
| 80 | 98 | // 把所有人员设为停用状态,然后在用金蝶人员数据匹配,匹配上的设为在职 |
| 81 | 99 | conn = DBUtils_Personnel.getConnection(); |
| 82 | 100 | // 服务器 |
| 83 | - ps = conn.prepareStatement("UPDATE control.bsth_c_personnel SET destroy = 1"); | |
| 101 | + ps = conn.prepareStatement("UPDATE pd_control.bsth_c_personnel SET destroy = 1"); | |
| 84 | 102 | // 本地 |
| 85 | 103 | // ps = conn.prepareStatement("UPDATE pd_control.bsth_c_personnel SET destroy = 1"); |
| 86 | 104 | ps.executeUpdate(); |
| ... | ... | @@ -200,4 +218,82 @@ public class personnelUpdateHandler { |
| 200 | 218 | logger.error("", e); |
| 201 | 219 | } |
| 202 | 220 | } |
| 221 | + | |
| 222 | + public void sync(String s) { | |
| 223 | + final Map<String, String> unit2company = new HashMap<>(4); | |
| 224 | + unit2company.put("KD01.0110", "55-上南公司"); | |
| 225 | + unit2company.put("KD01.0111", "22-金高公司"); | |
| 226 | + unit2company.put("KD01.0112", "26-南汇公司"); | |
| 227 | + unit2company.put("KD01.0113", "05-杨高公司"); | |
| 228 | + | |
| 229 | + PJDataSerivce ss = new PJDataSerivce(PJDataSerivce.WSDL_LOCATION, SERVICE_NAME); | |
| 230 | + PJDataSerivceSoap port = ss.getPJDataSerivceSoap12(); | |
| 231 | + //编程式事务 | |
| 232 | + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 233 | + DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 234 | + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 235 | + TransactionStatus status = tran.getTransaction(def); | |
| 236 | + try { | |
| 237 | + logger.info("人事数据同步 开始"); | |
| 238 | + List<Personnel> personnels = jdbcTemplate.query("select * from bsth_c_personnel", BeanPropertyRowMapper.newInstance(Personnel.class)); | |
| 239 | + logger.info("personnel 原数据:" + new ObjectMapper().writeValueAsString(personnels)); | |
| 240 | + // KD01.0110上南 KD01.0111金高 KD01.0112南汇 KD01.0113杨高 | |
| 241 | + jdbcTemplate.execute("delete from bsth_c_employee"); | |
| 242 | + for (int i = 0;i < 4;i++) { | |
| 243 | + final String unintCode = "KD01.011" + i; | |
| 244 | + String employeeXml = port.getEmployee(unintCode, ""); | |
| 245 | + logger.info(unintCode + ":" + employeeXml); | |
| 246 | + JSONObject json = XmlToJson.xml2Json(employeeXml); | |
| 247 | + final JSONArray emps = (JSONArray)json.get("Emp"); | |
| 248 | + jdbcTemplate.batchUpdate("insert into bsth_c_employee values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() { | |
| 249 | + @Override | |
| 250 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 251 | + JSONObject emp = emps.getJSONObject(i); | |
| 252 | + String jobCode = emp.getString("Code"), company = unit2company.get(unintCode), positName = emp.getString("PositName"); | |
| 253 | + String[] jobCodeSplit = jobCode.split("-"), companySplit = company.split("-"); | |
| 254 | + ps.setString(1, jobCode); | |
| 255 | + ps.setString(2, companySplit[0] + "-" + jobCodeSplit[1]); | |
| 256 | + ps.setString(3, jobCodeSplit[1]); | |
| 257 | + ps.setString(4, emp.getString("EmployeeName")); | |
| 258 | + ps.setString(5, gzname2code.get(positName) == null ? "14" : gzname2code.get(positName)); | |
| 259 | + ps.setString(6, companySplit[0]); | |
| 260 | + ps.setString(7, companySplit[1]); | |
| 261 | + ps.setString(8, emp.getString("IDCardID") == null ? "" : emp.getString("IDCardID")); | |
| 262 | + ps.setString(9, emp.getString("EnterDeptDate")); | |
| 263 | + ps.setString(10, emp.getString("EnterGroupDate")); | |
| 264 | + ps.setString(11, emp.getString("InpositionDate")); | |
| 265 | + } | |
| 266 | + | |
| 267 | + @Override | |
| 268 | + public int getBatchSize() { | |
| 269 | + return emps.size(); | |
| 270 | + } | |
| 271 | + }); | |
| 272 | + } | |
| 273 | + // 根据工号关联更新姓名、公司、工种、身份证号 | |
| 274 | + 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 where a.destroy = 0"); | |
| 275 | + logger.info(String.format("根据工号关联更新姓名、公司、工种、身份证号,记录数%d",rows)); | |
| 276 | + // 未匹配上工号的数据 用身份证号关联更新工号、姓名、公司、工种 | |
| 277 | + 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 where a.destroy = 0 and a.job_code <> b.job_code1"); | |
| 278 | + logger.info(String.format("根据身份证号关联更新工号、姓名、公司、工种,记录数%d",rows)); | |
| 279 | + // 可能会出现数据异常情况 如一个是最新的工号无身份证号,一个是老的工号有身份证号,最后更新的结果会造成工号和身份证号重复 | |
| 280 | + // 将更早创建的人员信息更新为停用 | |
| 281 | + 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 GROUP BY card having count(*) > 1) y on x.id = y.id set destroy = 1"); | |
| 282 | + logger.info(String.format("同一个人,将更早创建的人员停用,记录数%d",rows)); | |
| 283 | + // 仍未匹配上的调度数据作为停用人员 | |
| 284 | + 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"); | |
| 285 | + logger.info(String.format("调度系统未匹配数据标记为停用,记录数%d",rows)); | |
| 286 | + // 仍未匹配上的金蝶数据作为新人员 | |
| 287 | + rows = jdbcTemplate.update("insert into bsth_c_personnel (job_code,personnel_name,personnel_type,company,company_code,job_codeori) select b.job_code1,b.employee_name,b.job_type,b.company_name,b.company_code,b.job_code2 from bsth_c_employee b left join bsth_c_personnel a on b.job_code1 = a.job_code where a.job_code is null"); | |
| 288 | + logger.info(String.format("金蝶未匹配数据插入,记录数%d",rows)); | |
| 289 | + // 赋值分公司编码1 不然无法查询 | |
| 290 | + rows = jdbcTemplate.update("update bsth_c_personnel set branche_company_code = '1' where branche_company_code is null"); | |
| 291 | + logger.info(String.format("分公司代码更新为1,记录数%d",rows)); | |
| 292 | + logger.info("人事数据同步 结束"); | |
| 293 | + tran.commit(status); | |
| 294 | + } catch (Exception e) { | |
| 295 | + tran.rollback(status); | |
| 296 | + logger.error("", e); | |
| 297 | + } | |
| 298 | + } | |
| 203 | 299 | } | ... | ... |
src/main/java/com/bsth/thread/PersonnelUpdateThrad.java
src/main/java/com/bsth/wsdl/PJDataSerivce.java
| ... | ... | @@ -15,7 +15,7 @@ import java.net.URL; |
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | 17 | @WebServiceClient(name = "PJDataSerivce", |
| 18 | - wsdlLocation = "http://116.236.238.218:31/PJDataInterface/PJDataService.asmx?wsdl", | |
| 18 | + wsdlLocation = "http://116.228.98.212:31/PJDataInterface/PJDataService.asmx?wsdl", | |
| 19 | 19 | targetNamespace = "http://www.pd-transport.com/") |
| 20 | 20 | public class PJDataSerivce extends Service { |
| 21 | 21 | |
| ... | ... | @@ -27,11 +27,11 @@ public class PJDataSerivce extends Service { |
| 27 | 27 | static { |
| 28 | 28 | URL url = null; |
| 29 | 29 | try { |
| 30 | - url = new URL("http://116.236.238.218:31/PJDataInterface/PJDataService.asmx?wsdl"); | |
| 30 | + url = new URL("http://116.228.98.212:31/PJDataInterface/PJDataService.asmx?wsdl"); | |
| 31 | 31 | } catch (MalformedURLException e) { |
| 32 | 32 | java.util.logging.Logger.getLogger(PJDataSerivce.class.getName()) |
| 33 | 33 | .log(java.util.logging.Level.INFO, |
| 34 | - "Can not initialize the default wsdl from {0}", "http://116.236.238.218:31/PJDataInterface/PJDataService.asmx?wsdl"); | |
| 34 | + "Can not initialize the default wsdl from {0}", "http://116.228.98.212:31/PJDataInterface/PJDataService.asmx?wsdl"); | |
| 35 | 35 | } |
| 36 | 36 | WSDL_LOCATION = url; |
| 37 | 37 | } | ... | ... |
src/main/resources/application-dev.properties
| ... | ... | @@ -2,15 +2,15 @@ server.port=8776 |
| 2 | 2 | management.port= 9001 |
| 3 | 3 | management.address= 127.0.0.1 |
| 4 | 4 | |
| 5 | -spring.jpa.hibernate.ddl-auto= update | |
| 5 | +spring.jpa.hibernate.ddl-auto= none | |
| 6 | 6 | spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy |
| 7 | 7 | #DATABASE |
| 8 | 8 | spring.jpa.database= MYSQL |
| 9 | 9 | spring.jpa.show-sql= true |
| 10 | 10 | spring.datasource.driver-class-name= com.mysql.jdbc.Driver |
| 11 | -spring.datasource.url= jdbc:mysql://localhost:3306/pd_control?useUnicode=true&characterEncoding=utf-8&useSSL=false | |
| 11 | +spring.datasource.url= jdbc:mysql://192.168.168.241/pd_control?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8&useSSL=false | |
| 12 | 12 | spring.datasource.username= root |
| 13 | -spring.datasource.password= | |
| 13 | +spring.datasource.password= root2jsp | |
| 14 | 14 | #DATASOURCE |
| 15 | 15 | spring.datasource.max-active=100 |
| 16 | 16 | spring.datasource.max-idle=8 | ... | ... |
src/main/resources/application-prod.properties
| ... | ... | @@ -8,9 +8,9 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy |
| 8 | 8 | spring.jpa.database= MYSQL |
| 9 | 9 | spring.jpa.show-sql= true |
| 10 | 10 | spring.datasource.driver-class-name= com.mysql.jdbc.Driver |
| 11 | -spring.datasource.url= jdbc:mysql://10.10.150.24:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false | |
| 11 | +spring.datasource.url= jdbc:mysql://10.10.200.148/control?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8&useSSL=false | |
| 12 | 12 | spring.datasource.username= root |
| 13 | -spring.datasource.password= root2jsp | |
| 13 | +spring.datasource.password= root | |
| 14 | 14 | #DATASOURCE |
| 15 | 15 | spring.datasource.max-active=100 |
| 16 | 16 | spring.datasource.max-idle=8 | ... | ... |
src/main/resources/application.properties
src/main/resources/personnel-jdbc.properties
| ... | ... | @@ -4,6 +4,6 @@ |
| 4 | 4 | #ms.mysql.password= |
| 5 | 5 | |
| 6 | 6 | ms.mysql.driver= com.mysql.jdbc.Driver |
| 7 | -ms.mysql.url= jdbc:mysql://10.10.150.24:3306/personnel?useUnicode=true&characterEncoding=utf-8 | |
| 7 | +ms.mysql.url= jdbc:mysql://192.168.168.240:3306/personnel?useUnicode=true&characterEncoding=utf-8 | |
| 8 | 8 | ms.mysql.username= root |
| 9 | 9 | ms.mysql.password= root2jsp | ... | ... |