Commit 621ecce6 authored by 高宇's avatar 高宇

1.月度信息

parent e2bef935
......@@ -51,6 +51,13 @@
<!-- <version>3.0.0_nlt.25</version>-->
<!-- 排除oracle12的驱动,此处代码不能提交,测试使用的是12,生产为11 -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<!-- 时间统计 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
......
......@@ -137,23 +137,23 @@ public class Jnsp7xtmDqsjController extends CyPaginationController<Jnsp7xtmDqsj>
jnsp7xtmDqsjServiceImpl.getMonth());
}
@CyOpeLogAnno(title = "system-Jnsp7xtmDqsj管理-数据表清空", businessType = CyLogTypeEnum.QUERY)
@ApiOperation(value = "数据表清空", notes = "数据表清空")
@GetMapping(value = "/truncateTable")
@CyOpeLogAnno(title = "system-Jnsp7xtmDqsj管理-数据表重置", businessType = CyLogTypeEnum.QUERY)
@ApiOperation(value = "数据表重置", notes = "数据表重置")
@GetMapping(value = "/dataTableRese")
public CyResult truncateTable(String key) {
return CyResultGenUtil.builder(new CyPersistModel(1),
return CyResultGenUtil.builder(jnsp7xtmDqsjServiceImpl.dataTableRese(),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
jnsp7xtmDqsjServiceImpl.truncateTable(key));
null);
}
@CyOpeLogAnno(title = "system-Jnsp7xtmDqsj管理-流式添加数据", businessType = CyLogTypeEnum.QUERY)
@ApiOperation(value = "流式添加数据", notes = "流式添加数据")
@PostMapping (value = "/streamAdd")
public CyResult streamAdd() {
return CyResultGenUtil.builder(new CyPersistModel(1),
@CyOpeLogAnno(title = "system-Jnsp7xtmDqsj管理-月度表拉取", businessType = CyLogTypeEnum.QUERY)
@ApiOperation(value = "月度表拉取", notes = "月度表拉取")
@PostMapping (value = "/monthlyTablePull")
public CyResult monthlyTablePull() {
return CyResultGenUtil.builder(jnsp7xtmDqsjServiceImpl.monthlyTablePull(),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
jnsp7xtmDqsjServiceImpl.streamAdd());
null);
}
}
......@@ -35,13 +35,19 @@ public interface Jnsp7xtmDqsjRepository extends CyBaseMapper<Jnsp7xtmDqsj> {
List<String> getMonthList();
/**
* 截断表信息
* 截断表jnsp7xtm_dqsj信息
* **/
void truncateTable(@Param("key") String key);
void truncateJnsp7xtmDqsj(@Param("shema") String shema);
/**
* 流式查询Jnsp7xtmVo
* **/
void streamQuery(@Param("handler") ResultHandler<Jnsp7xtmVo> handler);
/**总数**/
Integer queryTotal();
/**
* 批量添加 Jnsp7xtmDqsj
* **/
void batchAddJnsp7xtmDqsj(@Param("list") List<Jnsp7xtmDqsj> list);
}
......@@ -354,9 +354,12 @@ public class Jnsp7xtmDqsj {
public static final String TERM_L = "L";
/**
*
* @param jnsp7xtmVo
* @return
*/
public static Jnsp7xtmDqsj generateJnsp7xtmDqsj(Jnsp7xtmVo jnsp7xtmVo){
Jnsp7xtmDqsj jnsp7xtmDqsj = new Jnsp7xtmDqsj();
// y.cust_group - cust_gc 20项
BeanUtil.copyProperties(jnsp7xtmVo,jnsp7xtmDqsj);
......@@ -389,7 +392,7 @@ public class Jnsp7xtmDqsj {
} else if (lastTwoNqy.equals("10") || lastTwoNqy.equals("11") || lastTwoNqy.equals("12")) {
jnsp7xtmDqsj.setQuarter("Q3");
}
jnsp7xtmDqsj.setCc(jnsp7xtmVo.getKhm());
jnsp7xtmDqsj.setCc(jnsp7xtmVo.getKhdm());
jnsp7xtmDqsj.setCn(jnsp7xtmVo.getKhm());
// if(x.xslj == "W0") ? y.io = I: y.io = O
if (StringUtils.isNotBlank(jnsp7xtmVo.getXslj())) {
......@@ -417,7 +420,6 @@ public class Jnsp7xtmDqsj {
jnsp7xtmDqsj.setCurrency(jnsp7xtmVo.getBz());
jnsp7xtmDqsj.setAmt(new BigDecimal(jnsp7xtmVo.getRmb()));
}
return jnsp7xtmDqsj;
}
......
......@@ -72,12 +72,12 @@ public interface Jnsp7xtmDqsjService {
Jnsp7xtmOptionDto getMonth();
/**
* 截断表
* 数据表重置
* **/
Integer truncateTable(String KeyTable);
CyPersistModel dataTableRese();
/**
* 流程添加
* **/
Integer streamAdd();
CyPersistModel monthlyTablePull();
}
......@@ -10,6 +10,7 @@ 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Stopwatch;
import com.mongodb.client.model.Collation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -59,12 +60,18 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,Jnsp7xtmDqsj> implements Jnsp7xtmDqsjService {
// 数据表锁
private static Lock dataTableLock = new ReentrantLock();
// 数据表重置锁
private static Lock dataTableResetLock = new ReentrantLock();
// 月度表拉取锁
private static Lock monthlyTablePullLock = new ReentrantLock();
@Value("${fetchSize}")
private Integer batchInsertSize;
@Value("${shema}")
private String shema;
/**
* 保存
* @param jnsp7xtmDqsj
......@@ -161,13 +168,13 @@ public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,
// 数据表重置
@Override
public Integer truncateTable(String keyTable) {
public CyPersistModel dataTableRese() {
try {
if (dataTableLock.tryLock(1000, TimeUnit.MILLISECONDS)) {
if (dataTableResetLock.tryLock(1000, TimeUnit.MILLISECONDS)) {
try {
baseMapper.truncateTable(keyTable);
baseMapper.truncateJnsp7xtmDqsj(shema);
} finally {
dataTableLock.unlock();
dataTableResetLock.unlock();
}
} else {
throw new CyServiceException(501,"该功能使用频繁,请稍后重试");
......@@ -175,32 +182,48 @@ public class Jnsp7xtmDqsjServiceImpl extends ServiceImpl<Jnsp7xtmDqsjRepository,
} catch (InterruptedException e) {
e.printStackTrace();
}
return 1;
return new CyPersistModel(1);
}
/**
* 流式添加
* 月度表重置
* **/
@Override
public Integer streamAdd() {
// 获取全部数据
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);
log.info("批量插入");
addList.clear();
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
public CyPersistModel monthlyTablePull() {
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();
}
});
if(CollectionUtil.isNotEmpty(addList))
baseMapper.batchAddJnsp7xtmDqsj(addList);
// 停止计时器
stopwatch.stop();
log.info("查询耗时秒" + stopwatch.elapsed().getSeconds());
log.info("查询耗时毫秒" + stopwatch.elapsed(TimeUnit.MILLISECONDS));
} finally {
monthlyTablePullLock.unlock();
}
} else {
throw new CyServiceException(501,"该功能使用频繁,请稍后重试");
}
});
if(CollectionUtil.isNotEmpty(addList)){
log.info("addList",addList);
log.info("批量插入");
} catch (InterruptedException e) {
e.printStackTrace();
}
return 1;
return new CyPersistModel(1);
}
}
......@@ -298,6 +298,8 @@ export:
fetchSize: 10
shema: 'demo.dbo'
login:
loginName: "00"
......
......@@ -3,7 +3,6 @@
<mapper namespace="org.rcisoft.bus.jnsp7xtmdqsj.dao.Jnsp7xtmDqsjRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.bus.jnsp7xtmdqsj.entity.Jnsp7xtmDqsj">
<id column="business_id" jdbcType="BIGINT" property="businessId"/>
<result column="term" jdbcType="VARCHAR" property="term"/>
<result column="half" jdbcType="VARCHAR" property="half"/>
<result column="quarter" jdbcType="VARCHAR" property="quarter"/>
......@@ -45,9 +44,13 @@
<result column="cust_gc" jdbcType="VARCHAR" property="custGc"/>
<result column="sypn" jdbcType="VARCHAR" property="sypn"/>
</resultMap>
<delete id="truncateTable">
TRUNCATE TABLE demo.dbo.jnsp7xtm_dqsj
</delete>
<insert id="batchAddJnsp7xtmDqsj" parameterType="java.util.List">
INSERT into jnsp7xtm_dqsj(term,half,quarter,month,cc,cn,io,route,pc,factory,size,pn,po,fc,qty,up,currency,rate,amt,cust_group,cust_group2,cust_rt1,cust_io,cust_newpic,cust_group1,cust_rt2,cust_rout,cust_addr,cust_g0,cust_g20,cust_g30,cust_g201,cust_save,cust_stype,cust_g1,cust_yj,cust_yj2,cust_yj3,cust_gc,sypn) values
<foreach collection="list" item="item" separator=",">
(#{item.term}, #{item.half},#{item.quarter},#{item.month},#{item.cc},#{item.cn},#{item.io},#{item.route},#{item.pc},#{item.factory},#{item.size},#{item.pn},#{item.po},#{item.fc},#{item.qty},#{item.up},#{item.currency},#{item.rate},#{item.amt},#{item.custGroup},#{item.custGroup2},#{item.custRt1},#{item.custIo},#{item.custNewpic},#{item.custGroup1},#{item.custRt2},#{item.custRout},#{item.custAddr},#{item.custG0},#{item.custG20},#{item.custG30},#{item.custG201},#{item.custSave},#{item.custStype},#{item.custG1},#{item.custYj},#{item.custYj2},#{item.custYj3},#{item.custGc},#{item.sypn})
</foreach>
</insert>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
<select id="queryJnsp7xtmDqsjs" resultMap="BaseResultMap">
......@@ -301,6 +304,10 @@
</if>
ORDER BY business_id DESC
</select>
<delete id="truncateJnsp7xtmDqsj">
TRUNCATE TABLE ${shema}.jnsp7xtm_dqsj
</delete>
<select id="getMonthList" resultType="java.lang.String">
SELECT
DISTINCT month
......@@ -337,12 +344,9 @@
FROM
jnsp7xtm jnsp left JOIN b_customer cust on jnsp.khdm = cust.cust_code
left join b_pn_sypn bps on bps.pn = jnsp.pn
where
jnsp.khdm is not null
and jnsp.pn is not null
</select>
<select id="queryTotal" resultType="java.lang.Integer">
SELECT
count(*)
FROM
jnsp7xtm jnsp left JOIN b_customer cust on jnsp.khdm = cust.cust_code
left join b_pn_sypn bps on bps.pn = jnsp.pn
</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