|
@@ -17,6 +17,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.rongwei.bscommon.sys.dao.ApsDeliveryOffsetDao;
|
|
@@ -26,11 +28,13 @@ import com.rongwei.bscommon.sys.listener.WorkShopImportListener;
|
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
|
import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bsentity.vo.*;
|
|
|
+import com.rongwei.rwadmincommon.system.service.SysGeneralCRUDService;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.rwcommon.vo.CriteriaBuilder;
|
|
|
import com.rongwei.rwcommon.vo.CriteriaQuery;
|
|
|
import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import com.rongwei.safecommon.fegin.CXAdminFeginClient;
|
|
@@ -56,6 +60,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.IntPredicate;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -130,6 +135,8 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
private ApsDeliveryOffsetDao apsDeliveryOffsetDao;
|
|
|
@Resource
|
|
|
private CXCommonFeginClient cxCommonFeginClient;
|
|
|
+ @Autowired
|
|
|
+ private SysGeneralCRUDService sysGeneralCRUDService;
|
|
|
|
|
|
// /**
|
|
|
// * 更新工序的待加工批次号信息
|
|
@@ -3029,7 +3036,7 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
currentUser = new SysUserVo();
|
|
|
currentUser.setId("0");
|
|
|
currentUser.setName("定时任务操作");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
tenantId = CXCommonUtils.getCurrentUserFactoryId(currentUser);
|
|
|
}
|
|
|
//查询所有没有交期偏差的生产卡片
|
|
@@ -3300,6 +3307,82 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getCardListData(CriteriaQuery query) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ query.setQuerySql(sysGeneralCRUDService.sqlStrReplaceByMap(query));
|
|
|
+
|
|
|
+ if (query.getQuerySql() != null && query.getQuerySql().contains("@{userId}")) {//替换占位符
|
|
|
+ query.setQuerySql(sysGeneralCRUDService.replaceSql(query));
|
|
|
+ }
|
|
|
+ CriteriaBuilder.initQuerySql(query);
|
|
|
+
|
|
|
+ IPage<Map<String, Object>> result = new Page<>();
|
|
|
+
|
|
|
+ queryCard3(result, query);
|
|
|
+
|
|
|
+ return R.ok(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
|
|
|
+ return R.queryError();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //并行查询,使用两次查询
|
|
|
+ private void queryCard3(IPage<Map<String, Object>> result, CriteriaQuery query) {
|
|
|
+ Page<Map<String, Object>> pageInfo = new Page<>(query.getCurrent(), query.getSize());
|
|
|
+ int offset = (query.getCurrent() - 1) * query.getSize();
|
|
|
+ String querySql1 = query.getQuerySql();
|
|
|
+ // 并行查询
|
|
|
+ CompletableFuture<List<Map<String, Object>>> pageFuture = CompletableFuture.supplyAsync(
|
|
|
+ () -> this.baseMapper.getCardListPage(offset, query.getSize(), querySql1));
|
|
|
+
|
|
|
+ String querySql2 = query.getQuerySql().replaceFirst("\\*", "count(1)");
|
|
|
+ CompletableFuture<Long> countFuture = CompletableFuture.supplyAsync(
|
|
|
+ () -> this.baseMapper.getCardListCount(querySql2));
|
|
|
+
|
|
|
+ try {
|
|
|
+ result.setCurrent(query.getCurrent());
|
|
|
+ result.setSize(query.getSize());
|
|
|
+ result.setRecords(pageFuture.get());
|
|
|
+ result.setTotal(countFuture.get());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("查询失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryCard2(IPage<Map<String, Object>> result, CriteriaQuery query) {
|
|
|
+ //窗口函数 优化查询效率
|
|
|
+ query.setQuerySql(query.getQuerySql().replaceFirst("\\*", "*, COUNT(*) OVER() AS total_count"));
|
|
|
+ int offset = (query.getCurrent() - 1) * query.getSize();
|
|
|
+ List<Map<String, Object>> list = this.baseMapper.getCardListPage(offset, query.getSize(), query.getQuerySql());
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ result.setTotal(0);
|
|
|
+ } else {
|
|
|
+ result.setTotal((Long) list.get(0).get("total_count"));
|
|
|
+ }
|
|
|
+ result.setCurrent(query.getCurrent());
|
|
|
+ result.setSize(query.getSize());
|
|
|
+ result.setRecords(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional//需要保持事务,还要注意防止数据库连接池不是同一个连接(仅限mysql使用,大数据量效率不高)
|
|
|
+ public void queryCard(IPage<Map<String, Object>> result, CriteriaQuery query) {
|
|
|
+ //mysql专属优化,全表扫描,但只扫描一次
|
|
|
+ query.setQuerySql(query.getQuerySql().replaceFirst("\\*", "SQL_CALC_FOUND_ROWS *"));
|
|
|
+
|
|
|
+ int offset = (query.getCurrent() - 1) * query.getSize();
|
|
|
+ List<Map<String, Object>> list = this.baseMapper.getCardListPage(offset, query.getSize(), query.getQuerySql());
|
|
|
+ Integer total = this.baseMapper.getTotal();
|
|
|
+
|
|
|
+ result.setCurrent(query.getCurrent());
|
|
|
+ result.setSize(query.getSize());
|
|
|
+ result.setRecords(list);
|
|
|
+ result.setTotal(total);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|