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.biz.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import com.pcloud.book.applet.biz.AppletBookScoreBiz;
import com.pcloud.book.applet.dto.AppletBookScoreSubTagDTO;
import com.pcloud.book.applet.dto.AppletBookScoreTagDTO;
import com.pcloud.book.applet.dto.AppletBookScoreTagInfoDTO;
import com.pcloud.book.applet.dto.AppletBookTagUserExportDTO;
import com.pcloud.book.applet.dto.AppletBookUserScoreDTO;
import com.pcloud.book.applet.dto.AppletBookUserScoreExportDTO;
import com.pcloud.book.applet.dto.AppletFeedbackDTO;
import com.pcloud.book.applet.dto.AppletUserFeedbackExportDTO;
import com.pcloud.book.applet.dto.AppletUserScoreHeadDTO;
import com.pcloud.book.applet.entity.AppletBookFeedback;
import com.pcloud.book.applet.entity.AppletBookUserScore;
import com.pcloud.book.applet.mapper.AppletBookFeedbackMapper;
import com.pcloud.book.applet.mapper.AppletBookScoreMapper;
import com.pcloud.book.applet.mapper.AppletBookUserScoreMapper;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.dao.BookDao;
import com.pcloud.book.book.dto.BookDto;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.utils.aliyun.OssUtils;
import com.pcloud.common.utils.robot.WeWorkWebHookRobotUtils;
import com.pcloud.readercenter.wechat.entity.WechatUser;
import com.pcloud.usercenter.party.adviser.dto.AdviserBaseInfoDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@Component
@Slf4j
public class AppletBookScoreBizImpl implements AppletBookScoreBiz {
@Autowired
private AppletBookUserScoreMapper appletBookUserScoreMapper;
@Autowired
private AppletBookScoreMapper appletBookScoreMapper;
@Autowired
private AppletBookFeedbackMapper appletBookFeedbackMapper;
@Autowired
private ReaderConsr readerConsr;
@Autowired
private AdviserConsr adviserConsr;
@Autowired
private BookDao bookDao;
@Override
public Long score(Long wechatUserId, Long bookId, Long channelId, Long adviserId, Long scoreTagId) {
public Long score(Long wechatUserId, Long bookId, Long channelId, Long adviserId, Long scoreTagId, Long subTagId) {
AppletBookUserScore appletBookUserScore = new AppletBookUserScore();
appletBookUserScore.setWechatUserId(wechatUserId);
appletBookUserScore.setBookId(bookId);
appletBookUserScore.setChannelId(channelId);
appletBookUserScore.setAdviserId(adviserId);
appletBookUserScore.setScoreTagId(scoreTagId);
appletBookUserScore.setSubTagId(subTagId);
// 不存在则新增
Long primaryKey = appletBookUserScoreMapper.selectPrimaryKey(appletBookUserScore);
if (Objects.isNull(primaryKey)) {
// 删除旧的选项
appletBookUserScoreMapper.deleteChosen(appletBookUserScore);
// 没有二级标签时 标签只能单选
if (Objects.isNull(subTagId)) {
appletBookUserScoreMapper.deleteChosenTag(appletBookUserScore);
}
appletBookUserScoreMapper.insert(appletBookUserScore);
return appletBookUserScore.getId();
}
// 存在则更新
appletBookUserScore.setId(primaryKey);
appletBookUserScoreMapper.updateByPrimaryKey(appletBookUserScore);
......@@ -53,28 +107,292 @@ public class AppletBookScoreBizImpl implements AppletBookScoreBiz {
public List<AppletBookUserScoreDTO> get(Long wechatUserId, Long bookId, Long channelId, Long adviserId) {
List<AppletBookScoreTagInfoDTO> dtos = appletBookScoreMapper.listTags(wechatUserId, bookId, channelId, adviserId);
Map<Long, List<AppletBookScoreTagDTO>> tagsMap = dtos.stream().collect(
// 获取选择的二级标签与以及标签
List<AppletBookScoreTagInfoDTO> chosenSubTag = appletBookUserScoreMapper.getSubTagChosen(wechatUserId, bookId, channelId, adviserId);
Map<Long, Long> tagRelateMap = Optional.ofNullable(chosenSubTag).map(
map -> map.stream().filter(x -> Objects.nonNull(x.getTagId()) && Objects.nonNull(x.getSubTagId())).collect(Collectors.toMap(AppletBookScoreTagInfoDTO::getTagId, AppletBookScoreTagInfoDTO::getSubTagId)))
.orElse(new HashMap<>());
List<Long> chosenScore = new ArrayList<>();
Map<Long, List<AppletBookScoreSubTagDTO>> subTagsMap = dtos.stream().filter(map -> Objects.nonNull(map.getTagId())).collect(
Collectors.groupingBy(AppletBookScoreTagInfoDTO::getTagId, Collectors.mapping(item -> {
if (Objects.isNull(item.getSubTagId())) return null;
AppletBookScoreSubTagDTO tag = new AppletBookScoreSubTagDTO();
tag.setTagId(item.getTagId());
tag.setSubTagName(item.getSubTagName());
tag.setSubTagId(item.getSubTagId());
tag.setChooseTime(item.getChosenTime());
tag.setChosen(Objects.equals(tagRelateMap.get(item.getTagId()), item.getSubTagId()));
return tag;
}, Collectors.toList())));
Map<Long, List<AppletBookScoreTagDTO>> tagsMap = dtos.stream().filter(distinctByKey1(AppletBookScoreTagInfoDTO::getTagId)).collect(
Collectors.groupingBy(AppletBookScoreTagInfoDTO::getScoreId, Collectors.mapping(item -> {
AppletBookScoreTagDTO tag = new AppletBookScoreTagDTO();
tag.setTagId(item.getTagId());
tag.setTagName(item.getTagName());
tag.setChosen(item.getChosen() == 1);
if (item.getChosen() == 1) {
chosenScore.add(item.getScoreId());
tag.setChosen(true);
}
tag.setChooseTime(item.getChosenTime());
List<AppletBookScoreSubTagDTO> subTags = Optional.ofNullable(subTagsMap).map(map -> map.get(item.getTagId())).orElse(new ArrayList<>());
subTags.removeAll(Collections.singleton(null));
tag.setSubTags(subTags);
return tag;
}, Collectors.toList())));
ArrayList<AppletBookUserScoreDTO> result = new ArrayList<>();
if (CollUtil.isEmpty(tagsMap)) return result;
dtos.stream().collect(Collectors.toMap(AppletBookScoreTagInfoDTO::getScoreId, AppletBookScoreTagInfoDTO::getScoreName, (key1, key2) -> key1)).forEach((scoreId, scoreName) -> {
AppletBookUserScoreDTO appletBookUserScoreDTO = new AppletBookUserScoreDTO();
appletBookUserScoreDTO.setScoreId(scoreId);
appletBookUserScoreDTO.setScoreName(scoreName);
appletBookUserScoreDTO.setWechatUserId(wechatUserId);
if (chosenScore.contains(scoreId)) appletBookUserScoreDTO.setChosen(true);
appletBookUserScoreDTO.setTags(Optional.of(tagsMap).map(map -> map.get(scoreId)).orElse(new ArrayList<>()));
result.add(appletBookUserScoreDTO);
});
return result;
}
@Override
public Void feedback(Long wechatUserId, AppletFeedbackDTO feedbackDTO) {
AppletBookFeedback appletBookFeedback = new AppletBookFeedback();
BeanUtil.copyProperties(feedbackDTO, appletBookFeedback);
appletBookFeedback.setCreateTime(new Date());
appletBookFeedback.setWechatUserId(wechatUserId);
appletBookFeedbackMapper.insert(appletBookFeedback);
ThreadPoolUtils.OTHER_THREAD_POOL.execute(() -> {
WeWorkWebHookRobotUtils.sendMarkdownMsg("8e58db23-c42d-414a-92d2-f344a1cd8407", getMarkdown(wechatUserId, feedbackDTO));
});
return null;
}
@Override
public List<String> uploadFile(MultipartFile[] file) {
List<String> urls = new ArrayList<>(file.length);
for (MultipartFile multipartFile : file) {
try {
UploadResultInfo uploadResultInfo = OssUtils.uploadFileStream(multipartFile.getInputStream(), UUID.randomUUID().toString(), FilenameUtils.getExtension(multipartFile.getOriginalFilename()));
urls.add(uploadResultInfo.getUrl());
} catch (IOException e) {
log.error("[upload4ScanCodeInfoByWxScanResult] 文件上传失败!err:{}", e.getMessage(), e);
throw new BookBizException(BookBizException.ERROR, "文件上传失败!");
}
}
return urls;
}
@Override
public byte[] export() {
// 每页sheet最大包含行数(不算标题栏)
File file = FileUtil.file("本书服务评价数据导出" + System.currentTimeMillis() + ".xlsx");
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
// 1. 本书服务用户评价明细表
exportAppletBookUserScore(writer);
// 2. 各评价用户人数统计表
exportTagUserCount(writer);
// 3. 用户反馈明细表
exportUserFeedback(writer);
writer.close();
byte[] bytes = FileUtil.readBytes(file);
file.delete();
return bytes;
}
/**
* 导出用户反馈明细表
*/
private void exportUserFeedback(BigExcelWriter writer) {
List<AppletBookFeedback> appletBookFeedbacks = appletBookFeedbackMapper.queryAll(null);
List<AppletUserFeedbackExportDTO> feedbackExportDTOS = fillAppletBookFeedbackExportDTOs(appletBookFeedbacks);
List<List<AppletUserFeedbackExportDTO>> feedbacks = CollUtil.split(feedbackExportDTOS, 1048575);
for (int i = 0; i < feedbacks.size(); i++) {
if (i == 0) {
writer.setSheet("本书服务用户反馈明细表");
} else {
writer.setSheet("本书服务用户反馈明细表(续" + i + ")");
}
writer.addHeaderAlias("wechatUserId", "用户ID");
writer.addHeaderAlias("nickname", "用户昵称");
writer.addHeaderAlias("mobile", "用户手机");
writer.addHeaderAlias("bookId", "图书ID");
writer.addHeaderAlias("bookName", "书名");
writer.addHeaderAlias("adviserId", "编辑ID");
writer.addHeaderAlias("adviserName", "编辑名称");
writer.addHeaderAlias("channelId", "渠道ID");
writer.addHeaderAlias("dateStr", "评价日期");
writer.addHeaderAlias("content", "反馈内容");
writer.addHeaderAlias("pic1", "反馈图片1");
writer.addHeaderAlias("pic2", "反馈图片2");
writer.addHeaderAlias("pic3", "反馈图片3");
writer.addHeaderAlias("pic4", "反馈图片4");
writer.write(feedbacks.get(i), true);
}
}
/**
* 填充用户反馈信息
*/
private List<AppletUserFeedbackExportDTO> fillAppletBookFeedbackExportDTOs(List<AppletBookFeedback> appletBookFeedbacks) {
if (CollUtil.isEmpty(appletBookFeedbacks)) return new ArrayList<>();
List<AppletUserFeedbackExportDTO> dtos = new ArrayList<>(appletBookFeedbacks.size());
// 编辑ID列表
List<Long> adviserIds = appletBookFeedbacks.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getAdviserId()))
.map(AppletBookFeedback::getAdviserId).distinct().collect(Collectors.toList());
// 读者ID列表
List<Long> userIds = appletBookFeedbacks.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getWechatUserId()))
.map(AppletBookFeedback::getWechatUserId).distinct().collect(Collectors.toList());
// 图书ID列表
List<Long> bookIds = appletBookFeedbacks.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getBookId()))
.map(AppletBookFeedback::getBookId).distinct().collect(Collectors.toList());
// 查询编辑信息
CompletableFuture<Map<Long, AdviserBaseInfoDto>> adviserFuture = CompletableFuture.supplyAsync(() -> adviserConsr.getAdviserId2AdviserInfoDtoMap(adviserIds));
// 查询图书信息
CompletableFuture<Map<Long, BookDto>> bookFuture = CompletableFuture.supplyAsync(() -> bookDao.getMapByIds(bookIds));
// 查询用户信息
CompletableFuture<Map<Long, WechatUser>> userFuture = CompletableFuture.supplyAsync(() -> readerConsr.getUserList(userIds));
try {
CompletableFuture.allOf(userFuture, adviserFuture, bookFuture).get();
Map<Long, WechatUser> userMap = Optional.of(userFuture.get()).orElse(new HashMap<>());
Map<Long, AdviserBaseInfoDto> adviserMap = Optional.of(adviserFuture.get()).orElse(new HashMap<>());
Map<Long, BookDto> bookMap = Optional.of(bookFuture.get()).orElse(new HashMap<>());
appletBookFeedbacks.stream().filter(Objects::nonNull).forEach(dto -> {
AppletUserFeedbackExportDTO feedbackExportDTO = new AppletUserFeedbackExportDTO();
BeanUtil.copyProperties(dto,feedbackExportDTO);
feedbackExportDTO.setAdviserName(Optional.ofNullable(dto.getAdviserId()).map(adviserMap::get).map(AdviserBaseInfoDto::getPartyName).orElse(""));
feedbackExportDTO.setNickname(Optional.ofNullable(dto.getWechatUserId()).map(userMap::get).map(WechatUser::getWechatUserNickname).orElse(""));
feedbackExportDTO.setMobile(Optional.ofNullable(dto.getWechatUserId()).map(userMap::get).map(WechatUser::getPhoneNumber).orElse(""));
feedbackExportDTO.setBookName(Optional.ofNullable(dto.getBookId()).map(bookMap::get).map(BookDto::getBookName).orElse(""));
feedbackExportDTO.setDateStr(Optional.ofNullable(dto.getCreateTime()).map(x -> DateUtil.format(x, DatePattern.NORM_DATETIME_FORMAT)).orElse(""));
dtos.add(feedbackExportDTO);
});
} catch (InterruptedException | ExecutionException e) {
log.warn("[fillAppletBookUserScoreExportDTOs] 填充信息失败", e);
}
return dtos;
}
/**
* 导出标签人数统计表
*/
private void exportTagUserCount(BigExcelWriter writer) {
List<AppletBookTagUserExportDTO> tagUser = appletBookUserScoreMapper.listTagUser();
writer.setSheet("本书服务各评价用户人数统计表");
writer.addHeaderAlias("scoreName", "表情");
writer.addHeaderAlias("tagName", "标签");
writer.addHeaderAlias("subTagName", "子标签");
writer.addHeaderAlias("userCount", "人数");
writer.write(tagUser, true);
}
/**
* 导出本书服务用户评价明细表
*/
private void exportAppletBookUserScore(BigExcelWriter writer) {
List<AppletBookUserScoreExportDTO> exportDTOS = appletBookUserScoreMapper.listBookUserScore();
// 填充读者信息 图书信息和编辑信息
List<AppletUserScoreHeadDTO> headDTOS = fillAppletBookUserScoreExportDTOs(exportDTOS);
// 写入表格 - 如果数据量过大需要分页
List<List<AppletUserScoreHeadDTO>> bookUserScoreList = CollUtil.split(headDTOS, 1048575);
for (int i = 0; i < bookUserScoreList.size(); i++) {
if (i == 0) {
writer.renameSheet("本书服务用户评价明细表");
} else {
writer.setSheet("本书服务用户评价明细表(续" + i + ")");
}
writer.addHeaderAlias("wechatUserId", "用户ID");
writer.addHeaderAlias("nickname", "用户昵称");
writer.addHeaderAlias("mobile", "用户手机");
writer.addHeaderAlias("scoreName", "表情");
writer.addHeaderAlias("tagName", "标签");
writer.addHeaderAlias("subTagName", "子标签");
writer.addHeaderAlias("bookId", "图书ID");
writer.addHeaderAlias("bookName", "书名");
writer.addHeaderAlias("adviserId", "编辑ID");
writer.addHeaderAlias("adviserName", "编辑名称");
writer.addHeaderAlias("channelId", "渠道ID");
writer.addHeaderAlias("dateStr", "评价日期");
writer.write(bookUserScoreList.get(i), true);
}
}
/**
* 补充导出数据
*/
private List<AppletUserScoreHeadDTO> fillAppletBookUserScoreExportDTOs(List<AppletBookUserScoreExportDTO> exportDTOS) {
if (CollUtil.isEmpty(exportDTOS)) return new ArrayList<>();
List<AppletUserScoreHeadDTO> dtos = new ArrayList<>(exportDTOS.size());
// 读者ID列表
List<Long> userIds = exportDTOS.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getWechatUserId()))
.map(AppletBookUserScoreExportDTO::getWechatUserId).distinct().collect(Collectors.toList());
// 编辑ID列表
List<Long> adviserIds = exportDTOS.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getAdviserId()))
.map(AppletBookUserScoreExportDTO::getAdviserId).distinct().collect(Collectors.toList());
// 图书ID列表
List<Long> bookIds = exportDTOS.stream().filter(x -> Objects.nonNull(x) && Objects.nonNull(x.getBookId()))
.map(AppletBookUserScoreExportDTO::getBookId).distinct().collect(Collectors.toList());
// 查询用户信息
CompletableFuture<Map<Long, WechatUser>> userFuture = CompletableFuture.supplyAsync(() -> readerConsr.getUserList(userIds));
// 查询编辑信息
CompletableFuture<Map<Long, AdviserBaseInfoDto>> adviserFuture = CompletableFuture.supplyAsync(() -> adviserConsr.getAdviserId2AdviserInfoDtoMap(adviserIds));
// 查询图书信息
CompletableFuture<Map<Long, BookDto>> bookFuture = CompletableFuture.supplyAsync(() -> bookDao.getMapByIds(bookIds));
try {
CompletableFuture.allOf(userFuture, adviserFuture, bookFuture).get();
Map<Long, WechatUser> userMap = Optional.of(userFuture.get()).orElse(new HashMap<>());
Map<Long, AdviserBaseInfoDto> adviserMap = Optional.of(adviserFuture.get()).orElse(new HashMap<>());
Map<Long, BookDto> bookMap = Optional.of(bookFuture.get()).orElse(new HashMap<>());
exportDTOS.stream().filter(Objects::nonNull).forEach(dto -> {
dto.setNickname(Optional.ofNullable(dto.getWechatUserId()).map(userMap::get).map(WechatUser::getWechatUserNickname).orElse(""));
dto.setMobile(Optional.ofNullable(dto.getWechatUserId()).map(userMap::get).map(WechatUser::getPhoneNumber).orElse(""));
dto.setAdviserName(Optional.ofNullable(dto.getAdviserId()).map(adviserMap::get).map(AdviserBaseInfoDto::getPartyName).orElse(""));
dto.setBookName(Optional.ofNullable(dto.getBookId()).map(bookMap::get).map(BookDto::getBookName).orElse(""));
dto.setDateStr(Optional.ofNullable(dto.getUpdateTime()).map(x -> DateUtil.format(x, DatePattern.NORM_DATETIME_FORMAT)).orElse(""));
AppletUserScoreHeadDTO appletUserScoreHeadDTO = new AppletUserScoreHeadDTO();
BeanUtil.copyProperties(dto,appletUserScoreHeadDTO);
dtos.add(appletUserScoreHeadDTO);
});
} catch (InterruptedException | ExecutionException e) {
log.warn("[fillAppletBookUserScoreExportDTOs] 填充信息失败", e);
}
return dtos;
}
private String getMarkdown(Long wechatUserId, AppletFeedbackDTO feedbackDTO) {
WechatUser wechatUser = Optional.ofNullable(readerConsr.getWechatUser(wechatUserId)).orElse(new WechatUser());
return "# 小睿小程序用户反馈" + DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT) + "\n"
+ "> 用户ID:" + wechatUserId + "\n"
+ (StrUtil.isBlank(wechatUser.getWechatUserNickname()) ? "" : ("> 用户昵称:" + wechatUser.getWechatUserNickname() + "\n"))
+ (StrUtil.isBlank(wechatUser.getPhoneNumber()) ? "" : ("> 用户手机号:" + wechatUser.getPhoneNumber() + "\n"))
+ "> 图书ID:" + feedbackDTO.getBookId() + "\n"
+ "> 渠道ID:" + feedbackDTO.getChannelId() + "\n"
+ "> 编辑ID:" + feedbackDTO.getAdviserId() + "\n"
+ (StrUtil.isBlank(feedbackDTO.getContent()) ? "" : ("> 反馈内容:" + feedbackDTO.getContent() + "\n"))
+ (StrUtil.isAllBlank(feedbackDTO.getPic1(), feedbackDTO.getPic2(), feedbackDTO.getPic3(), feedbackDTO.getPic4()) ? "" : ("> 反馈图片列表:"
+ ((StrUtil.isBlank(feedbackDTO.getPic1()) ? "" : String.format("[反馈图片|](%s)", feedbackDTO.getPic1())))
+ ((StrUtil.isBlank(feedbackDTO.getPic2()) ? "" : String.format("[反馈图片|](%s)", feedbackDTO.getPic2())))
+ ((StrUtil.isBlank(feedbackDTO.getPic3()) ? "" : String.format("[反馈图片|](%s)", feedbackDTO.getPic3())))
+ ((StrUtil.isBlank(feedbackDTO.getPic4()) ? "" : String.format("[反馈图片|](%s)", feedbackDTO.getPic4())))
));
}
// 用于方法去重
static <T> Predicate<T> distinctByKey1(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
}
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