Commit 3ea9516c by 阮思源

Merge branch 'feat-1002654' into 'master'

1002654定制服务内容展示

See merge request rays/pcloud-book!584
parents ac655a80 d60c470e
package com.pcloud.book.custom.biz;
import com.pcloud.book.custom.entity.CustomReadPlan;
import com.pcloud.common.page.PageBeanNew;
public interface CustomReadPlanBiz {
Long addCustomReadPlan(CustomReadPlan customReadPlan);
void updateCustomReadPlan(CustomReadPlan customReadPlan);
void deleteCustomReadPlan(Long customReadPlanId);
PageBeanNew<CustomReadPlan> getCustomReadPlanList(Integer currentPage, Integer numPerPage, Integer robotType);
CustomReadPlan getCustomReadPlanById(Long customReadPlanId);
Long copyCustomReadPlanById(Long customReadPlanId);
}
package com.pcloud.book.custom.biz.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.custom.biz.CustomReadPlanBiz;
import com.pcloud.book.custom.dao.CustomReadPlanDao;
import com.pcloud.book.custom.dao.CustomReadPlanPeriodDao;
import com.pcloud.book.custom.dto.PeriodCountAndReadPlanDTO;
import com.pcloud.book.custom.entity.CustomReadPlan;
import com.pcloud.book.custom.entity.CustomReadPlanPeriod;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class CustomReadPlanBizImpl implements CustomReadPlanBiz {
@Autowired
private CustomReadPlanDao customReadPlanDao;
@Autowired
private CustomReadPlanPeriodDao customReadPlanPeriodDao;
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增阅读计划")
@Override
public Long addCustomReadPlan(CustomReadPlan customReadPlan) {
checkAddCustomReadPlan(customReadPlan);
customReadPlanDao.insert(customReadPlan);
buildAndAddPeriods(customReadPlan);
return customReadPlan.getId();
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("修改阅读计划")
@Override
public void updateCustomReadPlan(CustomReadPlan customReadPlan) {
checkUpdateCustomReadPlan(customReadPlan);
customReadPlanDao.update(customReadPlan);
customReadPlanPeriodDao.deleteByCustomReadPlanId(customReadPlan.getId());
buildAndAddPeriods(customReadPlan);
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("删除阅读计划")
@Override
public void deleteCustomReadPlan(Long customReadPlanId) {
if (customReadPlanId==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"id为空");
}
customReadPlanDao.deleteById(customReadPlanId);
customReadPlanPeriodDao.deleteByCustomReadPlanId(customReadPlanId);
}
@ParamLog("获取阅读计划列表")
@Override
public PageBeanNew<CustomReadPlan> getCustomReadPlanList(Integer currentPage, Integer numPerPage, Integer robotType) {
if (currentPage==null||currentPage<0||numPerPage==null||numPerPage<=0){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"分页参数有误!");
}
Map<String,Object> map=new HashMap<>();
map.put("robotType",robotType);
PageBeanNew<CustomReadPlan> pageNew = customReadPlanDao.listPageNew(new PageParam(currentPage, numPerPage), map , "getCustomReadPlanList");
if (ListUtils.isEmpty(pageNew.getRecordList())){
return pageNew;
}
fillPeriodCount(pageNew.getRecordList());
return pageNew;
}
@ParamLog("填充周期数")
private void fillPeriodCount(List<CustomReadPlan> list) {
if (ListUtils.isEmpty(list)){
return;
}
List<Long> readPlanIds=list.stream().map(CustomReadPlan::getId).collect(Collectors.toList());
List<PeriodCountAndReadPlanDTO> group = customReadPlanPeriodDao.getPeriodCountGroupByReadPlanId(readPlanIds);
Map<Long,Integer> map=new HashMap<>();
if (!ListUtils.isEmpty(group)){
for (PeriodCountAndReadPlanDTO dto:group){
map.put(dto.getCustomReadPlanId(),dto.getPeriodCount());
}
}
for (CustomReadPlan customReadPlan:list){
if (map.get(customReadPlan.getId())!=null){
customReadPlan.setPeriodCount(map.get(customReadPlan.getId()));
}else {
customReadPlan.setPeriodCount(0);
}
}
}
@ParamLog("根据id获取阅读计划")
@Override
public CustomReadPlan getCustomReadPlanById(Long customReadPlanId) {
if (customReadPlanId==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"id为空");
}
CustomReadPlan customReadPlan = customReadPlanDao.getById(customReadPlanId);
List<CustomReadPlanPeriod> customReadPlanPeriods=customReadPlanPeriodDao.getListByCustomReadPlanId(customReadPlanId);
customReadPlan.setCustomReadPlanPeriods(customReadPlanPeriods);
return customReadPlan;
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("复制阅读计划")
@Override
public Long copyCustomReadPlanById(Long customReadPlanId) {
if (customReadPlanId==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"id为空");
}
CustomReadPlan customReadPlan = getCustomReadPlanById(customReadPlanId);
if (customReadPlan==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"没有该计划");
}
CustomReadPlan newCus=new CustomReadPlan();
newCus.setRobotType(customReadPlan.getRobotType());
newCus.setDetail(customReadPlan.getDetail());
newCus.setName(customReadPlan.getName());
newCus.setCustomReadPlanPeriods(customReadPlan.getCustomReadPlanPeriods());
addCustomReadPlan(newCus);
return customReadPlan.getId();
}
@ParamLog("修改阅读计划参数校验")
private void checkUpdateCustomReadPlan(CustomReadPlan customReadPlan) {
if (customReadPlan==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"参数为空");
}
if (customReadPlan.getId()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"id参数为空");
}
checkAddCustomReadPlan(customReadPlan);
}
@ParamLog("构建周期列表")
private void buildAndAddPeriods(CustomReadPlan customReadPlan) {
if (ListUtils.isEmpty(customReadPlan.getCustomReadPlanPeriods())){
return;
}
Long customReadPlanId=customReadPlan.getId();
int i=1;
for (CustomReadPlanPeriod period:customReadPlan.getCustomReadPlanPeriods()){
period.setCustomReadPlanId(customReadPlanId);
period.setSeqNum(i++);
}
customReadPlanPeriodDao.batchInsert(customReadPlan.getCustomReadPlanPeriods());
}
@ParamLog("新增阅读计划参数校验")
private void checkAddCustomReadPlan(CustomReadPlan customReadPlan) {
if (customReadPlan==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"参数为空");
}
if (customReadPlan.getRobotType()==null){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"机器人类型参数为空");
}
if (StringUtil.isEmpty(customReadPlan.getName())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"名称参数为空");
}
if (StringUtil.isEmpty(customReadPlan.getDetail())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"阅读计划介绍参数为空");
}
if (ListUtils.isEmpty(customReadPlan.getCustomReadPlanPeriods())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"周期集合为空");
}
if (customReadPlan.getCustomReadPlanPeriods().size()>52){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"周期不能超过52");
}
for (CustomReadPlanPeriod period:customReadPlan.getCustomReadPlanPeriods()){
if (StringUtil.isEmpty(period.getName())){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"周期名称参数为空");
}
}
}
}
package com.pcloud.book.custom.dao;
import com.pcloud.book.custom.entity.CustomReadPlan;
import com.pcloud.common.core.dao.BaseDao;
public interface CustomReadPlanDao extends BaseDao<CustomReadPlan> {
}
package com.pcloud.book.custom.dao;
import com.pcloud.book.custom.dto.PeriodCountAndReadPlanDTO;
import com.pcloud.book.custom.entity.CustomReadPlanPeriod;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
public interface CustomReadPlanPeriodDao extends BaseDao<CustomReadPlanPeriod> {
Integer batchInsert(List<CustomReadPlanPeriod> customReadPlanPeriods);
void deleteByCustomReadPlanId(Long customReadPlanId);
List<CustomReadPlanPeriod> getListByCustomReadPlanId(Long customReadPlanId);
List<PeriodCountAndReadPlanDTO> getPeriodCountGroupByReadPlanId(List<Long> readPlanIds);
}
package com.pcloud.book.custom.dao.impl;
import com.pcloud.book.custom.dao.CustomReadPlanDao;
import com.pcloud.book.custom.entity.CustomReadPlan;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
@Repository("customReadPlanDao")
public class CustomReadPlanDaoImpl extends BaseDaoImpl<CustomReadPlan> implements CustomReadPlanDao {
}
package com.pcloud.book.custom.dao.impl;
import com.pcloud.book.custom.dao.CustomReadPlanPeriodDao;
import com.pcloud.book.custom.dto.PeriodCountAndReadPlanDTO;
import com.pcloud.book.custom.entity.CustomReadPlanPeriod;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("customReadPlanPeriodDao")
public class CustomReadPlanPeriodDaoImpl extends BaseDaoImpl<CustomReadPlanPeriod> implements CustomReadPlanPeriodDao {
@Override
public Integer batchInsert(List<CustomReadPlanPeriod> list) {
return super.getSqlSession().insert(getStatement("batchInsert"), list);
}
@Override
public void deleteByCustomReadPlanId(Long customReadPlanId) {
super.getSqlSession().update(getStatement("deleteByCustomReadPlanId"), customReadPlanId);
}
@Override
public List<CustomReadPlanPeriod> getListByCustomReadPlanId(Long customReadPlanId) {
return super.getSqlSession().selectList(getStatement("getListByCustomReadPlanId"), customReadPlanId);
}
@Override
public List<PeriodCountAndReadPlanDTO> getPeriodCountGroupByReadPlanId(List<Long> list) {
return super.getSqlSession().selectList(getStatement("getPeriodCountGroupByReadPlanId"), list);
}
}
package com.pcloud.book.custom.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PeriodCountAndReadPlanDTO {
@ApiModelProperty("阅读计划id")
private Long customReadPlanId;
@ApiModelProperty("周期数量")
private Integer periodCount;
}
package com.pcloud.book.custom.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("阅读计划")
@Data
public class CustomReadPlan extends BaseEntity {
@ApiModelProperty("机器人类型")
private Integer robotType;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("详情")
private String detail;
@ApiModelProperty("周期数量")
private Integer periodCount;
@ApiModelProperty("周期集合")
private List<CustomReadPlanPeriod> customReadPlanPeriods;
}
package com.pcloud.book.custom.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("阅读计划周期")
@Data
public class CustomReadPlanPeriod extends BaseEntity {
@ApiModelProperty("阅读计划id")
private Long customReadPlanId;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("附加说明")
private String additionExplain;
@ApiModelProperty("排序值")
private Integer seqNum;
}
...@@ -2,8 +2,10 @@ package com.pcloud.book.custom.facade; ...@@ -2,8 +2,10 @@ package com.pcloud.book.custom.facade;
import com.pcloud.book.custom.biz.CustomPlanBiz; import com.pcloud.book.custom.biz.CustomPlanBiz;
import com.pcloud.book.custom.biz.CustomPlanEmailBiz; import com.pcloud.book.custom.biz.CustomPlanEmailBiz;
import com.pcloud.book.custom.biz.CustomReadPlanBiz;
import com.pcloud.book.custom.dto.CustomPlanEmailDto; import com.pcloud.book.custom.dto.CustomPlanEmailDto;
import com.pcloud.book.custom.entity.CustomPlan; import com.pcloud.book.custom.entity.CustomPlan;
import com.pcloud.book.custom.entity.CustomReadPlan;
import com.pcloud.book.custom.vo.AddBookNameVO; import com.pcloud.book.custom.vo.AddBookNameVO;
import com.pcloud.book.custom.vo.AddCustomPlan4UserVO; import com.pcloud.book.custom.vo.AddCustomPlan4UserVO;
import com.pcloud.book.custom.vo.AddSuggestionVO; import com.pcloud.book.custom.vo.AddSuggestionVO;
...@@ -38,6 +40,8 @@ public class CustomPlanFacade { ...@@ -38,6 +40,8 @@ public class CustomPlanFacade {
private CustomPlanBiz customPlanBiz; private CustomPlanBiz customPlanBiz;
@Autowired @Autowired
private CustomPlanEmailBiz customPlanEmailBiz; private CustomPlanEmailBiz customPlanEmailBiz;
@Autowired
private CustomReadPlanBiz customReadPlanBiz;
@ApiOperation("创建定制方案") @ApiOperation("创建定制方案")
@PostMapping("createCustomPlan") @PostMapping("createCustomPlan")
...@@ -198,4 +202,69 @@ public class CustomPlanFacade { ...@@ -198,4 +202,69 @@ public class CustomPlanFacade {
return new ResponseDto<>(customPlanBiz.getUserBookServiceById(userBookServiceId)); return new ResponseDto<>(customPlanBiz.getUserBookServiceById(userBookServiceId));
} }
@ApiOperation("新增阅读计划")
@PostMapping("addCustomReadPlan")
ResponseDto<?> addCustomReadPlan(
@RequestHeader("token") String token,
@RequestBody CustomReadPlan customReadPlan
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customReadPlanBiz.addCustomReadPlan(customReadPlan));
}
@ApiOperation("修改阅读计划")
@PostMapping("updateCustomReadPlan")
ResponseDto<?> updateCustomReadPlan(
@RequestHeader("token") String token,
@RequestBody CustomReadPlan customReadPlan
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
customReadPlanBiz.updateCustomReadPlan(customReadPlan);
return new ResponseDto<>();
}
@ApiOperation("删除阅读计划")
@GetMapping("deleteCustomReadPlan")
ResponseDto<?> deleteCustomReadPlan(
@RequestHeader("token") String token,
@RequestParam("customReadPlanId") Long customReadPlanId
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
customReadPlanBiz.deleteCustomReadPlan(customReadPlanId);
return new ResponseDto<>();
}
@ApiOperation("获取阅读计划列表")
@GetMapping("getCustomReadPlanList")
ResponseDto<?> getCustomReadPlanList(
@RequestHeader("token") String token,
@RequestParam("currentPage") Integer currentPage,
@RequestParam("numPerPage") Integer numPerPage,
@RequestParam(value = "robotType",required = false) Integer robotType
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customReadPlanBiz.getCustomReadPlanList(currentPage,numPerPage,robotType));
}
@ApiOperation("根据id获取阅读计划")
@GetMapping("getCustomReadPlanById")
ResponseDto<?> getCustomReadPlanById(
@RequestHeader("token") String token,
@RequestParam("customReadPlanId") Long customReadPlanId
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customReadPlanBiz.getCustomReadPlanById(customReadPlanId));
}
@ApiOperation("复制阅读计划")
@GetMapping("copyCustomReadPlanById")
ResponseDto<?> copyCustomReadPlanById(
@RequestHeader("token") String token,
@RequestParam("customReadPlanId") Long customReadPlanId
)throws BizException, PermissionException{
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customReadPlanBiz.copyCustomReadPlanById(customReadPlanId));
}
} }
<?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.pcloud.book.custom.dao.impl.CustomReadPlanDaoImpl" >
<resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomReadPlan" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="robot_type" property="robotType" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="detail" property="detail" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List">
id, robot_type,name,detail,create_time,update_time
</sql>
<insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomReadPlan" useGeneratedKeys="true" keyProperty="id">
insert into custom_read_plan
(robot_type,name,detail,create_time,update_time)
values
(#{robotType},#{name},#{detail},now(),now())
</insert>
<update id="update" parameterType="com.pcloud.book.custom.entity.CustomReadPlan">
update custom_read_plan
<set>
<if test="robotType != null">
robot_type = #{robotType},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="detail != null">
detail = #{detail},
</if>
update_time = NOW()
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteById">
delete from custom_read_plan
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="getById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from custom_read_plan
where id = #{id,jdbcType=INTEGER}
</select>
<select id="getCustomReadPlanList" parameterType="map" resultMap="BaseResultMap">
select
t1.id,
t1.robot_type,
t1.name,
t1.detail,
t1.create_time,
t1.update_time
from custom_read_plan t1
where 1=1
<if test="robotType!=null">
and t1.robot_type=#{robotType}
</if>
order by t1.create_time desc
</select>
</mapper>
\ No newline at end of file
<?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.pcloud.book.custom.dao.impl.CustomReadPlanPeriodDaoImpl" >
<resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomReadPlanPeriod" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="custom_read_plan_id" property="customReadPlanId" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="addition_explain" property="additionExplain" jdbcType="VARCHAR" />
<result column="seq_num" property="seqNum" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List">
id, custom_read_plan_id,name,addition_explain,seq_num,create_time
</sql>
<insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomReadPlanPeriod" useGeneratedKeys="true" keyProperty="id">
insert into custom_read_plan_period
(custom_read_plan_id,name,addition_explain,seq_num,create_time)
values
(#{customReadPlanId},#{name},#{additionExplain},#{seqNum},now())
</insert>
<update id="update" parameterType="com.pcloud.book.custom.entity.CustomReadPlanPeriod">
update custom_read_plan_period
<set>
<if test="customReadPlanId != null">
custom_read_plan_id = #{customReadPlanId},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="additionExplain != null">
addition_explain = #{additionExplain},
</if>
<if test="seqNum != null">
seq_num = #{seqNum},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteById">
delete from custom_read_plan_period
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="getById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from custom_read_plan_period
where id = #{id,jdbcType=INTEGER}
</select>
<insert id="batchInsert" parameterType="com.pcloud.book.custom.entity.CustomReadPlanPeriod" useGeneratedKeys="true" keyProperty="id">
insert into custom_read_plan_period (
custom_read_plan_id,
name,
addition_explain,
seq_num,
create_time
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.customReadPlanId,jdbcType=BIGINT},
#{item.name,jdbcType=VARCHAR},
#{item.additionExplain,jdbcType=VARCHAR},
#{item.seqNum,jdbcType=INTEGER},
NOW()
)
</foreach>
</insert>
<delete id="deleteByCustomReadPlanId" parameterType="long">
delete from custom_read_plan_period
where custom_read_plan_id = #{customReadPlanId}
</delete>
<select id="getListByCustomReadPlanId" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from custom_read_plan_period
where custom_read_plan_id = #{customReadPlanId}
</select>
<select id="getPeriodCountGroupByReadPlanId" parameterType="list" resultType="com.pcloud.book.custom.dto.PeriodCountAndReadPlanDTO">
select
custom_read_plan_id customReadPlanId,
ifnull(count(1),0) periodCount
from custom_read_plan_period
where custom_read_plan_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
${item}
</foreach>
group by custom_read_plan_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