package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.constValue.CommonLabel; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.dto.AttCountryDto; import cn.com.goldenwater.dcproj.dto.BisInspVillqhRgstrDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.Builder; import cn.com.goldenwater.dcproj.utils.Constant; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; 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.*; /** * @author lhc * @date 2021-2-1 */ @Service @Transactional public class BisInspVillqhRgstrServiceImpl extends AbstractCrudService implements BisInspVillqhRgstrService, BisInspObjStrategy { @Autowired private BisInspVillqhRgstrDao bisInspVillqhRgstrDao; @Autowired private AttAdXBaseDao attAdXBaseDao; @Autowired private BisInspVillqhFeeService feeService; @Autowired private BisInspVillqhPoorService poorService; @Autowired private BisInspVillqhRgstrRelVillService relVillService; @Autowired private BisInspPblmDao bisInspPblmDao; @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private BisInspAllRlationDao bisInspAllRlationDao; public BisInspVillqhRgstrServiceImpl(BisInspVillqhRgstrDao bisInspVillqhRgstrDao) { super(bisInspVillqhRgstrDao); this.bisInspVillqhRgstrDao = bisInspVillqhRgstrDao; } @Override public int insert(BisInspVillqhRgstr bisInspVillqhRgstr) { bisInspVillqhRgstr.setId(UuidUtil.uuid()); Date now = new Date(); bisInspVillqhRgstr.setIntm(now); bisInspVillqhRgstr.setUptm(now); // 数据状态 默认为 0 // 督查状态(0:未督查;1:督查中;2:已督查) bisInspVillqhRgstr.setState(CommonLabel.INIT_DATA); // 子表状态(0:未督查;1:督查中;2:已督查) bisInspVillqhRgstr.setFeeState(CommonLabel.INIT_DATA); bisInspVillqhRgstr.setPoorState(CommonLabel.INIT_DATA); return this.bisInspVillqhRgstrDao.insert(bisInspVillqhRgstr); } @Override public int update(BisInspVillqhRgstr bisInspVillqhRgstr) { bisInspVillqhRgstr.setUptm(new Date()); return this.bisInspVillqhRgstrDao.update(bisInspVillqhRgstr); } @Override public int delete(String id) { return this.bisInspVillqhRgstrDao.delete(id); } @Override public void insertObj(BisInspAllObj bisInspAllObj, String persId) { BisInspVillqhRgstr b = new BisInspVillqhRgstr(); AttAdXBase base = attAdXBaseDao.get(bisInspAllObj.getCode()); BeanUtils.copyProperties(base, b); b.setObjId(bisInspAllObj.getObjId()); // 创建人 b.setPersId(persId); /* 添加 登记表 */ insert(b); } @Override public String getType() { return BisInspEnum.VILLQH.getValue(); } @Override public void cleanObjData(String objId) { BisInspVillqhRgstrParam rgstrParam = new BisInspVillqhRgstrParam(); rgstrParam.setObjId(objId); List list = this.bisInspVillqhRgstrDao.findList(rgstrParam); if (list.size() > 0) { String id = list.get(0).getId(); // 删除子表 BisInspVillqhRgstrRelVillParam relVillParam = new BisInspVillqhRgstrRelVillParam(); relVillParam.setRegstrId(id); relVillService.deleteBy(relVillParam); // 删除登记表 this.bisInspVillqhRgstrDao.delete(id); } } @Override public PageInfo findObjPageByType(TypeParam typeParam, HttpServletResponse response) { if (StringUtils.isNotBlank(typeParam.getAdCode())) { typeParam.setAdCode(String.valueOf(AdLevelUtil.SubAd(typeParam.getAdCode()).get(SplitValue.SUBAD))); } PageHelper.startPage(typeParam); String[] groupIds = bisInspAllRlationDao.getIdByPersid(Builder .of(BisInspAllRlationParam::new) .with(BisInspAllRlationParam::setPersid, typeParam.getPresId()) .with(BisInspAllRlationParam::setpType, typeParam.getpType()) .build()); typeParam.setGroupIds(groupIds); List list = this.bisInspVillqhRgstrDao.findPageList(typeParam); return (PageInfo) new PageInfo(list); } @Override public Object findObjListByType(TypeParam typeParam) { return this.bisInspVillqhRgstrDao.findPageList(typeParam); } @Override public Map findNode(String adCode, String regstrId) { Map map = new HashMap<>(2); adCode = AdLevelUtil.getAddvcd(adCode); // 获取工程暗访情况 BisInspVillqhFeeParam feeParam = Builder.of(BisInspVillqhFeeParam::new) .with(BisInspVillqhFeeParam::setRegstrId, regstrId) .with(BisInspVillqhFeeParam::setAdCode, adCode) .build(); List feeList = feeService.findList(feeParam); // 获取农牧民情况 BisInspVillqhPoorParam poorParam = Builder.of(BisInspVillqhPoorParam::new) .with(BisInspVillqhPoorParam::setRegstrId, regstrId) .with(BisInspVillqhPoorParam::setAdCode, adCode) .build(); List poorList = poorService.findList(poorParam); map.put("poor", poorList); map.put("fee", feeList); return map; } @Override public List findCheckTree(String code, String regstrId) { // 获取镇信息 List zhenDtoList = attAdXBaseDao.findXZCZhenList(code); // 获取村信息 List countryDtoList = attAdXBaseDao.findXZCCunList(code, regstrId, BisInspEnum.VILLQH.getValue()); for (AttCountryDto attCountryDto : zhenDtoList) { String adCode = attCountryDto.getAdCode().replace("000", ""); List childList = new ArrayList<>(); for (AttCountryDto countryDto : countryDtoList) { if (countryDto.getAdCode().startsWith(adCode)) { childList.add(countryDto); } } attCountryDto.setAttCountryDtoList(childList); } return zhenDtoList; } @Override public void updateState(Map map) { BisInspVillqhRgstr rgstr = get(MapUtils.getString(map, "rgstrId")); if (!Constant.STRING_TWO.equals(rgstr.getState()) && StringUtils.isNotBlank(MapUtils.getString(map, "state"))) { rgstr.setUptm(new Date()); rgstr.setState(Constant.STRING_ONE); switch (MapUtils.getString(map, "param")) { case "fee": rgstr.setFeeState(MapUtils.getString(map, "state")); break; case "poor": rgstr.setPoorState(MapUtils.getString(map, "state")); break; default: } update(rgstr); } } }