fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/ShamUserMapper.java
@@ -52,4 +52,10 @@ // 随机取出数据 List<ShamUser> listRand(@Param("count") int count); /** * 检出所有 * @return */ List<ShamUser> listAll(); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/SpreadImgMapper.java
New file @@ -0,0 +1,15 @@ package com.yeshi.fanli.dao.mybatis.user; import java.util.List; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.bus.invite.SpreadImg; public interface SpreadImgMapper extends BaseMapper<SpreadImg> { /** * 获取所有推广图 * * @return */ List<SpreadImg> listAll(); } fanli/src/main/java/com/yeshi/fanli/dao/user/ShamUserDao.java
File was deleted fanli/src/main/java/com/yeshi/fanli/dao/user/SpreadImgDao.java
File was deleted fanli/src/main/java/com/yeshi/fanli/entity/bus/invite/SpreadImg.java
@@ -2,34 +2,24 @@ import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; import org.yeshi.utils.mybatis.Column; import org.yeshi.utils.mybatis.Table; import com.google.gson.annotations.Expose; @Entity @Table(name = "yeshi_ec_spread_img") @org.yeshi.utils.mybatis.Table("yeshi_ec_spread_img") @Table( "yeshi_ec_spread_img") public class SpreadImg { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "si_id") @Expose @org.yeshi.utils.mybatis.Column(name="si_id") private long id; private Long id; @org.yeshi.utils.mybatis.Column(name="si_url") @Expose @Column(name="si_url") private String url; @org.yeshi.utils.mybatis.Column(name="si_createtime") @Expose @Column(name="si_createtime") private Date createtime; @@ -45,11 +35,11 @@ this.md5 = md5; } public long getId() { public Long getId() { return id; } public void setId(long id) { public void setId(Long id) { this.id = id; } fanli/src/main/java/com/yeshi/fanli/mapping/user/ShamUserMapper.xml
@@ -2,102 +2,136 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.user.ShamUserMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.ShamUser"> <id column="id" property="id" jdbcType="BIGINT"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="picUrl" property="picUrl" jdbcType="VARCHAR"/> </resultMap> <sql id="Base_Column_List">id,name,picUrl</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select <include refid="Base_Column_List"/>from yeshi_ec_sham_user where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_sham_user where id = #{id,jdbcType=BIGINT}</delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_sham_user (id,name,picUrl) values (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picUrl,jdbcType=VARCHAR})</insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_sham_user <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="name != null">name,</if> <if test="picUrl != null">picUrl,</if> </trim>values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="name != null">#{name,jdbcType=VARCHAR},</if> <if test="picUrl != null">#{picUrl,jdbcType=VARCHAR},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser">update yeshi_ec_sham_user set name = #{name,jdbcType=VARCHAR},picUrl = #{picUrl,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT}</update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser">update yeshi_ec_sham_user <set> <if test="name != null">name=#{name,jdbcType=VARCHAR},</if> <if test="picUrl != null">picUrl=#{picUrl,jdbcType=VARCHAR},</if> </set> where id = #{id,jdbcType=BIGINT} </update> <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List"> insert into yeshi_ec_sham_user (<include refid="Base_Column_List" />) values <foreach collection="list" item="item" separator=","> ( #{item.id,jdbcType=BIGINT}, #{item.name,jdbcType=VARCHAR}, #{item.picUrl,jdbcType=VARCHAR} ) </foreach> </insert> <update id="updateBatchSelective" parameterType="java.util.List"> update yeshi_ec_sham_user <trim prefix="set" suffixOverrides=","> <trim prefix="name =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.name !=null"> when id=#{item.id} then #{item.name} </if> </foreach> </trim> <trim prefix="picUrl =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.picUrl !=null"> when id=#{item.id} then #{item.picUrl} </if> </foreach> </trim> </trim> where id in <foreach collection="list" index="index" item="item" separator="," open="(" close=")"> #{item.id,jdbcType=BIGINT} </foreach> </update> <select id="listShamUserByKey" resultMap="BaseResultMap"> <!-- 根据条件查询所有标签 --> SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_sham_user WHERE 1=1 <if test='key != null and key != ""'> AND (id like '%${key}%' OR name like '%${key}%') </if> ORDER BY id DESC LIMIT ${start},${count} </select> <select id="countShamUserByKey" resultType="java.lang.Long"> SELECT count(id) FROM yeshi_ec_sham_user WHERE 1=1 <if test='key != null and key != ""'> AND (id like '%${key}%' OR name like '%${key}%') </if> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.ShamUser"> <id column="id" property="id" jdbcType="BIGINT" /> <result column="name" property="name" jdbcType="VARCHAR" /> <result column="picUrl" property="picUrl" jdbcType="VARCHAR" /> </resultMap> <sql id="Base_Column_List">id,name,picUrl</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_sham_user where id = #{id,jdbcType=BIGINT} </select> <select id="listByDistinctPicUrl" resultMap="BaseResultMap"> SELECT B.* FROM (SELECT DISTINCT(f.`picUrl`),f.`id` FROM `yeshi_ec_sham_user` f ORDER BY id DESC LIMIT ${start},${count})A LEFT JOIN yeshi_ec_sham_user B ON A.id = B.id </select> <select id="listRand" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_sham_user ORDER BY RAND() LIMIT #{count} </select> <select id="listAll" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from yeshi_ec_sham_user </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_sham_user where id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_sham_user (id,name,picUrl) values (#{id,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{picUrl,jdbcType=VARCHAR}) </insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser" useGeneratedKeys="true" keyProperty="id"> insert into yeshi_ec_sham_user <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="name != null">name,</if> <if test="picUrl != null">picUrl,</if> </trim> values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="name != null">#{name,jdbcType=VARCHAR},</if> <if test="picUrl != null">#{picUrl,jdbcType=VARCHAR},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser">update yeshi_ec_sham_user set name = #{name,jdbcType=VARCHAR},picUrl = #{picUrl,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.ShamUser"> update yeshi_ec_sham_user <set> <if test="name != null">name=#{name,jdbcType=VARCHAR},</if> <if test="picUrl != null">picUrl=#{picUrl,jdbcType=VARCHAR},</if> </set> where id = #{id,jdbcType=BIGINT} </update> <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List"> insert into yeshi_ec_sham_user ( <include refid="Base_Column_List" /> ) values <foreach collection="list" item="item" separator=","> ( #{item.id,jdbcType=BIGINT}, #{item.name,jdbcType=VARCHAR}, #{item.picUrl,jdbcType=VARCHAR} ) </foreach> </insert> <update id="updateBatchSelective" parameterType="java.util.List"> update yeshi_ec_sham_user <trim prefix="set" suffixOverrides=","> <trim prefix="name =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.name !=null"> when id=#{item.id} then #{item.name} </if> </foreach> </trim> <trim prefix="picUrl =case" suffix="end,"> <foreach collection="list" item="item" index="index"> <if test="item.picUrl !=null"> when id=#{item.id} then #{item.picUrl} </if> </foreach> </trim> </trim> where id in <foreach collection="list" index="index" item="item" separator="," open="(" close=")"> #{item.id,jdbcType=BIGINT} </foreach> </update> <select id="listShamUserByKey" resultMap="BaseResultMap"> <!-- 根据条件查询所有标签 --> SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_sham_user WHERE 1=1 <if test='key != null and key != ""'> AND (id like '%${key}%' OR name like '%${key}%') </if> ORDER BY id DESC LIMIT ${start},${count} </select> <select id="countShamUserByKey" resultType="java.lang.Long"> SELECT count(id) FROM yeshi_ec_sham_user WHERE 1=1 <if test='key != null and key != ""'> AND (id like '%${key}%' OR name like '%${key}%') </if> </select> <select id="listByDistinctPicUrl" resultMap="BaseResultMap"> SELECT B.* FROM (SELECT DISTINCT(f.`picUrl`),f.`id` FROM `yeshi_ec_sham_user` f ORDER BY id DESC LIMIT ${start},${count})A LEFT JOIN yeshi_ec_sham_user B ON A.id = B.id </select> <select id="listRand" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_sham_user ORDER BY RAND() LIMIT #{count} </select> </mapper> fanli/src/main/java/com/yeshi/fanli/mapping/user/SpreadImgMapper.xml
New file @@ -0,0 +1,59 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.user.SpreadImgMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.invite.SpreadImg"> <id column="si_id" property="id" jdbcType="BIGINT" /> <result column="si_url" property="url" jdbcType="VARCHAR" /> <result column="si_createtime" property="createtime" jdbcType="TIMESTAMP" /> </resultMap> <sql id="Base_Column_List">si_id,si_url,si_createtime</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_spread_img where si_id = #{id,jdbcType=BIGINT} </select> <select id="listAll" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from yeshi_ec_spread_img </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_spread_img where si_id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadImg" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_spread_img (si_id,si_url,si_createtime) values (#{id,jdbcType=BIGINT},#{url,jdbcType=VARCHAR},#{createtime,jdbcType=TIMESTAMP}) </insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadImg" useGeneratedKeys="true" keyProperty="id"> insert into yeshi_ec_spread_img <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">si_id,</if> <if test="url != null">si_url,</if> <if test="createtime != null">si_createtime,</if> </trim> values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="url != null">#{url,jdbcType=VARCHAR},</if> <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadImg">update yeshi_ec_spread_img set si_url = #{url,jdbcType=VARCHAR},si_createtime = #{createtime,jdbcType=TIMESTAMP} where si_id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadImg"> update yeshi_ec_spread_img <set> <if test="url != null">si_url=#{url,jdbcType=VARCHAR},</if> <if test="createtime != null">si_createtime=#{createtime,jdbcType=TIMESTAMP},</if> </set> where si_id = #{id,jdbcType=BIGINT} </update> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/user/ShamUserServiceImpl.java
@@ -7,15 +7,10 @@ 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.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.user.ShamUserService; @@ -25,55 +20,25 @@ @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) { @@ -104,23 +69,22 @@ 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>(); @@ -149,7 +113,7 @@ @Override public List<ShamUser> listRandShareUser(int count, BigDecimal shareMoney, int small, int large) { List<Integer> listMultiple = new ArrayList<Integer>(); while (listMultiple.size() < count) { @@ -182,8 +146,9 @@ 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); } @@ -192,7 +157,7 @@ public void transformId(ShamUser shamUser) { String id = shamUser.getId() + ""; if (id.length() == 1) { shamUser.setShowId("2****" + id); } else { @@ -200,7 +165,6 @@ } } @Override public List<ShamUser> listRandUser(int count) { return shamUserMapper.listRand(count); fanli/src/main/java/com/yeshi/fanli/service/impl/user/SpreadUserImgServiceImpl.java
@@ -10,9 +10,11 @@ import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.yeshi.utils.ListUtil; import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.mybatis.share.SpreadUserImgMapper; import com.yeshi.fanli.dao.user.SpreadImgDao; import com.yeshi.fanli.dao.mybatis.user.SpreadImgMapper; import com.yeshi.fanli.dao.user.SpreadUserImgDao; import com.yeshi.fanli.dao.user.UserInfoDao; import com.yeshi.fanli.entity.bus.invite.SpreadImg; @@ -22,8 +24,6 @@ import com.yeshi.fanli.service.inter.user.SpreadUserImgService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import org.yeshi.utils.ListUtil; import org.yeshi.utils.tencentcloud.COSManager; @Service public class SpreadUserImgServiceImpl implements SpreadUserImgService { @@ -35,7 +35,7 @@ private SpreadUserImgMapper spreadUserImgMapper; @Resource private SpreadImgDao spreadImgDao; private SpreadImgMapper spreadImgMapper; @Resource private QrCodeService qrCodeService; @@ -95,7 +95,7 @@ // 查询当前用户的推广图 List<SpreadUserImg> spreadUserImgList = spreadUserImgDao.list("from SpreadUserImg su where su.uid=" + uid); // 查询系统的推广图 List<SpreadImg> spreadImgList = spreadImgDao.list("from SpreadImg"); List<SpreadImg> spreadImgList = spreadImgMapper.listAll(); for (SpreadUserImg img : spreadUserImgList) { img.setMd5(getSpreadUserImgMD5(img.getUrl())); fanli/src/main/java/com/yeshi/fanli/service/inter/user/ShamUserService.java
@@ -18,9 +18,6 @@ public List<ShamUser> getAll(); public void delete(long id); public List<ShamUser> findShamUserList(int sum); fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java
@@ -56,7 +56,7 @@ if (cell.getContents() == null || "".equals(cell.getContents().trim())) { continue; } shamUserService.delete(Long.parseLong(cell.getContents())); shamUserService.deleteByPrimaryKey(Long.parseLong(cell.getContents())); } } catch (BiffException e) { e.printStackTrace();