zhanghl
2025-05-21 d75541110d428f61a9fe3378110248b7dd78e240
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsGasPipelinePredictionServiceImpl.java
@@ -4,8 +4,10 @@
import com.aps.common.core.utils.DateUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.domain.ApsGasPipelinePrediction;
import com.aps.core.domain.ApsMaterialProductGroupManagement;
import com.aps.core.mapper.ApsGasPipelinePredictionMapper;
import com.aps.core.service.IApsGasPipelinePredictionService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.micrometer.common.util.StringUtils;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row;
@@ -18,9 +20,10 @@
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/**
 * 管路手工气体预测数据Service业务层处理
@@ -29,8 +32,7 @@
 * @date 2025-05-19
 */
@Service
public class ApsGasPipelinePredictionServiceImpl implements IApsGasPipelinePredictionService
{
public class ApsGasPipelinePredictionServiceImpl implements IApsGasPipelinePredictionService {
    @Autowired
    private ApsGasPipelinePredictionMapper apsGasPipelinePredictionMapper;
@@ -41,8 +43,7 @@
     * @return 管路手工气体预测数据
     */
    @Override
    public ApsGasPipelinePrediction selectApsGasPipelinePredictionById(Long id)
    {
    public ApsGasPipelinePrediction selectApsGasPipelinePredictionById(Long id) {
        return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionById(id);
    }
@@ -53,8 +54,7 @@
     * @return 管路手工气体预测数据
     */
    @Override
    public List<ApsGasPipelinePrediction> selectApsGasPipelinePredictionList(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
    public List<ApsGasPipelinePrediction> selectApsGasPipelinePredictionList(ApsGasPipelinePrediction apsGasPipelinePrediction) {
        return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionList(apsGasPipelinePrediction);
    }
@@ -65,8 +65,7 @@
     * @return 结果
     */
    @Override
    public int insertApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
    public int insertApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction) {
        apsGasPipelinePrediction.setCreateTime(DateUtils.getNowDate());
        return apsGasPipelinePredictionMapper.insertApsGasPipelinePrediction(apsGasPipelinePrediction);
    }
@@ -78,8 +77,7 @@
     * @return 结果
     */
    @Override
    public int updateApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
    public int updateApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction) {
        apsGasPipelinePrediction.setUpdateTime(DateUtils.getNowDate());
        return apsGasPipelinePredictionMapper.updateApsGasPipelinePrediction(apsGasPipelinePrediction);
    }
@@ -91,8 +89,7 @@
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelinePredictionByIds(Long[] ids)
    {
    public int deleteApsGasPipelinePredictionByIds(Long[] ids) {
        return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionByIds(ids);
    }
@@ -103,8 +100,7 @@
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelinePredictionById(Long id)
    {
    public int deleteApsGasPipelinePredictionById(Long id) {
        return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionById(id);
    }
@@ -117,9 +113,9 @@
        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;
@@ -142,13 +138,37 @@
                    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()) {
                apsGasPipelinePredictionMapper.deleteAll();
                List<Map<String, Object>> facCodeKey = apsGasPipelinePredictionMapper.selectByFacOrMaterial(keys);
                if (!facCodeKey.isEmpty()) {
                    Iterator<ApsGasPipelinePrediction> it = list.iterator();
                    while (it.hasNext()) {
                        ApsGasPipelinePrediction item = it.next();
                        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()) {
                apsGasPipelinePredictionMapper.insert(list);
            }
            }
            return list.size();
        }
        return 0;