添加数据同步代码

This commit is contained in:
hzj
2024-01-09 14:34:28 +08:00
parent a1a0217e59
commit 82fba66226
8 changed files with 108 additions and 34 deletions

View File

@@ -1,8 +1,13 @@
package com.njcn.oracle.bo.param; package com.njcn.oracle.bo.param;
import com.njcn.oracle.bo.po.JobDetail; import com.njcn.oracle.bo.po.JobDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;
/** /**
* Description: * Description:
* Date: 2024/1/9 9:21【需求编号】 * Date: 2024/1/9 9:21【需求编号】
@@ -12,7 +17,14 @@ import lombok.Data;
*/ */
@Data @Data
public class JobQueryParam extends DataAsynParam{ 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;
} }

View File

@@ -15,4 +15,25 @@
<!--@mbg.generated--> <!--@mbg.generated-->
"TABLE_NAME", START_TIME, END_TIME, "STATE", "ROW_COUNT", UPDATE_TIME "TABLE_NAME", START_TIME, END_TIME, "STATE", "ROW_COUNT", UPDATE_TIME
</sql> </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 &lt;= #{jobQueryParam.currentPage} * #{jobQueryParam.pageSize} ) where rownum_ &gt; (#{jobQueryParam.currentPage} - 1) * #{jobQueryParam.pageSize}
</select>
</mapper> </mapper>

View File

@@ -2,7 +2,11 @@ package com.njcn.oracle.mybatis.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.oracle.bo.param.JobQueryParam;
import com.njcn.oracle.bo.po.JobDetail; 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 * @version V1.0.0
*/ */
public interface JobDetailMapper extends MppBaseMapper<JobDetail> { public interface JobDetailMapper extends MppBaseMapper<JobDetail> {
List<JobDetail> query(@Param("jobQueryParam") JobQueryParam jobQueryParam);
} }

View File

@@ -21,8 +21,8 @@ public abstract class ReplenishMybatisServiceImpl<M extends BatchBaseMapper<T>,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insertBatchBySlice(List<T> data, int size) { public void insertBatchBySlice(List<T> data, int size) throws RuntimeException{
try {
int totalCount = data.size(); int totalCount = data.size();
int idxLimit = Math.min(size, totalCount); int idxLimit = Math.min(size, totalCount);
List<T> dataTemp = new ArrayList<>(data); List<T> dataTemp = new ArrayList<>(data);
@@ -44,9 +44,7 @@ public abstract class ReplenishMybatisServiceImpl<M extends BatchBaseMapper<T>,
} else { } else {
this.baseMapper.insertBatchSomeColumn(dataTemp); this.baseMapper.insertBatchSomeColumn(dataTemp);
} }
} catch (Exception e) {
throw new RuntimeException("分片批量插入数据异常,异常为:" + e);
}
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.oracle.service; package com.njcn.oracle.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.jeffreyning.mybatisplus.service.IMppService; import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.oracle.bo.param.JobQueryParam; import com.njcn.oracle.bo.param.JobQueryParam;
import com.njcn.oracle.bo.po.JobDetail; import com.njcn.oracle.bo.po.JobDetail;
@@ -19,5 +20,5 @@ public interface JobDetailService extends IMppService<JobDetail> {
JobDetail select(JobDetail jobDetail); JobDetail select(JobDetail jobDetail);
List<JobDetail> selectByParam(JobQueryParam jobQueryParam); IPage<JobDetail> selectByParam(JobQueryParam jobQueryParam);
} }

View File

@@ -1,6 +1,9 @@
package com.njcn.oracle.service.impl; package com.njcn.oracle.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS; 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.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.oracle.bo.param.JobQueryParam; import com.njcn.oracle.bo.param.JobQueryParam;
import com.njcn.oracle.bo.param.ServiceTypeEnum; import com.njcn.oracle.bo.param.ServiceTypeEnum;
@@ -36,13 +39,19 @@ public class JobDetailServiceImpl extends MppServiceImpl<JobDetailMapper, JobDet
} }
@Override @Override
public List<JobDetail> selectByParam(JobQueryParam jobQueryParam) { public IPage<JobDetail> selectByParam(JobQueryParam jobQueryParam) {
List<JobDetail> list = this.lambdaQuery().between(JobDetail::getStartTime, jobQueryParam.getStartTime(), jobQueryParam.getEndTime()). IPage<JobDetail> page = new Page<>(jobQueryParam.getCurrentPage(), jobQueryParam.getPageSize());
eq(StringUtils.isNotBlank(jobQueryParam.getState()), JobDetail::getState, jobQueryParam.getState()). QueryWrapper<JobDetail> queryWrapper = new QueryWrapper<>();
in(!CollectionUtils.isEmpty(jobQueryParam.getTableNames()), JobDetail::getTableName, jobQueryParam.getTableNames()). queryWrapper.lambda().between(JobDetail::getStartTime, jobQueryParam.getStartTime(), jobQueryParam.getEndTime()).
list(); in(!CollectionUtils.isEmpty(jobQueryParam.getStates()), JobDetail::getState, jobQueryParam.getStates()).
list.stream().forEach(temp->temp.setTableName_CN(ServiceTypeEnum.getValueByCode(temp.getTableName()))); in(!CollectionUtils.isEmpty(jobQueryParam.getTableNames()), JobDetail::getTableName, jobQueryParam.getTableNames()).orderByDesc(JobDetail::getStartTime);
return list;
Integer integer = this.getBaseMapper().selectCount(queryWrapper);
List<JobDetail> jobDetailIPage = this.getBaseMapper().query(jobQueryParam);
page.setRecords(jobDetailIPage);
page.setTotal(Long.parseLong(integer+""));
return page;
} }

View File

@@ -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);
}
}

View File

@@ -1,6 +1,7 @@
package com.njcn.oracle.controller; package com.njcn.oracle.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.oracle.bo.param.JobQueryParam; import com.njcn.oracle.bo.param.JobQueryParam;
import com.njcn.oracle.bo.po.JobDetail; import com.njcn.oracle.bo.po.JobDetail;
import com.njcn.oracle.service.JobDetailService; import com.njcn.oracle.service.JobDetailService;
@@ -36,8 +37,8 @@ public class JobDetailController {
@PostMapping("/jobQuery") @PostMapping("/jobQuery")
@ApiOperation("任务查询") @ApiOperation("任务查询")
@ApiImplicitParam(name = "jobQueryParam", value = "任务查询参数", required = true) @ApiImplicitParam(name = "jobQueryParam", value = "任务查询参数", required = true)
public List<JobDetail> jobQuery(@RequestBody JobQueryParam jobQueryParam){ public IPage<JobDetail> jobQuery(@RequestBody JobQueryParam jobQueryParam){
List<JobDetail> jobDetails = jobDetailService.selectByParam(jobQueryParam); IPage<JobDetail> jobDetails = jobDetailService.selectByParam(jobQueryParam);
return jobDetails;//HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, jobDetails, "任务查询"); return jobDetails;//HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, jobDetails, "任务查询");
} }
@PostMapping("/jobRemove") @PostMapping("/jobRemove")