Commit efa15a92 authored by 高宇's avatar 高宇

1.月度信息

parent bf72e4fc
......@@ -31,6 +31,8 @@ import org.rcisoft.bus.jnsp7xtmdqsj.entity.Jnsp7xtmDqsj;
import org.rcisoft.bus.jnsp7xtmdqsj.service.Jnsp7xtmDqsjService;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* Created by cy on 2024年5月14日 上午10:20:48.
......@@ -43,6 +45,8 @@ public class Jnsp7xtmDqsjController extends CyPaginationController<Jnsp7xtmDqsj>
@Autowired
private Jnsp7xtmDqsjService jnsp7xtmDqsjServiceImpl;
//@PreAuthorize("@cyPerm.hasPerm('sys:p7xtmDqsj:add')")
@CyOpeLogAnno(title = "system-Jnsp7xtmDqsj管理-新增Jnsp7xtmDqsj", businessType = CyLogTypeEnum.INSERT)
@ApiOperation(value="添加Jnsp7xtmDqsj", notes="添加Jnsp7xtmDqsj")
......@@ -156,7 +160,7 @@ public class Jnsp7xtmDqsjController extends CyPaginationController<Jnsp7xtmDqsj>
TaskInfo taskInfo = jnsp7xtmDqsjServiceImpl.addTaskInfo();
//service2
jnsp7xtmDqsjServiceImpl.monthlyTablePull(taskInfo.getTackId());
return CyResultGenUtil.builder(new CyPersistModel(1),
return CyResultGenUtil.builder(jnsp7xtmDqsjServiceImpl.monthlyTablePull(taskInfo.getTackId()),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
taskInfo);
......
......@@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;
import org.rcisoft.bus.jnsp7xtm.vo.Jnsp7xtmVo;
import org.rcisoft.bus.jnsp7xtmdqsj.dto.Jnsp7xtmDqsjPageHandleDto;
import org.rcisoft.core.mapper.CyBaseMapper;
import org.rcisoft.bus.jnsp7xtmdqsj.entity.Jnsp7xtmDqsj;
import org.springframework.beans.factory.annotation.Value;
......@@ -42,12 +43,17 @@ public interface Jnsp7xtmDqsjRepository extends CyBaseMapper<Jnsp7xtmDqsj> {
/**
* 流式查询Jnsp7xtmVo
* **/
void streamQuery(@Param("handler") ResultHandler<Jnsp7xtmVo> handler);
void streamQuery(ResultHandler<Jnsp7xtmVo> handler,@Param("entity") Jnsp7xtmDqsjPageHandleDto jnsp7xtmDqsjPageHandleDto );
/**
* 批量添加 Jnsp7xtmDqsj
* **/
void batchAddJnsp7xtmDqsj(@Param("list") List<Jnsp7xtmDqsj> list);
/**
* 查询Jnsp7xtmVo的总数
* **/
Integer queryTotalJnsp7xtmDqs();
}
package org.rcisoft.bus.jnsp7xtmdqsj.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: gy
* @Date: 2024/5/16 13:23
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Jnsp7xtmDqsjPageHandleDto {
// 总数
private Integer total;
// 当前页
private Integer page;
// 页长度
private Integer rows;
}
......@@ -22,6 +22,7 @@ import org.rcisoft.bus.jnsp7xtm.entity.Jnsp7xtm;
import org.rcisoft.bus.jnsp7xtm.enums.ColTransitionEnum;
import org.rcisoft.bus.jnsp7xtm.enums.Jnsp7xtmDqsjType;
import org.rcisoft.bus.jnsp7xtm.vo.Jnsp7xtmVo;
import org.rcisoft.bus.jnsp7xtmdqsj.dto.Jnsp7xtmDqsjPageHandleDto;
import org.rcisoft.bus.taskinfo.dao.TaskInfoRepository;
import org.rcisoft.bus.taskinfo.entity.TaskInfo;
import org.rcisoft.core.exception.CyServiceException;
......@@ -75,6 +76,9 @@ public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,
@Value("${jnsp7xtmDqsj.batchAddPagesize}")
private Integer batchInsertSize;
@Value("${jnsp7xtmDqsj.pageQuestSize}")
private Integer pageQuerySize;
@Value("${jnsp7xtmDqsj.shema}")
private String shema;
......@@ -197,35 +201,24 @@ public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,
* 月度表拉取
* **/
@Override
@Async
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
public CyPersistModel monthlyTablePull(String taskId) {
try {
if (monthlyTablePullLock.tryLock(1000, TimeUnit.MILLISECONDS)) {
try {
// 创建并启动计时器
Stopwatch stopwatch = Stopwatch.createStarted();
// 获取全部数据
List<Jnsp7xtmDqsj> addList = new ArrayList<>();
// khdm is not null && pn is not null
baseMapper.streamQuery(resultContext -> {
Jnsp7xtmVo resultObject = resultContext.getResultObject();
Jnsp7xtmDqsj jnsp7xtmDqsj = Jnsp7xtmDqsj.generateJnsp7xtmDqsj(resultObject);
addList.add(jnsp7xtmDqsj);
if (addList.size() > batchInsertSize) {
baseMapper.batchAddJnsp7xtmDqsj(addList);
addList.clear();
// 获取数据的总数
Integer total = baseMapper.queryTotalJnsp7xtmDqs();
Integer pageNumber = 1;
if (total >= pageQuerySize) {
pageNumber = (int) Math.ceil((double) total / pageQuerySize);
}
for (int i = 1; i <= pageNumber ; i++) {
Jnsp7xtmDqsjPageHandleDto jnsp7xtmDqsjPageHandleDto = Jnsp7xtmDqsjPageHandleDto.builder().page(i).rows(pageQuerySize).build();
addJnsp7xtmDqsjByPage(jnsp7xtmDqsjPageHandleDto);
}
});
if(CollectionUtil.isNotEmpty(addList))
baseMapper.batchAddJnsp7xtmDqsj(addList);
// 停止计时器
stopwatch.stop();
QueryWrapper<TaskInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tack_id",taskId);
TaskInfo taskInfo = taskInfoRepository.selectOne(queryWrapper);
taskInfo.setStatus("1");
taskInfoRepository.updateById(taskInfo);
log.info("查询耗时秒" + stopwatch.elapsed().getSeconds());
log.info("查询耗时毫秒" + stopwatch.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
......@@ -244,17 +237,47 @@ public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,
return new CyPersistModel(1);
}
public void addJnsp7xtmDqsjByPage(Jnsp7xtmDqsjPageHandleDto jnsp7xtmDqsjPageHandleDto) {
log.info("页数: {}",jnsp7xtmDqsjPageHandleDto.getPage());
List<Jnsp7xtmDqsj> addList = new ArrayList<>();
baseMapper.streamQuery(resultContext -> {
Jnsp7xtmVo resultObject = resultContext.getResultObject();
Jnsp7xtmDqsj jnsp7xtmDqsj = Jnsp7xtmDqsj.generateJnsp7xtmDqsj(resultObject);
addList.add(jnsp7xtmDqsj);
if (addList.size() > batchInsertSize) {
log.info("addList",addList);
baseMapper.batchAddJnsp7xtmDqsj(addList);
addList.clear();
}
},jnsp7xtmDqsjPageHandleDto);
if(CollectionUtil.isNotEmpty(addList))
baseMapper.batchAddJnsp7xtmDqsj(addList);
}
/**添加任务**/
@Override
public TaskInfo addTaskInfo() {
TaskInfo taskInfo = new TaskInfo();
try {
if (monthlyTablePullLock.tryLock(1000, TimeUnit.MILLISECONDS)) {
try {
taskInfo.setStatus("0");
taskInfo.setType(Jnsp7xtmDqsjType.JNSP7XTMDDQS.getCode());
taskInfo.setFlag("1");
// 生成uuid
taskInfo.setTackId(CyIdGenUtil.uuid());
taskInfoRepository.insert(taskInfo);
return taskInfo;
} catch (Exception e) {
e.printStackTrace();
throw new CyServiceException(501,"数据同步异常");
} finally {
monthlyTablePullLock.unlock();
}
} else {
throw new CyServiceException(501,"该功能使用频繁,请稍后重试");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return taskInfo;
}
}
......@@ -130,7 +130,9 @@ jnsp7xtm:
pageSize: 20
jnsp7xtmDqsj:
# 每次查询分页的长度
pageQuestSize: 5000
# 每次添加到数据库的长度
batchAddPagesize: 50
batchAddPagesize: 30
# service 要重置的数据库
shema: 'demo.dbo'
......@@ -401,7 +401,19 @@
where
jnsp.khdm is not null
and jnsp.pn is not null
ORDER BY jnsp.khdm
OFFSET (#{entity.page} - 1) * #{entity.rows} ROWS
FETCH NEXT #{entity.rows} ROWS ONLY
</select>
<select id="queryTotalJnsp7xtmDqs" resultType="java.lang.Integer">
SELECT
count(*)
FROM
jnsp7xtm jnsp left JOIN b_customer cust on jnsp.khdm = cust.cust_code and cust.del_flag = '0'
left join b_pn_sypn bps on bps.pn = jnsp.pn and bps.del_flag = '0'
where
jnsp.khdm is not null
and jnsp.pn is not null
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment