添加数据同步代码
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package com.njcn.oracle.bo.param;
|
||||
|
||||
import com.njcn.oracle.bo.po.JobDetail;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/1/9 9:21【需求编号】
|
||||
@@ -12,7 +17,14 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class JobQueryParam extends DataAsynParam{
|
||||
private String state;
|
||||
|
||||
private List<String> states;
|
||||
@NotNull(message="当前页不能为空!")
|
||||
@Min(value = 1, message = "当前页不能为0")
|
||||
@ApiModelProperty(value = "当前页",name = "currentPage",dataType ="Integer",required = true)
|
||||
private Integer currentPage;
|
||||
/**显示条数*/
|
||||
@NotNull(message="显示条数不能为空!")
|
||||
@ApiModelProperty(value = "显示条数",name = "pageSize",dataType ="Integer",required = true)
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,25 @@
|
||||
<!--@mbg.generated-->
|
||||
"TABLE_NAME", START_TIME, END_TIME, "STATE", "ROW_COUNT", UPDATE_TIME
|
||||
</sql>
|
||||
|
||||
<select id="query" resultMap="BaseResultMap">
|
||||
select * from ( select row_.*, rownum rownum_ from (
|
||||
select * from JOB_DETAIL a where 1=1
|
||||
and a.START_TIME between #{jobQueryParam.startTime,jdbcType=DATE} and #{jobQueryParam.endTime,jdbcType=DATE}
|
||||
<if test="jobQueryParam.states!=null and jobQueryParam.states.size()!=0">
|
||||
AND a.STATE IN
|
||||
<foreach collection="jobQueryParam.states" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="jobQueryParam.tableNames!=null and jobQueryParam.tableNames.size()!=0">
|
||||
AND a.TABLE_NAME IN
|
||||
<foreach collection="jobQueryParam.tableNames" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
order by a.START_TIME desc
|
||||
) row_
|
||||
where rownum <= #{jobQueryParam.currentPage} * #{jobQueryParam.pageSize} ) where rownum_ > (#{jobQueryParam.currentPage} - 1) * #{jobQueryParam.pageSize}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -2,7 +2,11 @@ package com.njcn.oracle.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.oracle.bo.param.JobQueryParam;
|
||||
import com.njcn.oracle.bo.po.JobDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -13,4 +17,5 @@ import com.njcn.oracle.bo.po.JobDetail;
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface JobDetailMapper extends MppBaseMapper<JobDetail> {
|
||||
List<JobDetail> query(@Param("jobQueryParam") JobQueryParam jobQueryParam);
|
||||
}
|
||||
@@ -21,32 +21,30 @@ public abstract class ReplenishMybatisServiceImpl<M extends BatchBaseMapper<T>,
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertBatchBySlice(List<T> data, int size) {
|
||||
try {
|
||||
int totalCount = data.size();
|
||||
int idxLimit = Math.min(size, totalCount);
|
||||
List<T> dataTemp = new ArrayList<>(data);
|
||||
//保存单批提交的数据集合
|
||||
if (idxLimit == size) {
|
||||
int times = totalCount / idxLimit + 1;
|
||||
for (int i = 1; i <= times; i++) {
|
||||
if (totalCount >= idxLimit) {
|
||||
List<T> temp = dataTemp.subList(0, idxLimit);
|
||||
this.baseMapper.insertBatchSomeColumn(temp);
|
||||
temp.clear();
|
||||
totalCount = totalCount - idxLimit;
|
||||
} else {
|
||||
if (CollectionUtil.isNotEmpty(dataTemp)) {
|
||||
this.baseMapper.insertBatchSomeColumn(dataTemp);
|
||||
}
|
||||
public void insertBatchBySlice(List<T> data, int size) throws RuntimeException{
|
||||
|
||||
int totalCount = data.size();
|
||||
int idxLimit = Math.min(size, totalCount);
|
||||
List<T> dataTemp = new ArrayList<>(data);
|
||||
//保存单批提交的数据集合
|
||||
if (idxLimit == size) {
|
||||
int times = totalCount / idxLimit + 1;
|
||||
for (int i = 1; i <= times; i++) {
|
||||
if (totalCount >= idxLimit) {
|
||||
List<T> temp = dataTemp.subList(0, idxLimit);
|
||||
this.baseMapper.insertBatchSomeColumn(temp);
|
||||
temp.clear();
|
||||
totalCount = totalCount - idxLimit;
|
||||
} else {
|
||||
if (CollectionUtil.isNotEmpty(dataTemp)) {
|
||||
this.baseMapper.insertBatchSomeColumn(dataTemp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.baseMapper.insertBatchSomeColumn(dataTemp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("分片批量插入数据异常,异常为:" + e);
|
||||
} else {
|
||||
this.baseMapper.insertBatchSomeColumn(dataTemp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.oracle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.jeffreyning.mybatisplus.service.IMppService;
|
||||
import com.njcn.oracle.bo.param.JobQueryParam;
|
||||
import com.njcn.oracle.bo.po.JobDetail;
|
||||
@@ -19,5 +20,5 @@ public interface JobDetailService extends IMppService<JobDetail> {
|
||||
|
||||
JobDetail select(JobDetail jobDetail);
|
||||
|
||||
List<JobDetail> selectByParam(JobQueryParam jobQueryParam);
|
||||
IPage<JobDetail> selectByParam(JobQueryParam jobQueryParam);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.njcn.oracle.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.oracle.bo.param.JobQueryParam;
|
||||
import com.njcn.oracle.bo.param.ServiceTypeEnum;
|
||||
@@ -36,13 +39,19 @@ public class JobDetailServiceImpl extends MppServiceImpl<JobDetailMapper, JobDet
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobDetail> selectByParam(JobQueryParam jobQueryParam) {
|
||||
List<JobDetail> list = this.lambdaQuery().between(JobDetail::getStartTime, jobQueryParam.getStartTime(), jobQueryParam.getEndTime()).
|
||||
eq(StringUtils.isNotBlank(jobQueryParam.getState()), JobDetail::getState, jobQueryParam.getState()).
|
||||
in(!CollectionUtils.isEmpty(jobQueryParam.getTableNames()), JobDetail::getTableName, jobQueryParam.getTableNames()).
|
||||
list();
|
||||
list.stream().forEach(temp->temp.setTableName_CN(ServiceTypeEnum.getValueByCode(temp.getTableName())));
|
||||
return list;
|
||||
public IPage<JobDetail> selectByParam(JobQueryParam jobQueryParam) {
|
||||
IPage<JobDetail> page = new Page<>(jobQueryParam.getCurrentPage(), jobQueryParam.getPageSize());
|
||||
QueryWrapper<JobDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().between(JobDetail::getStartTime, jobQueryParam.getStartTime(), jobQueryParam.getEndTime()).
|
||||
in(!CollectionUtils.isEmpty(jobQueryParam.getStates()), JobDetail::getState, jobQueryParam.getStates()).
|
||||
in(!CollectionUtils.isEmpty(jobQueryParam.getTableNames()), JobDetail::getTableName, jobQueryParam.getTableNames()).orderByDesc(JobDetail::getStartTime);
|
||||
|
||||
Integer integer = this.getBaseMapper().selectCount(queryWrapper);
|
||||
|
||||
List<JobDetail> jobDetailIPage = this.getBaseMapper().query(jobQueryParam);
|
||||
page.setRecords(jobDetailIPage);
|
||||
page.setTotal(Long.parseLong(integer+""));
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.oracle.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/1/9 10:51【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
// 允许所有域名访问
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.oracle.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.njcn.oracle.bo.param.JobQueryParam;
|
||||
import com.njcn.oracle.bo.po.JobDetail;
|
||||
import com.njcn.oracle.service.JobDetailService;
|
||||
@@ -36,8 +37,8 @@ public class JobDetailController {
|
||||
@PostMapping("/jobQuery")
|
||||
@ApiOperation("任务查询")
|
||||
@ApiImplicitParam(name = "jobQueryParam", value = "任务查询参数", required = true)
|
||||
public List<JobDetail> jobQuery(@RequestBody JobQueryParam jobQueryParam){
|
||||
List<JobDetail> jobDetails = jobDetailService.selectByParam(jobQueryParam);
|
||||
public IPage<JobDetail> jobQuery(@RequestBody JobQueryParam jobQueryParam){
|
||||
IPage<JobDetail> jobDetails = jobDetailService.selectByParam(jobQueryParam);
|
||||
return jobDetails;//HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, jobDetails, "任务查询");
|
||||
}
|
||||
@PostMapping("/jobRemove")
|
||||
|
||||
Reference in New Issue
Block a user