| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- 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<AttAdXBase, AttAdXBaseParam> 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<String, Double> 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<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 PageInfo<AttAdXBase> queryListByPage(AttAdXBaseParam p) throws Exception {
- PageHelper.startPage(p.getPageNum(), p.getPageSize());
- List<AttAdXBase> list = attAdXBaseDao.findList(p);
- return new PageInfo<AttAdXBase>(list);
- }
- @Override
- public List<AttAdXBase> queryList(AttAdXBaseParam p) throws Exception {
- List<AttAdXBase> list = attAdXBaseDao.findList(p);
- return list;
- }
- @Override
- public PageInfo<AttAdXTownDto> queryTCList(AttCwsBaseListParam param) throws Exception {
- AttAdXBaseParam p = new AttAdXBaseParam();
- p.setAdFcode(param.getObjId());
- Page page = PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<AttAdXBase> townList = attAdXBaseDao.findList(p);
- List<AttAdXTownDto> 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<AttAdXBase> villList = attAdXBaseDao.findList(p1);
- List<AttAdXVillageDto> 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<AttAdXTownDto>(townDtoList);
- pageInfo.setTotal(page.getTotal());
- pageInfo.setPages(page.getPages());
- return pageInfo;
- }
- @Override
- public List<AttAdXTownDto> queryTCListLast(QueryTCListParam param) throws Exception {
- List<TCListBean> list = attAdXBaseDao.queryTCListLast(param);
- List<AttAdXTownDto> townDtoList = new ArrayList<>();
- List<String> 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<AttAdXVillageDto> 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<AttAdXTownDto> queryTCList(AttCwsBaseListParamNew param) throws Exception {
- AttAdXBaseParam p = new AttAdXBaseParam();
- p.setAdFcode(param.getObjId());
- Page page = PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<AttAdXBase> townList = attAdXBaseDao.findList(p);
- List<AttAdXTownDto> 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<AttAdXBase> villList = attAdXBaseDao.findList(p1);
- List<AttAdXVillageDto> 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<AttAdXTownDto>(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<AttAdXBase> getTableList(AttAdXBaseParam attAdXBaseParam) throws Exception {
- return attAdXBaseDao.getTableList(attAdXBaseParam);
- }
- @Override
- public PageInfo<AttAdXBase> getTableListByPage(AttAdXBaseParam attAdXBaseParam) throws Exception {
- PageHelper.startPage(attAdXBaseParam.getPageNum(), attAdXBaseParam.getPageSize());
- List<AttAdXBase> list = attAdXBaseDao.getTableList(attAdXBaseParam);
- return new PageInfo<AttAdXBase>(list);
- }
- @Override
- public List<AttAdXBase> 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<AttAdXBaseNode> list = attAdXBaseDao.getAllNodeByPid(adCd, num);
- list = packNodes(list, adCd);
- adXBaseNode.setChildren(list);
- }
- return adXBaseNode;
- }
- @Override
- public List<AttAdXBaseNode> getAdTreeByAdCdS(String adCdS, String level) {
- List<AttAdXBaseNode> list = attAdXBaseDao.getAllNodeByPids(adCdS, level);
- if (list != null && list.size() > 0) {
- for (int i = 0; i < list.size(); i++) {
- List<AttAdXBaseNode> list1 = attAdXBaseDao.getAllNodeByIds(list.get(i).getId());
- list.get(i).setChildren(list1);
- }
- }
- return list;
- }
- @Override
- public void exportAdXBase(AttAdXBaseParam attAdXBaseParam, HttpServletResponse response) {
- List<AttAdXBase> list = attAdXBaseDao.findList(attAdXBaseParam);
- List<Map<String, Object>> 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<Object> cols = new ArrayList<Object>();
- 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<BisNewDcuserRelVillDto> findZhenList(String code, String rgstrId, String type) {
- List<BisZhejiangDcuserRelVill> AllList = attAdXBaseDao.findCunList(code, rgstrId, type);
- List<String> zhenList = new ArrayList<>();
- for (BisZhejiangDcuserRelVill bisZhejiangDcuserRelVill : AllList) {
- String townName = bisZhejiangDcuserRelVill.getTownName();
- if (!zhenList.contains(townName)) {
- zhenList.add(townName);
- }
- }
- List<BisNewDcuserRelVillDto> dcuserRelVillDtos = new ArrayList<>();
- for (String s : zhenList) {
- BisNewDcuserRelVillDto dcuserRelVillDto = new BisNewDcuserRelVillDto();
- List<BisZhejiangDcuserRelVill> 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<AttAdXBaseNode> packNodes(List<AttAdXBaseNode> prefectureAll, String code) {
- List<AttAdXBaseNode> 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<AttAdXBase> getAdData(String adCode) {
- return this.attAdXBaseDao.getAdData(adCode);
- }
- @Override
- public List<AttAdXBase> getAdDataXj(String adCode) {
- return this.attAdXBaseDao.getAdDataXj(adCode);
- }
- @Override
- public List<AttAdXBase> getAdDataByAdCode(String adCodes) {
- return this.attAdXBaseDao.getAdDataByAdCode(adCodes);
- }
- @Override
- public void updateLgtdLttd(String adCode) throws IOException {
- List<AttAdXBase> 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;
- }
- }
- }
- }
|