3d4a1b221dbab77e70650d17e54b9577918d2ffc.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package cn.com.goldenwater.dcproj.service.impl.grw;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.AttGrwBaseCrrctDao;
  4. import cn.com.goldenwater.dcproj.dao.AttGrwBaseDao;
  5. import cn.com.goldenwater.dcproj.dao.BisInspGrwDao;
  6. import cn.com.goldenwater.dcproj.enums.GrwSttpBaseEnum;
  7. import cn.com.goldenwater.dcproj.enums.GrwSttpEnum;
  8. import cn.com.goldenwater.dcproj.enums.RequestSourceEnum;
  9. import cn.com.goldenwater.dcproj.enums.SqlExecuteStateEnum;
  10. import cn.com.goldenwater.dcproj.model.AttGrwBase;
  11. import cn.com.goldenwater.dcproj.model.AttGrwBaseCrrct;
  12. import cn.com.goldenwater.dcproj.model.BisInspGrw;
  13. import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrtParam;
  14. import cn.com.goldenwater.dcproj.param.AttGrwBaseParam;
  15. import cn.com.goldenwater.dcproj.param.AttGrwListByParam;
  16. import cn.com.goldenwater.dcproj.service.AttGrwBaseCrrctService;
  17. import cn.com.goldenwater.dcproj.service.AttGrwBaseService;
  18. import cn.com.goldenwater.dcproj.utils.BeanUtil;
  19. import cn.com.goldenwater.dcproj.utils.DateUtils;
  20. import cn.com.goldenwater.dcproj.utils.GeoUtil;
  21. import cn.com.goldenwater.dcproj.utils.expExcel.ExcelExport;
  22. import cn.com.goldenwater.dcproj.utils.expExcel.ExportAbstract;
  23. import com.github.pagehelper.PageHelper;
  24. import com.github.pagehelper.PageInfo;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import javax.servlet.http.HttpServletResponse;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. * @author zhengdafei
  35. * @date 2019-3-30
  36. */
  37. @Service
  38. @Transactional(rollbackFor = Exception.class)
  39. public class AttGrwBaseServiceImpl extends AbstractCrudService<AttGrwBase, AttGrwBaseParam> implements AttGrwBaseService {
  40. @Autowired
  41. private AttGrwBaseDao attGrwBaseDao;
  42. @Autowired
  43. private BisInspGrwDao bisInspGrwDao;
  44. @Autowired
  45. AttGrwBaseCrrctDao attGrwBaseCrrctDao;
  46. @Autowired
  47. AttGrwBaseCrrctService attGrwBaseCrrctService;
  48. public AttGrwBaseServiceImpl(AttGrwBaseDao attGrwBaseDao) {
  49. super(attGrwBaseDao);
  50. this.attGrwBaseDao = attGrwBaseDao;
  51. }
  52. @Override
  53. public AttGrwBase add(AttGrwBase p) throws Exception {
  54. String now = DateUtils.getTodayYMDHMS();
  55. p.setIntm(now);
  56. if (StringUtils.isBlank(p.getStcd())) {
  57. throw new Exception("测站编码不能为空");
  58. }
  59. AttGrwBase one = attGrwBaseDao.get(p.getStcd());
  60. if (one != null) {
  61. throw new Exception("该测站编码已存在");
  62. }
  63. int ret = attGrwBaseDao.insert(p);
  64. if (ret != SqlExecuteStateEnum.SUCCESS.getValue()) {
  65. throw new Exception("插入失败");
  66. }
  67. AttGrwBase attGrwBase = attGrwBaseDao.get(p.getStcd());
  68. return attGrwBase;
  69. }
  70. @Override
  71. public AttGrwBase modify(AttGrwBase p) throws Exception {
  72. if (StringUtils.isBlank(p.getStcd())) {
  73. throw new Exception("测站编码 不能为空!");
  74. }
  75. AttGrwBase attGrwBase = attGrwBaseDao.get(p.getStcd());
  76. if (attGrwBase == null) {
  77. throw new Exception("该记录不存在,请刷新页面重试!");
  78. }
  79. int ret = attGrwBaseDao.update(p);
  80. if (ret != -2147482646) {
  81. throw new Exception("更新失败");
  82. }
  83. AttGrwBase bean = attGrwBaseDao.get(p.getStcd());
  84. return bean;
  85. }
  86. @Override
  87. public void remove(String id) throws Exception {
  88. if (StringUtils.isBlank(id)) {
  89. throw new Exception("测站编码 不能为空!");
  90. }
  91. AttGrwBase attGrwBase = attGrwBaseDao.get(id);
  92. if (attGrwBase == null) {
  93. throw new Exception("该记录不存在,请刷新页面重试");
  94. }
  95. int ret = attGrwBaseDao.delete(id);
  96. if (ret != -2147482646) {
  97. throw new Exception("删除失败");
  98. }
  99. }
  100. @Override
  101. public PageInfo<AttGrwBase> getListBy(AttGrwListByParam param) throws Exception {
  102. if ("NAT".equals(param.getSttp()) || GrwSttpEnum.NATIONAL.getValue().equals(param.getSttp())) {
  103. param.setSttp2("1");
  104. } else if (GrwSttpEnum.PROV.getValue().equals(param.getSttp()) || "PRO".equals(param.getSttp())) {
  105. param.setSttp2("5");
  106. }
  107. PageHelper.startPage(param);
  108. List<AttGrwBase> list = attGrwBaseDao.getListBy(param);
  109. for (AttGrwBase att : list) {
  110. if (GrwSttpBaseEnum.NATIONAL.getValue().equals(att.getSttp())) {
  111. att.setSttp(GrwSttpEnum.NATIONAL.getValue());
  112. } else if (GrwSttpBaseEnum.PROV.getValue().equals(att.getSttp())) {
  113. att.setSttp(GrwSttpEnum.PROV.getValue());
  114. }
  115. att.setSttpNm(GrwSttpEnum.getName(att.getSttp()));
  116. }
  117. return new PageInfo<AttGrwBase>(list);
  118. }
  119. @Override
  120. public AttGrwBase crrctBase(AttGrwBaseCrrtParam p) throws Exception {
  121. AttGrwBase attGrwBase = new AttGrwBase();
  122. if (StringUtils.isBlank(p.getStcd())) {
  123. throw new Exception("测站编码 不能为空!");
  124. }
  125. if (StringUtils.isBlank(p.getStlc())) {
  126. throw new Exception("测站位置 不能为空!");
  127. }
  128. if (StringUtils.isBlank(p.getSrc())) {
  129. throw new Exception("数据来源 不能为空!");
  130. }
  131. attGrwBase.setStcd(p.getStcd());
  132. attGrwBase.setStlc(p.getStlc());
  133. attGrwBase.setLgtd(p.getLgtd());
  134. attGrwBase.setLttd(p.getLttd());
  135. attGrwBase.setLgtdPc(p.getLgtdpc());
  136. attGrwBase.setLttdPc(p.getLttdpc());
  137. transferGeo(attGrwBase, p.getSrc());
  138. String now = DateUtils.getTodayYMDHMS();
  139. AttGrwBaseCrrct attGrwBaseCrrct = new AttGrwBaseCrrct();
  140. attGrwBaseCrrct.setStcd(p.getStcd());
  141. attGrwBaseCrrct.setStlc(p.getStlc());
  142. attGrwBaseCrrct.setLgtd(p.getLgtd());
  143. attGrwBaseCrrct.setLttd(p.getLttd());
  144. attGrwBaseCrrct.setLgtdPc(p.getLgtdpc());
  145. attGrwBaseCrrct.setLttdPc(p.getLttdpc());
  146. attGrwBaseCrrct.setEdtrPesr(p.getCheckPid());
  147. attGrwBaseCrrct.setSrc(p.getSrc());
  148. attGrwBaseCrrctService.add(attGrwBaseCrrct);
  149. AttGrwBase one = modify(attGrwBase);
  150. BisInspGrw grw = new BisInspGrw();
  151. grw.setStcd(p.getStcd());
  152. grw.setStlc(p.getStlc());
  153. grw.setCheckPid(p.getCheckPid());
  154. grw.setCheckPname(p.getCheckPname());
  155. grw.setUpTm(now);
  156. int ret = bisInspGrwDao.updateByStcd(grw);
  157. if (ret != -2147482646) {
  158. throw new Exception("更新登记表失败");
  159. }
  160. return one;
  161. }
  162. @Override
  163. public void transferGeo(AttGrwBase p, String src) {
  164. if (StringUtils.isNotBlank(src)) {
  165. if (RequestSourceEnum.PC.getValue().equalsIgnoreCase(src)) {
  166. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  167. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  168. p.setLgtd(map.get("lon"));
  169. p.setLttd(map.get("lat"));
  170. }
  171. } else if (RequestSourceEnum.MOBILE.getValue().equalsIgnoreCase(src)) {
  172. if (p.getLgtd() != null && p.getLttd() != null) {
  173. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  174. p.setLgtdPc(map.get("lon"));
  175. p.setLttdPc(map.get("lat"));
  176. }
  177. }
  178. } else {
  179. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  180. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  181. p.setLgtd(map.get("lon"));
  182. p.setLttd(map.get("lat"));
  183. } else if (p.getLgtd() != null && p.getLttd() != null) {
  184. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  185. p.setLgtdPc(map.get("lon"));
  186. p.setLttdPc(map.get("lat"));
  187. }
  188. }
  189. }
  190. @Override
  191. public void exportAttGrwBase(AttGrwBaseParam attAdXBaseParam, HttpServletResponse response) {
  192. List<AttGrwBase> list = attGrwBaseDao.findList(attAdXBaseParam);
  193. List<Map<String, Object>> mapList = new ArrayList<>();
  194. for (AttGrwBase attGrwBase : list) {
  195. String sttp = attGrwBase.getSttp();
  196. if ("NATIONAL".equals(sttp)) {
  197. attGrwBase.setSttp("国家级");
  198. } else if ("PROVAUTO".equals(sttp)) {
  199. attGrwBase.setSttp("省级自动");
  200. } else if ("PROV".equals(sttp)) {
  201. attGrwBase.setSttp("省级监测站(未知手动自动)");
  202. } else if ("PROVHAND".equals(sttp)) {
  203. attGrwBase.setSttp("省级人工");
  204. }
  205. mapList.add(BeanUtil.transBean2Map(attGrwBase));
  206. }
  207. ExportAbstract export = new ExcelExport();
  208. export.setFileName("地下水监测站基础信息列表");
  209. export.setExport_ps_export(true);
  210. export.setExport_ps_type(ExportAbstract.XLS);
  211. export.setExport_bzip(false);
  212. export.setTitle("地下水监测站基础信息列表");
  213. ArrayList<Object> cols = new ArrayList<Object>();
  214. cols.add("stcd[监测站编码]");
  215. cols.add("stnm[监测站名称]");
  216. cols.add("adcd[行政区划代码]");
  217. cols.add("adnm[行政区划名称]");
  218. cols.add("sttp[监测站类型]");
  219. cols.add("stlc[监测站位置]");
  220. cols.add("rvnm[监测站所属流域]");
  221. cols.add("mnun[管理单位]");
  222. cols.add("esstym[设站日期]");
  223. export.setCols(cols);
  224. export.setGroupable(false);
  225. // 设置视图指标
  226. export.setLevel(1);
  227. export.setLocksize(0);
  228. try {
  229. export.Export(response);
  230. export.ExportHeadForCustom(response);//导出表头
  231. export.ContinueExport(mapList);
  232. export.EndExport();
  233. } catch (Exception e) {
  234. e.printStackTrace();
  235. }
  236. }
  237. public void transferGeo(AttGrwBaseCrrct p, String src) throws Exception {
  238. if (StringUtils.isNotBlank(src)) {
  239. if (RequestSourceEnum.PC.getValue().equalsIgnoreCase(src)) {
  240. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  241. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  242. p.setLgtd(map.get("lon"));
  243. p.setLttd(map.get("lat"));
  244. }
  245. } else if (RequestSourceEnum.MOBILE.getValue().equalsIgnoreCase(src)) {
  246. if (p.getLgtd() != null && p.getLttd() != null) {
  247. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  248. p.setLgtdPc(map.get("lon"));
  249. p.setLttdPc(map.get("lat"));
  250. }
  251. }
  252. } else {
  253. if (p.getLgtdPc() != null && p.getLttdPc() != null) {
  254. Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
  255. p.setLgtd(map.get("lon"));
  256. p.setLttd(map.get("lat"));
  257. } else if (p.getLgtd() != null && p.getLttd() != null) {
  258. Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
  259. p.setLgtdPc(map.get("lon"));
  260. p.setLttdPc(map.get("lat"));
  261. }
  262. }
  263. }
  264. }