IncidentAssignManagerTask.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.dashitech.migration.task.incident;
  2. import com.dashitech.migration.BaseTask;
  3. import com.dashitech.migration.SqlTask;
  4. import com.dashitech.migration.core.DataMigrationter;
  5. import com.dashitech.migration.core.FieldMapper;
  6. import com.dashitech.migration.util.JdbcUtil;
  7. import org.apache.commons.logging.Log;
  8. import org.apache.commons.logging.LogFactory;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Component;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.util.List;
  13. import java.util.Map;
  14. /**
  15. * Created by CX on 2024/10/10.
  16. */
  17. @Component
  18. public class IncidentAssignManagerTask extends BaseTask {
  19. @Autowired
  20. SqlTask hospitalTask;
  21. @Autowired
  22. SqlTask departmentTask;
  23. @Autowired
  24. SqlTask userTask;
  25. @Autowired
  26. SqlTask groupTask;
  27. public static Log log = LogFactory.getLog(IncidentAssignManagerTask.class);
  28. @Override
  29. @Transactional(rollbackFor = Exception.class)
  30. public void start() {
  31. log.info(" *** IncidentAssignManagerTask start 开始 *** ");
  32. StringBuffer sb = new StringBuffer();
  33. sb.append(" select * from itsm_incident_assign_manager ");
  34. List list = jdbcTemplateMdv2.queryForList(sb.toString());
  35. FieldMapper mapper = new FieldMapper();
  36. mapper.addOperationRemove("id").addOperationRemove("userOrGroupType").addOperationRemove("branch_id");
  37. mapper.addOperationUpdate("handle_group", "_group");
  38. mapper.addOperationUpdate("batch_no", "batch_id");
  39. mapper.addOperationUpdate("hos_id", "duty_id");
  40. mapper.addOperationReplace("duty_id", hospitalTask.loadCache().getIdCache());
  41. mapper.addOperationReplace("dept_id", departmentTask.loadCache().getIdCache());
  42. mapper.addOperationReplace("handle_user", userTask.loadCache().getIdCache());
  43. mapper.addOperationReplace("_group", groupTask.loadCache().getIdCache());
  44. mapper.trans2JdbcRow(list);
  45. JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
  46. jdbcUtil.batchPageInsert("itsm_itsm_incident_assign_manager", mapper.getRows());
  47. //clear释放内存
  48. mapper.clear();
  49. }
  50. @Override
  51. public FieldMapper loadCache() {
  52. log.info(" *** IncidentAssignManagerTask loadCache 开始 *** ");
  53. String sql = " select id,ACCOUNT,delete_flag from itsm_incident ";
  54. List<Map<String, Object>> list = jdbcTemplateHsms.queryForList(sql);
  55. sql = " select id,ACCOUNT,delete_flag from itsm_itsm_incident ";
  56. List<Map<String, Object>> list2 = jdbcTemplateMdv2.queryForList(sql);
  57. FieldMapper mapper = new FieldMapper();
  58. mapper.addFieldMapper("ACCOUNT", "ACCOUNT");
  59. mapper.addFieldMapper("delete_flag", "delete_flag");
  60. DataMigrationter.loadCache(list, list2, mapper);
  61. return mapper;
  62. }
  63. }