| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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.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.StringUtil;
|
| | |
| | |
|
| | | @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_sham_user").addEntity(ShamUser.class);
|
| | | query.setFirstResult(0);
|
| | | query.setMaxResults(sum);
|
| | | List<ShamUser> list = query.list();
|
| | | return list;
|
| | | }
|
| | | });
|
| | | public List<ShamUser> findShamUserList(int sum) {
|
| | | return shamUserMapper.listShamUserByKey(0, sum, null);
|
| | | }
|
| | | |
| | | |
| | | @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;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | @Override
|
| | | public int deleteByPrimaryKey(Long id) {
|
| | |
| | | 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>();
|
| | |
| | |
|
| | | transformId(shamUser);
|
| | |
|
| | | shamUser.setMsg(listTime.get(listTime.size() - i) + "秒前领券购买了这个商品");
|
| | | 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) {
|
| | |
| | | }
|
| | |
|
| | | List<String> imgList = new ArrayList<String>();
|
| | | String value = configService.get("shareBonusPicture");
|
| | | String value = configService.get(ConfigKeyEnum.shareBonusPicture.getKey());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(value)) {
|
| | | JSONArray array = JSONArray.fromObject(value);
|
| | |
| | | shamUser.setShareBonusPic((String) imgList.get(randBonusPic));
|
| | | }
|
| | |
|
| | | BigDecimal money = shareMoney.multiply(new BigDecimal(((Integer) listMultiple.get(i)).intValue())).setScale(2, 1);
|
| | | // 必须包含 【奖金¥】 这3个符号, 用于前端颜色区分
|
| | | BigDecimal money = shareMoney.multiply(new BigDecimal(((Integer) listMultiple.get(i)).intValue()))
|
| | | .setScale(2, 1);
|
| | | // 必须包含 【奖金¥】 这3个符号, 用于前端颜色区分
|
| | | shamUser.setMsg("分享了这个商品,累计获得奖金¥" + money);
|
| | | }
|
| | |
|
| | |
| | |
|
| | | 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);
|