|
@@ -5,21 +5,21 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.TCStatisticsDto;
|
|
|
import com.qmth.distributed.print.business.entity.TCStatistics;
|
|
|
import com.qmth.distributed.print.business.entity.TCStatisticsTemp;
|
|
|
import com.qmth.distributed.print.business.enums.StatisticsStatusEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.TCStatisticsMapper;
|
|
|
-import com.qmth.distributed.print.business.mapper.TCStatisticsTempMapper;
|
|
|
import com.qmth.distributed.print.business.service.TCStatisticsService;
|
|
|
import com.qmth.distributed.print.business.service.TCStatisticsTempService;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
|
-import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
-import org.springframework.boot.SpringApplication;
|
|
|
+import com.qmth.teachcloud.common.util.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -47,6 +47,9 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
@Resource
|
|
|
SysOrgService sysOrgService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
/**
|
|
|
* 查找印刷计划信息
|
|
|
*
|
|
@@ -78,6 +81,19 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
return tcStatisticsMapper.findByBatchNoCount(schoolId, batchNo, orgIds);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据batchNo统计信息
|
|
|
+ *
|
|
|
+ * @param schoolId
|
|
|
+ * @param batchNo
|
|
|
+ * @param orgIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TCStatisticsDto> findByBatchNoCountJoin(Long schoolId, String batchNo, Set<Long> orgIds) {
|
|
|
+ return tcStatisticsMapper.findByBatchNoCountJoin(schoolId, batchNo, orgIds);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 导入关联数据
|
|
|
*
|
|
@@ -142,4 +158,119 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
.in(TCStatisticsTemp::getClazzId, setCollections[2]);
|
|
|
tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新关联数据
|
|
|
+ *
|
|
|
+ * @param sysUser
|
|
|
+ * @param batchNoSet
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void freshenJoinData(SysUser sysUser, Set<String> batchNoSet) {
|
|
|
+ for (String batchNo : batchNoSet) {
|
|
|
+ List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNoJoin(sysUser.getSchoolId(), batchNo);
|
|
|
+ if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
|
|
|
+ String batchNoNew = SystemConstant.getUuid();
|
|
|
+ Set<Long> collegeIdSet = new HashSet<>();
|
|
|
+ for (TCStatisticsTemp t : tcStatisticsTempList) {
|
|
|
+ collegeIdSet.add(t.getCollegeId());
|
|
|
+ t.insertInfo(sysUser.getId());
|
|
|
+ t.setBatchNo(batchNoNew);
|
|
|
+ }
|
|
|
+ tcStatisticsTempService.saveBatch(tcStatisticsTempList);
|
|
|
+
|
|
|
+ Set<Long> orgIds = new HashSet<>();
|
|
|
+ for (Long l : collegeIdSet) {
|
|
|
+ List<SysOrg> sysOrgList = sysOrgService.findByConnectByRootOrgId(l);
|
|
|
+ Set<Long> orgTempIds = sysOrgList.stream().map(s -> s.getId()).collect(Collectors.toSet());
|
|
|
+ orgIds.addAll(orgTempIds);
|
|
|
+ }
|
|
|
+ List<TCStatisticsDto> tcStatisticsDtoList = this.findByBatchNoCountJoin(sysUser.getSchoolId(), batchNoNew, orgIds);
|
|
|
+ if (Objects.nonNull(tcStatisticsDtoList) && tcStatisticsDtoList.size() > 0) {
|
|
|
+ TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ List<TCStatistics> tcStatisticsList = gson.fromJson(JacksonUtil.parseJson(tcStatisticsDtoList), new TypeToken<List<TCStatistics>>() {
|
|
|
+ }.getType());
|
|
|
+ for (TCStatistics t : tcStatisticsList) {
|
|
|
+ t.insertInfo(sysUser.getId());
|
|
|
+ }
|
|
|
+ tcStatisticsService.saveBatch(tcStatisticsList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除旧的关联数据
|
|
|
+ *
|
|
|
+ * @param batchNoSet
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void removeOldJoinData(Set<String> batchNoSet) {
|
|
|
+ QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
|
|
|
+ tcStatisticsTempQueryWrapper.lambda().in(TCStatisticsTemp::getBatchNo, batchNoSet);
|
|
|
+ tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
|
|
|
+
|
|
|
+ TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
|
|
|
+ QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
|
|
|
+ tcStatisticsQueryWrapper.lambda().in(TCStatistics::getBatchNo, batchNoSet);
|
|
|
+ tcStatisticsService.remove(tcStatisticsQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result freshenData() {
|
|
|
+ TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
|
|
|
+ tcStatisticsQueryWrapper.select(" DISTINCT batch_no ");
|
|
|
+ List<TCStatistics> tcStatisticsList = tcStatisticsService.list(tcStatisticsQueryWrapper);
|
|
|
+ if (Objects.nonNull(tcStatisticsList) && tcStatisticsList.size() > 0) {
|
|
|
+ Set<String> batchNoSet = tcStatisticsList.stream().map(s -> s.getBatchNo()).collect(Collectors.toSet());
|
|
|
+ try {
|
|
|
+ if (redisUtil.lock(SystemConstant.REDIS_LOCK_BATCH_NO_PREFIX + Math.abs(batchNoSet.toString().hashCode()),
|
|
|
+ SystemConstant.REDIS_LOCK_BATCH_NO_TIME_OUT)) {
|
|
|
+ tcStatisticsService.freshenJoinData(sysUser, batchNoSet);
|
|
|
+ tcStatisticsService.removeOldJoinData(batchNoSet);
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("正在刷新数据,请稍候再试!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("请求出错", e);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ return ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ return ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_BATCH_NO_PREFIX + Math.abs(batchNoSet.toString().hashCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultUtil.ok(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result deleteData(List<Long> ids) {
|
|
|
+ TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
|
|
|
+ List<TCStatistics> tcStatisticsList = tcStatisticsService.listByIds(ids);
|
|
|
+ if (Objects.nonNull(tcStatisticsList) && tcStatisticsList.size() > 0) {
|
|
|
+ Set<String> batchNoSet = tcStatisticsList.stream().map(s -> s.getBatchNo()).collect(Collectors.toSet());
|
|
|
+ tcStatisticsService.removeOldJoinData(batchNoSet);
|
|
|
+ }
|
|
|
+ return ResultUtil.ok(true);
|
|
|
+ }
|
|
|
}
|