FileData2DB.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.persagy.business.maintain;
  2. import java.io.File;
  3. import java.util.HashSet;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import javax.annotation.Resource;
  8. import org.springframework.stereotype.Service;
  9. import com.persagy.core.service.BaseBusinessService;
  10. import com.persagy.core.service.BusinessService;
  11. import com.persagy.weather.service.HourRecordService;
  12. import com.persagy.weather.thread.FileDataTransThread;
  13. /**
  14. * 城市小时历史文件数据入库
  15. *
  16. */
  17. @Service("FileData2DB")
  18. @SuppressWarnings({"unchecked","rawtypes" })
  19. public class FileData2DB extends BaseBusinessService<Map> implements BusinessService {
  20. @Resource
  21. HourRecordService hourRecordService;
  22. @Override
  23. public void handle(Map dto, List content) throws Exception {
  24. String dirPath = (String) dto.get("dirPath");
  25. List<String> cityList = (List<String>) dto.get("cityList");
  26. File dir = new File(dirPath);
  27. if(!dir.exists() || !dir.isDirectory()) {
  28. throw new Exception("dirPath不是有效的目录");
  29. }
  30. if(null == cityList || cityList.isEmpty()) {
  31. throw new Exception("cityList不能为空");
  32. }
  33. Set<String> cityIds = new HashSet<>(cityList);
  34. if(FileDataTransThread.runningLogic.contains(dirPath)) {
  35. content.add("Task is Running");
  36. }else {
  37. new Thread(new FileDataTransThread(dirPath, hourRecordService, cityIds)).start();
  38. content.add("Task start Running");
  39. }
  40. }
  41. }