package cn.com.goldenwater.dcproj.service.impl.gdyjhtc; import cn.com.goldenwater.dcproj.dao.BisInspPlanMonthDao; import cn.com.goldenwater.dcproj.model.AttAdBase; import cn.com.goldenwater.dcproj.model.BisInspPlanMonth; import cn.com.goldenwater.dcproj.model.BisInspPlanMonthSD; import cn.com.goldenwater.dcproj.model.BisInspPlanYear; import cn.com.goldenwater.dcproj.param.BisInspPlanMonthParam; import cn.com.goldenwater.dcproj.service.AttAdBaseService; import cn.com.goldenwater.dcproj.service.BisInspPlanMonthAreaService; import cn.com.goldenwater.dcproj.service.BisInspPlanMonthService; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.service.BisInspPlanYearService; import cn.com.goldenwater.dcproj.utils.ExcelVerifyUtil; import cn.com.goldenwater.dcproj.utils.ImportUtil; import cn.com.goldenwater.dcproj.utils.StringUtils; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; 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 org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @Service @Transactional public class BisInspPlanMonthServiceImpl extends AbstractCrudService implements BisInspPlanMonthService { @Autowired private BisInspPlanMonthDao bisInspPlanMonthDao; @Autowired BisInspPlanMonthAreaService areaService; @Autowired BisInspPlanYearService bisInspPlanYearService; @Autowired AttAdBaseService attAdBaseService; public BisInspPlanMonthServiceImpl(BisInspPlanMonthDao bisInspPlanMonthDao) { super(bisInspPlanMonthDao); this.bisInspPlanMonthDao = bisInspPlanMonthDao; } @Override public int insert(BisInspPlanMonth bisInspPlanMonth) { String uuid = UuidUtil.uuid(); // 生成uuid bisInspPlanMonth.setId(uuid); bisInspPlanMonth.setIntm(new Date()); bisInspPlanMonth.setUptm(new Date()); bisInspPlanMonth.setDataStat("0"); if (StringUtils.isNotEmpty(bisInspPlanMonth.getYearPlanId())) { BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(bisInspPlanMonth.getYearPlanId()); bisInspPlanMonth.setYearChkName(bisInspPlanYear.getChkName()); bisInspPlanMonth.setYearChkType(bisInspPlanYear.getChkType()); } areaService.insertByplanMonth(bisInspPlanMonth); return this.bisInspPlanMonthDao.insert(bisInspPlanMonth); } @Override public int update(BisInspPlanMonth bisInspPlanMonth) { areaService.updateByplanMonth(bisInspPlanMonth); bisInspPlanMonth.setUptm(new Date()); if (StringUtils.isNotEmpty(bisInspPlanMonth.getYearPlanId())) { BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(bisInspPlanMonth.getYearPlanId()); bisInspPlanMonth.setYearChkName(bisInspPlanYear.getChkName()); bisInspPlanMonth.setYearChkType(bisInspPlanYear.getChkType()); } return this.bisInspPlanMonthDao.update(bisInspPlanMonth); } @Override public int delete(String id) { areaService.deleteByplanMonth(id); return this.bisInspPlanMonthDao.delete(id); } @Override public List getPageInfo(BisInspPlanMonthParam param) { //PageHelper.startPage(param.getPageNum(), param.getPageSize()); List list = bisInspPlanMonthDao.findList(param); this.verifyAdCodeAndTime(list, param.getChkMonth()); return list; } @Override public void export(BisInspPlanMonthParam param, HttpServletResponse response) throws Exception { List list = bisInspPlanMonthDao.findList(param); ImportUtil util = new ImportUtil<>(); Workbook wb; if ("37".equals(param.getAdCode())) { List list1 = new ArrayList<>(); list.forEach(a -> { BisInspPlanMonthSD o = new BisInspPlanMonthSD(); BeanUtils.copyProperties(a, o); list1.add(o); }); wb = util.export(list1, BisInspPlanMonthSD.class); } else { wb = util.export(list, BisInspPlanMonth.class); } util.buildResponse(wb, "督查检查考核计划调度安排表.xls", response); } @Override public List importExcel(MultipartFile file, String persId,String addvcd) throws Exception { Class c; if ("37".equals(addvcd)) { c = BisInspPlanMonthSD.class; } else { c = BisInspPlanMonth.class; } ImportUtil util = new ImportUtil() { @Override public void before(BisInspPlanMonth bisInspPlanMonth) { bisInspPlanMonth.setPersId(persId); } }; List list = util.fileToList(file, c); ExcelVerifyUtil verifyUtil = new ExcelVerifyUtil<>(list, null); List rightList = verifyUtil.getRightList(); rightList.forEach(a -> { List cityCode = Arrays.asList(a.getChkCityCode().split(",")); List countryCode = Arrays.asList(a.getChkCountryCode().split(",")); List cityList = new ArrayList<>(); List countryList = new ArrayList<>(); cityCode.forEach(b -> cityList.add(attAdBaseService.getByAdcode(b))); countryCode.forEach(d -> countryList.add(attAdBaseService.getByAdcode(d))); StringJoiner citySj = new StringJoiner(","); StringJoiner countrySj = new StringJoiner(","); cityList.stream().filter(x -> x != null).forEach(e -> citySj.add(e.getAdName())); countryList.stream().filter(y -> y != null).forEach(f ->countrySj.add(f.getAdName())); a.setChkCity(citySj.toString()); a.setChkCountry(countrySj.toString()); }); rightList.forEach(a -> this.insert(a)); return verifyUtil.getErrorList(); } @Override public BisInspPlanMonth getOne(String id) { BisInspPlanMonth bisInspPlanMonth = bisInspPlanMonthDao.get(id); return bisInspPlanMonth; } public void verifyAdCodeAndTime(List list, Date checkMonth) { Map idAndColorMap = new HashMap<>(); AtomicInteger colorCount = new AtomicInteger(); if (list == null || list.size() == 0) { return; } List dbList = bisInspPlanMonthDao.getByTimeRange(checkMonth); list.forEach(a -> { dbList.stream() .filter(o -> !o.getId().equals(a.getId())) .forEach(b -> a.verifyRepeat(b, idAndColorMap, colorCount)); }); list.forEach(a -> { a.setColor(idAndColorMap.get(a.getId())); }); } }