TestController.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package thyyxxk.webserver.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import thyyxxk.webserver.config.auth.PassToken;
  9. import thyyxxk.webserver.dao.his.MyTestDao;
  10. import thyyxxk.webserver.entity.ResultVo;
  11. import thyyxxk.webserver.entity.dictionary.PureCodeName;
  12. import thyyxxk.webserver.utils.BaiduMapGeocoderUtil;
  13. import thyyxxk.webserver.utils.ResultVoUtil;
  14. import java.util.List;
  15. @Slf4j
  16. @RestController
  17. @RequestMapping("/test")
  18. public class TestController {
  19. private final MyTestDao dao;
  20. @Autowired
  21. public TestController(MyTestDao dao) {
  22. this.dao = dao;
  23. }
  24. @PassToken
  25. @GetMapping("/exec")
  26. public ResultVo<String> test() {
  27. List<PureCodeName> list = dao.selectPatientRawAddress();
  28. int total = list.size();
  29. int count = 0;
  30. for (PureCodeName item : list) {
  31. JSONObject cityinfo = BaiduMapGeocoderUtil.getAddressInfoByLngAndLat(item.getName());
  32. if (null == cityinfo) {
  33. dao.updateLocation(item.getCode(), null, null, "0");
  34. continue;
  35. }
  36. String adcode = cityinfo.getString("adcode");
  37. if (null != adcode && !adcode.equals("0") && cityinfo.getString("district") != null) {
  38. log.info("【{}】:{}", item.getName(), cityinfo);
  39. dao.updateLocation(item.getCode(), null, null, adcode);
  40. count += 1;
  41. }
  42. }
  43. String message = String.format("总数据【%d】条,完成【%d】条。", total, count);
  44. return ResultVoUtil.success(message);
  45. }
  46. }