42d3032c98547e028207d7ceee3722c2d5e2af16.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package cn.com.goldenwater.dcproj.service.impl.grw;
  2. import cn.com.goldenwater.dcproj.dao.AttGrwBaseCrrctDao;
  3. import cn.com.goldenwater.dcproj.enums.RequestSourceEnum;
  4. import cn.com.goldenwater.dcproj.model.AttGrwBase;
  5. import cn.com.goldenwater.dcproj.model.AttGrwBaseCrrct;
  6. import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrctParam;
  7. import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrtParam;
  8. import cn.com.goldenwater.dcproj.service.AttGrwBaseCrrctService;
  9. import cn.com.goldenwater.core.service.AbstractCrudService;
  10. import cn.com.goldenwater.dcproj.utils.DateUtils;
  11. import cn.com.goldenwater.dcproj.utils.GeoUtil;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import cn.com.goldenwater.id.util.UuidUtil;
  16. import org.apache.commons.lang3.StringUtils;
  17. import java.util.Map;
  18. /**
  19. * @author gaobowen
  20. * @date 2019-4-8
  21. */
  22. @Service
  23. @Transactional(rollbackFor = Exception.class)
  24. public class AttGrwBaseCrrctServiceImpl extends AbstractCrudService<AttGrwBaseCrrct, AttGrwBaseCrrctParam> implements AttGrwBaseCrrctService {
  25. @Autowired
  26. private AttGrwBaseCrrctDao attGrwBaseCrrctDao;
  27. public AttGrwBaseCrrctServiceImpl(AttGrwBaseCrrctDao attGrwBaseCrrctDao) {
  28. super(attGrwBaseCrrctDao);
  29. this.attGrwBaseCrrctDao = attGrwBaseCrrctDao;
  30. }
  31. @Override
  32. public AttGrwBaseCrrct add(AttGrwBaseCrrct p) throws Exception {
  33. String now = DateUtils.getTodayYMDHMS();
  34. p.setIntm(now);
  35. p.setUptm(now);
  36. if (StringUtils.isBlank(p.getStcd())) {
  37. throw new Exception("测站编码不能为空");
  38. }
  39. String uuid = UuidUtil.uuid();
  40. p.setCrrctId(uuid);
  41. p.setChkState("0");
  42. transferGeo(p, p.getSrc());
  43. int ret = attGrwBaseCrrctDao.insert(p);
  44. if (ret != -2147482646) {
  45. throw new Exception("插入失败");
  46. }
  47. AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(p.getStcd());
  48. return attGrwBaseCrrct;
  49. }
  50. private void transferGeo(AttGrwBaseCrrct p, String src) throws Exception {
  51. if (StringUtils.isNotBlank(src)) {
  52. if (RequestSourceEnum.PC.getValue().equalsIgnoreCase(src)) {
  53. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  54. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  55. p.setLgtd(map.get("lon"));
  56. p.setLttd(map.get("lat"));
  57. }
  58. } else if (RequestSourceEnum.MOBILE.getValue().equalsIgnoreCase(src)) {
  59. if (p.getLgtd() != null && p.getLttd() != null) {
  60. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  61. p.setLgtdPc(map.get("lon"));
  62. p.setLttdPc(map.get("lat"));
  63. }
  64. }
  65. } else {
  66. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  67. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  68. p.setLgtd(map.get("lon"));
  69. p.setLttd(map.get("lat"));
  70. } else if (p.getLgtd() != null && p.getLttd() != null) {
  71. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  72. p.setLgtdPc(map.get("lon"));
  73. p.setLttdPc(map.get("lat"));
  74. }
  75. }
  76. }
  77. /*@Override
  78. public AttGrwBaseCrrct modify(AttGrwBaseCrrct p) throws Exception {
  79. if(StringUtils.isBlank(p.getGuid())){
  80. throw new Exception("id 不能为空!");
  81. }
  82. AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(p.getGuid());
  83. if(attGrwBaseCrrct == null){
  84. throw new Exception("该记录不存在,请刷新页面重试!");
  85. }
  86. String now = DateUtils.getTodayYMDHMS();
  87. p.setUpdateTime(now);
  88. int ret = attGrwBaseCrrctDao.update(p);
  89. if(ret!= -2147482646){
  90. throw new Exception("更新失败");
  91. }
  92. AttGrwBaseCrrct bean = attGrwBaseCrrctDao.get(p.getId());
  93. return bean;
  94. }*/
  95. /* @Override
  96. public void remove(String id) throws Exception {
  97. if(StringUtils.isBlank(id)){
  98. throw new Exception("id 不能为空!");
  99. }
  100. AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(id);
  101. if(attGrwBaseCrrct == null){
  102. throw new Exception("该记录不存在,请刷新页面重试");
  103. }
  104. int ret = attGrwBaseCrrctDao.delete(id);
  105. if(ret!= -2147482646){
  106. throw new Exception("删除失败");
  107. }
  108. }*/
  109. }