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 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 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 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 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 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("删除失败"); } }*/ }