4e6a9ac902da29aeb12bfeb328201523361b5f7e.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package cn.com.goldenwater.dcproj.service.impl.gdyjhtc;
  2. import cn.com.goldenwater.dcproj.dao.BisInspPlanMonthDao;
  3. import cn.com.goldenwater.dcproj.model.AttAdBase;
  4. import cn.com.goldenwater.dcproj.model.BisInspPlanMonth;
  5. import cn.com.goldenwater.dcproj.model.BisInspPlanMonthSD;
  6. import cn.com.goldenwater.dcproj.model.BisInspPlanYear;
  7. import cn.com.goldenwater.dcproj.param.BisInspPlanMonthParam;
  8. import cn.com.goldenwater.dcproj.service.AttAdBaseService;
  9. import cn.com.goldenwater.dcproj.service.BisInspPlanMonthAreaService;
  10. import cn.com.goldenwater.dcproj.service.BisInspPlanMonthService;
  11. import cn.com.goldenwater.core.service.AbstractCrudService;
  12. import cn.com.goldenwater.dcproj.service.BisInspPlanYearService;
  13. import cn.com.goldenwater.dcproj.utils.ExcelVerifyUtil;
  14. import cn.com.goldenwater.dcproj.utils.ImportUtil;
  15. import cn.com.goldenwater.dcproj.utils.StringUtils;
  16. import org.apache.poi.ss.usermodel.Workbook;
  17. import org.springframework.beans.BeanUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import cn.com.goldenwater.id.util.UuidUtil;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.util.*;
  25. import java.util.concurrent.atomic.AtomicInteger;
  26. @Service
  27. @Transactional
  28. public class BisInspPlanMonthServiceImpl extends AbstractCrudService<BisInspPlanMonth, BisInspPlanMonthParam> implements BisInspPlanMonthService {
  29. @Autowired
  30. private BisInspPlanMonthDao bisInspPlanMonthDao;
  31. @Autowired
  32. BisInspPlanMonthAreaService areaService;
  33. @Autowired
  34. BisInspPlanYearService bisInspPlanYearService;
  35. @Autowired
  36. AttAdBaseService attAdBaseService;
  37. public BisInspPlanMonthServiceImpl(BisInspPlanMonthDao bisInspPlanMonthDao) {
  38. super(bisInspPlanMonthDao);
  39. this.bisInspPlanMonthDao = bisInspPlanMonthDao;
  40. }
  41. @Override
  42. public int insert(BisInspPlanMonth bisInspPlanMonth) {
  43. String uuid = UuidUtil.uuid(); // 生成uuid
  44. bisInspPlanMonth.setId(uuid);
  45. bisInspPlanMonth.setIntm(new Date());
  46. bisInspPlanMonth.setUptm(new Date());
  47. bisInspPlanMonth.setDataStat("0");
  48. if (StringUtils.isNotEmpty(bisInspPlanMonth.getYearPlanId())) {
  49. BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(bisInspPlanMonth.getYearPlanId());
  50. bisInspPlanMonth.setYearChkName(bisInspPlanYear.getChkName());
  51. bisInspPlanMonth.setYearChkType(bisInspPlanYear.getChkType());
  52. }
  53. areaService.insertByplanMonth(bisInspPlanMonth);
  54. return this.bisInspPlanMonthDao.insert(bisInspPlanMonth);
  55. }
  56. @Override
  57. public int update(BisInspPlanMonth bisInspPlanMonth) {
  58. areaService.updateByplanMonth(bisInspPlanMonth);
  59. bisInspPlanMonth.setUptm(new Date());
  60. if (StringUtils.isNotEmpty(bisInspPlanMonth.getYearPlanId())) {
  61. BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(bisInspPlanMonth.getYearPlanId());
  62. bisInspPlanMonth.setYearChkName(bisInspPlanYear.getChkName());
  63. bisInspPlanMonth.setYearChkType(bisInspPlanYear.getChkType());
  64. }
  65. return this.bisInspPlanMonthDao.update(bisInspPlanMonth);
  66. }
  67. @Override
  68. public int delete(String id) {
  69. areaService.deleteByplanMonth(id);
  70. return this.bisInspPlanMonthDao.delete(id);
  71. }
  72. @Override
  73. public List<BisInspPlanMonth> getPageInfo(BisInspPlanMonthParam param) {
  74. //PageHelper.startPage(param.getPageNum(), param.getPageSize());
  75. List<BisInspPlanMonth> list = bisInspPlanMonthDao.findList(param);
  76. this.verifyAdCodeAndTime(list, param.getChkMonth());
  77. return list;
  78. }
  79. @Override
  80. public void export(BisInspPlanMonthParam param, HttpServletResponse response) throws Exception {
  81. List<BisInspPlanMonth> list = bisInspPlanMonthDao.findList(param);
  82. ImportUtil util = new ImportUtil<>();
  83. Workbook wb;
  84. if ("37".equals(param.getAdCode())) {
  85. List<BisInspPlanMonthSD> list1 = new ArrayList<>();
  86. list.forEach(a -> {
  87. BisInspPlanMonthSD o = new BisInspPlanMonthSD();
  88. BeanUtils.copyProperties(a, o);
  89. list1.add(o);
  90. });
  91. wb = util.export(list1, BisInspPlanMonthSD.class);
  92. } else {
  93. wb = util.export(list, BisInspPlanMonth.class);
  94. }
  95. util.buildResponse(wb, "督查检查考核计划调度安排表.xls", response);
  96. }
  97. @Override
  98. public List<String> importExcel(MultipartFile file, String persId,String addvcd) throws Exception {
  99. Class c;
  100. if ("37".equals(addvcd)) {
  101. c = BisInspPlanMonthSD.class;
  102. } else {
  103. c = BisInspPlanMonth.class;
  104. }
  105. ImportUtil<BisInspPlanMonth> util = new ImportUtil<BisInspPlanMonth>() {
  106. @Override
  107. public void before(BisInspPlanMonth bisInspPlanMonth) {
  108. bisInspPlanMonth.setPersId(persId);
  109. }
  110. };
  111. List<BisInspPlanMonth> list = util.fileToList(file, c);
  112. ExcelVerifyUtil verifyUtil = new ExcelVerifyUtil<>(list, null);
  113. List<BisInspPlanMonth> rightList = verifyUtil.getRightList();
  114. rightList.forEach(a -> {
  115. List<String> cityCode = Arrays.asList(a.getChkCityCode().split(","));
  116. List<String> countryCode = Arrays.asList(a.getChkCountryCode().split(","));
  117. List<AttAdBase> cityList = new ArrayList<>();
  118. List<AttAdBase> countryList = new ArrayList<>();
  119. cityCode.forEach(b -> cityList.add(attAdBaseService.getByAdcode(b)));
  120. countryCode.forEach(d -> countryList.add(attAdBaseService.getByAdcode(d)));
  121. StringJoiner citySj = new StringJoiner(",");
  122. StringJoiner countrySj = new StringJoiner(",");
  123. cityList.stream().filter(x -> x != null).forEach(e -> citySj.add(e.getAdName()));
  124. countryList.stream().filter(y -> y != null).forEach(f ->countrySj.add(f.getAdName()));
  125. a.setChkCity(citySj.toString());
  126. a.setChkCountry(countrySj.toString());
  127. });
  128. rightList.forEach(a -> this.insert(a));
  129. return verifyUtil.getErrorList();
  130. }
  131. @Override
  132. public BisInspPlanMonth getOne(String id) {
  133. BisInspPlanMonth bisInspPlanMonth = bisInspPlanMonthDao.get(id);
  134. return bisInspPlanMonth;
  135. }
  136. public void verifyAdCodeAndTime(List<BisInspPlanMonth> list, Date checkMonth) {
  137. Map<String, String> idAndColorMap = new HashMap<>();
  138. AtomicInteger colorCount = new AtomicInteger();
  139. if (list == null || list.size() == 0) {
  140. return;
  141. }
  142. List<BisInspPlanMonth> dbList = bisInspPlanMonthDao.getByTimeRange(checkMonth);
  143. list.forEach(a -> {
  144. dbList.stream()
  145. .filter(o -> !o.getId().equals(a.getId()))
  146. .forEach(b -> a.verifyRepeat(b, idAndColorMap, colorCount));
  147. });
  148. list.forEach(a -> {
  149. a.setColor(idAndColorMap.get(a.getId()));
  150. });
  151. }
  152. }