| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 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<BisInspPlanMonth, BisInspPlanMonthParam> 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<BisInspPlanMonth> getPageInfo(BisInspPlanMonthParam param) {
- //PageHelper.startPage(param.getPageNum(), param.getPageSize());
- List<BisInspPlanMonth> list = bisInspPlanMonthDao.findList(param);
- this.verifyAdCodeAndTime(list, param.getChkMonth());
- return list;
- }
- @Override
- public void export(BisInspPlanMonthParam param, HttpServletResponse response) throws Exception {
- List<BisInspPlanMonth> list = bisInspPlanMonthDao.findList(param);
- ImportUtil util = new ImportUtil<>();
- Workbook wb;
- if ("37".equals(param.getAdCode())) {
- List<BisInspPlanMonthSD> 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<String> importExcel(MultipartFile file, String persId,String addvcd) throws Exception {
- Class c;
- if ("37".equals(addvcd)) {
- c = BisInspPlanMonthSD.class;
- } else {
- c = BisInspPlanMonth.class;
- }
- ImportUtil<BisInspPlanMonth> util = new ImportUtil<BisInspPlanMonth>() {
- @Override
- public void before(BisInspPlanMonth bisInspPlanMonth) {
- bisInspPlanMonth.setPersId(persId);
- }
- };
- List<BisInspPlanMonth> list = util.fileToList(file, c);
- ExcelVerifyUtil verifyUtil = new ExcelVerifyUtil<>(list, null);
- List<BisInspPlanMonth> rightList = verifyUtil.getRightList();
- rightList.forEach(a -> {
- List<String> cityCode = Arrays.asList(a.getChkCityCode().split(","));
- List<String> countryCode = Arrays.asList(a.getChkCountryCode().split(","));
- List<AttAdBase> cityList = new ArrayList<>();
- List<AttAdBase> 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<BisInspPlanMonth> list, Date checkMonth) {
- Map<String, String> idAndColorMap = new HashMap<>();
- AtomicInteger colorCount = new AtomicInteger();
- if (list == null || list.size() == 0) {
- return;
- }
- List<BisInspPlanMonth> 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()));
- });
- }
- }
|