| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package cn.com.goldenwater.dcproj.service.impl.grw;
- import cn.com.goldenwater.dcproj.dao.AttGrwBaseCrrctDao;
- import cn.com.goldenwater.dcproj.enums.RequestSourceEnum;
- import cn.com.goldenwater.dcproj.model.AttGrwBase;
- import cn.com.goldenwater.dcproj.model.AttGrwBaseCrrct;
- import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrctParam;
- import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrtParam;
- import cn.com.goldenwater.dcproj.service.AttGrwBaseCrrctService;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.utils.DateUtils;
- import cn.com.goldenwater.dcproj.utils.GeoUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.goldenwater.id.util.UuidUtil;
- import org.apache.commons.lang3.StringUtils;
- import java.util.Map;
- /**
- * @author gaobowen
- * @date 2019-4-8
- */
- @Service
- @Transactional(rollbackFor = Exception.class)
- public class AttGrwBaseCrrctServiceImpl extends AbstractCrudService<AttGrwBaseCrrct, AttGrwBaseCrrctParam> implements AttGrwBaseCrrctService {
- @Autowired
- private AttGrwBaseCrrctDao attGrwBaseCrrctDao;
- public AttGrwBaseCrrctServiceImpl(AttGrwBaseCrrctDao attGrwBaseCrrctDao) {
- super(attGrwBaseCrrctDao);
- this.attGrwBaseCrrctDao = attGrwBaseCrrctDao;
- }
- @Override
- public AttGrwBaseCrrct add(AttGrwBaseCrrct p) throws Exception {
- String now = DateUtils.getTodayYMDHMS();
- p.setIntm(now);
- p.setUptm(now);
- if (StringUtils.isBlank(p.getStcd())) {
- throw new Exception("测站编码不能为空");
- }
- String uuid = UuidUtil.uuid();
- p.setCrrctId(uuid);
- p.setChkState("0");
- transferGeo(p, p.getSrc());
- int ret = attGrwBaseCrrctDao.insert(p);
- if (ret != -2147482646) {
- throw new Exception("插入失败");
- }
- AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(p.getStcd());
- return attGrwBaseCrrct;
- }
- private void transferGeo(AttGrwBaseCrrct p, String src) throws Exception {
- if (StringUtils.isNotBlank(src)) {
- if (RequestSourceEnum.PC.getValue().equalsIgnoreCase(src)) {
- if (p.getLgtdPc() != null && p.getLttdPc() != null) {
- Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
- p.setLgtd(map.get("lon"));
- p.setLttd(map.get("lat"));
- }
- } else if (RequestSourceEnum.MOBILE.getValue().equalsIgnoreCase(src)) {
- if (p.getLgtd() != null && p.getLttd() != null) {
- Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
- p.setLgtdPc(map.get("lon"));
- p.setLttdPc(map.get("lat"));
- }
- }
- } else {
- if (p.getLgtdPc() != null && p.getLttdPc() != null) {
- Map<String, Double> map = GeoUtil.wgs84togcj02(p.getLgtdPc(), p.getLttdPc());
- p.setLgtd(map.get("lon"));
- p.setLttd(map.get("lat"));
- } else if (p.getLgtd() != null && p.getLttd() != null) {
- Map<String, Double> map = GeoUtil.gcj02towgs84(p.getLgtd(), p.getLttd());
- p.setLgtdPc(map.get("lon"));
- p.setLttdPc(map.get("lat"));
- }
- }
- }
- /*@Override
- public AttGrwBaseCrrct modify(AttGrwBaseCrrct p) throws Exception {
- if(StringUtils.isBlank(p.getGuid())){
- throw new Exception("id 不能为空!");
- }
- AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(p.getGuid());
- if(attGrwBaseCrrct == null){
- throw new Exception("该记录不存在,请刷新页面重试!");
- }
- String now = DateUtils.getTodayYMDHMS();
- p.setUpdateTime(now);
- int ret = attGrwBaseCrrctDao.update(p);
- if(ret!= -2147482646){
- throw new Exception("更新失败");
- }
- AttGrwBaseCrrct bean = attGrwBaseCrrctDao.get(p.getId());
- return bean;
- }*/
- /* @Override
- public void remove(String id) throws Exception {
- if(StringUtils.isBlank(id)){
- throw new Exception("id 不能为空!");
- }
- AttGrwBaseCrrct attGrwBaseCrrct = attGrwBaseCrrctDao.get(id);
- if(attGrwBaseCrrct == null){
- throw new Exception("该记录不存在,请刷新页面重试");
- }
- int ret = attGrwBaseCrrctDao.delete(id);
- if(ret!= -2147482646){
- throw new Exception("删除失败");
- }
- }*/
- }
|