From 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 09 五月 2020 21:41:27 +0800
Subject: [PATCH] 2.1需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java |  272 +++++++++++++++++++++++++++++------------------------
 1 files changed, 149 insertions(+), 123 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java
index 92394d9..18a9098 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java
@@ -1,150 +1,44 @@
 package com.yeshi.fanli.service.impl.user;
 
-import java.text.DecimalFormat;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import javax.annotation.Resource;
 
-import org.apache.ibatis.annotations.Param;
-import org.hibernate.HibernateException;
-import org.hibernate.SQLQuery;
-import org.hibernate.Session;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import com.yeshi.fanli.dao.mybatis.user.ShamUserMapper;
-import com.yeshi.fanli.dao.user.ShamUserDao;
-import com.yeshi.fanli.entity.bus.user.HongBaoMessage;
 import com.yeshi.fanli.entity.bus.user.ShamUser;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.user.ShamUserService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.Utils;
+import com.yeshi.fanli.util.StringUtil;
+
+import net.sf.json.JSONArray;
 
 @Service
 public class ShamUserServiceImpl implements ShamUserService {
-	
-	@Resource
-	private ShamUserDao dao;
-	
+
 	@Resource
 	private ShamUserMapper shamUserMapper;
-	
-	
+
+	@Resource
+	private ConfigService configService;
+
 	@Transactional
 	public void addShamUser(ShamUser shamUser) {
-		dao.save(shamUser);
+		shamUserMapper.insertSelective(shamUser);
 	}
 
 	public List<ShamUser> getAll() {
-		return dao.list("from ShamUser");
+		return shamUserMapper.listAll();
 	}
 
-	
-	@SuppressWarnings("unchecked")
-	public List<ShamUser> findShamUserList(int sum){
-		return (List<ShamUser>) dao.excute(new HibernateCallback<List<ShamUser>>() {
-
-			public List<ShamUser> doInHibernate(Session session)
-					throws HibernateException {
-				SQLQuery query = session.createSQLQuery("SELECT * FROM yeshi_ec_demouser ORDER BY id desc").addEntity(ShamUser.class);
-				query.setFirstResult(0);
-				query.setMaxResults(sum);
-				List<ShamUser> list = query.list();
-				return list;
-			}
-		});
-	}
-	
-	@SuppressWarnings("unchecked")
-	public List<HongBaoMessage> getManyData() {
-		
-		return (List<HongBaoMessage>) dao.excute(new HibernateCallback<List<HongBaoMessage>>() {
-
-			public List<HongBaoMessage> doInHibernate(Session session)
-					throws HibernateException {
-				SQLQuery query = session.createSQLQuery("SELECT * FROM yeshi_ec_sham_user ORDER BY RAND()").addEntity(ShamUser.class);
-				query.setFirstResult(0);
-				query.setMaxResults(Constant.PAGE_SIZE);
-				List<ShamUser> list = query.list();
-				List<HongBaoMessage> hbmList=new ArrayList<HongBaoMessage>();
-				if(list.size()>0){
-					HongBaoMessage hbm = null;
-					DecimalFormat df = new DecimalFormat("######0.00");  
-					for (ShamUser shamUser : list) {
-						hbm=new HongBaoMessage();
-						hbm.setName(shamUser.getName());
-						hbm.setPicUrl(shamUser.getPicUrl());
-						double random = (Math.random()+0.01)*20;
-						String format = df.format(random);
-						hbm.setContent("鎮勬倓棰嗗彇浜�"+format+"鍏冪孩鍖�");
-						hbmList.add(hbm);
-					}
-				}
-				return hbmList;
-			}
-		});
-	}
-	@Transactional
-	public void delete(final long id) {
-		dao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session)
-					throws HibernateException {
-					session.createQuery(" delete ShamUser su where su.id = ? ").setParameter(0, id).executeUpdate();
-				return null;
-			}
-		});
-	}
-
-	@SuppressWarnings("unchecked")
-	public List<HongBaoMessage> findShamThreeSaleInfo() {
-
-		return (List<HongBaoMessage>) dao.excute(new HibernateCallback<List<HongBaoMessage>>() {
-
-			public List<HongBaoMessage> doInHibernate(Session session)
-					throws HibernateException {
-				SQLQuery query = session.createSQLQuery("SELECT * FROM yeshi_ec_sham_user ORDER BY RAND()").addEntity(ShamUser.class);
-				query.setFirstResult(0);
-				query.setMaxResults(5);
-				List<ShamUser> list = query.list();
-				List<HongBaoMessage> hbmList=new ArrayList<HongBaoMessage>();
-				if(list.size()>0){
-					HongBaoMessage hbm = null;
-					DecimalFormat df = new DecimalFormat("######0.00");  
-					for (ShamUser shamUser : list) {
-						String name = shamUser.getName();
-						if(name != null){
-							if(name.length() > 2){
-								name = Utils.getStarString(name,1,name.length()-1);
-							}else{
-								name = name.substring(0, 1)+"**"+name.substring(name.length()-1);
-							}
-						}
-						shamUser.setName(name);
-						hbm=new HongBaoMessage();
-						hbm.setName(shamUser.getName());
-						hbm.setPicUrl(shamUser.getPicUrl());
-						double random = (Math.random()+100)*10;
-						String format = df.format(random);
-						hbm.setContent(format+"");
-						hbmList.add(hbm);
-					}
-				}
-				Collections.sort(hbmList, new Comparator<HongBaoMessage>() {
-					public int compare(HongBaoMessage o1, HongBaoMessage o2) {
-						double o1m = Double.parseDouble(o1.getContent());
-						double o2m = Double.parseDouble(o2.getContent());
-						double m=o1m-o2m;
-						return m<0?1:-1;
-					}
-				});
-				return hbmList;
-			}
-		});
-	
+	public List<ShamUser> findShamUserList(int sum) {
+		return shamUserMapper.listShamUserByKey(0, sum, null);
 	}
 
 	@Override
@@ -176,12 +70,144 @@
 	public int updateByPrimaryKey(ShamUser record) {
 		return shamUserMapper.updateByPrimaryKey(record);
 	}
-	
-	
+
 	@Override
 	public List<ShamUser> listDistinctPicUrl(long start, int count) {
 		return shamUserMapper.listByDistinctPicUrl(start, count);
 	}
 
+	@Override
+	public int insertBatch(List<ShamUser> list) {
+		return shamUserMapper.insertBatch(list);
+	}
 
+	@Override
+	public int updateBatchSelective(List<ShamUser> list) {
+		return shamUserMapper.updateBatchSelective(list);
+	}
+
+	@Override
+	public List<ShamUser> listRandCouponUser(int count, int smallTime, int largeTime) {
+		List<Integer> listTime = new ArrayList<Integer>();
+
+		while (listTime.size() < count) {
+			int time = smallTime + (int) (Math.random() * (largeTime - smallTime + 1));
+			if (!listTime.contains(Integer.valueOf(time))) {
+				listTime.add(Integer.valueOf(time));
+			}
+		}
+
+		Collections.sort(listTime);
+
+		List<ShamUser> listRand = shamUserMapper.listRand(count);
+
+		for (int i = 1; i <= count; i++) {
+			ShamUser shamUser = (ShamUser) listRand.get(i - 1);
+
+			transformId(shamUser);
+
+			shamUser.setMsg(listTime.get(listTime.size() - i) + "绉掑墠璐拱浜嗘鍟嗗搧");
+		}
+
+		return listRand;
+	}
+
+	@Override
+	public List<ShamUser> listRandShareUser(int count, BigDecimal shareMoney, int small, int large) {
+
+		List<Integer> listMultiple = new ArrayList<Integer>();
+
+		while (listMultiple.size() < count) {
+			int Multiple = small + (int) (Math.random() * (large - small + 1));
+			listMultiple.add(Integer.valueOf(Multiple));
+		}
+
+		List<String> imgList = new ArrayList<String>();
+		String value = configService.get(ConfigKeyEnum.shareBonusPicture.getKey());
+
+		if (!StringUtil.isNullOrEmpty(value)) {
+			JSONArray array = JSONArray.fromObject(value);
+			if (array != null) {
+				for (int n = 0; n < array.size(); n++) {
+					imgList.add(array.optString(n));
+				}
+			}
+
+		}
+
+		List<ShamUser> listRand = shamUserMapper.listRand(count);
+
+		for (int i = 0; i < count; i++) {
+			ShamUser shamUser = (ShamUser) listRand.get(i);
+
+			transformId(shamUser);
+
+			if (imgList.size() > 0) {
+				int randBonusPic = (int) (Math.random() * imgList.size());
+				shamUser.setShareBonusPic((String) imgList.get(randBonusPic));
+			}
+
+			BigDecimal money = shareMoney.multiply(new BigDecimal(((Integer) listMultiple.get(i)).intValue()))
+					.setScale(2, 1);
+			// 蹇呴』鍖呭惈 銆愬閲懧ャ�� 杩�3涓鍙凤紝 鐢ㄤ簬鍓嶇棰滆壊鍖哄垎
+			shamUser.setMsg("鍒嗕韩浜嗚繖涓晢鍝�,绱鑾峰緱濂栭噾楼" + money);
+		}
+
+		return listRand;
+	}
+
+	public void transformId(ShamUser shamUser) {
+		String id = shamUser.getId() + "";
+		if (id.length() == 1) {
+			shamUser.setShowId("2****" + id);
+		} else {
+			shamUser.setShowId(id.substring(0, 1) + "****" + id.substring(id.length() - 2, id.length() - 1));
+		}
+		
+		String name = shamUser.getName();
+		if(StringUtil.isNullOrEmpty(name)) {
+			// 鍚嶅瓧涓虹┖鏃�
+			String start = randomName();
+			String end = randomName();
+			shamUser.setName(start + "**" +end);
+		} else if (name.length() == 1) {
+			// 涓�涓瓧
+			String start = name;
+			if (start.trim().length() == 0 || start.equals("*")) {
+				start = randomName();
+			}
+			String end = randomName();
+			shamUser.setName(start + "**" +end);
+		} else {
+			// 涓や釜瀛楀強鍏朵互涓�
+			String start = name.substring(0, 1);
+			String end = name.substring(name.length() - 2, name.length() - 1);
+			if (start.trim().length() == 0 || start.equals("*")) {
+				start = randomName();
+			}
+			if (end.trim().length() == 0 || end.equals("*")) {
+				end = randomName();
+			}
+			shamUser.setName(start + "**" +end);
+		}
+	}
+	
+	/**
+	 * 闅忔満鍚嶇О
+	 * @return
+	 */
+	public String randomName() {
+		String[] array = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
+				"鎴�","鍗�","澹�","鎬�","涓�","鎴�","鍩�","缃�","钀�","鑺�","鍖�","澶�","绂�","鎵�","娴�","鐢�","鑻�","姊�","浣�","绻�","鍗�","涓�","璧�","涓�","鏄�","宸�","鎰�","琛�",
+				"涓�","鍚�","椋�","宄�","鏋�","闊�","鍚�","缁�","鍊�","绌�","绂�","涓�","鍘�","鐣�","鍏�","娴�","鐦�","闄�","閺�","闄�","绱�","瑾�","鐐�","缇�","闄�","濉�","杌�","鏅�",
+				"鍏�","闆�","楸�","钘�","闆�","鍙�","浜�","閰�","鑸�","鍌�","璩�","娈�","姗�","宸�","鍠�","鎰�","鍟�","鍡�","璀�","璜�","璨�","閵�","姹�","鑸�","瀛�","鍚�","鏄�","鏄�","闂�"
+				,"閾�","楦�","鍐�","椋�","璐�","闈�","搴�","杈�","鍘�","鏇�","娓�","灏�","绗�","鏅�","娑�","鏍�","瑗�","濡�","濞�","鐮�","鐪�","鍑�","寰�","鍏�","銇�","瓒�","榛�","鑸�","绱�",
+				"鎲�","鏃�","銇�","銇�","鐑�","鏉�","鐑�","寮�","缁�","闆�","鏈�","鑸�"};
+		return array[(int) (Math.random() * array.length-1)];
+	}
+
+	@Override
+	public List<ShamUser> listRandUser(int count) {
+		return shamUserMapper.listRand(count);
+	}
 }

--
Gitblit v1.8.0