package com.yssh.service;
|
|
import com.google.common.collect.Lists;
|
import com.yssh.entity.VocCoords;
|
import com.yssh.entity.VocVals;
|
import com.yssh.mapper.VocValsMapper;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.concurrent.CountDownLatch;
|
|
@Service
|
public class VocValsService {
|
@Resource
|
VocValsMapper vocValsMapper;
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
public List<VocVals> selectByTime(String time) {
|
return vocValsMapper.selectByTime(time);
|
}
|
|
public int countByTime(String time) {
|
return vocValsMapper.countByTime(time);
|
}
|
|
public List<VocCoords> selectCoords(Integer x, Integer y) {
|
return vocValsMapper.selectCoords(x, y);
|
}
|
|
public int insert(VocVals vv) {
|
return vocValsMapper.insert(vv);
|
}
|
|
public int inserts(List<VocVals> list) {
|
return vocValsMapper.inserts(list);
|
}
|
|
public int deleteLastYear() {
|
return vocValsMapper.deleteLastYear();
|
}
|
|
public int deleteByTime(String time) {
|
return vocValsMapper.deleteByTime(time);
|
}
|
|
public void insertVocSync(List<VocVals> list) {
|
List<List<VocVals>> subLists = Lists.partition(list, 100);
|
for (List<VocVals> sub : subLists) {
|
vocValsMapper.inserts(sub);
|
}
|
|
logger.info("------ VOC.csv," + list.size() + " 条数据已入库 ------");
|
}
|
|
@Async("threadPoolTaskExecutor")
|
public void insertVocVals(List<VocVals> list) throws InterruptedException {
|
List<List<VocVals>> lists = Lists.partition(list, AsyncService.BATCH_INSERT_500);
|
|
CountDownLatch countDownLatch = new CountDownLatch(list.size());
|
for (List<VocVals> corpList : lists) {
|
executeAsync(corpList, countDownLatch);
|
}
|
|
countDownLatch.await();
|
logger.info("------ VOC.csv," + lists.size() + " 条数据已入库 ------");
|
}
|
|
private void executeAsync(List<VocVals> corpList, CountDownLatch countDownLatch) {
|
try {
|
vocValsMapper.inserts(corpList);
|
} finally {
|
countDownLatch.countDown();
|
}
|
}
|
}
|