Authored by caoyan

cps四期

... ... @@ -21,4 +21,6 @@ public interface UnionShareOrdersMonthMapper {
int selectTotalByCondition(UnionShareOrdersMonthReqBO req);
List<UnionShareOrdersMonth> selectByCondition(UnionShareOrdersMonthReqBO req);
int batchInsert(List<UnionShareOrdersMonth> list);
}
\ No newline at end of file
... ...
... ... @@ -2,25 +2,41 @@ package com.yoho.unions.dal.model;
import java.math.BigDecimal;
import com.yoho.unions.common.annotation.BatchExportField;
import com.yoho.unions.common.annotation.BatchImportField;
public class UnionShareOrdersMonth {
private Integer id;
@BatchImportField(index = 0)
@BatchExportField(name = "uid")
private Integer uid;
private Integer type;
@BatchImportField(index = 1)
@BatchExportField(name = "昵称")
private String nickname;
@BatchImportField(index = 2)
@BatchExportField(name = "头像")
private String image;
@BatchImportField(index = 3)
@BatchExportField(name = "年月")
private Integer date;
@BatchImportField(index = 4)
@BatchExportField(name = "预估收入")
private BigDecimal amount;
private BigDecimal orderAmount;
private BigDecimal extraAmount;
@BatchImportField(index = 5)
@BatchExportField(name = "订单数")
private Integer orderNum;
private Integer createTime;
... ...
... ... @@ -209,4 +209,16 @@
limit #{start},#{size}
</if>
</select>
<insert id="batchInsert" parameterType="java.util.List">
insert into union_share_orders_month (uid, type, nickname, image, date,
amount, order_amount, extra_amount, order_num, create_time, update_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.uid,jdbcType=INTEGER}, #{item.type,jdbcType=INTEGER}, #{item.nickname,jdbcType=VARCHAR}, #{item.image,jdbcType=VARCHAR},
#{item.date,jdbcType=INTEGER}, #{item.amount,jdbcType=DECIMAL}, #{item.orderAmount,jdbcType=DECIMAL},
#{item.extraAmount,jdbcType=DECIMAL}, #{item.orderNum,jdbcType=INTEGER}, #{item.createTime,jdbcType=INTEGER},
#{item.updateTime,jdbcType=INTEGER})
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
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;
}
}
... ...
... ... @@ -112,6 +112,7 @@
<entry key="MobileUidImport" value-ref="userInfoImportServiceImpl"/>
<entry key="idfaMatchImport" value-ref="idfaMatchImportServiceImpl"/>
<entry key="imeiMatchImport" value-ref="idfaMatchImportServiceImpl"/>
<entry key="unionShareOrdersMonthImport" value-ref="unionShareOrdersMonthImportServiceImpl"/>
</util:map>
<!-- 批量操作服务定义 -->
<util:map id="batchExportBusiness" key-type="java.lang.String"
... ...
... ... @@ -29,7 +29,7 @@
uploadInputName: "file", //上传文件的控件名称
url: contextPath + "/batch/import", //提交到后端的url
queryParams: {
type: "MobileUidImport",
type: "unionShareOrdersMonthImport",
args: "import"
}, //提交到后端额外参数
showFileName: false, //上传成功后,是否显示文件名
... ...