|
|
package com.yoho.unions.server.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrdersMonthReqBO;
|
|
|
import com.yoho.unions.common.service.IBusinessImportService;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersMonthMapper;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrdersMonth;
|
|
|
|
|
|
@Service
|
|
|
public class UnionShareOrdersMonthImportServiceImpl implements IBusinessImportService {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UnionShareOrdersMonthImportServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
UnionShareOrdersMonthMapper unionShareOrdersMonthMapper;
|
|
|
|
|
|
@Override
|
|
|
public Class getDataClass() {
|
|
|
return UnionShareOrdersMonth.class;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object batchImport(List<Object> dataList) throws ExecutionException, InterruptedException {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object batchImport(List<Object> dataList, String args) throws ExecutionException, InterruptedException {
|
|
|
logger.debug("method batchImport(List<Object>) in.dataList is {}, args:{}", dataList, args);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(dataList)) {
|
|
|
logger.warn("batch import dataList is empty");
|
|
|
}
|
|
|
|
|
|
List<UnionShareOrdersMonth> unionShareOrdersMonthList = Lists.newArrayList();
|
|
|
|
|
|
for (Object unionShareOrdersMonth : dataList) {
|
|
|
unionShareOrdersMonthList.add((UnionShareOrdersMonth) unionShareOrdersMonth);
|
|
|
}
|
|
|
|
|
|
List<UnionShareOrdersMonth> vestList = new ArrayList<>();
|
|
|
List<UnionShareOrdersMonth> unionList = new ArrayList<>();
|
|
|
|
|
|
for (UnionShareOrdersMonth item : unionShareOrdersMonthList) {
|
|
|
UnionShareOrdersMonth dbItem = new UnionShareOrdersMonth();
|
|
|
BeanUtils.copyProperties(item, dbItem);
|
|
|
dbItem.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
dbItem.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
Integer uid = item.getUid();
|
|
|
Integer type = 2;//马甲用户
|
|
|
if(null != uid && 0 != uid) {//联盟用户
|
|
|
type = 1;
|
|
|
dbItem.setType(type);
|
|
|
unionList.add(dbItem);
|
|
|
}else {//马甲用户
|
|
|
dbItem.setType(type);
|
|
|
vestList.add(dbItem);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//马甲用户直接插入数据表
|
|
|
if(CollectionUtils.isNotEmpty(vestList)) {
|
|
|
List<List<UnionShareOrdersMonth>> subList = split(vestList, 20);
|
|
|
for(int i=0; i<subList.size(); i++) {
|
|
|
unionShareOrdersMonthMapper.batchInsert(subList.get(i));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//联盟用户查询数据库是否已经存在,存在则更新,不存在则增加
|
|
|
if(CollectionUtils.isNotEmpty(unionList)) {
|
|
|
for(UnionShareOrdersMonth item : unionList) {
|
|
|
UnionShareOrdersMonthReqBO req = new UnionShareOrdersMonthReqBO();
|
|
|
req.setUid(item.getUid());
|
|
|
req.setBeginDate(item.getDate());
|
|
|
req.setEndDate(item.getDate());
|
|
|
List<UnionShareOrdersMonth> list = unionShareOrdersMonthMapper.selectByCondition(req);
|
|
|
if(CollectionUtils.isEmpty(list)) {
|
|
|
unionShareOrdersMonthMapper.insertSelective(item);
|
|
|
}else {
|
|
|
unionShareOrdersMonthMapper.updateByPrimaryKeySelective(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logger.debug("method batchImport(List<Object>) out.");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 集合操作:子集分割
|
|
|
private <T> List<List<T>> split(Collection<T> collection, int subCount) {
|
|
|
List<List<T>> pieceList = new ArrayList<>();
|
|
|
List<T> p = new ArrayList<>();
|
|
|
for (T t : collection) {
|
|
|
if (p.size() >= subCount) {
|
|
|
pieceList.add(p);
|
|
|
p = new ArrayList<>();
|
|
|
}
|
|
|
p.add(t);
|
|
|
}
|
|
|
if (!p.isEmpty()) {
|
|
|
pieceList.add(p);
|
|
|
}
|
|
|
return pieceList;
|
|
|
}
|
|
|
} |
...
|
...
|
|