Authored by jianhui_wang

删除

package com.yoho.unions.server.service.impl;
import com.google.common.collect.Lists;
import com.yoho.service.model.union.response.PageuserRegisterBuyResponseBO;
import com.yoho.unions.bo.UserRegisterBuyBO;
import com.yoho.unions.common.redis.RedisTemplate;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessImportService;
import com.yoho.unions.dal.IOrdersMapper;
import com.yoho.unions.dal.IUserProfileDAO;
import com.yoho.unions.dal.model.UserProfile;
import com.yoho.unions.utils.DateUtils;
import com.yoho.unions.vo.UserMobileAndUidVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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 java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@Service
public class userInfoImportServiceImpl implements IBusinessImportService {
private static final Logger logger = LoggerFactory.getLogger(userInfoImportServiceImpl.class);
@Autowired
IOrdersMapper ordersMapper;
@Autowired
IUserProfileDAO userProfileDAO;
@Autowired
private RedisValueCache redisValueCache;
@Autowired
private RedisTemplate redisTemplate;
@Override
public Class getDataClass() {
return UserMobileAndUidVO.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<UserMobileAndUidVO> userMobileAndUidVOList = Lists.newArrayList();
for (Object userMobileAndUidVO : dataList) {
userMobileAndUidVOList.add((UserMobileAndUidVO) userMobileAndUidVO);
}
UserProfile userProfile = new UserProfile();
List<UserRegisterBuyBO> userRegisterBuyList = new ArrayList<>();
List<UserRegisterBuyBO> TestuserRegisterBuyList = new ArrayList<>();
redisTemplate.delete("userRegisterBuyListKey*");
for (int i = 0; i < userMobileAndUidVOList.size(); i++) {
String mobile = userMobileAndUidVOList.get(i).getMobile();
int uid = userMobileAndUidVOList.get(i).getUid();
if (uid > 0) {
userProfile = userProfileDAO.selectByPrimaryKey(uid);
}
if (uid <= 0 && StringUtils.isNoneEmpty(mobile)) {
userProfile = userProfileDAO.selectProfileByMobile(mobile);
}
UserRegisterBuyBO userRegisterBuyBO_i = new UserRegisterBuyBO();
if (userProfile == null) {
// logger.warn("UserRegisterBuyInfo:uid is {},mobile is {},userSource is {}", userProfile.getUid(), userProfile.getMobile(), userProfile.getUserSource());
// throw new ServiceException(ServiceError.USER_NOT_EXIST);
userRegisterBuyBO_i.setId(i + 1);
userRegisterBuyBO_i.setMobile(mobile.substring(0, 3) + " **** " + mobile.substring(6, 10));
userRegisterBuyBO_i.setRegister("未注册");
userRegisterBuyBO_i.setUid(uid <= 0 ? 0 : uid);
userRegisterBuyBO_i.setRegisterTime("0");
userRegisterBuyBO_i.setBuy("未购买");
} else {
userRegisterBuyBO_i.setId(i + 1);
userRegisterBuyBO_i.setMobile(userProfile.getMobile().substring(0, 3) + " **** " + userProfile.getMobile().substring(6, 10));
userRegisterBuyBO_i.setRegister("已注册");
userRegisterBuyBO_i.setUid(userProfile.getUid());
userRegisterBuyBO_i.setRegisterTime(DateUtils.getDateString(userProfile.getCreateTime()));
int flag = ordersMapper.selectCountShipStatusOrderSince(userProfile.getUid(), userProfile.getCreateTime());
if (flag > 0) {
userRegisterBuyBO_i.setBuy("已购买");
} else {
userRegisterBuyBO_i.setBuy("未购买");
}
}
userRegisterBuyList.add(userRegisterBuyBO_i);
// redisTemplate.delete("userRegisterBuyListKey"+Integer.toString(i));
redisValueCache.set("userRegisterBuyListKey"+Integer.toString(i),userRegisterBuyBO_i,120, TimeUnit.MINUTES);
}
// if (redisValueCache.get(ListKey) == null) {
// redisValueCache.set(ListKey, userRegisterBuyList, 120, TimeUnit.MINUTES);
// } else {
// redisTemplate.delete(ListKey);
// redisValueCache.set(ListKey, userRegisterBuyList, 120, TimeUnit.MINUTES);
// }
/* redisTemplate.delete(ListKey);
redisListCache.rightPushAll(ListKey, userRegisterBuyList.toString(), 120, TimeUnit.MINUTES);
redisListCache.range(ListKey, UserRegisterBuyBO.class, 0, -1);
*/
// redisValueCache.set(ListKey, userRegisterBuyList, 120, TimeUnit.MINUTES);
userRegisterBuyList = Lists.transform(Lists.newArrayList(userRegisterBuyList), input -> {
UserRegisterBuyBO output = new UserRegisterBuyBO();
BeanUtils.copyProperties(input, output);
return output;
});
PageuserRegisterBuyResponseBO pageuserRegisterBuyResponseBO = new PageuserRegisterBuyResponseBO();
pageuserRegisterBuyResponseBO.setList(userRegisterBuyList);
pageuserRegisterBuyResponseBO.setTotal(userRegisterBuyList.size());
pageuserRegisterBuyResponseBO.setPage(1);
pageuserRegisterBuyResponseBO.setTotalPage(1);
logger.debug("method batchImport(List<Object>) out.");
return pageuserRegisterBuyResponseBO;
}
}
package com.yoho.unions.server.service.impl;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.response.PageResponseBO;
import com.yoho.service.model.union.request.UserRegisterBuyVO;
import com.yoho.service.model.union.response.UserRegisterBuyBO;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessExportService;
import com.yoho.unions.dal.IOrdersMapper;
import com.yoho.unions.dal.IUserProfileDAO;
import com.yoho.unions.dal.model.UserProfile;
import com.yoho.unions.server.service.IUserRegisterBuyInfoService;
import com.yoho.unions.utils.DateUtils;
import com.yoho.unions.vo.UserMobileAndUidVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jianhui.wang on 2017/7/25.
*/
@Service
public class UserRegisterBuyInfoserviceImpl implements IUserRegisterBuyInfoService, IBusinessExportService {
static Logger logger = LoggerFactory.getLogger("UserRegisterBuyInfoserviceImpl");
@Autowired
IUserProfileDAO userProfileDAO;
@Autowired
IOrdersMapper ordersMapper;
@Autowired
private RedisValueCache redisValueCache;
@Override
public List<UserRegisterBuyBO> UserRegisterBuyInfo(UserMobileAndUidVO userPhoneNumberVO) {
logger.info("enter UserRegisterBuyInfo with mobile={}", userPhoneNumberVO.getMobile());
if (userPhoneNumberVO == null || StringUtils.isEmpty(userPhoneNumberVO.getMobile())) {
logger.warn("UserRegisterBuyInfo: request param is null");
throw new ServiceException(ServiceError.REQUEST_PARAM_INVALID);
}
boolean isMobile = false;
// PhoneUtil.areaMobileVerify(userPhoneNumberVO.getUid(), userPhoneNumberVO.getMobile());
if (!isMobile) {
// 402, '手机号码格式错误'
logger.warn("checkBindParam error because MOBILE_IS_ERROR mobile={}", userPhoneNumberVO.getMobile());
throw new ServiceException(ServiceError.MOBILE_IS_ERROR);
}
UserProfile userProfile = userProfileDAO.selectProfileByMobile(userPhoneNumberVO.getMobile());
if (userProfile == null) {
logger.warn("UserRegisterBuyInfo:uid is {},mobile is {},userSource is {}", userProfile.getUid(), userProfile.getMobile(), userProfile.getUserSource());
throw new ServiceException(ServiceError.USER_NOT_EXIST);
}
UserRegisterBuyBO userRegisterBuyBO = new UserRegisterBuyBO();
userRegisterBuyBO.setRegister("");
userRegisterBuyBO.setUid(userProfile.getUid());
userRegisterBuyBO.setRegisterTime(DateUtils.getDateString(userProfile.getCreateTime()));
int flag = ordersMapper.selectCountShipStatusOrderSince(userProfile.getUid(), userProfile.getCreateTime());
if (flag > 0) {
userRegisterBuyBO.setBuy("已购买");
}
List<UserRegisterBuyBO> UserRegisterBuyList = new ArrayList<>();
UserRegisterBuyList.add(userRegisterBuyBO);
return UserRegisterBuyList;
}
@Override
public PageResponseBO<UserRegisterBuyBO> getUserRegisterBuyList(UserRegisterBuyVO userRegisterBuyVO) {
PageResponseBO<UserRegisterBuyBO> page = new PageResponseBO<>();
List<UserRegisterBuyBO> userInfoList = new ArrayList<>();
List<UserRegisterBuyBO> getuserInfoList = new ArrayList<>();
int i = 0;
UserRegisterBuyBO userRegisterBuyBO = new UserRegisterBuyBO();
do {
userRegisterBuyBO = redisValueCache.get("userRegisterBuyListKey" + Integer.toString(i), UserRegisterBuyBO.class);
if (userRegisterBuyBO == null) {
break;
}
userInfoList.add(i, userRegisterBuyBO);
i++;
}
while (userRegisterBuyBO != null);
for (int k = 0; k < userInfoList.size(); k++) {
if (null==userRegisterBuyVO.getRegister()||null==userRegisterBuyVO.getBuy()) {
getuserInfoList.add(userInfoList.get(k));
}
if ("0".equals(userRegisterBuyVO.getRegister()) && ("0".equals(userInfoList.get(k).getBuy()) || "1".equals(userInfoList.get(k).getBuy()))) {
if ("未注册".equals(userInfoList.get(k).getRegister()) && "未购买".equals(userInfoList.get(k).getBuy())) {
getuserInfoList.add(userInfoList.get(k));
}
}
if ("1".equals(userRegisterBuyVO.getRegister()) && "0".equals(userRegisterBuyVO.getBuy())) {
if ("已注册".equals(userInfoList.get(k).getRegister()) && "未购买".equals(userInfoList.get(k).getBuy())) {
getuserInfoList.add(userInfoList.get(k));
}
}
if ("1".equals(userRegisterBuyVO.getRegister()) && "1".equals(userRegisterBuyVO.getBuy())) {
if ("已注册".equals(userInfoList.get(k).getRegister()) && "已购买".equals(userInfoList.get(k).getBuy())) {
getuserInfoList.add(userInfoList.get(k));
}
}
}
page.setPage_total(1);
page.setTotal(getuserInfoList.size());
page.setPageSize(getuserInfoList.size());
page.setPage(1);
page.setList(getuserInfoList);
return page;
}
@Override
public Class getDataClass() {
return UserRegisterBuyBO.class;
}
@Override
public List<? extends Object> batchExport(String confStr) {
try {
UserRegisterBuyVO userRegisterBuyVO = JSONObject.parseObject(confStr, UserRegisterBuyVO.class);
PageResponseBO<UserRegisterBuyBO> pageResponseBO = getUserRegisterBuyList(userRegisterBuyVO);
List<UserRegisterBuyBO> UserRegisterBuyBOList = pageResponseBO.getList();
if (CollectionUtils.isEmpty(UserRegisterBuyBOList)) {
throw new ServiceException(400, "没有要导出的数据");
}
return UserRegisterBuyBOList;
} catch (JSONException e) {
logger.warn("parse confStr error: confStr {}, e {}", confStr, e);
throw new ServiceException(400, "传入数据格式错误");
} catch (com.yoho.error.exception.ServiceException e) {
logger.warn("make url error params is confStr {}, e {}", confStr, e);
throw new ServiceException(e.getCode(), e.getErrorMessage());
}
}
}