Commit b297ce35 by “Kongxiangkun”

增加积分商城相关代码

parent 6ee74af5
package com.yizhi.point.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.point.application.vo.PointDetailListVO;
import com.yizhi.point.application.vo.PointSearchParamVO;
import com.yizhi.point.application.vo.domain.PointProductVo;
import com.yizhi.point.application.vo.domain.PointVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* 积分设置
*
* @author HUIHUI.DUAN
* @date 2018/3/28 10:44
*/
@FeignClient(name = "point", contextId = "PointApiFeignClients")
public interface PointApiFeignClients {
@GetMapping("/api/point/exchange")
boolean exchange(
@RequestParam(name = "companyId" ,required = false ) Long companyId,
@RequestParam(name = "orgId" ,required = false ) Long orgId,
@RequestParam(name = "siteId" ,required = false ) Long siteId,
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "accountName" ,required = false ) String accountName,
@RequestParam(name = "productIds" ,required = false ) String productIds);
@GetMapping("/api/point/list")
List<PointDetailListVO> list(@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "pageNo" ,required = false ) Integer pageNo,
@RequestParam(name = "pageSize" ,required = false ) Integer pageSize);
@GetMapping("/api/point/product/list")
List<PointProductVo> productList(@RequestParam(name = "pageNo" ,required = false ) Integer pageNo,
@RequestParam(name = "pageSize" ,required = false ) Integer pageSize);
}
package com.yizhi.point.application.vo;
import com.baomidou.mybatisplus.annotations.TableField;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
@Data
public class PointDetailListVO {
@ApiModelProperty(value = "时间")
private Date time;
@ApiModelProperty(value = "积分")
private Integer point;
@ApiModelProperty(value = "变动后积分总量")
private Integer changeAfter;
@ApiModelProperty(value = "积分描述")
private String learnName;
}
package com.yizhi.point.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "PointExchangeApplyVo", description = "兑换申请")
@TableName("point_exchange_apply")
public class PointExchangeApplyVo extends Model<PointExchangeApplyVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "user_id")
private Long userId;
@ApiModelProperty(value = "产品ids")
@TableField("product_ids")
private String productIds;
@ApiModelProperty(value = "0-待审核,1-通过,2-驳回")
private Integer state;
@ApiModelProperty(value = "创建时间")
@TableField("create_time")
private Date createTime;
@ApiModelProperty(value = "修改时间")
@TableField("update_time")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
......@@ -43,6 +43,14 @@ public class PointProductVo extends Model<PointProductVo> {
@ApiModelProperty(value = "0删除 1上架 2下架")
private Integer state;
@ApiModelProperty(value = "兑换开始时间")
@TableField("startTime")
private Date startTime;
@ApiModelProperty(value = "兑换结束时间")
@TableField("endTime")
private Date endTime;
@ApiModelProperty(value = "创建时间")
@TableField("create_time")
private Date createTime;
......
package com.yizhi.application.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.application.domain.Point;
import com.yizhi.application.service.PointDetailsService;
import com.yizhi.application.service.PointProductService;
import com.yizhi.application.service.PointService;
import com.yizhi.application.service.PointUserService;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.point.application.vo.PointDetailListVO;
import com.yizhi.point.application.vo.PointDetailsVO;
import com.yizhi.point.application.vo.domain.PointProductVo;
import com.yizhi.point.application.vo.domain.PointVo;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.vo.AccountVO;
import io.swagger.annotations.Api;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
* 积分设置 前端控制器
* </p>
*
* @author bob123
* @since 2018-04-20
*/
@Api(tags="积分商城", description="积分商城")
@RestController
@RequestMapping("/api/point")
public class PointApiController {
private static final Logger LOG = LoggerFactory.getLogger(PointApiController.class);
@Autowired
PointService pointService;
@Autowired
PointProductService pointProductService;
@GetMapping("/list")
public List<PointDetailListVO> list(@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "pageNo" ,required = false ) Integer pageNo,
@RequestParam(name = "pageSize" ,required = false ) Integer pageSize){
return pointService.getPointDetailsList(accountId, pageNo, pageSize);
}
@GetMapping("/productList")
public List<PointProductVo> productList(
@RequestParam(name = "pageNo" ,required = false ) Integer pageNo,
@RequestParam(name = "pageSize" ,required = false ) Integer pageSize){
return pointProductService.productListExchange(pageNo, pageSize);
}
@GetMapping("/exchange")
public boolean exchange(
@RequestParam(name = "companyId" ,required = false ) Long companyId,
@RequestParam(name = "orgId" ,required = false ) Long orgId,
@RequestParam(name = "siteId" ,required = false ) Long siteId,
@RequestParam(name = "accountId" ,required = false ) Long accountId,
@RequestParam(name = "accountName" ,required = false ) String accountName,
@RequestParam(name = "productIds" ,required = false ) String productIds) {
return pointService.exchange(companyId, orgId, siteId, accountId, accountName, productIds);
}
}
......@@ -3,6 +3,7 @@ package com.yizhi.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.application.domain.PointDetails;
import com.yizhi.point.application.vo.PointDetailListVO;
import com.yizhi.point.application.vo.PointDetailsVO;
import com.yizhi.point.application.vo.domain.PointDetailsVo;
import org.apache.ibatis.annotations.Param;
......@@ -101,4 +102,6 @@ public interface PointDetailsMapper extends BaseMapper<PointDetails> {
Integer getAmount(@Param("accountId") Long accountId, @Param("siteId")Long siteId);
Integer getCountToDay(@Param("accountId") Long accountId, @Param("siteId")Long siteId, @Param("type")String type,@Param("toDay")String toDay);
List<PointDetailListVO> getPointDetailsList(@Param("accountId") Long accountId, @Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize);
}
......@@ -22,4 +22,7 @@ public interface PointProductMapper extends BaseMapper<PointProduct> {
List<PointProductVo> productList(@Param("page") Page<PointProductVo> page, @Param("name") String name);
List<PointProductVo> productListExchange(@Param("page") Page<PointProductVo> page);
Integer getSumPointByProductId(@Param("productIds") List<String> productIds);
}
......@@ -3,6 +3,7 @@ package com.yizhi.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.application.domain.PointDetails;
import com.yizhi.point.application.vo.PointDetailListVO;
import com.yizhi.point.application.vo.PointDetailVO;
import com.yizhi.point.application.vo.PointDetailsVO;
import com.yizhi.point.application.vo.PointImportVO;
......@@ -67,4 +68,5 @@ public interface PointDetailsService extends IService<PointDetails> {
void updateChangeAfter(Long accountId,Long siteId);
List<PointDetailListVO> getPointDetailsList(Long accountId, Integer pageNo, Integer pageSize);
}
......@@ -31,4 +31,5 @@ public interface PointProductService extends IService<PointProduct> {
Page<PointProductVo> productList(PointSearchParamVO searchParamVO);
List<PointProductVo> productListExchange(Integer pageNo, Integer pageSize) ;
}
......@@ -2,6 +2,10 @@ package com.yizhi.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.application.domain.Point;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.point.application.vo.PointDetailListVO;
import java.util.List;
/**
* <p>
......@@ -17,4 +21,8 @@ public interface PointService extends IService<Point> {
boolean updateList(Point point);
void addPoint(Long accountId, String type, String sourceId);
boolean exchange(Long companyId, Long orgId, Long siteId, Long accountId, String accountName, String productIds);
List<PointDetailListVO> getPointDetailsList(Long accountId, Integer pageNo, Integer pageSize);
}
......@@ -15,13 +15,11 @@ import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.application.repository.PointDetailsRepository;
import com.yizhi.application.service.PointDetailsService;
import com.yizhi.application.service.PointUserService;
import com.yizhi.point.application.vo.PointDetailVO;
import com.yizhi.point.application.vo.PointDetailsVO;
import com.yizhi.point.application.vo.PointImportVO;
import com.yizhi.point.application.vo.PointVo;
import com.yizhi.point.application.vo.*;
import com.yizhi.point.application.vo.domain.PointDetailsVo;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -478,6 +476,11 @@ public class PointDetailsServiceImpl extends ServiceImpl<PointDetailsMapper, com
return pointDetailsMapper.getCountToDay(accountId,siteId,type,toDay);
}
@Override
public List<PointDetailListVO> getPointDetailsList(Long accountId, Integer pageNo, Integer pageSize) {
return pointDetailsMapper.getPointDetailsList(accountId, pageNo, pageSize);
}
public static void main(String[] args) {
DateTime yesterday = DateUtil.yesterday();
DateTime beginOfDay = DateUtil.beginOfDay(yesterday);
......
......@@ -89,4 +89,10 @@ public class PointProductServiceImpl extends ServiceImpl<PointProductMapper, Poi
List<PointProductVo> list = pointProductMapper.productList(page, searchParamVO.getName());
return page.setRecords(list);
}
@Override
public List<PointProductVo> productListExchange(Integer pageNo, Integer pageSize) {
Page<PointProductVo> page = new Page<>(pageNo, pageSize);
return pointProductMapper.productListExchange(page);
}
}
\ No newline at end of file
......@@ -9,17 +9,23 @@ import com.yizhi.application.domain.PointDetails;
import com.yizhi.application.domain.PointTypeStrategy;
import com.yizhi.application.domain.PointUser;
import com.yizhi.application.mapper.PointMapper;
import com.yizhi.application.mapper.PointProductMapper;
import com.yizhi.application.mapper.PointUserMapper;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.application.service.PointDetailsService;
import com.yizhi.application.service.PointService;
import com.yizhi.application.service.PointUserService;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.point.application.vo.PointDetailListVO;
import com.yizhi.point.application.vo.PointUserExchangeVO;
import com.yizhi.util.application.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* <p>
......@@ -41,7 +47,11 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
PointDetailsService pointDetailsService;
@Autowired
PointUserService pointUserService;
@Autowired
private PointUserMapper pointUserMapper;
@Autowired
private PointProductMapper pointProductMapper;
@Override
public Point pointList(Long companyId, Long siteId) {
Point point = pointMapper.pointList(companyId, siteId);
......@@ -169,4 +179,49 @@ public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements
}
return null;
}
public boolean exchange(Long companyId, Long orgId, Long siteId, Long accountId, String accountName, String productIds){
log.info("积分兑换入参 accountId:{}, productIds:{}", accountId, productIds);
//查询本次积分兑换需要扣减的积分
Integer point = pointProductMapper.getSumPointByProductId(Arrays.asList(productIds.split(",")));
log.info("积分兑换扣减积分 point:{}", point);
PointUser pu = new PointUser();
pu.setUserId(accountId);
EntityWrapper<PointUser> wrapper = new EntityWrapper<PointUser>(pu);
PointUser pointUser = pointUserService.selectOne(wrapper);
if(pointUser == null) {
return false;
}
PointDetails pd = new PointDetails();
pd.setId(idGenerator.generate());
pd.setTime(new Date());
pd.setChangeBefore(pointUser.getTotalPoint());
pd.setPoint(point * -1);
pd.setChangeAfter(pointUser.getTotalPoint() - point);
pd.setMultiple(1);
pd.setAccountId(accountId);
pd.setLearnName(PointTypeEnum.EXCHANGE.getDesc());
pd.setLearnSource(productIds);
pd.setLearnSourceId(0L);
pd.setLearnType(PointTypeEnum.EXCHANGE.getKey());
pd.setState(1);
pd.setCreateById(accountId);
pd.setCreateByName(accountName);
pd.setCreateTime(new Date());
pd.setOrgId(orgId);
pd.setCompanyId(companyId);
pd.setSiteId(siteId);
pointDetailsService.insert(pd);
PointUserExchangeVO pointUserExchangeVO = new PointUserExchangeVO();
pointUserExchangeVO.setUserId(accountId);
pointUserExchangeVO.setPoint(point);
int ret = pointUserMapper.updateUserPointExchange(pointUserExchangeVO);
return ret > 0;
}
public List<PointDetailListVO> getPointDetailsList(Long accountId, Integer pageNo, Integer pageSize) {
pageNo = (pageNo - 1) * pageSize;
return pointDetailsService.getPointDetailsList(accountId, pageNo, pageSize);
}
}
......@@ -263,5 +263,9 @@
and DATE_FORMAT(mpp.create_point_time, '%Y-%m-%d' ) = #{toDay}
</select>
<select id="getPointDetailsList" resultType="com.yizhi.point.application.vo.PointDetailListVO">
select time, point, learn_name, change_after from point_details
where account_id = #{accountId} order by time desc limit #{pageNo},#{pageSize}
</select>
</mapper>
......@@ -12,4 +12,17 @@
</if>
</select>
<select id="productListExchange" resultType="com.yizhi.point.application.vo.domain.PointProductVo">
SELECT *
FROM point_product
WHERE state != 0 and ( now() between start_time and end_time )
</select>
<select id="getSumPointByProductId" resultType="java.lang.Integer">
select sum(point) from point_product where id in
<foreach collection="productIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
</mapper>
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