Commit 0c19fdae by 郑勇

去掉券包图片验证

parent 1c76296d
package com.pcloud.book.giftcoupon.biz;
import com.pcloud.book.giftcoupon.dto.GiftPackageDTO;
import com.pcloud.book.giftcoupon.dto.MyGiftPackageDTO;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.page.PageBeanNew;
......@@ -17,4 +18,8 @@ public interface GiftCouponPackageBiz {
void createGiftReceive(GiftReceive giftReceive);
PageBeanNew<GiftPackageDTO> list4GiftPackage(String title, Integer state, Integer currentPage, Integer numPerPage);
PageBeanNew<MyGiftPackageDTO> list4MyGiftPackage(Long wechatUserId,Integer currentPage, Integer numPerPage);
void useGiftCoupon(Long wechatUserId, Long giftPackageId);
}
......@@ -6,6 +6,8 @@ import com.pcloud.book.giftcoupon.check.GiftParamCheck;
import com.pcloud.book.giftcoupon.dao.GiftCouponPackageDao;
import com.pcloud.book.giftcoupon.dao.GiftReceiveDao;
import com.pcloud.book.giftcoupon.dto.GiftPackageDTO;
import com.pcloud.book.giftcoupon.dto.GiftReceiveDTO;
import com.pcloud.book.giftcoupon.dto.MyGiftPackageDTO;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.core.aspect.ParamLog;
......@@ -13,13 +15,16 @@ import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component("giftCouponPackageBiz")
public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
......@@ -32,7 +37,7 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
private GiftParamCheck giftParamCheck;
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增专享礼包")
@ParamLog(value = "新增专享礼包", isAfterReturn = false)
@Override
public void createGiftPackage(GiftCouponPackage giftCouponPackage) {
giftParamCheck.checkGiftAddParam(giftCouponPackage);
......@@ -40,7 +45,7 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("修改专享礼包")
@ParamLog(value = "修改专享礼包", isAfterReturn = false)
@Override
public void updateGiftPackage(GiftCouponPackage giftCouponPackage) {
giftParamCheck.checkGiftAddParam(giftCouponPackage);
......@@ -67,9 +72,25 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
if (pageBeanNew == null || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, new ArrayList<>());
}
buildReceiveNum(pageBeanNew.getRecordList());
return pageBeanNew;
}
private void buildReceiveNum(List<GiftPackageDTO> recordList) {
List<Long> giftIds = recordList.stream().filter(a -> null != a.getId()).map(a -> a.getId()).distinct().collect(Collectors.toList());
List<GiftReceiveDTO> giftReceiveNumList = ListUtils.isEmpty(giftIds)?new ArrayList<>():giftReceiveDao.getGiftReceiveNumList(giftIds);
Map<Long, Integer> receiveNumMap = new HashMap<>();
if(!ListUtils.isEmpty(giftReceiveNumList)){
receiveNumMap= giftReceiveNumList.stream().collect(Collectors.toMap(a -> a.getGiftPackageId(), a -> a.getReceiveNum(), (k1, k2) -> k2));
}
for (GiftPackageDTO giftPackageDTO : recordList) {
giftPackageDTO.setReceiveNum(0);
if(MapUtils.isNotEmpty(receiveNumMap) && receiveNumMap.containsKey(giftPackageDTO.getId())){
giftPackageDTO.setReceiveNum(receiveNumMap.get(giftPackageDTO.getId()));
}
}
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增专享礼包")
@Override
......@@ -93,5 +114,28 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
}
}
@Override
public PageBeanNew<MyGiftPackageDTO> list4MyGiftPackage(Long wechatUserId,Integer currentPage, Integer numPerPage) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("wechatUserId", wechatUserId);
PageBeanNew<MyGiftPackageDTO> pageBeanNew=giftCouponPackageDao.listPageNew(new PageParam(currentPage, numPerPage), paramMap, "list4MyGiftPackage");
if (pageBeanNew == null || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, new ArrayList<>());
}
return pageBeanNew;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void useGiftCoupon(Long wechatUserId, Long giftPackageId) {
GiftReceive giftReceive = giftReceiveDao.getGiftReceive(wechatUserId, giftPackageId);
if(null==giftReceive){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "当前奖券包不存在");
}
if(giftReceive.getReceiveNum()-giftReceive.getUsedNum()<=0){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "当前奖券包已经使用完了");
}
//todo 可能有其他操作,如果点击不跳转页面,需要控制重复点击
giftReceiveDao.useGiftCoupon(wechatUserId,giftPackageId);
}
}
......@@ -20,9 +20,6 @@ public class GiftParamCheck {
if (null == giftCouponPackage) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数为空");
}
if (StringUtil.isEmpty(giftCouponPackage.getCoverPic())) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "封面为空");
}
if (StringUtil.isEmpty(giftCouponPackage.getTitle())) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "名称为空");
}
......
package com.pcloud.book.giftcoupon.dao;
import com.pcloud.book.giftcoupon.dto.GiftReceiveDTO;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.core.dao.BaseDao;
......@@ -22,32 +23,12 @@ public interface GiftReceiveDao extends BaseDao<GiftReceive> {
*/
GiftReceive getGiftReceive(Long wechatUserId,Long giftPackageId);
/**
* 查询指定行数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<GiftReceive> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
void useGiftCoupon(Long wechatUserId,Long giftPackageId);
/**
* 通过实体作为筛选条件查询
*
* @param giftReceive 实例对象
* @return 对象列表
*/
List<GiftReceive> queryAll(GiftReceive giftReceive);
List<GiftReceiveDTO> getGiftReceiveNumList(List<Long> giftPackageIds);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Integer id);
}
\ No newline at end of file
package com.pcloud.book.giftcoupon.dao.impl;
import com.pcloud.book.giftcoupon.dao.GiftReceiveDao;
import com.pcloud.book.giftcoupon.dto.GiftReceiveDTO;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.core.dao.BaseDaoImpl;
......@@ -21,18 +22,20 @@ public class GiftReceiveDaoImpl extends BaseDaoImpl<GiftReceive> implements Gift
return super.getSessionTemplate().selectOne(getStatement("getGiftReceive"),map);
}
@Override
public List<GiftReceive> queryAllByLimit(int offset, int limit) {
return null;
}
@Override
public List<GiftReceive> queryAll(GiftReceive giftReceive) {
return null;
public void useGiftCoupon(Long wechatUserId, Long giftPackageId) {
Map<String,Object> map=new HashMap<>();
map.put("wechatUserId",wechatUserId);
map.put("giftPackageId",giftPackageId);
super.getSessionTemplate().update(getStatement("getGiftReceive"),map);
}
@Override
public int deleteById(Integer id) {
return 0;
public List<GiftReceiveDTO> getGiftReceiveNumList(List<Long> giftPackageIds) {
Map<String,Object> map=new HashMap<>();
map.put("giftPackageIds",giftPackageIds);
return super.getSessionTemplate().selectList(getStatement("getGiftReceiveNumList"),map);
}
}
package com.pcloud.book.giftcoupon.dto;
import com.pcloud.common.entity.BaseEntity;
import lombok.Data;
/**
* 专享礼券包领取表(GiftReceive)实体类
*
* @author makejava
* @since 2020-04-19 14:59:34
*/
@Data
public class GiftReceiveDTO {
private Long giftPackageId;
/**
* 领取数量
*/
private Integer receiveNum;
}
\ No newline at end of file
package com.pcloud.book.giftcoupon.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import lombok.Data;
@Data
public class MyGiftPackageDTO {
/**
* 券id
*/
private Long id;
/**
* 封面图
*/
private String coverPic;
/**
* 名称
*/
private String title;
/**
* 有效期开始时间
*/
@JsonFormat(
pattern = "yyyy-MM-dd",
timezone = "GMT+8"
)
private Date validDateBegin;
/**
* 有效期结束时间
*/
@JsonFormat(
pattern = "yyyy-MM-dd",
timezone = "GMT+8"
)
private Date validDateEnd;
/**
* 面额
*/
private Integer denomination;
/**
* 未使用数量
*/
private Integer notUsedNum;
}
......@@ -13,10 +13,12 @@ import com.pcloud.book.cultivate.entity.CultivateBookUser;
import com.pcloud.book.cultivate.entity.CultivateRobotClassify;
import com.pcloud.book.giftcoupon.biz.GiftCouponPackageBiz;
import com.pcloud.book.giftcoupon.dto.GiftPackageDTO;
import com.pcloud.book.giftcoupon.dto.MyGiftPackageDTO;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.cookie.Cookie;
......@@ -82,7 +84,7 @@ public class GiftCouponPackageFacade {
@ApiOperation("礼券包列表")
@GetMapping("/list4GiftPackage")
public ResponseDto<?> list4GiftPackage(
public ResponseDto<PageBeanNew<GiftPackageDTO>> list4GiftPackage(
@RequestParam(value = "title",required = false) @ApiParam("礼包券名称") String title,
@RequestParam(value = "state",required = false) @ApiParam("状态") Integer state,
@RequestParam(value = "currentPage", required = false) Integer currentPage,
......@@ -103,4 +105,26 @@ public class GiftCouponPackageFacade {
return new ResponseDto<>();
}
@ApiOperation("我的礼券包列表")
@GetMapping("/list4MyGiftPackage")
public ResponseDto<PageBeanNew<MyGiftPackageDTO>> list4MyGiftPackage(
@CookieValue(value = "userInfo") String userInfo ,
@RequestParam(value = "currentPage", required = false) Integer currentPage,
@RequestParam(value = "numPerPage", required = false) Integer numPerPage
) throws BizException, PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
return new ResponseDto<>(giftCouponPackageBiz.list4MyGiftPackage(wechatUserId,currentPage,numPerPage));
}
@ApiOperation("券包使用")
@PostMapping("/useGiftCoupon")
public ResponseDto<?> useGiftCoupon(
@CookieValue(value = "userInfo") String userInfo ,
@RequestParam(value = "giftPackageId",required = false) @ApiParam("礼券id") Long giftPackageId
) throws BizException, PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
giftCouponPackageBiz.useGiftCoupon(wechatUserId,giftPackageId);
return new ResponseDto<>();
}
}
......@@ -125,13 +125,11 @@
a.denomination denomination,
a.receive_limit receiveLimit,
a.stock,
ifnull(sum(b.receive_num),0) receiveNum,
a.valid_date_begin validDateBegin,
a.valid_date_end validDateEnd,
if(NOW()<![CDATA[ < ]]> a.valid_date_begin,1,if(NOW() between a.valid_date_begin and a.valid_date_end,2,3)) state
from
gift_coupon_package a LEFT JOIN gift_receive b
on a.id=b.gift_package_id
gift_coupon_package a
where a.is_delete=0
<if test="title !=null and title !=''">
and a.title like concat('%',#{title},'%')
......
......@@ -102,4 +102,39 @@
limit 1
</select>
<select id="useGiftCoupon" parameterType="map">
update gift_receive
set used_num=used_num+1
where wechat_user_id=#{wechatUserId}
and gift_package_id=#{giftPackageId}
</select>
<select id="list4MyGiftPackage" parameterType="map" resultType="com.pcloud.book.giftcoupon.dto.MyGiftPackageDTO">
select
a.title title,
a.cover_pic coverPic,
a.denomination denomination,
a.valid_date_begin validDateBegin,
a.valid_date_end validDateEnd,
a.id id,
(b.receive_num-ifnull(b.used_num,0)) noUsedNum
from
gift_receive b LEFT JOIN gift_coupon_package a
on a.id=b.gift_package_id
where b.wechat_user_id=#{wechatUserId}
and b.used_num <![CDATA[ < ]]> b.receive_num
order by b.update_time desc
</select>
<select id="getGiftReceiveNumList" parameterType="map" resultType="com.pcloud.book.giftcoupon.dto.GiftReceiveDTO">
select gift_package_id giftPackageId,
ifnull(sum(receive_num),0) receiveNum
from gift_receive
where gift_package_id in
<foreach collection="giftPackageIds" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
group by gift_package_id
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment