| | |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | int rows = sheet.getLastRowNum(); |
| | | if (rows > 0) { |
| | | List<ApsGasPipelinePrediction> list = new ArrayList<>(); |
| | | |
| | | Set<String> keys = new HashSet<>(); |
| | | /*数据列从1开始*/ |
| | | for (int i = 1; i <= rows; i++) { |
| | | for (int i = rows; i > 0; --i) { |
| | | Row row = sheet.getRow(i); |
| | | if (row.getCell(0) == null) { |
| | | continue; |
| | |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setPredictQuantity(new BigDecimal(quantity)); |
| | | item.setPredictDate(new Timestamp(date.getTime())); |
| | | if (!keys.contains(item.getKey())) { |
| | | keys.add(item.getKey()); |
| | | list.add(item); |
| | | } |
| | | } |
| | | } |
| | | if (!list.isEmpty()) { |
| | | |
| | | List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial( |
| | | list.stream().map(ApsGasPipelinePrediction::getFactory).collect(Collectors.toSet()), |
| | | list.stream().map(ApsGasPipelinePrediction::getMaterialCode).collect(Collectors.toSet()) |
| | | ); |
| | | List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(keys); |
| | | if (!facCodeKey.isEmpty()) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
| | | Iterator<ApsGasPipelinePrediction> it = list.iterator(); |
| | | while (it.hasNext()) { |
| | | ApsGasPipelinePrediction item = it.next(); |
| | | String key = item.getFactory() + "##" + item.getMaterialCode() + "##" + sdf.format(item.getPredictDate()); |
| | | facCodeKey.stream() |
| | | .filter(map -> map.get("key").equals(key)) |
| | | .forEach(row -> { |
| | | long count = facCodeKey.stream() |
| | | .filter(map -> map.get("key").equals(item.getKey())) |
| | | .peek(row -> { |
| | | item.setId((Long) row.get("id")); |
| | | item.setCreateBy(null); |
| | | item.setCreateTime(null); |
| | | item.setUpdateBy(SecurityUtils.getUsername()); |
| | | item.setUpdateTime(new Timestamp(System.currentTimeMillis())); |
| | | apsGasPipelinePredictionMapper.updateById(item); |
| | | }).count(); |
| | | if (count > 0){ |
| | | it.remove(); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | if (!list.isEmpty()) { |