package cn.com.goldenwater.dcproj.service.impl.wr; import cn.com.goldenwater.dcproj.dao.WrSwsBDao; import cn.com.goldenwater.dcproj.model.WrSwsB; import cn.com.goldenwater.dcproj.param.WrSwsBParam; import cn.com.goldenwater.dcproj.service.WrSwsBService; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.utils.BeanUtil; 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 org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.github.pagehelper.PageInfo; import java.util.ArrayList; import java.util.List; import java.util.Map; import cn.com.goldenwater.dcproj.utils.DateUtils; import javax.servlet.http.HttpServletResponse; /** * @author zhengdafei * @date 2019-3-3 */ @Service @Transactional public class WrSwsBServiceImpl extends AbstractCrudService implements WrSwsBService { @Autowired private WrSwsBDao wrSwsBDao; public WrSwsBServiceImpl(WrSwsBDao wrSwsBDao) { super(wrSwsBDao); this.wrSwsBDao = wrSwsBDao; } @Override public String add(WrSwsB p) throws Exception { String uuid = ""; String now = DateUtils.getTodayYMDHMS(); if (StringUtils.isNotBlank(p.getAdCode())) { String maxCwsCode = wrSwsBDao.getMaxCwsCode(p.getAdCode().substring(0, 6)); //根据最大code生成cwscode if (maxCwsCode != null) { Long mCcode = 0L; if (maxCwsCode == null) { mCcode = NumberUtils.createLong(p.getAdCode()); Long gwsCode = mCcode + 1; p.setSwsCd(gwsCode + ""); } else { mCcode = NumberUtils.createLong(maxCwsCode); Long gwsCode = mCcode + 1; p.setSwsCd(gwsCode + ""); } } } else { throw new Exception("adCode不能为空"); } transferGeo(p); p.setTs(now); wrSwsBDao.insert(p); uuid = p.getSwsCd(); return uuid; } @Override public int modify(WrSwsB p) throws Exception { String now = DateUtils.getTodayYMDHMS(); p.setTs(now); transferGeo(p); int ret = wrSwsBDao.update(p); return ret; } public void transferGeo(WrSwsB p) { String src = p.getSrc(); if (StringUtils.isNotBlank(src)) { if ("PC".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 ("MOBILE".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 PageInfo queryListByPage(WrSwsBParam p) throws Exception { PageHelper.startPage(p.getPageNum(), p.getPageSize()); List list = wrSwsBDao.findList(p); return new PageInfo(list); } @Override public List queryList(WrSwsBParam p) throws Exception { List list = wrSwsBDao.findList(p); return list; } @Override public void exportWrSwsB(WrSwsBParam wrSwsBParam, HttpServletResponse response) { List list=new ArrayList<>(); list=wrSwsBDao.findList(wrSwsBParam); List> mapList = new ArrayList<>(); for (WrSwsB wrSwsB : list) { String swsTp=wrSwsB.getSwsTp(); String wqGoal=wrSwsB.getWqGoal(); String consCond=wrSwsB.getConsCond(); String wsCond=wrSwsB.getWsCond(); String monG=wrSwsB.getMonG(); if("1".equals(swsTp)){ wrSwsB.setSwsTp("河道(江河)"); }else if ("2".equals(swsTp)){ wrSwsB.setSwsTp("水库"); }else if ("3".equals(swsTp)){ wrSwsB.setSwsTp("湖泊"); }else if ("9".equals(swsTp)){ wrSwsB.setSwsTp("其他"); } if ("1".equals(wqGoal)){ wrSwsB.setWqGoal("Ⅰ类"); }else if ("2".equals(wqGoal)){ wrSwsB.setWqGoal("Ⅱ类"); }else if ("3".equals(wqGoal)){ wrSwsB.setWqGoal("Ⅲ类"); }else if ("4".equals(wqGoal)){ wrSwsB.setWqGoal("Ⅳ类"); }else if ("5".equals(wqGoal)){ wrSwsB.setWqGoal("Ⅴ类"); }else if ("6".equals(wqGoal)){ wrSwsB.setWqGoal("劣Ⅴ类"); }else if ("12".equals(wqGoal)){ wrSwsB.setWqGoal("I-II类"); }else if ("13".equals(wqGoal)){ wrSwsB.setWqGoal("I-III类"); }else if ("14".equals(wqGoal)){ wrSwsB.setWqGoal("I-IV类"); }else if ("15".equals(wqGoal)){ wrSwsB.setWqGoal("I-V类"); }else if ("16".equals(wqGoal)){ wrSwsB.setWqGoal("I-劣Ⅴ类"); }else if ("23".equals(wqGoal)){ wrSwsB.setWqGoal("II-III类"); }else if ("24".equals(wqGoal)){ wrSwsB.setWqGoal("II-IV类"); }else if ("25".equals(wqGoal)){ wrSwsB.setWqGoal("II-V类"); }else if ("26".equals(wqGoal)){ wrSwsB.setWqGoal("II-劣V类"); }else if ("34".equals(wqGoal)){ wrSwsB.setWqGoal("III-IV类"); }else if ("35".equals(wqGoal)){ wrSwsB.setWqGoal("III-V类"); }else if ("36".equals(wqGoal)){ wrSwsB.setWqGoal("III-劣Ⅴ类"); }else if ("45".equals(wqGoal)){ wrSwsB.setWqGoal("IV-V类"); }else if ("46".equals(wqGoal)){ wrSwsB.setWqGoal("IV-劣V类"); }else if ("56".equals(wqGoal)){ wrSwsB.setWqGoal("V-劣V类"); } if ("1".equals(consCond)){ wrSwsB.setConsCond("已建"); }else if ("2".equals(consCond)){ wrSwsB.setConsCond("在建"); }else if ("3".equals(consCond)){ wrSwsB.setConsCond("待建"); } if ("1".equals(wsCond)){ wrSwsB.setWsCond("常年"); }else if ("2".equals(wsCond)){ wrSwsB.setWsCond("汛期"); }else if ("3".equals(wsCond)){ wrSwsB.setWsCond("非汛期"); } if ("0".equals(monG)||"9".equals(monG)){ wrSwsB.setMonG("其他"); }else if ("1".equals(monG)){ wrSwsB.setMonG("国控级"); }else if ("2".equals(monG)){ wrSwsB.setMonG("省控级"); }else if ("3".equals(monG)){ wrSwsB.setMonG("地市级"); } mapList.add(BeanUtil.transBean2Map(wrSwsB)); } 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("swsCd[地表水水源地代码]"); cols.add("swsNm[地表水水源地名称]"); cols.add("swsTp[地表水水源地类型]"); cols.add("watA[水面面积(平方公里)]"); cols.add("wqGoal[水质目标]"); cols.add("consCond[建设状况]"); cols.add("putProdTm[投产时间]"); cols.add("runCond[运行状况]"); cols.add("wsCond[水源供水持续状况]"); cols.add("wsObj[供水对象]"); cols.add("dywsPp[设计年供水人口(万人)]"); cols.add("dywsW[设计年供水量(万立方米)]"); cols.add("whsManCd[水源地管理单位代码]"); cols.add("whsApprCd[水源地审批单位代码]"); cols.add("emCd[应急管理单位代码]"); cols.add("monG[监控级别]"); cols.add("ts[时间戳]"); cols.add("nt[备注]"); 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(); } } }