From 1e53e5f28c55ece70b28c752fa318e2fd951e643 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期三, 20 三月 2019 16:33:51 +0800 Subject: [PATCH] taobao 下dao改造以及删除dao --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java | 231 +++++++++++++++++++++++++++------------------------------ 1 files changed, 108 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..d107b63 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,43 @@ 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.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 +69,104 @@ 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("shareBonusPicture"); + + 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)); + } + } + + @Override + public List<ShamUser> listRandUser(int count) { + return shamUserMapper.listRand(count); + } } -- Gitblit v1.8.0