package cn.com.goldenwater.dcproj.service.impl.plansd; import cn.com.goldenwater.dcproj.dao.BisInspPlanDtlAddvcdDao; import cn.com.goldenwater.dcproj.dao.BisInspPlanDtlPtypDao; import cn.com.goldenwater.dcproj.dto.BisInspPlanDtlDto; import cn.com.goldenwater.dcproj.model.BisInspPlanDtlAddvcd; import cn.com.goldenwater.dcproj.model.BisInspPlanDtlPtyp; import cn.com.goldenwater.dcproj.param.BisInspPlanDtlAddvcdParam; import cn.com.goldenwater.dcproj.param.BisInspPlanDtlPtypParam; import cn.com.goldenwater.dcproj.service.BisInspPlanDtlAddvcdService; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.utils.StringUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import cn.com.goldenwater.id.util.UuidUtil; import java.util.*; import java.util.stream.Collectors; /** * @author hjp * @date 2022-8-9 */ @Service @Transactional public class BisInspPlanDtlAddvcdServiceImpl extends AbstractCrudService implements BisInspPlanDtlAddvcdService { @Autowired private BisInspPlanDtlAddvcdDao bisInspPlanDtlAddvcdDao; @Autowired private BisInspPlanDtlPtypDao bisInspPlanDtlPtypDao; public BisInspPlanDtlAddvcdServiceImpl(BisInspPlanDtlAddvcdDao bisInspPlanDtlAddvcdDao) { super(bisInspPlanDtlAddvcdDao); this.bisInspPlanDtlAddvcdDao = bisInspPlanDtlAddvcdDao; } @Override public int insert(BisInspPlanDtlAddvcd bisInspPlanDtlAddvcd) { String uuid = UuidUtil.uuid(); // 生成uuid bisInspPlanDtlAddvcd.setId(uuid); bisInspPlanDtlAddvcd.setIntm(new Date()); bisInspPlanDtlAddvcd.setUptm(new Date()); bisInspPlanDtlAddvcd.setDataStat("0"); return this.bisInspPlanDtlAddvcdDao.insert(bisInspPlanDtlAddvcd); } @Override public int update(BisInspPlanDtlAddvcd bisInspPlanDtlAddvcd) { bisInspPlanDtlAddvcd.setUptm(new Date()); return this.bisInspPlanDtlAddvcdDao.update(bisInspPlanDtlAddvcd); } @Override public int delete(String id) { return this.bisInspPlanDtlAddvcdDao.delete(id); } @Override public List> getByAdCodeAndTm(BisInspPlanDtlDto dto) { // 同一个市 String adCodeStr = CollectionUtils.isEmpty(dto.getdAdCodes()) ? "" : dto.getdAdCodes().stream().map(m->m.substring(0,4)).distinct().collect(Collectors.joining("','","'","'")); if (StringUtils.isBlank(adCodeStr) || Objects.isNull(dto.getStTm()) || Objects.isNull(dto.getEnTm())){ return Lists.newArrayList(); } return bisInspPlanDtlAddvcdDao.getByAdCodeAndTm(adCodeStr,dto.getStTm(),dto.getEnTm()); } @Override public List> getByAdCodeAndTmAndPlan(BisInspPlanDtlDto dto) { // 同一年度同一月份不同区域 String adCodeStr = CollectionUtils.isEmpty(dto.getdAdCodes()) ? "" : dto.getdAdCodes().stream().map(m->m.substring(0,4)).distinct().collect(Collectors.joining("','","'","'")); if (StringUtils.isBlank(adCodeStr) || Objects.isNull(dto.getStTm()) || Objects.isNull(dto.getPlanId())){ return Lists.newArrayList(); } return bisInspPlanDtlAddvcdDao.getByAdCodeAndTmAndPlan(adCodeStr,dto.getStTm(),dto.getPlanId()); } @Override public List getByAdCodeAndTmList(String hasAdCodes, BisInspPlanDtlDto dto) { if (StringUtils.isBlank(hasAdCodes) || Objects.isNull(dto.getStTm()) || Objects.isNull(dto.getEnTm())){ return Lists.newArrayList(); } List byAdCodeAndTmList = bisInspPlanDtlAddvcdDao.getByAdCodeAndTmList(hasAdCodes, dto.getStTm(), dto.getEnTm()); if(null != byAdCodeAndTmList && byAdCodeAndTmList.size()>0){ byAdCodeAndTmList.forEach(l->{ //检查行政区 Optional.ofNullable(bisInspPlanDtlAddvcdDao.findList(new BisInspPlanDtlAddvcdParam(l.getId()))).ifPresent(a -> { l.setdAdName(a.stream().map(BisInspPlanDtlAddvcd::getAdName).collect(Collectors.joining(","))); l.setdAdCodes(a.stream().map(BisInspPlanDtlAddvcd::getAdCode).collect(Collectors.toList())); }); //督查类型 Optional.ofNullable(bisInspPlanDtlPtypDao.findList(new BisInspPlanDtlPtypParam(l.getId()))).ifPresent(b -> { l.setpTypeNames(b.stream().map(BisInspPlanDtlPtyp::getNm).collect(Collectors.joining(","))); l.setPtypIds(b.stream().map(BisInspPlanDtlPtyp::getPtype).collect(Collectors.toList())); }); }); } return byAdCodeAndTmList ; } }