Commit 4aff4f7e by 桂前礼

feat: [1004330] 本书服务评价文案功能优化

parent cda94852
package com.pcloud.book.applet.biz;
import com.pcloud.book.applet.dto.AppletBookUserScoreDTO;
import com.pcloud.book.applet.dto.AppletFeedbackDTO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -14,17 +16,43 @@ public interface AppletBookScoreBiz {
* @param channelId 渠道ID
* @param adviserId 编辑ID
* @param scoreTagId 评价
* @param subTagId 二级 标签ID
* @return 主键ID
*/
Long score(Long wechatUserId, Long bookId, Long channelId, Long adviserId, Long scoreTagId);
Long score(Long wechatUserId, Long bookId, Long channelId, Long adviserId, Long scoreTagId, Long subTagId);
/**
* 获取本书服务评价信息
*
* @param wechatUserId 用户ID
* @param bookId 图书ID
* @param channelId 渠道ID
* @param adviserId 评价
* @return
* @return 评价信息
*/
List<AppletBookUserScoreDTO> get(Long wechatUserId, Long bookId, Long channelId, Long adviserId);
/**
* 用户本书服务反馈意见
*
* @param wechatUserId 用户ID
* @param feedbackDTO 反馈意见
* @return null
*/
Void feedback(Long wechatUserId, AppletFeedbackDTO feedbackDTO);
/**
* 文件上传
*
* @param file 文件数组
* @return 文件地址集合
*/
List<String> uploadFile(MultipartFile[] file);
/**
* 导出本书服务评价数据
*
* @return 文件字节流
*/
byte[] export();
}
package com.pcloud.book.applet.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel("标签信息封装")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AppletBookScoreSubTagDTO {
@ApiModelProperty("二级标签ID")
private Long subTagId;
@ApiModelProperty("腹肌标签ID")
private Long tagId;
@ApiModelProperty("二级标签名称")
private String subTagName;
@ApiModelProperty("是否选中")
private boolean chosen = false;
@ApiModelProperty("选中时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date chooseTime;
}
......@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@ApiModel("标签信息封装")
......@@ -26,4 +27,6 @@ public class AppletBookScoreTagDTO {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date chooseTime;
@ApiModelProperty("二级标签列表")
private List<AppletBookScoreSubTagDTO> subTags;
}
......@@ -12,6 +12,8 @@ public class AppletBookScoreTagInfoDTO {
private Long tagId;
private String tagName;
private Integer chosen;
private Long subTagId;
private String subTagName;
private Date chosenTime;
}
package com.pcloud.book.applet.dto;
import lombok.Data;
@Data
public class AppletBookTagUserExportDTO {
private String scoreName;
private String tagName;
private String subTagName;
private Integer userCount;
}
......@@ -2,6 +2,7 @@ package com.pcloud.book.applet.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
......@@ -20,6 +21,9 @@ public class AppletBookUserScoreDTO {
private String scoreName;
@ApiModelProperty("是否选中")
private boolean chosen = false;
private List<AppletBookScoreTagDTO> tags;
}
package com.pcloud.book.applet.dto;
import lombok.Data;
import java.util.Date;
@Data
public class AppletBookUserScoreExportDTO {
private Long scoreId;
private String scoreName;
private Long tagId;
private String tagName;
private Long subTagId;
private String subTagName;
private Long wechatUserId;
private String nickname;
private String mobile;
private Long bookId;
private String bookName;
private Long adviserId;
private String adviserName;
private Long channelId;
private Date updateTime;
private String dateStr;
}
package com.pcloud.book.applet.dto;
import lombok.Data;
@Data
public class AppletFeedbackDTO {
private Long bookId;
private Long channelId;
private Long adviserId;
private String content;
private String pic1;
private String pic2;
private String pic3;
private String pic4;
}
package com.pcloud.book.applet.dto;
import lombok.Data;
@Data
public class AppletUserFeedbackExportDTO {
private Long wechatUserId;
private String nickname;
private String mobile;
private Long bookId;
private String bookName;
private Long adviserId;
private String adviserName;
private Long channelId;
private String dateStr;
private String content;
private String pic1;
private String pic2;
private String pic3;
private String pic4;
}
package com.pcloud.book.applet.dto;
import lombok.Data;
@Data
public class AppletUserScoreHeadDTO {
private String scoreName;
private String tagName;
private String subTagName;
private Long wechatUserId;
private String nickname;
private String mobile;
private Long bookId;
private String bookName;
private Long adviserId;
private String adviserName;
private Long channelId;
private String dateStr;
}
package com.pcloud.book.applet.entity;
import java.util.Date;
import java.io.Serializable;
/**
* 小程序书刊资源意见反馈记录表(AppletBookFeedback)实体类
*
* @author guiq
* @since 2021-02-20 17:13:22
*/
public class AppletBookFeedback implements Serializable {
private static final long serialVersionUID = -23562759782689190L;
/**
* 主键ID
*/
private Long id;
/**
* 意见反馈内容
*/
private String content;
/**
* 图片1
*/
private String pic1;
/**
* 图片2
*/
private String pic2;
/**
* 图片3
*/
private String pic3;
/**
* 图片4
*/
private String pic4;
/**
* 用户ID
*/
private Long wechatUserId;
/**
* 图书ID
*/
private Long bookId;
/**
* 渠道ID
*/
private Long channelId;
/**
* 编辑ID
*/
private Long adviserId;
/**
* 创建时间
*/
private Date createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPic1() {
return pic1;
}
public void setPic1(String pic1) {
this.pic1 = pic1;
}
public String getPic2() {
return pic2;
}
public void setPic2(String pic2) {
this.pic2 = pic2;
}
public String getPic3() {
return pic3;
}
public void setPic3(String pic3) {
this.pic3 = pic3;
}
public String getPic4() {
return pic4;
}
public void setPic4(String pic4) {
this.pic4 = pic4;
}
public Long getWechatUserId() {
return wechatUserId;
}
public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId;
}
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
public Long getChannelId() {
return channelId;
}
public void setChannelId(Long channelId) {
this.channelId = channelId;
}
public Long getAdviserId() {
return adviserId;
}
public void setAdviserId(Long adviserId) {
this.adviserId = adviserId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
package com.pcloud.book.applet.entity;
import java.util.Date;
import java.io.Serializable;
/**
* 小程序本书服务评价二级标签表(AppletBookScoreSubTag)实体类
*
* @author guiq
* @since 2021-02-20 15:26:51
*/
public class AppletBookScoreSubTag implements Serializable {
private static final long serialVersionUID = -38345844548988860L;
/**
* 主键ID
*/
private Integer id;
/**
* 标签名称
*/
private String name;
/**
* 父级标签ID
*/
private Integer tagId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getTagId() {
return tagId;
}
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
......@@ -41,6 +41,11 @@ public class AppletBookUserScore implements Serializable {
private Long scoreTagId;
/**
* 二级标签
*/
private Long subTagId;
/**
* 创建时间
*/
private Date createTime;
......
......@@ -2,26 +2,50 @@ package com.pcloud.book.applet.facade;
import com.pcloud.book.applet.biz.AppletBookScoreBiz;
import com.pcloud.book.applet.dto.AppletBookUserScoreDTO;
import com.pcloud.book.applet.dto.AppletFeedbackDTO;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.channelcenter.base.exceptions.ChannelBizException;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.cookie.Cookie;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;
@Api(tags = "小程序本服务用户评价相关接口")
@RestController
@Slf4j
@RequestMapping("/appletBookScore")
public class AppletBookScoreFacade {
@Autowired
private AppletBookScoreBiz appletBookScoreBiz;
@ApiOperation(value = "上传图片获取二维码信息", httpMethod = "POST")
@PostMapping("/uploadFile")
ResponseDto<?> uploadFile(@RequestParam(value = "file") MultipartFile[] file)
throws PermissionException, BizException {
if (file.length < 1) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "上传失败,请选择文件!");
}
return new ResponseDto<>(appletBookScoreBiz.uploadFile(file));
}
@ApiOperation("新增小程序本服务评价")
@GetMapping("/add")
......@@ -29,9 +53,11 @@ public class AppletBookScoreFacade {
@RequestParam("bookId") Long bookId,
@RequestParam("channelId") Long channelId,
@RequestParam("adviserId") Long adviserId,
@RequestParam("score") Long score) {
@RequestParam("tagId") Long tagId,
@RequestParam("subTagId") Long subTagId
) {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
return new ResponseDto<>(appletBookScoreBiz.score(wechatUserId, bookId, channelId, adviserId, score));
return new ResponseDto<>(appletBookScoreBiz.score(wechatUserId, bookId, channelId, adviserId, tagId, subTagId));
}
......@@ -44,4 +70,25 @@ public class AppletBookScoreFacade {
return new ResponseDto<>(appletBookScoreBiz.get(wechatUserId, bookId, channelId, adviserId));
}
@PostMapping("/feedback")
ResponseDto<Void> feedback(@CookieValue("userInfo") String userInfo, @RequestBody AppletFeedbackDTO feedbackDTO){
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
return new ResponseDto<>(appletBookScoreBiz.feedback(wechatUserId, feedbackDTO));
}
@GetMapping("/export")
void export(HttpServletResponse response) {
try {
ServletOutputStream outputStream = response.getOutputStream();
// 指定下载文件名称
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("本书服务评价数据导出.xlsx", "UTF-8"));
// 指定下载文件类型
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
outputStream.write(appletBookScoreBiz.export());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
log.warn("[AppletBookScoreFacade.export] 数据导出失败!", e);
}
}
}
package com.pcloud.book.applet.mapper;
import com.pcloud.book.applet.entity.AppletBookFeedback;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小程序书刊资源意见反馈记录表(AppletBookFeedback)表数据库访问层
*
* @author guiq
* @since 2021-02-20 17:13:22
*/
@Mapper
@Component
public interface AppletBookFeedbackMapper {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
AppletBookFeedback queryById(Long id);
/**
* 查询指定行数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<AppletBookFeedback> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
/**
* 通过实体作为筛选条件查询
*
* @param appletBookFeedback 实例对象
* @return 对象列表
*/
List<AppletBookFeedback> queryAll(AppletBookFeedback appletBookFeedback);
/**
* 新增数据
*
* @param appletBookFeedback 实例对象
* @return 影响行数
*/
int insert(AppletBookFeedback appletBookFeedback);
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<AppletBookFeedback> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<AppletBookFeedback> entities);
/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<AppletBookFeedback> 实例对象列表
* @return 影响行数
*/
int insertOrUpdateBatch(@Param("entities") List<AppletBookFeedback> entities);
/**
* 修改数据
*
* @param appletBookFeedback 实例对象
* @return 影响行数
*/
int update(AppletBookFeedback appletBookFeedback);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Long id);
}
package com.pcloud.book.applet.mapper;
import com.pcloud.book.applet.entity.AppletBookScoreSubTag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小程序本书服务评价二级标签表(AppletBookScoreSubTag)表数据库访问层
*
* @author guiq
* @since 2021-02-20 15:26:56
*/
@Mapper
@Component
public interface AppletBookScoreSubTagMapper {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
AppletBookScoreSubTag queryById(Integer id);
/**
* 查询指定行数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<AppletBookScoreSubTag> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
/**
* 通过实体作为筛选条件查询
*
* @param appletBookScoreSubTag 实例对象
* @return 对象列表
*/
List<AppletBookScoreSubTag> queryAll(AppletBookScoreSubTag appletBookScoreSubTag);
/**
* 新增数据
*
* @param appletBookScoreSubTag 实例对象
* @return 影响行数
*/
int insert(AppletBookScoreSubTag appletBookScoreSubTag);
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<AppletBookScoreSubTag> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<AppletBookScoreSubTag> entities);
/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<AppletBookScoreSubTag> 实例对象列表
* @return 影响行数
*/
int insertOrUpdateBatch(@Param("entities") List<AppletBookScoreSubTag> entities);
/**
* 修改数据
*
* @param appletBookScoreSubTag 实例对象
* @return 影响行数
*/
int update(AppletBookScoreSubTag appletBookScoreSubTag);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Integer id);
}
package com.pcloud.book.applet.mapper;
import com.pcloud.book.applet.dto.AppletBookScoreTagInfoDTO;
import com.pcloud.book.applet.dto.AppletBookTagUserExportDTO;
import com.pcloud.book.applet.dto.AppletBookUserScoreExportDTO;
import com.pcloud.book.applet.entity.AppletBookUserScore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
@Mapper
@Component
public interface AppletBookUserScoreMapper {
......@@ -21,5 +27,13 @@ public interface AppletBookUserScoreMapper {
Long selectPrimaryKey(AppletBookUserScore appletBookUserScore);
List<AppletBookScoreTagInfoDTO> getSubTagChosen(@Param("wechatUserId") Long wechatUserId, @Param("bookId") Long bookId, @Param("channelId") Long channelId, @Param("adviserId") Long adviserId);
void deleteChosen(AppletBookUserScore appletBookUserScore);
List<AppletBookUserScoreExportDTO> listBookUserScore();
List<AppletBookTagUserExportDTO> listTagUser();
void deleteChosenTag(AppletBookUserScore appletBookUserScore);
}
\ 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.applet.mapper.AppletBookFeedbackMapper">
<resultMap type="com.pcloud.book.applet.entity.AppletBookFeedback" id="AppletBookFeedbackMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="pic1" column="pic1" jdbcType="VARCHAR"/>
<result property="pic2" column="pic2" jdbcType="VARCHAR"/>
<result property="pic3" column="pic3" jdbcType="VARCHAR"/>
<result property="pic4" column="pic4" jdbcType="VARCHAR"/>
<result property="wechatUserId" column="wechat_user_id" jdbcType="INTEGER"/>
<result property="bookId" column="book_id" jdbcType="INTEGER"/>
<result property="channelId" column="channel_id" jdbcType="INTEGER"/>
<result property="adviserId" column="adviser_id" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="AppletBookFeedbackMap">
select id,
content,
pic1,
pic2,
pic3,
pic4,
wechat_user_id,
book_id,
channel_id,
adviser_id,
create_time
from book.applet_book_feedback
where id = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="AppletBookFeedbackMap">
select id,
content,
pic1,
pic2,
pic3,
pic4,
wechat_user_id,
book_id,
channel_id,
adviser_id,
create_time
from book.applet_book_feedback limit #{offset}, #{limit}
</select>
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="AppletBookFeedbackMap">
select
id, content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id, adviser_id, create_time
from book.applet_book_feedback
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="content != null and content != ''">
and content = #{content}
</if>
<if test="pic1 != null and pic1 != ''">
and pic1 = #{pic1}
</if>
<if test="pic2 != null and pic2 != ''">
and pic2 = #{pic2}
</if>
<if test="pic3 != null and pic3 != ''">
and pic3 = #{pic3}
</if>
<if test="pic4 != null and pic4 != ''">
and pic4 = #{pic4}
</if>
<if test="wechatUserId != null">
and wechat_user_id = #{wechatUserId}
</if>
<if test="bookId != null">
and book_id = #{bookId}
</if>
<if test="channelId != null">
and channel_id = #{channelId}
</if>
<if test="adviserId != null">
and adviser_id = #{adviserId}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
adviser_id, create_time)
values (#{content}, #{pic1}, #{pic2}, #{pic3}, #{pic4}, #{wechatUserId}, #{bookId}, #{channelId}, #{adviserId},
#{createTime})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
adviser_id, create_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.content}, #{entity.pic1}, #{entity.pic2}, #{entity.pic3}, #{entity.pic4}, #{entity.wechatUserId},
#{entity.bookId}, #{entity.channelId}, #{entity.adviserId}, #{entity.createTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_feedback(content, pic1, pic2, pic3, pic4, wechat_user_id, book_id, channel_id,
adviser_id, create_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.content}, #{entity.pic1}, #{entity.pic2}, #{entity.pic3}, #{entity.pic4}, #{entity.wechatUserId},
#{entity.bookId}, #{entity.channelId}, #{entity.adviserId}, #{entity.createTime})
</foreach>
on duplicate key update
content = values(content) , pic1 = values(pic1) , pic2 = values(pic2) , pic3 = values(pic3) , pic4 =
values(pic4) , wechat_user_id = values(wechat_user_id) , book_id = values(book_id) , channel_id =
values(channel_id) , adviser_id = values(adviser_id) , create_time = values(create_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update book.applet_book_feedback
<set>
<if test="content != null and content != ''">
content = #{content},
</if>
<if test="pic1 != null and pic1 != ''">
pic1 = #{pic1},
</if>
<if test="pic2 != null and pic2 != ''">
pic2 = #{pic2},
</if>
<if test="pic3 != null and pic3 != ''">
pic3 = #{pic3},
</if>
<if test="pic4 != null and pic4 != ''">
pic4 = #{pic4},
</if>
<if test="wechatUserId != null">
wechat_user_id = #{wechatUserId},
</if>
<if test="bookId != null">
book_id = #{bookId},
</if>
<if test="channelId != null">
channel_id = #{channelId},
</if>
<if test="adviserId != null">
adviser_id = #{adviserId},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from book.applet_book_feedback
where id = #{id}
</delete>
</mapper>
......@@ -83,6 +83,8 @@
b.id tagId,
b.name tagName,
c.update_time chosenTime,
d.id subTagId,
d.`name` subTagName,
IF(c.id IS NULL, 0, 1) chosen
FROM applet_book_score a
LEFT JOIN applet_book_score_tag b ON a.id = b.score_id
......@@ -93,6 +95,7 @@
AND wechat_user_id = ${wechatUserId}
AND adviser_id = ${adviserId}
) c ON c.score_tag_id = b.id
ORDER BY a.id, b.id
LEFT JOIN applet_book_score_sub_tag d on d.tag_id = b.id
ORDER BY a.id, b.id, d.id
</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.applet.mapper.AppletBookScoreSubTagMapper">
<resultMap type="com.pcloud.book.applet.entity.AppletBookScoreSubTag" id="AppletBookScoreSubTagMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="tagId" column="tag_id" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="AppletBookScoreSubTagMap">
select id,
name,
tag_id,
create_time,
update_time
from book.applet_book_score_sub_tag
where id = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="AppletBookScoreSubTagMap">
select id,
name,
tag_id,
create_time,
update_time
from book.applet_book_score_sub_tag limit #{offset}, #{limit}
</select>
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="AppletBookScoreSubTagMap">
select
id, name, tag_id, create_time, update_time
from book.applet_book_score_sub_tag
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="tagId != null">
and tag_id = #{tagId}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
values (#{name}, #{tagId}, #{createTime}, #{updateTime})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name}, #{entity.tagId}, #{entity.createTime}, #{entity.updateTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into book.applet_book_score_sub_tag(name, tag_id, create_time, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name}, #{entity.tagId}, #{entity.createTime}, #{entity.updateTime})
</foreach>
on duplicate key update
name = values(name) , tag_id = values(tag_id) , create_time = values(create_time) , update_time =
values(update_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update book.applet_book_score_sub_tag
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="tagId != null">
tag_id = #{tagId},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from book.applet_book_score_sub_tag
where id = #{id}
</delete>
</mapper>
......@@ -8,12 +8,13 @@
<result column="channel_id" jdbcType="BIGINT" property="channelId"/>
<result column="adviser_id" jdbcType="BIGINT" property="adviserId"/>
<result column="score_tag_id" jdbcType="BIGINT" property="scoreTagId"/>
<result column="sub_tag_id" jdbcType="INTEGER" property="subTagId"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
</resultMap>
<sql id="Base_Column_List">
id
, wechat_user_id, book_id, channel_id, adviser_id, score_tag_id, create_time, update_time
, wechat_user_id, book_id, channel_id, adviser_id, score_tag_id, sub_tag_id, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
......@@ -29,10 +30,10 @@
<insert id="insert" keyColumn="id" keyProperty="id"
parameterType="com.pcloud.book.applet.entity.AppletBookUserScore" useGeneratedKeys="true">
insert into applet_book_user_score (wechat_user_id, book_id, channel_id,
adviser_id, score_tag_id, create_time,
adviser_id, score_tag_id, sub_tag_id, create_time,
update_time)
values (#{wechatUserId,jdbcType=BIGINT}, #{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT},
#{adviserId,jdbcType=BIGINT}, #{scoreTagId,jdbcType=BIGINT}, NOW(), NOW())
#{adviserId,jdbcType=BIGINT}, #{scoreTagId,jdbcType=BIGINT}, #{subTagId,jdbcType=INTEGER}, NOW(), NOW())
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.pcloud.book.applet.entity.AppletBookUserScore" useGeneratedKeys="true">
......@@ -53,6 +54,9 @@
<if test="scoreTagId != null">
score_tag_id,
</if>
<if test="subTagId != null">
sub_tag_id,
</if>
create_time,
update_time
</trim>
......@@ -72,6 +76,9 @@
<if test="scoreTagId != null">
#{scoreTagId,jdbcType=BIGINT},
</if>
<if test="subTagId != null">
#{subTagId,jdbcType=INTEGER},
</if>
NOW(),
NOW()
</trim>
......@@ -94,6 +101,9 @@
<if test="scoreTagId != null">
score_tag_id = #{scoreTagId,jdbcType=BIGINT},
</if>
<if test="subTagId != null">
sub_tag_id = #{subTagId,jdbcType=INTEGER},
</if>
update_time = NOW()
</set>
where id = #{id,jdbcType=BIGINT}
......@@ -105,6 +115,7 @@
channel_id = #{channelId,jdbcType=BIGINT},
adviser_id = #{adviserId,jdbcType=BIGINT},
score_tag_id = #{scoreTagId,jdbcType=BIGINT},
sub_tag_id = #{subTagId,jdbcType=INTEGER},
update_time = NOW()
where id = #{id,jdbcType=BIGINT}
</update>
......@@ -116,6 +127,86 @@
and book_id = #{bookId,jdbcType=BIGINT}
and channel_id = #{channelId,jdbcType=BIGINT}
and adviser_id = #{adviserId,jdbcType=BIGINT}
and score_tag_id = #{scoreTagId,jdbcType=BIGINT}
</select>
<select id="getSubTagChosen" resultType="com.pcloud.book.applet.dto.AppletBookScoreTagInfoDTO">
select
score_tag_id tagId,
sub_tag_id subTagId
from applet_book_user_score
where wechat_user_id = #{wechatUserId,jdbcType=BIGINT}
and book_id = #{bookId,jdbcType=BIGINT}
and channel_id = #{channelId,jdbcType=BIGINT}
and adviser_id = #{adviserId,jdbcType=BIGINT}
</select>
<select id="listBookUserScore" resultType="com.pcloud.book.applet.dto.AppletBookUserScoreExportDTO">
SELECT
c.id scoreId,
c.`name` scoreName,
b.id tagId,
b.`name` tagName,
d.id subTagId,
d.`name` subTagName,
a.wechat_user_id wechatUserId,
a.book_id bookId,
a.adviser_id adviserId,
a.channel_id channelId,
a.update_time updateTime
FROM
applet_book_user_score a
LEFT JOIN applet_book_score_tag b ON a.score_tag_id = b.id
LEFT JOIN applet_book_score c ON b.score_id = c.id
LEFT JOIN applet_book_score_sub_tag d ON d.id = a.sub_tag_id
</select>
<select id="listTagUser" resultType="com.pcloud.book.applet.dto.AppletBookTagUserExportDTO">
SELECT
t1.`scoreName`,
t1.`tagName`,
t1.`subTagName`,
count( t2.wechat_user_id ) userCount
FROM
(
SELECT
a.`name` scoreName,
b.`name` tagName,
IFNULL( c.`name`, '' ) subTagName,
b.id tagId,
c.id subId
FROM
applet_book_score a
LEFT JOIN applet_book_score_tag b ON a.id = b.score_id
LEFT JOIN applet_book_score_sub_tag c ON b.id = c.tag_id
) t1
LEFT JOIN applet_book_user_score t2 ON t1.tagId = t2.score_tag_id
AND IFNULL( t1.subId, 0 ) = IFNULL( t2.sub_tag_id, 0 )
GROUP BY
t1.`scoreName`,
t1.`tagName`,
t1.`subTagName`
</select>
<delete id="deleteChosen">
DELETE FROM
applet_book_user_score
WHERE
score_tag_id IN ( SELECT id FROM applet_book_score_tag WHERE score_id NOT IN ( SELECT DISTINCT score_id FROM applet_book_score_tag WHERE id = #{scoreTagId,jdbcType=BIGINT} ) )
AND wechat_user_id = #{wechatUserId,jdbcType=BIGINT}
and book_id = #{bookId,jdbcType=BIGINT}
and channel_id = #{channelId,jdbcType=BIGINT}
and adviser_id = #{adviserId,jdbcType=BIGINT}
</delete>
<delete id="deleteChosenTag">
DELETE FROM
applet_book_user_score
WHERE
score_tag_id != #{scoreTagId,jdbcType=BIGINT}
AND wechat_user_id = #{wechatUserId,jdbcType=BIGINT}
and book_id = #{bookId,jdbcType=BIGINT}
and channel_id = #{channelId,jdbcType=BIGINT}
and adviser_id = #{adviserId,jdbcType=BIGINT}
</delete>
</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