package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.BisInspPblmDao; import cn.com.goldenwater.dcproj.dao.BisInspVillqhRgstrRelVillDao; import cn.com.goldenwater.dcproj.model.AttAdXBase; import cn.com.goldenwater.dcproj.model.BisInspVillqhRgstr; import cn.com.goldenwater.dcproj.model.BisInspVillqhRgstrRelVill; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.utils.Builder; import cn.com.goldenwater.dcproj.utils.Constant; import cn.com.goldenwater.id.util.UuidUtil; 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.util.Date; import java.util.List; import static cn.com.goldenwater.dcproj.util.CheckUtil.check; import static cn.com.goldenwater.dcproj.util.CheckUtil.notNull; /** * @author lhc * @date 2021-2-1 */ @Service @Transactional public class BisInspVillqhRgstrRelVillServiceImpl extends AbstractCrudService implements BisInspVillqhRgstrRelVillService { @Autowired private BisInspVillqhRgstrRelVillDao bisInspVillqhRgstrRelVillDao; @Autowired private BisInspVillqhRgstrService bisInspVillqhRgstrService; @Autowired private BisInspVillqhPoorService bisInspVillqhPoorService; @Autowired private BisInspVillqhFeeService bisInspVillqhFeeService; @Autowired private AttAdXBaseService attAdXBaseService; @Autowired private BisInspPblmDao bisInspPblmDao; public BisInspVillqhRgstrRelVillServiceImpl(BisInspVillqhRgstrRelVillDao bisInspVillqhRgstrRelVillDao) { super(bisInspVillqhRgstrRelVillDao); this.bisInspVillqhRgstrRelVillDao = bisInspVillqhRgstrRelVillDao; } @Override public int insert(BisInspVillqhRgstrRelVill bisInspVillqhRgstrRelVill) { String uuid = UuidUtil.uuid(); bisInspVillqhRgstrRelVill.setId(uuid); bisInspVillqhRgstrRelVill.setIntm(new Date()); bisInspVillqhRgstrRelVill.setUptm(new Date()); bisInspVillqhRgstrRelVill.setDataStat(Constant.STRING_ZERO); return this.bisInspVillqhRgstrRelVillDao.insert(bisInspVillqhRgstrRelVill); } @Override public int update(BisInspVillqhRgstrRelVill bisInspVillqhRgstrRelVill) { bisInspVillqhRgstrRelVill.setUptm(new Date()); return this.bisInspVillqhRgstrRelVillDao.update(bisInspVillqhRgstrRelVill); } @Override public int delete(String id) { BisInspVillqhRgstrRelVill relVill = get(id); notNull(relVill, "未查询到相应的行政村!", id); return deleteBy(Builder.of(BisInspVillqhRgstrRelVillParam::new) .with(BisInspVillqhRgstrRelVillParam::setRegstrId, relVill.getRegstrId()) .with(BisInspVillqhRgstrRelVillParam::setVillCode, relVill.getVillCode()) .build()); } @Override public List addbatch(List countryParamList, String persId) { for (CountryParam countryParam : countryParamList) { if (StringUtils.isBlank(countryParam.getCodes())) { continue; } String[] arrays = countryParam.getCodes().split(SplitValue.FENHAO_SPLIT); for (String arr : arrays) { AttAdXBase attAdXBase = attAdXBaseService.getBy(Builder.of(AttAdXBaseParam::new) .with(AttAdXBaseParam::setAdCode, arr) .build()); // 判断 adCode 对应的基础表是否 存在 if (attAdXBase == null) { continue; } BisInspVillqhRgstrRelVillParam relVillParam = Builder.of(BisInspVillqhRgstrRelVillParam::new) .with(BisInspVillqhRgstrRelVillParam::setRegstrId, countryParam.getRegstrId()) .with(BisInspVillqhRgstrRelVillParam::setAdCode, attAdXBase.getAdCode()) .build(); BisInspVillqhRgstrRelVill relVill = getBy(relVillParam); // 判断 村是否重复添加,已添加则跳过 if (relVill != null) { continue; } relVill = new BisInspVillqhRgstrRelVill(); relVill.setAdCode(attAdXBase.getAdCode().substring(0, 9) + "000"); relVill.setVillCode(attAdXBase.getAdCode()); relVill.setVillageNm(attAdXBase.getAdName()); relVill.setTownName(countryParam.getTownName()); relVill.setRegstrId(countryParam.getRegstrId()); relVill.setStatus(Constant.STRING_ONE); relVill.setPersId(persId); insert(relVill); } } // 修改登记表状态 updateRgstr(countryParamList.get(0).getRegstrId()); return countryParamList; } private void updateRgstr(String rgstrId) { updateRgstr(rgstrId, Constant.STRING_ONE); } private void updateRgstr(String rgstrId, String state) { // 修改 登记表状态 BisInspVillqhRgstr rgstr = bisInspVillqhRgstrService.get(rgstrId); // 如果状态为 1:督查中 2:已督查 if (rgstr == null || Constant.STRING_ONE.equals(rgstr.getState()) || Constant.STRING_TWO.equals(rgstr.getState())) { return; } BisInspVillqhRgstr villqhRgstr = new BisInspVillqhRgstr(); rgstr.setId(rgstrId); rgstr.setState(state); bisInspVillqhRgstrService.update(villqhRgstr); } @Override public int deleteBy(BisInspVillqhRgstrRelVillParam param) { check(StringUtils.isNotBlank(param.getRegstrId()), "regstrId.no"); bisInspVillqhFeeService.deleteBy(Builder.of(BisInspVillqhFeeParam::new) .with(BisInspVillqhFeeParam::setRegstrId, param.getRegstrId()) .with(BisInspVillqhFeeParam::setAdCode, param.getVillCode()) .build()); bisInspVillqhPoorService.deleteBy(Builder.of(BisInspVillqhPoorParam::new) .with(BisInspVillqhPoorParam::setRegstrId, param.getRegstrId()) .with(BisInspVillqhPoorParam::setAdCode, param.getVillCode()) .build()); return super.deleteBy(param); } }