package cn.com.goldenwater.dcproj.service.impl.grw; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.AttGrwBaseCrrctDao; import cn.com.goldenwater.dcproj.dao.AttGrwBaseDao; import cn.com.goldenwater.dcproj.dao.BisInspGrwDao; import cn.com.goldenwater.dcproj.enums.GrwSttpBaseEnum; import cn.com.goldenwater.dcproj.enums.GrwSttpEnum; import cn.com.goldenwater.dcproj.enums.RequestSourceEnum; import cn.com.goldenwater.dcproj.enums.SqlExecuteStateEnum; import cn.com.goldenwater.dcproj.model.AttGrwBase; import cn.com.goldenwater.dcproj.model.AttGrwBaseCrrct; import cn.com.goldenwater.dcproj.model.BisInspGrw; import cn.com.goldenwater.dcproj.param.AttGrwBaseCrrtParam; import cn.com.goldenwater.dcproj.param.AttGrwBaseParam; import cn.com.goldenwater.dcproj.param.AttGrwListByParam; import cn.com.goldenwater.dcproj.service.AttGrwBaseCrrctService; import cn.com.goldenwater.dcproj.service.AttGrwBaseService; import cn.com.goldenwater.dcproj.utils.BeanUtil; import cn.com.goldenwater.dcproj.utils.DateUtils; import cn.com.goldenwater.dcproj.utils.GeoUtil; import cn.com.goldenwater.dcproj.utils.expExcel.ExcelExport; import cn.com.goldenwater.dcproj.utils.expExcel.ExportAbstract; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author zhengdafei * @date 2019-3-30 */ @Service @Transactional(rollbackFor = Exception.class) public class AttGrwBaseServiceImpl extends AbstractCrudService implements AttGrwBaseService { @Autowired private AttGrwBaseDao attGrwBaseDao; @Autowired private BisInspGrwDao bisInspGrwDao; @Autowired AttGrwBaseCrrctDao attGrwBaseCrrctDao; @Autowired AttGrwBaseCrrctService attGrwBaseCrrctService; public AttGrwBaseServiceImpl(AttGrwBaseDao attGrwBaseDao) { super(attGrwBaseDao); this.attGrwBaseDao = attGrwBaseDao; } @Override public AttGrwBase add(AttGrwBase p) throws Exception { String now = DateUtils.getTodayYMDHMS(); p.setIntm(now); if (StringUtils.isBlank(p.getStcd())) { throw new Exception("测站编码不能为空"); } AttGrwBase one = attGrwBaseDao.get(p.getStcd()); if (one != null) { throw new Exception("该测站编码已存在"); } int ret = attGrwBaseDao.insert(p); if (ret != SqlExecuteStateEnum.SUCCESS.getValue()) { throw new Exception("插入失败"); } AttGrwBase attGrwBase = attGrwBaseDao.get(p.getStcd()); return attGrwBase; } @Override public AttGrwBase modify(AttGrwBase p) throws Exception { if (StringUtils.isBlank(p.getStcd())) { throw new Exception("测站编码 不能为空!"); } AttGrwBase attGrwBase = attGrwBaseDao.get(p.getStcd()); if (attGrwBase == null) { throw new Exception("该记录不存在,请刷新页面重试!"); } int ret = attGrwBaseDao.update(p); if (ret != -2147482646) { throw new Exception("更新失败"); } AttGrwBase bean = attGrwBaseDao.get(p.getStcd()); return bean; } @Override public void remove(String id) throws Exception { if (StringUtils.isBlank(id)) { throw new Exception("测站编码 不能为空!"); } AttGrwBase attGrwBase = attGrwBaseDao.get(id); if (attGrwBase == null) { throw new Exception("该记录不存在,请刷新页面重试"); } int ret = attGrwBaseDao.delete(id); if (ret != -2147482646) { throw new Exception("删除失败"); } } @Override public PageInfo getListBy(AttGrwListByParam param) throws Exception { if ("NAT".equals(param.getSttp()) || GrwSttpEnum.NATIONAL.getValue().equals(param.getSttp())) { param.setSttp2("1"); } else if (GrwSttpEnum.PROV.getValue().equals(param.getSttp()) || "PRO".equals(param.getSttp())) { param.setSttp2("5"); } PageHelper.startPage(param); List list = attGrwBaseDao.getListBy(param); for (AttGrwBase att : list) { if (GrwSttpBaseEnum.NATIONAL.getValue().equals(att.getSttp())) { att.setSttp(GrwSttpEnum.NATIONAL.getValue()); } else if (GrwSttpBaseEnum.PROV.getValue().equals(att.getSttp())) { att.setSttp(GrwSttpEnum.PROV.getValue()); } att.setSttpNm(GrwSttpEnum.getName(att.getSttp())); } return new PageInfo(list); } @Override public AttGrwBase crrctBase(AttGrwBaseCrrtParam p) throws Exception { AttGrwBase attGrwBase = new AttGrwBase(); if (StringUtils.isBlank(p.getStcd())) { throw new Exception("测站编码 不能为空!"); } if (StringUtils.isBlank(p.getStlc())) { throw new Exception("测站位置 不能为空!"); } if (StringUtils.isBlank(p.getSrc())) { throw new Exception("数据来源 不能为空!"); } attGrwBase.setStcd(p.getStcd()); attGrwBase.setStlc(p.getStlc()); attGrwBase.setLgtd(p.getLgtd()); attGrwBase.setLttd(p.getLttd()); attGrwBase.setLgtdPc(p.getLgtdpc()); attGrwBase.setLttdPc(p.getLttdpc()); transferGeo(attGrwBase, p.getSrc()); String now = DateUtils.getTodayYMDHMS(); AttGrwBaseCrrct attGrwBaseCrrct = new AttGrwBaseCrrct(); attGrwBaseCrrct.setStcd(p.getStcd()); attGrwBaseCrrct.setStlc(p.getStlc()); attGrwBaseCrrct.setLgtd(p.getLgtd()); attGrwBaseCrrct.setLttd(p.getLttd()); attGrwBaseCrrct.setLgtdPc(p.getLgtdpc()); attGrwBaseCrrct.setLttdPc(p.getLttdpc()); attGrwBaseCrrct.setEdtrPesr(p.getCheckPid()); attGrwBaseCrrct.setSrc(p.getSrc()); attGrwBaseCrrctService.add(attGrwBaseCrrct); AttGrwBase one = modify(attGrwBase); BisInspGrw grw = new BisInspGrw(); grw.setStcd(p.getStcd()); grw.setStlc(p.getStlc()); grw.setCheckPid(p.getCheckPid()); grw.setCheckPname(p.getCheckPname()); grw.setUpTm(now); int ret = bisInspGrwDao.updateByStcd(grw); if (ret != -2147482646) { throw new Exception("更新登记表失败"); } return one; } @Override public void transferGeo(AttGrwBase p, String src) { 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 void exportAttGrwBase(AttGrwBaseParam attAdXBaseParam, HttpServletResponse response) { List list = attGrwBaseDao.findList(attAdXBaseParam); List> mapList = new ArrayList<>(); for (AttGrwBase attGrwBase : list) { String sttp = attGrwBase.getSttp(); if ("NATIONAL".equals(sttp)) { attGrwBase.setSttp("国家级"); } else if ("PROVAUTO".equals(sttp)) { attGrwBase.setSttp("省级自动"); } else if ("PROV".equals(sttp)) { attGrwBase.setSttp("省级监测站(未知手动自动)"); } else if ("PROVHAND".equals(sttp)) { attGrwBase.setSttp("省级人工"); } mapList.add(BeanUtil.transBean2Map(attGrwBase)); } ExportAbstract export = new ExcelExport(); export.setFileName("地下水监测站基础信息列表"); export.setExport_ps_export(true); export.setExport_ps_type(ExportAbstract.XLS); export.setExport_bzip(false); export.setTitle("地下水监测站基础信息列表"); ArrayList cols = new ArrayList(); cols.add("stcd[监测站编码]"); cols.add("stnm[监测站名称]"); cols.add("adcd[行政区划代码]"); cols.add("adnm[行政区划名称]"); cols.add("sttp[监测站类型]"); cols.add("stlc[监测站位置]"); cols.add("rvnm[监测站所属流域]"); cols.add("mnun[管理单位]"); cols.add("esstym[设站日期]"); export.setCols(cols); export.setGroupable(false); // 设置视图指标 export.setLevel(1); export.setLocksize(0); try { export.Export(response); export.ExportHeadForCustom(response);//导出表头 export.ContinueExport(mapList); export.EndExport(); } catch (Exception e) { e.printStackTrace(); } } public 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")); } } } }