package cn.com.goldenwater.dcproj.service.impl.base; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.AttAdXBaseDao; import cn.com.goldenwater.dcproj.dao.BisInspSecsurveyVlgDao; import cn.com.goldenwater.dcproj.dto.AttAdXTownDto; import cn.com.goldenwater.dcproj.dto.AttAdXVillageDto; import cn.com.goldenwater.dcproj.dto.BisNewDcuserRelVillDto; import cn.com.goldenwater.dcproj.model.AttAdXBase; import cn.com.goldenwater.dcproj.model.AttAdXBaseNode; import cn.com.goldenwater.dcproj.model.BisZhejiangDcuserRelVill; import cn.com.goldenwater.dcproj.model.TCListBean; import cn.com.goldenwater.dcproj.param.AttAdXBaseParam; import cn.com.goldenwater.dcproj.param.AttCwsBaseListParam; import cn.com.goldenwater.dcproj.param.AttCwsBaseListParamNew; import cn.com.goldenwater.dcproj.param.QueryTCListParam; import cn.com.goldenwater.dcproj.service.AttAdXBaseService; import cn.com.goldenwater.dcproj.utils.AMapUtil; 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 cn.com.goldenwater.id.util.UuidUtil; import cn.com.goldenwater.util.common.SqlUtils; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; 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 javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author zhengdafei * @date 2019-2-22 */ @Service @Transactional(rollbackFor = Exception.class) public class AttAdXBaseServiceImpl extends AbstractCrudService implements AttAdXBaseService { @Autowired private AttAdXBaseDao attAdXBaseDao; @Autowired private BisInspSecsurveyVlgDao bisInspSecsurveyVlgDao; public AttAdXBaseServiceImpl(AttAdXBaseDao attAdXBaseDao) { super(attAdXBaseDao); this.attAdXBaseDao = attAdXBaseDao; } @Override public AttAdXBase add(AttAdXBase p) throws Exception { String uuid = UuidUtil.uuid(); String now = DateUtils.getTodayYMDHMS(); p.setEffDate(now); p.setUpdDate(now); p.setGuid(uuid); p.setAdSign("1"); p.setIsReport("0"); String type = "village"; if (StringUtils.isNotBlank(p.getAdFcode())) { String maxAdCode = attAdXBaseDao.getMaxVillageCode(p.getAdFcode()); //根据最大code生成adcode Long step = 1L; if (p.getAdFcode().indexOf("000000") > -1) { //新增乡镇 step = 1000L; type = "town"; } // if(maxAdCode!=null){ Long mCcode = 0L; if (maxAdCode == null) { mCcode = NumberUtils.createLong(p.getAdFcode()); Long cwsCode = mCcode + step; p.setAdCode(cwsCode + ""); } else { mCcode = NumberUtils.createLong(maxAdCode); Long cwsCode = mCcode + step; p.setAdCode(cwsCode + ""); } // } AttAdXBaseParam ap = new AttAdXBaseParam(); ap.setAdCode(p.getAdFcode()); AttAdXBase upAd = attAdXBaseDao.getBy(ap); if (upAd != null) { p.setUpAdName(upAd.getAdName()); p.setAdFullName(upAd.getAdFullName() + "-" + p.getAdName()); } } if ("village".equals(type)) { transferGeo(p); } attAdXBaseDao.insert(p); return p; } @Override public int modify(AttAdXBase p) throws Exception { String now = DateUtils.getTodayYMDHMS(); p.setUpdDate(now); transferGeo(p); int ret = attAdXBaseDao.update(p); return ret; } public void transferGeo(AttAdXBase 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(AttAdXBaseParam p) throws Exception { PageHelper.startPage(p.getPageNum(), p.getPageSize()); List list = attAdXBaseDao.findList(p); return new PageInfo(list); } @Override public List queryList(AttAdXBaseParam p) throws Exception { List list = attAdXBaseDao.findList(p); return list; } @Override public PageInfo queryTCList(AttCwsBaseListParam param) throws Exception { AttAdXBaseParam p = new AttAdXBaseParam(); p.setAdFcode(param.getObjId()); Page page = PageHelper.startPage(param.getPageNum(), param.getPageSize()); List townList = attAdXBaseDao.findList(p); List townDtoList = new ArrayList<>(); for (AttAdXBase town : townList) { AttAdXTownDto townDto = new AttAdXTownDto(); townDto.setTownName(town.getAdName()); townDto.setTownCode(town.getAdCode()); townDto.setTownFullName(town.getAdFullName()); townDto.setGuid(town.getGuid()); AttAdXBaseParam p1 = new AttAdXBaseParam(); p1.setAdFcode(town.getAdCode()); p1.setIsPoveryt(param.getIsPoverty()); p1.setAdName(param.getName()); List villList = attAdXBaseDao.findList(p1); List villDtoList = new ArrayList<>(); for (AttAdXBase vill : villList) { AttAdXVillageDto villageDto = new AttAdXVillageDto(); villageDto.setVillageCode(vill.getAdCode()); villageDto.setVillageName(vill.getAdName()); villageDto.setVillageFullName(vill.getAdFullName()); villageDto.setLgtd(vill.getLgtd()); villageDto.setLttd(vill.getLttd()); villageDto.setLgtdpc(vill.getLttdpc()); villageDto.setIsPoverty(vill.getIsPoveryt()); villageDto.setLttdpc(vill.getLttdpc()); villageDto.setStatus(checkVillageStatus(param.getEngId(), vill.getAdCode())); villageDto.setGuid(vill.getGuid()); villDtoList.add(villageDto); } townDto.setList(villDtoList); townDtoList.add(townDto); } PageInfo pageInfo = new PageInfo(townDtoList); pageInfo.setTotal(page.getTotal()); pageInfo.setPages(page.getPages()); return pageInfo; } @Override public List queryTCListLast(QueryTCListParam param) throws Exception { List list = attAdXBaseDao.queryTCListLast(param); List townDtoList = new ArrayList<>(); List townCodes = new ArrayList<>(); for (TCListBean bean : list) { if (!townCodes.contains(bean.getTownCode())) { townCodes.add(bean.getTownCode()); AttAdXTownDto dto = new AttAdXTownDto(); dto.setGuid(bean.getTownId()); dto.setTownCode(bean.getTownCode()); dto.setTownName(bean.getTownName()); townDtoList.add(dto); } } for (AttAdXTownDto dto : townDtoList) { List villDtoList = new ArrayList<>(); for (TCListBean bean : list) { if (dto.getTownCode().equals(bean.getTownCode())) { AttAdXVillageDto villDto = new AttAdXVillageDto(); villDto.setIsPoverty(bean.getIsPoveryt()); villDto.setGuid(bean.getVillId()); villDto.setVillageName(bean.getVillName()); villDto.setVillageCode(bean.getVillCode()); villDto.setStatus(bean.getStatus()); villDto.setLgtd(bean.getLgtd()); villDto.setLttd(bean.getLttd()); villDto.setLgtdpc(bean.getLgtdpc()); villDto.setLttdpc(bean.getLttdpc()); villDtoList.add(villDto); } } dto.setList(villDtoList); } return townDtoList; } @Override public PageInfo queryTCList(AttCwsBaseListParamNew param) throws Exception { AttAdXBaseParam p = new AttAdXBaseParam(); p.setAdFcode(param.getObjId()); Page page = PageHelper.startPage(param.getPageNum(), param.getPageSize()); List townList = attAdXBaseDao.findList(p); List townDtoList = new ArrayList<>(); for (AttAdXBase town : townList) { AttAdXTownDto townDto = new AttAdXTownDto(); townDto.setTownName(town.getAdName()); townDto.setTownCode(town.getAdCode()); townDto.setTownFullName(town.getAdFullName()); townDto.setGuid(town.getGuid()); AttAdXBaseParam p1 = new AttAdXBaseParam(); p1.setAdFcode(town.getAdCode()); p1.setIsPoveryt(param.getIsPoverty()); p1.setAdName(param.getName()); List villList = attAdXBaseDao.findList(p1); List villDtoList = new ArrayList<>(); for (AttAdXBase vill : villList) { AttAdXVillageDto villageDto = new AttAdXVillageDto(); villageDto.setVillageCode(vill.getAdCode()); villageDto.setVillageName(vill.getAdName()); villageDto.setVillageFullName(vill.getAdFullName()); villageDto.setLgtd(vill.getLgtd()); villageDto.setLttd(vill.getLttd()); villageDto.setLgtdpc(vill.getLttdpc()); villageDto.setIsPoverty(vill.getIsPoveryt()); villageDto.setLttdpc(vill.getLttdpc()); villageDto.setStatus(checkVillageStatus(param.getEngId(), vill.getAdCode())); villageDto.setGuid(vill.getGuid()); villDtoList.add(villageDto); } townDto.setList(villDtoList); townDtoList.add(townDto); } PageInfo pageInfo = new PageInfo(townDtoList); pageInfo.setTotal(page.getTotal()); pageInfo.setPages(page.getPages()); return pageInfo; } public int checkVillageStatus(String engId, String villageCode) { int status = 0; status = bisInspSecsurveyVlgDao.checkVillageStatus(engId, villageCode); if (status > 0) { status = 1; } return status; } /** * 获取行政区划数据列表 * * @param attAdXBaseParam * @return */ @Override public List getTableList(AttAdXBaseParam attAdXBaseParam) throws Exception { return attAdXBaseDao.getTableList(attAdXBaseParam); } @Override public PageInfo getTableListByPage(AttAdXBaseParam attAdXBaseParam) throws Exception { PageHelper.startPage(attAdXBaseParam.getPageNum(), attAdXBaseParam.getPageSize()); List list = attAdXBaseDao.getTableList(attAdXBaseParam); return new PageInfo(list); } @Override public List getTargetAdByNodeId(String nodeIds, String persGuid, String province) { //按逗号切割字符串 if (StringUtils.isNotBlank(nodeIds)) { String[] nodes = nodeIds.split(","); if (null != nodes && 0 < nodes.length) { //查询 return attAdXBaseDao.getTargetAdByNodeId(nodes, persGuid, SqlUtils.getinIdsSql(persGuid, province)); } } else { return attAdXBaseDao.getTargetAdByNodeId(null, persGuid, SqlUtils.getinIdsSql(persGuid, province)); } return null; } @Override public AttAdXBaseNode getAdTreeByAdCd(String adCd, String level) { AttAdXBaseNode adXBaseNode = new AttAdXBaseNode(); AttAdXBase attAdXBase = attAdXBaseDao.get(adCd); if (attAdXBase != null) { adXBaseNode.setId(adCd); adXBaseNode.setNm(attAdXBase.getAdName()); adXBaseNode.setPid(attAdXBase.getAdFcode()); String grad = attAdXBase.getAdGrad(); int num = 0; if (StringUtils.isNotBlank(level)) { num = Integer.parseInt(level); } if (StringUtils.isNotBlank(grad)) { num += Integer.parseInt(grad); } List list = attAdXBaseDao.getAllNodeByPid(adCd, num); list = packNodes(list, adCd); adXBaseNode.setChildren(list); } return adXBaseNode; } @Override public List getAdTreeByAdCdS(String adCdS, String level) { List list = attAdXBaseDao.getAllNodeByPids(adCdS, level); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { List list1 = attAdXBaseDao.getAllNodeByIds(list.get(i).getId()); list.get(i).setChildren(list1); } } return list; } @Override public void exportAdXBase(AttAdXBaseParam attAdXBaseParam, HttpServletResponse response) { List list = attAdXBaseDao.findList(attAdXBaseParam); List> mapList = new ArrayList<>(); for (AttAdXBase attAdXBase : list) { String isPoveryt = attAdXBase.getIsPoveryt(); String adGrad = attAdXBase.getAdGrad(); if ("1".equals(isPoveryt)) { attAdXBase.setIsPoveryt("是"); } else { attAdXBase.setIsPoveryt("否"); } if ("1".equals(adGrad)) { attAdXBase.setAdGrad("中国"); } else if ("2".equals(adGrad)) { attAdXBase.setAdGrad("省级"); } else if ("3".equals(adGrad)) { attAdXBase.setAdGrad("地市级"); } else if ("4".equals(adGrad)) { attAdXBase.setAdGrad("县级"); } else if ("5".equals(adGrad)) { attAdXBase.setAdGrad("乡级"); } else if ("6".equals(adGrad)) { attAdXBase.setAdGrad("村"); } mapList.add(BeanUtil.transBean2Map(attAdXBase)); } 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("adCode[行政区划编码]"); cols.add("adName[行政区划名称]"); cols.add("adGrad[行政区划等级]"); cols.add("adFullName[行政区划全称]"); cols.add("adFcode[上级行政区划编码]"); cols.add("upAdName[上级行政区划名称]"); cols.add("isPoveryt[是否贫困]"); 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(); } } @Override public List findZhenList(String code, String rgstrId, String type) { List AllList = attAdXBaseDao.findCunList(code, rgstrId, type); List zhenList = new ArrayList<>(); for (BisZhejiangDcuserRelVill bisZhejiangDcuserRelVill : AllList) { String townName = bisZhejiangDcuserRelVill.getTownName(); if (!zhenList.contains(townName)) { zhenList.add(townName); } } List dcuserRelVillDtos = new ArrayList<>(); for (String s : zhenList) { BisNewDcuserRelVillDto dcuserRelVillDto = new BisNewDcuserRelVillDto(); List cunList = new ArrayList<>(); String townCode = ""; for (BisZhejiangDcuserRelVill bisZhejiangDcuserRelVill : AllList) { if (s.equals(bisZhejiangDcuserRelVill.getTownName())) { cunList.add(bisZhejiangDcuserRelVill); townCode = bisZhejiangDcuserRelVill.getAdCode(); townCode = townCode.substring(0, townCode.length() - 3); if (StringUtils.isBlank(bisZhejiangDcuserRelVill.getVillageNm()) && StringUtils.isNotBlank(bisZhejiangDcuserRelVill.getAdName())) { bisZhejiangDcuserRelVill.setVillageNm(bisZhejiangDcuserRelVill.getAdName()); } if (StringUtils.isNotBlank(bisZhejiangDcuserRelVill.getRegstrId())) { bisZhejiangDcuserRelVill.setRgstrId(bisZhejiangDcuserRelVill.getRegstrId()); } if (StringUtils.isNotBlank(bisZhejiangDcuserRelVill.getRgstrId())) { bisZhejiangDcuserRelVill.setRegstrId(bisZhejiangDcuserRelVill.getRgstrId()); } } } dcuserRelVillDto.setTownCode(townCode); dcuserRelVillDto.setTownName(s); dcuserRelVillDto.setDcuserRelVilles(cunList); dcuserRelVillDtos.add(dcuserRelVillDto); } return dcuserRelVillDtos; } /** * 对查询的所有结果递归遍历 */ private List packNodes(List prefectureAll, String code) { List nodesList = new ArrayList<>(); for (AttAdXBaseNode prefecture : prefectureAll) { if (code.equals(prefecture.getPid())) { AttAdXBaseNode nodes = new AttAdXBaseNode(); nodes.setId(prefecture.getId()); nodes.setNm(prefecture.getNm()); nodes.setPid(prefecture.getPid()); nodes.setLevel(prefecture.getLevel()); nodes.setChildren(this.packNodes(prefectureAll, prefecture.getId() )); nodesList.add(nodes); } } return nodesList; } /** * 判断村是否处于督查中状态 * * @param adCode * @param engId * @return */ private boolean isDC(String adCode, String engId) { boolean result = false; int num = 0; num = attAdXBaseDao.getDcVillNum(engId, adCode); if (num > 0) { result = true; } return result; } @Override public List getAdData(String adCode) { return this.attAdXBaseDao.getAdData(adCode); } @Override public List getAdDataXj(String adCode) { return this.attAdXBaseDao.getAdDataXj(adCode); } @Override public List getAdDataByAdCode(String adCodes) { return this.attAdXBaseDao.getAdDataByAdCode(adCodes); } @Override public void updateLgtdLttd(String adCode) throws IOException { List attAdXBases = attAdXBaseDao.getAdChild(adCode); for (AttAdXBase attAdXBase : attAdXBases) { String fullName = attAdXBase.getAdFullName(); try { String[] coordinate = new AMapUtil().getCoordinate(fullName); System.out.println(coordinate[0] + " " + coordinate[1]);//0:经度 1:纬度 AttAdXBase attAdXBaseTemp = new AttAdXBase(); attAdXBaseTemp.setGuid(attAdXBase.getGuid()); attAdXBaseTemp.setLgtd(Double.parseDouble(coordinate[0])); attAdXBaseTemp.setLttd(Double.parseDouble(coordinate[1])); attAdXBaseDao.update(attAdXBaseTemp); } catch (Exception ex) { ex.getMessage(); } finally { continue; } } } }