xiangpei
2024-08-29 3e9a6da99aae968123ee7bca352fc08becd7f1f2
ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java
@@ -6,16 +6,13 @@
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.dataListener.CurrencyDataListener;
import com.ycl.platform.base.BaseSelect;
import com.ycl.platform.domain.entity.YwPeople;
import com.ycl.platform.domain.entity.YwPoint;
import com.ycl.platform.domain.entity.YwUnit;
import com.ycl.platform.domain.excel.PointExport;
import com.ycl.platform.domain.form.BatchEditPointForm;
import com.ycl.platform.domain.form.YwPointForm;
import com.ycl.platform.domain.query.YwPointQuery;
import com.ycl.platform.domain.vo.YwPointVO;
import com.ycl.platform.domain.excel.PointExport;
import com.ycl.platform.domain.excel.PointSelectHandler;
import com.ycl.platform.mapper.YwPeopleMapper;
import com.ycl.platform.mapper.YwPointMapper;
import com.ycl.platform.service.YwPointService;
@@ -29,12 +26,10 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@@ -219,11 +214,11 @@
                .eq(YwPoint::getUnitId, unitId)
                .like(YwPoint::getPointName, keyword)
                .list();
        List<BaseSelect> data = list.stream().map(item -> {
            BaseSelect baseSelect = new BaseSelect();
            baseSelect.setId(item.getId());
            baseSelect.setValue(item.getPointName());
            return baseSelect;
        List data = list.stream().map(item -> {
            Map map = new HashMap<String, Object>();
            map.put("id", item.getSerialNumber());
            map.put("value", item.getPointName());
            return map;
        }).collect(Collectors.toList());
        return Result.ok().data(data);
    }
@@ -292,17 +287,6 @@
            return point;
        }).collect(Collectors.toList());
        this.waitAllFinishAndGetResult(pointList);
//        for (PointExport pointExport : dataList) {
//            YwPoint point = new YwPoint();
//            point.setImportantCommandImageTag("是".equals(pointExport.getImportantCommandImageTagString()));
//            point.setProvinceTag("是".equals(pointExport.getProvinceTagString()));
//            point.setUnitId(Long.valueOf(unitId));
//            point.setStartTime(startTime);
//            point.setEndTime(endTime);
//            point.setPointName(pointExport.getPointName());
//            point.setSerialNumber(pointExport.getSerialNumber());
//            this.baseMapper.updatePoint(point);
//        }
    }
    public void waitAllFinishAndGetResult(List<YwPoint> dataList) throws InterruptedException, ExecutionException {
@@ -311,34 +295,18 @@
        int start = 0;
        Date startTime = new Date();
        while (true) {
            if (dataList.size() < start + 50) {
            if (dataList.size() < start + 100) {
                List<YwPoint> list = dataList.subList(start, dataList.size() - 1);
                Callable<Boolean> callable = new PointImportCallable(list, this.baseMapper);
                FutureTask<Boolean> futureTask = new FutureTask(callable);
                Thread thread = new Thread(futureTask);
                thread.start();
                // 不能直接调用Future的get方法,否则就变成串行执行了,失去多线程意义
                resultList.add(futureTask);
                this.baseMapper.updatePoint(list);
                break;
            } else {
                List<YwPoint> list = dataList.subList(start, start + 50);
                Callable<Boolean> callable = new PointImportCallable(list, this.baseMapper);
                FutureTask<Boolean> futureTask = new FutureTask(callable);
                Thread thread = new Thread(futureTask);
                thread.start();
                // 不能直接调用Future的get方法,否则就变成串行执行了,失去多线程意义
                resultList.add(futureTask);
                start += 50;
                List<YwPoint> list = dataList.subList(start, start + 100);
                this.baseMapper.updatePoint(list);
                start += 100;
            }
        }
        for (FutureTask<Boolean> futureTask : resultList) {
            data.add(futureTask.get());
        }
        Date endTime = new Date();
        log.error("总共耗时:" + (endTime.getTime() - startTime.getTime()) / 1000);
        if (data.stream().allMatch(item -> item == Boolean.TRUE)) {
            System.out.println("执行成功");
        }
        log.error("总共耗时:" + (endTime.getTime() - startTime.getTime()));
    }
}