| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.File;
|
| | | import java.io.FileInputStream;
|
| | | import java.io.FileReader;
|
| | | import java.io.InputStream;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.transaction.Transactional;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.UserRankingsMapper;
|
| | | import com.yeshi.fanli.dto.money.InviteGetMoney;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRankings;
|
| | | import com.yeshi.fanli.exception.UserRankingsException;
|
| | | import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserRankingsService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.vo.order.HongBaoV2VO;
|
| | |
|
| | | @Service
|
| | | public class UserRankingsServiceImpl implements UserRankingsService {
|
| | | @Resource
|
| | | private UserRankingsMapper userRankingsMapper;
|
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | @Resource
|
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileReader; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.UserRankingsMapper; |
| | | import com.yeshi.fanli.dto.money.InviteGetMoney; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserRankings; |
| | | import com.yeshi.fanli.exception.user.UserRankingsException; |
| | | import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; |
| | | import com.yeshi.fanli.service.inter.user.UserRankingsService; |
| | | import com.yeshi.fanli.util.FilePathEnum; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.vo.order.HongBaoV2VO; |
| | | |
| | | @Service |
| | | public class UserRankingsServiceImpl implements UserRankingsService { |
| | | @Resource |
| | | private UserRankingsMapper userRankingsMapper; |
| | | |
| | | @Resource |
| | | private HongBaoV2CountService hongBaoV2CountService; |
| | |
|
| | | @Override
|
| | | public int insertSelective(UserRankings record) throws UserRankingsException {
|
| | | // TODO Auto-generated method stub
|
| | | return userRankingsMapper.insertSelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKey(UserRankings record) throws UserRankingsException {
|
| | | return userRankingsMapper.updateByPrimaryKey(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(UserRankings record) throws UserRankingsException {
|
| | | return userRankingsMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateBatchSelective(List<UserRankings> list) throws UserRankingsException {
|
| | | return userRankingsMapper.updateBatchSelective(list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteBatchById(Long id) throws UserRankingsException {
|
| | | return userRankingsMapper.deleteByPrimaryKey(id);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void updateClearTradeState() throws UserRankingsException {
|
| | | userRankingsMapper.updateClearTradeState();
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteBatchByPrimaryKey(List<Long> arrayID) throws UserRankingsException {
|
| | | for (Long id : arrayID) {
|
| | |
|
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id);
|
| | | String portrait = userRankings.getPortrait();
|
| | | if (!StringUtil.isNullOrEmpty(portrait)) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | | userRankingsMapper.deleteByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | return arrayID.size();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserRankings selectByPrimaryKey(Long id) throws UserRankingsException {
|
| | | // TODO Auto-generated method stub
|
| | | return userRankingsMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserRankings> selectByNickName(String nickName) throws UserRankingsException {
|
| | | // TODO Auto-generated method stub
|
| | | return userRankingsMapper.selectByNickName(nickName);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserRankings> selectByShowId(String id) throws UserRankingsException {
|
| | | // TODO Auto-generated method stub
|
| | | return userRankingsMapper.selectByShowId(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void insertAndUploadFile(UserRankings record, MultipartFile file) throws Exception {
|
| | | // TODO Auto-generated method stub
|
| | | record.setCreatetime(new Date());
|
| | | userRankingsMapper.insertSelective(record);
|
| | |
|
| | | // 上传图片
|
| | | if (file != null) {
|
| | | uploadPicture(file, record);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void uploadPicture(MultipartFile file, UserRankings userRankings) throws Exception {
|
| | |
|
| | | /* 修改图片时,先删除已存在图片 */
|
| | | String portrait = userRankings.getPortrait();
|
| | | if (!StringUtil.isNullOrEmpty(portrait)) {
|
| | | COSManager.getInstance().deleteFile(portrait);
|
| | | }
|
| | |
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | |
|
| | | // 上传文件相对位置
|
| | | String fileUrl = "userRankings/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | |
|
| | | InputStream inputStream = file.getInputStream();
|
| | | String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
|
| | |
|
| | | /* 更新数据库信息 */
|
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
|
| | | userRankings.setPortrait(uploadFilePath);
|
| | | userRankingsMapper.updateByPrimaryKeySelective(userRankings);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void removePicture(UserRankings userRankings) throws Exception {
|
| | |
|
| | | /* 修改图片时,先删除已存在图片 */
|
| | | String portrait = userRankings.getPortrait();
|
| | | if (!StringUtil.isNullOrEmpty(portrait)) {
|
| | | boolean deleteFile = COSManager.getInstance().deleteFile(portrait);
|
| | | if (deleteFile) {
|
| | | userRankings.setPortrait(null);
|
| | | userRankingsMapper.updateByPrimaryKey(userRankings);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserRankings> query(long start, int count, String key, Integer tradeState, Integer shareState, Integer sort)
|
| | | throws UserRankingsException {
|
| | | return userRankingsMapper.query(start, count, key, tradeState, shareState, sort);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long queryCount(String key, Integer tradeState, Integer shareState) throws UserRankingsException {
|
| | | return userRankingsMapper.queryCount(key, tradeState, shareState);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void setRewardtBatch(List<Long> idList, Integer type, Double reward, Double startReward, Double endReward) throws Exception {
|
| | |
|
| | | for (Long id : idList) {
|
| | |
|
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id);
|
| | |
|
| | | if (userRankings == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | Double result = 0.00;
|
| | |
|
| | | if (reward != null && reward >= 0) {
|
| | | result = reward;
|
| | | } else {
|
| | | if (startReward != null && endReward != null) {
|
| | | // 随机权重
|
| | | result = startReward + (Math.random() * ((endReward - startReward) + 1));
|
| | | } else {
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | if (type == 1 || type.equals(1)) {
|
| | | userRankings.setTradeReward(new BigDecimal(result));
|
| | | } else {
|
| | | userRankings.setShareReward(new BigDecimal(result));
|
| | | }
|
| | |
|
| | | userRankingsMapper.updateByPrimaryKeySelective(userRankings);
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void setStateBatch(List<Long> idList, Integer type, Integer state) throws Exception {
|
| | |
|
| | | for (Long id : idList) {
|
| | |
|
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id);
|
| | |
|
| | | if (userRankings == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | if (type == 1 || type.equals(1)) {
|
| | | userRankings.setTradeState(state);
|
| | |
|
| | | if (state != null && state.equals(1)) {
|
| | | userRankings.setTradeTime(new Date());
|
| | | }
|
| | | } else {
|
| | | userRankings.setShareState(state);
|
| | |
|
| | | if (state != null && state.equals(1)) {
|
| | | userRankings.setShareTime(new Date());
|
| | | }
|
| | | }
|
| | |
|
| | | userRankingsMapper.updateByPrimaryKey(userRankings);
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void uploadFile(File file) throws Exception {
|
| | |
|
| | | List<UserRankings> list = new ArrayList<UserRankings>();
|
| | |
|
| | | File[] files = file.listFiles();
|
| | |
|
| | | for (File filePic : files) {// 遍历这个数组
|
| | | String name = filePic.getName();
|
| | | System.out.println("name" + name);
|
| | | String prefix = name.substring(name.lastIndexOf(".") + 1);
|
| | | // 上传文件相对位置
|
| | | String fileUrl = "userRankings/" + UUID.randomUUID().toString().replace("-", "") + "." + prefix;
|
| | | System.out.println(fileUrl);
|
| | |
|
| | | FileInputStream is = new FileInputStream(filePic);
|
| | |
|
| | | String uploadFilePath = COSManager.getInstance().uploadFile(is, fileUrl).getUrl();
|
| | |
|
| | | /* 更新数据库信息 */
|
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
|
| | | UserRankings userRankings = new UserRankings();
|
| | | userRankings.setPortrait(uploadFilePath);
|
| | | userRankings.setCreatetime(new Date());
|
| | | list.add(userRankings);
|
| | | }
|
| | |
|
| | | is.close();
|
| | | }
|
| | |
|
| | | if (list.size() > 0) {
|
| | | userRankingsMapper.insertBatch(list);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void updateShowID(File file) throws Exception {
|
| | | List<String> listID = new ArrayList<String>();
|
| | |
|
| | | BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件
|
| | | String s = "";
|
| | | while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行
|
| | | listID.add(s);
|
| | | }
|
| | | br.close();
|
| | |
|
| | | int i = 0;
|
| | | List<UserRankings> list = userRankingsMapper.queryAll();
|
| | | for (UserRankings userRankings : list) {
|
| | |
|
| | | String showId = listID.get(i);
|
| | | i++;
|
| | |
|
| | | userRankings.setShowId(showId);
|
| | | }
|
| | |
|
| | | userRankingsMapper.updateBatchSelective(list);
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void batchUpNickName(File file) throws Exception {
|
| | | List<String> listID = new ArrayList<String>();
|
| | |
|
| | | BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件
|
| | | String s = "";
|
| | | while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行
|
| | | listID.add(s);
|
| | | }
|
| | | br.close();
|
| | |
|
| | | int i = 0;
|
| | | List<UserRankings> list = userRankingsMapper.queryAll();
|
| | | for (UserRankings userRankings : list) {
|
| | |
|
| | | String nickName = listID.get(i);
|
| | | i++;
|
| | |
|
| | | userRankings.setNickName(nickName);
|
| | | }
|
| | |
|
| | | userRankingsMapper.updateBatchSelective(list);
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserRankings> listQueryByIds(List<Long> ids) throws UserRankingsException {
|
| | | return userRankingsMapper.listQueryByIds(ids);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<InviteGetMoney> getRank(long start, int count) {
|
| | | |
| | | List<InviteGetMoney> resultList = new ArrayList<InviteGetMoney>();
|
| | | |
| | | List<InviteGetMoney> rankingsList = new ArrayList<InviteGetMoney>();
|
| | | |
| | | try {
|
| | |
|
| | | List<UserRankings> userRankingsList = query(0, count, null, 1, null, 2);
|
| | |
|
| | | for (UserRankings userRankings : userRankingsList) {
|
| | |
|
| | | InviteGetMoney invite = new InviteGetMoney();
|
| | | String showId = userRankings.getShowId();
|
| | | if (StringUtil.isNullOrEmpty(showId)) {
|
| | | showId = "2***5";
|
| | | }
|
| | | invite.setUid(showId);
|
| | | invite.setName(userRankings.getNickName());
|
| | | // invite.setIcon(userRankings.getPortrait());
|
| | | invite.setPortrait(userRankings.getPortrait());
|
| | | invite.setMoney(userRankings.getTradeReward());
|
| | | invite.setCreateTime(userRankings.getCreatetime());
|
| | | rankingsList.add(invite);
|
| | | }
|
| | |
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.add(Calendar.DATE, -1);
|
| | |
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
|
| | | String defaultDate = sdf.format(calendar.getTime()); // 格式化前一天
|
| | |
|
| | | // 真实用户
|
| | | List<HongBaoV2VO> listHongBao = hongBaoV2CountService.listShareAndInviteMoney(0, count, defaultDate);
|
| | | if (listHongBao != null && listHongBao.size() > 0) {
|
| | | HongBaoV2VO hongBao = listHongBao.get(0);
|
| | | BigDecimal maxMoney = hongBao.getTotalMoney();
|
| | |
|
| | | UserRankings userRankings = userRankingsList.get(userRankingsList.size() - 1);
|
| | | BigDecimal mminMoney = userRankings.getTradeReward();
|
| | |
|
| | | // 真实数据大于最低金额
|
| | | if (maxMoney.compareTo(mminMoney) > 0) {
|
| | | for (HongBaoV2VO hb : listHongBao) {
|
| | | BigDecimal rewardMoney = hb.getTotalMoney();
|
| | |
|
| | | // 奖金高到低排序,不满足结束循环
|
| | | if (rewardMoney.compareTo(mminMoney) <= 0) {
|
| | | break;
|
| | | }
|
| | |
|
| | | UserInfo userInfo = hb.getUserInfo();
|
| | | if (userInfo != null) {
|
| | |
|
| | | InviteGetMoney invite = new InviteGetMoney();
|
| | |
|
| | | invite.setName(userInfo.getNickName());
|
| | | // invite.setIcon(userRankings.getPortrait());
|
| | | invite.setPortrait(userInfo.getPortrait());
|
| | | invite.setMoney(rewardMoney);
|
| | | invite.setCreateTime(new Date());
|
| | |
|
| | | // 处理id
|
| | | Long id = userInfo.getId();
|
| | | String uid = id + "";
|
| | | String index = uid.substring(0, 1);
|
| | | String end = uid.substring(uid.length() - 1, uid.length());
|
| | | invite.setUid(index + "***" + end);
|
| | | rankingsList.add(invite);
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | List<InviteGetMoney> list = listSort(rankingsList);
|
| | | |
| | | if (list.size() > count) {
|
| | | resultList = list.subList(0, count-1);
|
| | | } else {
|
| | | resultList = list;
|
| | | }
|
| | | |
| | | for (int i = 0 ;i<resultList.size() ; i++) {
|
| | | long n = i+1;
|
| | | String icon = "";
|
| | | if (n == 1) {
|
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/5e75b65b6eca4c74850a7306d7584663.png";
|
| | | }
|
| | | if (n == 2) {
|
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/442c950dd14a41a8849c0597f643ddd2.png";
|
| | | }
|
| | | if (n == 3) {
|
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/5c9559905f034541888e674b30dbbeb3.png";
|
| | | }
|
| | | if (n == 4) {
|
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/531b640cf73042ac929750e5ff610a20.png";
|
| | | }
|
| | | if (n == 5) {
|
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/2a229650a22c4ce09e3c60e8cddafdd6.png";
|
| | | }
|
| | | resultList.get(i).setIcon(icon);
|
| | | |
| | | |
| | | resultList.get(i).setRankIcon("http://ec-1255749512.file.myqcloud.com/resource/rank/rank_icon_3.png");
|
| | | resultList.get(i).setId(n);
|
| | | }
|
| | | |
| | | |
| | | } catch (UserRankingsException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | return resultList;
|
| | | |
| | | |
| | | }
|
| | |
|
| | | public List<InviteGetMoney> listSort(List<InviteGetMoney> list) {
|
| | |
|
| | | Collections.sort(list, new Comparator<InviteGetMoney>() {
|
| | | public int compare(InviteGetMoney p1, InviteGetMoney p2) {
|
| | |
|
| | | // 按照Person的年龄进行升序排列
|
| | | if (p1.getMoney().compareTo(p2.getMoney()) < 0) {
|
| | | return 1;
|
| | | }
|
| | |
|
| | | if (p1.getMoney().compareTo(p2.getMoney()) == 0) {
|
| | | return 0;
|
| | | }
|
| | | return -1;
|
| | | }
|
| | | });
|
| | |
|
| | | return list;
|
| | | }
|
| | | }
|
| | | |
| | | @Override |
| | | public int insertSelective(UserRankings record) throws UserRankingsException { |
| | | // TODO Auto-generated method stub |
| | | return userRankingsMapper.insertSelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public int updateByPrimaryKey(UserRankings record) throws UserRankingsException { |
| | | return userRankingsMapper.updateByPrimaryKey(record); |
| | | } |
| | | |
| | | @Override |
| | | public int updateByPrimaryKeySelective(UserRankings record) throws UserRankingsException { |
| | | return userRankingsMapper.updateByPrimaryKeySelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public int updateBatchSelective(List<UserRankings> list) throws UserRankingsException { |
| | | return userRankingsMapper.updateBatchSelective(list); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public int deleteBatchById(Long id) throws UserRankingsException { |
| | | return userRankingsMapper.deleteByPrimaryKey(id); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateClearTradeState() throws UserRankingsException { |
| | | userRankingsMapper.updateClearTradeState(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void clearShareReward() { |
| | | userRankingsMapper.clearShareReward(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public int deleteBatchByPrimaryKey(List<Long> arrayID) throws UserRankingsException { |
| | | for (Long id : arrayID) { |
| | | |
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id); |
| | | String portrait = userRankings.getPortrait(); |
| | | if (!StringUtil.isNullOrEmpty(portrait)) { |
| | | COSManager.getInstance().deleteFile(portrait); |
| | | } |
| | | userRankingsMapper.deleteByPrimaryKey(id); |
| | | } |
| | | |
| | | return arrayID.size(); |
| | | } |
| | | |
| | | @Override |
| | | public UserRankings selectByPrimaryKey(Long id) throws UserRankingsException { |
| | | // TODO Auto-generated method stub |
| | | return userRankingsMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserRankings> selectByNickName(String nickName) throws UserRankingsException { |
| | | // TODO Auto-generated method stub |
| | | return userRankingsMapper.selectByNickName(nickName); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserRankings> selectByShowId(String id) throws UserRankingsException { |
| | | // TODO Auto-generated method stub |
| | | return userRankingsMapper.selectByShowId(id); |
| | | } |
| | | |
| | | @Override |
| | | public void insertAndUploadFile(UserRankings record, MultipartFile file) throws Exception { |
| | | // TODO Auto-generated method stub |
| | | record.setCreatetime(new Date()); |
| | | userRankingsMapper.insertSelective(record); |
| | | |
| | | // 上传图片 |
| | | if (file != null) { |
| | | uploadPicture(file, record); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void uploadPicture(MultipartFile file, UserRankings userRankings) throws Exception { |
| | | |
| | | /* 修改图片时,先删除已存在图片 */ |
| | | String portrait = userRankings.getPortrait(); |
| | | if (!StringUtil.isNullOrEmpty(portrait)) { |
| | | COSManager.getInstance().deleteFile(portrait); |
| | | } |
| | | |
| | | String contentType = file.getContentType(); |
| | | String type = contentType.substring(contentType.indexOf("/") + 1); |
| | | |
| | | // 上传文件相对位置 |
| | | String fileUrl = FilePathEnum.userRankings.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; |
| | | |
| | | InputStream inputStream = file.getInputStream(); |
| | | String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl(); |
| | | |
| | | /* 更新数据库信息 */ |
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) { |
| | | userRankings.setPortrait(uploadFilePath); |
| | | userRankingsMapper.updateByPrimaryKeySelective(userRankings); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void removePicture(UserRankings userRankings) throws Exception { |
| | | |
| | | /* 修改图片时,先删除已存在图片 */ |
| | | String portrait = userRankings.getPortrait(); |
| | | if (!StringUtil.isNullOrEmpty(portrait)) { |
| | | boolean deleteFile = COSManager.getInstance().deleteFile(portrait); |
| | | if (deleteFile) { |
| | | userRankings.setPortrait(null); |
| | | userRankingsMapper.updateByPrimaryKey(userRankings); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<UserRankings> query(long start, int count, String key, Integer tradeState, Integer shareState, Integer sort) { |
| | | return userRankingsMapper.query(start, count, key, tradeState, shareState, sort); |
| | | } |
| | | |
| | | @Override |
| | | public long queryCount(String key, Integer tradeState, Integer shareState) throws UserRankingsException { |
| | | return userRankingsMapper.queryCount(key, tradeState, shareState); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void setRewardtBatch(List<Long> idList, Integer type, Double reward, Double startReward, Double endReward) throws Exception { |
| | | |
| | | for (Long id : idList) { |
| | | |
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id); |
| | | |
| | | if (userRankings == null) { |
| | | continue; |
| | | } |
| | | |
| | | Double result = 0.00; |
| | | |
| | | if (reward != null && reward >= 0) { |
| | | result = reward; |
| | | } else { |
| | | if (startReward != null && endReward != null) { |
| | | // 随机权重 |
| | | result = startReward + (Math.random() * ((endReward - startReward) + 1)); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (type == 1 || type.equals(1)) { |
| | | userRankings.setTradeReward(new BigDecimal(result)); |
| | | } else { |
| | | userRankings.setShareReward(new BigDecimal(result)); |
| | | } |
| | | |
| | | userRankingsMapper.updateByPrimaryKeySelective(userRankings); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void setStateBatch(List<Long> idList, Integer type, Integer state) throws Exception { |
| | | |
| | | for (Long id : idList) { |
| | | |
| | | UserRankings userRankings = userRankingsMapper.selectByPrimaryKey(id); |
| | | |
| | | if (userRankings == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (type == 1 || type.equals(1)) { |
| | | userRankings.setTradeState(state); |
| | | |
| | | if (state != null && state.equals(1)) { |
| | | userRankings.setTradeTime(new Date()); |
| | | } |
| | | } else { |
| | | userRankings.setShareState(state); |
| | | |
| | | if (state != null && state.equals(1)) { |
| | | userRankings.setShareTime(new Date()); |
| | | } |
| | | } |
| | | |
| | | userRankingsMapper.updateByPrimaryKey(userRankings); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void uploadFile(File file) throws Exception { |
| | | |
| | | List<UserRankings> list = new ArrayList<UserRankings>(); |
| | | |
| | | File[] files = file.listFiles(); |
| | | |
| | | for (File filePic : files) {// 遍历这个数组 |
| | | String name = filePic.getName(); |
| | | System.out.println("name" + name); |
| | | String prefix = name.substring(name.lastIndexOf(".") + 1); |
| | | // 上传文件相对位置 |
| | | String fileUrl = FilePathEnum.userRankings.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + prefix; |
| | | System.out.println(fileUrl); |
| | | |
| | | FileInputStream is = new FileInputStream(filePic); |
| | | |
| | | String uploadFilePath = COSManager.getInstance().uploadFile(is, fileUrl).getUrl(); |
| | | |
| | | /* 更新数据库信息 */ |
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) { |
| | | UserRankings userRankings = new UserRankings(); |
| | | userRankings.setPortrait(uploadFilePath); |
| | | userRankings.setCreatetime(new Date()); |
| | | list.add(userRankings); |
| | | } |
| | | |
| | | is.close(); |
| | | } |
| | | |
| | | if (list.size() > 0) { |
| | | userRankingsMapper.insertBatch(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void updateShowID(File file) throws Exception { |
| | | List<String> listID = new ArrayList<String>(); |
| | | |
| | | BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件 |
| | | String s = ""; |
| | | while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行 |
| | | listID.add(s); |
| | | } |
| | | br.close(); |
| | | |
| | | int i = 0; |
| | | List<UserRankings> list = userRankingsMapper.queryAll(); |
| | | for (UserRankings userRankings : list) { |
| | | |
| | | String showId = listID.get(i); |
| | | i++; |
| | | |
| | | userRankings.setShowId(showId); |
| | | } |
| | | |
| | | userRankingsMapper.updateBatchSelective(list); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void batchUpNickName(File file) throws Exception { |
| | | List<String> listID = new ArrayList<String>(); |
| | | |
| | | BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件 |
| | | String s = ""; |
| | | while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行 |
| | | listID.add(s); |
| | | } |
| | | br.close(); |
| | | |
| | | int i = 0; |
| | | List<UserRankings> list = userRankingsMapper.queryAll(); |
| | | for (UserRankings userRankings : list) { |
| | | |
| | | String nickName = listID.get(i); |
| | | i++; |
| | | |
| | | userRankings.setNickName(nickName); |
| | | } |
| | | |
| | | userRankingsMapper.updateBatchSelective(list); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<UserRankings> listQueryByIds(List<Long> ids) throws UserRankingsException { |
| | | return userRankingsMapper.listQueryByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<UserRankings> getRankList(long start, int count) { |
| | | return userRankingsMapper.getRankList(start, count); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<InviteGetMoney> getRank(long start, int count) { |
| | | |
| | | List<InviteGetMoney> resultList = new ArrayList<InviteGetMoney>(); |
| | | |
| | | List<InviteGetMoney> rankingsList = new ArrayList<InviteGetMoney>(); |
| | | |
| | | List<UserRankings> userRankingsList = query(0, count, null, 1, null, 2); |
| | | |
| | | for (UserRankings userRankings : userRankingsList) { |
| | | |
| | | InviteGetMoney invite = new InviteGetMoney(); |
| | | String showId = userRankings.getShowId(); |
| | | if (StringUtil.isNullOrEmpty(showId)) { |
| | | showId = "2***5"; |
| | | } |
| | | invite.setUid(showId); |
| | | invite.setName(userRankings.getNickName()); |
| | | // invite.setIcon(userRankings.getPortrait()); |
| | | invite.setPortrait(userRankings.getPortrait()); |
| | | invite.setMoney(userRankings.getTradeReward()); |
| | | invite.setCreateTime(userRankings.getCreatetime()); |
| | | rankingsList.add(invite); |
| | | } |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.DATE, -1); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式 |
| | | String defaultDate = sdf.format(calendar.getTime()); // 格式化前一天 |
| | | |
| | | // 真实用户 |
| | | List<HongBaoV2VO> listHongBao = hongBaoV2CountService.listShareAndInviteMoney(0, count, defaultDate); |
| | | if (listHongBao != null && listHongBao.size() > 0) { |
| | | HongBaoV2VO hongBao = listHongBao.get(0); |
| | | BigDecimal maxMoney = hongBao.getTotalMoney(); |
| | | |
| | | UserRankings userRankings = userRankingsList.get(userRankingsList.size() - 1); |
| | | BigDecimal mminMoney = userRankings.getTradeReward(); |
| | | |
| | | // 真实数据大于最低金额 |
| | | if (maxMoney.compareTo(mminMoney) > 0) { |
| | | for (HongBaoV2VO hb : listHongBao) { |
| | | BigDecimal rewardMoney = hb.getTotalMoney(); |
| | | |
| | | // 奖金高到低排序,不满足结束循环 |
| | | if (rewardMoney.compareTo(mminMoney) <= 0) { |
| | | break; |
| | | } |
| | | |
| | | UserInfo userInfo = hb.getUserInfo(); |
| | | if (userInfo != null) { |
| | | |
| | | InviteGetMoney invite = new InviteGetMoney(); |
| | | |
| | | invite.setName(userInfo.getNickName()); |
| | | // invite.setIcon(userRankings.getPortrait()); |
| | | invite.setPortrait(userInfo.getPortrait()); |
| | | invite.setMoney(rewardMoney); |
| | | invite.setCreateTime(new Date()); |
| | | |
| | | // 处理id |
| | | Long id = userInfo.getId(); |
| | | String uid = id + ""; |
| | | String index = uid.substring(0, 1); |
| | | String end = uid.substring(uid.length() - 1, uid.length()); |
| | | invite.setUid(index + "***" + end); |
| | | rankingsList.add(invite); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<InviteGetMoney> list = listSort(rankingsList); |
| | | |
| | | if (list.size() > count) { |
| | | resultList = list.subList(0, count-1); |
| | | } else { |
| | | resultList = list; |
| | | } |
| | | |
| | | for (int i = 0 ;i<resultList.size() ; i++) { |
| | | long n = i+1; |
| | | String icon = ""; |
| | | if (n == 1) { |
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/5e75b65b6eca4c74850a7306d7584663.png"; |
| | | } |
| | | if (n == 2) { |
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/442c950dd14a41a8849c0597f643ddd2.png"; |
| | | } |
| | | if (n == 3) { |
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/5c9559905f034541888e674b30dbbeb3.png"; |
| | | } |
| | | if (n == 4) { |
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/531b640cf73042ac929750e5ff610a20.png"; |
| | | } |
| | | if (n == 5) { |
| | | icon ="http://buxinimg.oss-cn-qingdao.aliyuncs.com/2a229650a22c4ce09e3c60e8cddafdd6.png"; |
| | | } |
| | | resultList.get(i).setIcon(icon); |
| | | |
| | | |
| | | resultList.get(i).setRankIcon("http://ec-1255749512.file.myqcloud.com/resource/rank/rank_icon_3.png"); |
| | | resultList.get(i).setId(n); |
| | | } |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | public List<InviteGetMoney> listSort(List<InviteGetMoney> list) { |
| | | |
| | | Collections.sort(list, new Comparator<InviteGetMoney>() { |
| | | public int compare(InviteGetMoney p1, InviteGetMoney p2) { |
| | | |
| | | // 按照Person的年龄进行升序排列 |
| | | if (p1.getMoney().compareTo(p2.getMoney()) < 0) { |
| | | return 1; |
| | | } |
| | | |
| | | if (p1.getMoney().compareTo(p2.getMoney()) == 0) { |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | }); |
| | | |
| | | return list; |
| | | } |
| | | } |