package cn.com.goldenwater.dcproj.service.impl.ducha; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.AttAdXBaseDao; import cn.com.goldenwater.dcproj.dao.BisInspSelAreaDao; import cn.com.goldenwater.dcproj.model.AttAdXBase; import cn.com.goldenwater.dcproj.model.AttRsBase; import cn.com.goldenwater.dcproj.model.BisInspSelArea; import cn.com.goldenwater.dcproj.param.BisInspSelAreaParam; import cn.com.goldenwater.dcproj.param.InGroupResParam; import cn.com.goldenwater.dcproj.param.PagePersObjParam; import cn.com.goldenwater.dcproj.service.BisInspObjService; import cn.com.goldenwater.dcproj.service.BisInspSelAreaService; import cn.com.goldenwater.dcproj.service.SupervisionPlanService; import cn.com.goldenwater.dcproj.util.StringUtil; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; 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 java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author litf * @date 2019-3-6 */ @Service @Transactional(rollbackFor = Exception.class) public class BisInspSelAreaServiceImpl extends AbstractCrudService implements BisInspSelAreaService { @Autowired private BisInspSelAreaDao bisInspSelAreaDao; @Autowired private AttAdXBaseDao attAdXBaseDao; @Autowired private BisInspObjService bisInspObjService; @Autowired private SupervisionPlanService supervisionPlanService; @Override public List> getAddvcdByAdCode(String adCode, String adGrad) { return bisInspSelAreaDao.getAddvcdByAdCode(adCode, adGrad); } @Override public List> getProvinceAreaByPersid(String persId, String end, String str, String pattern, String adCode, String pType, String orgId) { return bisInspSelAreaDao.getProvinceAreaByPersid(persId, end, str, pattern, adCode, pType, orgId); } @Override public PageInfo> getResByArea(BisInspSelAreaParam p) { PageHelper.startPage(p.getPageNum(), p.getPageSize()); PageHelper.orderBy(p.getOrderBy()); List> list = bisInspSelAreaDao.getResByArea(p); return new PageInfo>(list); } @Override public List> getAreaByPersid(String persId, String orgId) { return bisInspSelAreaDao.getAreaByPersid(persId, orgId); } @Override public PageInfo getAllSub(BisInspSelAreaParam p) { PageHelper.startPage(p.getPageNum(), p.getPageSize()); List list = bisInspSelAreaDao.getAllSub(p); return new PageInfo(list); } @Override public List> getAddvcdCacheByAdCode(String adCode, String adGrad) { return bisInspSelAreaDao.getAddvcdCacheByAdCode(adCode, adGrad); } @Override public PageInfo getResByGroup(InGroupResParam inGroupResParam) { if (inGroupResParam.getAdcd() != null) { //如果有多个行政区划编码,要根据逗号分隔截取 if (inGroupResParam.getAdcd().contains(SplitValue.DOUHAO_SPLIT)) { StringBuilder stringBuffer = new StringBuilder(); String[] split = inGroupResParam.getAdcd().split(SplitValue.DOUHAO_SPLIT); //拼接sql,对多个截取后的行政区划进行模糊查询 for (String s : split) { String subAd = AdLevelUtil.SubAd(s).get(SplitValue.SUBAD).toString(); stringBuffer.append(subAd); stringBuffer.append("%"); stringBuffer.append("' OR ADM_DIV LIKE '"); } //将最后的“ OR ADM_DIV LIKE ”截掉 String substring = stringBuffer.substring(0, stringBuffer.length() - 18); substring = "(ADM_DIV LIKE '" + substring + ")"; inGroupResParam.setAdcd(substring); } else { String subAd = AdLevelUtil.SubAd(inGroupResParam.getAdcd()).get(SplitValue.SUBAD).toString(); if (subAd.equals("__")) { subAd = "ADM_DIV LIKE '" + inGroupResParam.getProvince() + "%'"; } else { subAd = "ADM_DIV LIKE '" + subAd + "%'"; } inGroupResParam.setAdcd(subAd); } } PageHelper.startPage(inGroupResParam.getPageNum(), inGroupResParam.getPageSize()); List attGrwBaseList = this.bisInspSelAreaDao.getResByGroup(inGroupResParam); return new PageInfo<>(attGrwBaseList); } @Override public int deleteByGroupId(String id, String adCode, String orgId) { return this.bisInspSelAreaDao.deleteByGroupId(id, adCode, orgId); } @Override public List> getAreaByGroup(String id, String ad, String adName, String adCode, String province) { if ("000000000000".equals(adCode)) { List> list = new ArrayList<>(); if (StringUtils.isNotBlank(province)) { ad = ""; Map params = new HashMap<>(5); AttAdXBase attAdXBase = attAdXBaseDao.get(province); params.put("AD_CODE", province); params.put("AD_NAME", attAdXBase.getAdName()); params.put("AD_GRAD", attAdXBase.getAdGrad()); list.add(params); } list.addAll(this.bisInspSelAreaDao.getAreaByGroup(id, ad, adName, adCode, province)); return list; } else { return this.bisInspSelAreaDao.getAreaByAdCode(adCode, adName); } } @Override public List> getOptionalArea(String id, String ad, String adName, String adCode, String orgId) { String batchId = id.substring(0, 9); List> areaList = bisInspSelAreaDao.getOptionalArea(id, ad, adName, adCode, orgId); if (CollectionUtils.isNotEmpty(areaList)) { areaList.forEach(area -> { String ac = MapUtils.getString(area, "AD_CODE"); List> pnmList = bisInspSelAreaDao.getPnmByBatchAndAdCode(batchId, ac); area.put("GROUPS", pnmList); }); } return areaList; } @Override public List> getPersByArea(String adCode, String orgId) { return bisInspSelAreaDao.getPersByArea(adCode, orgId); } public BisInspSelAreaServiceImpl(BisInspSelAreaDao bisInspSelAreaDao) { super(bisInspSelAreaDao); this.bisInspSelAreaDao = bisInspSelAreaDao; } @Override public PageInfo> getPawpByArea(BisInspSelAreaParam p) { PageHelper.startPage(p.getPageNum(), p.getPageSize()); PageHelper.orderBy(p.getOrderBy()); List> list = bisInspSelAreaDao.getResByArea(p); return new PageInfo>(list); } @Override public int deleteAreaData(String id, String province) { BisInspSelArea area = bisInspSelAreaDao.get(id); if (area == null) { return 0; } // 删除区域 bisInspSelAreaDao.delete(id); // 删除区域下的对象以及所有数据 String objType = String.valueOf(Integer.valueOf(area.getId().substring(0, 3))); PagePersObjParam pagePersObjParam = new PagePersObjParam(); pagePersObjParam.setAdCode(String.valueOf(AdLevelUtil.SubAd(area.getAdCode()).get(SplitValue.SUBAD))); if (province.length() == 12) { pagePersObjParam.setProvince(province.substring(0, 2)); } pagePersObjParam.setObjType(objType); pagePersObjParam.setIsAll("1"); pagePersObjParam.setInspGroupId(area.getId()); List list = bisInspObjService.getObjListByTypeAndAdCode(pagePersObjParam); if (list != null && list.size() > 0) { for (Object obj : list) { try { Field field = obj.getClass().getDeclaredField("objId"); field.setAccessible(true); String objId = (String) field.get(obj); if (StringUtils.isBlank(objId)) { continue; } supervisionPlanService.cleanObjDataByObjId(objType, objId); } catch (Exception e) { e.printStackTrace(); } } } return 0; } }