Commit 936261ab by 田超

Merge branch 'feature/1005530' into 'master'

feat: [1005530] 只扫一个二维码即可实现版本保护

See merge request rays/pcloud-book!1446
parents fa552b51 ebc391d0
......@@ -72,7 +72,11 @@ public enum BookStatusEnum {
/**
* 不正确
*/
NOT_RIGHT(2);
NOT_RIGHT(2),
/**
* 满了
*/
FULL(3);
public final Integer value;
......
......@@ -162,6 +162,11 @@ public class BookConstant {
public static final String BOOK_HOT_APP = "BOOK_CHANNEL:HOT_APP_TOP_5_KEY:";
/**
* 图书生成授权保护码
*/
public static final String BOOK_AUTH_CODE_CACHE = CacheConstant.BOOK + "BOOK_AUTH_CODE_CACHE:";
/**
* 微信群默认头像
*/
public static final List<String> DEFAULT_HEADURL =Arrays.asList(
......
......@@ -60,6 +60,19 @@ public class BookAuthCodeDTO extends BaseDto {
@ApiModelProperty("使用授权码的用户")
private List<BookAuthUserDTO> bookAuthUserList;
/**
* 新版 授权码链接
*/
private String qrcodeUrl;
public String getQrcodeUrl() {
return qrcodeUrl;
}
public void setQrcodeUrl(String qrcodeUrl) {
this.qrcodeUrl = qrcodeUrl;
}
public String getFullCode() {
return fullCode;
}
......
package com.pcloud.book.copyright.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 二维码授权码列表查询返回dto
*/
@ApiModel
@Data
public class SceneAuthCodeResponseDTO {
@ApiModelProperty("运营标识")
private Long sceneId;
@ApiModelProperty("最多激活人数")
private Integer maxUserCount;
@ApiModelProperty("激活次数用完后提示")
private String fullUseTips;
@ApiModelProperty("授权码个数")
private Integer counts;
}
package com.pcloud.book.copyright.dto;
import java.util.List;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 二维码授权码列表查询
*/
@ApiModel
@Data
public class SceneAuthCodeSearchDTO{
private Long bookId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("编辑标识")
private Long adviserId;
private List<Long> sceneIds;
}
......@@ -3,6 +3,8 @@ package com.pcloud.book.copyright.service;
import com.pcloud.book.copyright.dto.BookAuthInfoCountDTO;
import com.pcloud.book.copyright.dto.BookAuthTotalCountDTO;
import com.pcloud.book.copyright.dto.CheckUserAuthDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeSearchDTO;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import io.swagger.annotations.Api;
......@@ -52,5 +54,8 @@ public interface BookAuthInfoService {
ResponseEntity<ResponseDto<BigDecimal>> getGroupBookAuthPrice(@RequestParam("bookId") Long bookId, @RequestParam("channelId")Long channelId,
@RequestParam("adviserId")Long adviserId) throws BizException;
@ApiOperation(value = "获取二维码授权码信息", httpMethod = "POST")
@RequestMapping(value = "/getSceneAuthInfo", method = RequestMethod.POST)
ResponseEntity<ResponseDto<List<SceneAuthCodeResponseDTO>>> getSceneAuthInfo(@RequestBody SceneAuthCodeSearchDTO sceneAuthCodeSearchDTO) throws BizException;
}
......@@ -86,7 +86,7 @@ public interface BookAuthCodeBiz {
Map<String, Object> getCodeExcel(Long bookId, String codeIds, Long channelId, Long status, String systemCode, Long partyId, Integer authBookType);
/**
*一键删除未使用的授权码
* 一键清空未使用的授权码
*/
void deleteNoUsedAuthCode(DeleteAuthCodeDTO deleteAuthCodeDTO, Long adviserId);
}
......@@ -2,6 +2,7 @@ package com.pcloud.book.copyright.biz;
import com.pcloud.book.copyright.dto.BookAuthInfoCountDTO;
import com.pcloud.book.copyright.dto.BookAuthTotalCountDTO;
import com.pcloud.book.copyright.vo.AuthOpenVO;
import com.pcloud.book.copyright.vo.BookAuthInfoAndServesVO;
import com.pcloud.book.copyright.vo.BookAuthInfoVO;
import com.pcloud.book.copyright.vo.BookAuthInfoWechatVO;
......@@ -27,6 +28,8 @@ public interface BookAuthInfoBiz {
*/
void setBookAuthOpen(SetAuthOpenParam setAuthOpenParam, Long adviserId);
void sendLetter(Long adviserId, String bookName, String url, String commitTime);
/**
* 设置授权后付费查看
*/
......@@ -99,4 +102,8 @@ public interface BookAuthInfoBiz {
*/
Boolean isHaveExport(Long bookId, Long channelId, Long adviserId);
/**
* 升级版权保护
*/
void setBookCodeAuth(AuthOpenVO authOpenVO, Long adviserId);
}
......@@ -45,7 +45,7 @@ public interface BookAuthUserBiz {
/**
* 校验用户是否已经授权
*/
Boolean checkIsHaveAuth(Long bookId, Long channelId, Long adviserId, Long wechatUserId, Integer authBookType);
Boolean checkIsHaveAuth(Long bookId, Long channelId, Long adviserId, Long wechatUserId, Integer authBookType,Long sceneId,Long bookAuthCodeId);
/**
* 校验用户针对指定的服务是否被授权
......@@ -75,5 +75,5 @@ public interface BookAuthUserBiz {
/**
* 获取使用授权码的用户
*/
Map<Long, List<BookAuthUserDTO>> getByAuthCodeIds(List<Long> authCodeIds);
Map<Long, List<BookAuthUserDTO>> getByAuthCodeIds(List<Long> authCodeIds,Long sceneId);
}
......@@ -37,5 +37,10 @@ public interface BookExportRecordBiz {
/**
* 查看授权码生成记录
*/
PageBeanNew<BookExportRecordDTO> getGenerateCodeHistory(Long bookId, Long adviserId, Long channelId, PageParam pageParam);
PageBeanNew<BookExportRecordDTO> getGenerateCodeHistory(Long bookId, Long adviserId, Long channelId,Long sceneId, PageParam pageParam);
/**
* 获取最后一次导出的地址
*/
String getExportUrl(Long bookId, Long channelId, Long adviserId,Long sceneId);
}
package com.pcloud.book.copyright.biz;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.dto.DeleteAuthCodeDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeSearchDTO;
import com.pcloud.book.copyright.entity.BookSceneAuth;
import com.pcloud.book.copyright.vo.CheckAuthCodeVO;
import com.pcloud.book.copyright.vo.GenerateCodeVO;
import com.pcloud.book.copyright.vo.UseAuthCodeVO;
import com.pcloud.common.page.PageBeanNew;
import java.util.List;
import java.util.Map;
/**
* 书籍二维码授权表(BookSceneAuth)表服务接口
*
* @author makejava
* @since 2021-10-19 14:14:22
*/
public interface BookSceneAuthBiz {
/**
* 自动创建授权码
*/
void autoGenerateAuthCode(GenerateCodeVO generateCodeVO, Long adviserId);
/**
* 二维码下授权码列表
*/
PageBeanNew<BookAuthCodeDTO> listSceneAuthCode(Long bookId, Long channelId, Long sceneId, String keyword, Integer state, Integer authBookType, Integer currentPage, Integer numPerPage, Long adviserId);
/**
* 删除授权码
*/
void deleteSceneAuthCode(List<Long> ids);
/**
* 一键清空未使用的授权码
*/
void clearNoUsedAuthCode(DeleteAuthCodeDTO deleteAuthCodeDTO, Long adviserId);
/**
* 升级用户扫描授权码之后
*/
CheckAuthCodeVO checkSceneAuthCode(UseAuthCodeVO useAuthCodeVO, Long channelId, Long wechatUserId);
/**
* 修改二维码授权信息
*/
void setBookCodeAuth(BookSceneAuth bookSceneAuth, Long adviserId);
/**
* 保存二维码授权信息
*/
void saveSceneAuthInfo(List<BookSceneAuth> list, Long adviserId);
/**
* 获取二维码授权码信息
*/
List<SceneAuthCodeResponseDTO> getSceneAuthInfo(SceneAuthCodeSearchDTO sceneAuthCodeSearchDTO);
/**
* 升级用户扫描授权码之后
*/
Map<String, Object> exportSceneAuthCode(Long bookId, String codeIds, Long channelId,Long sceneId, Long status, String systemCode, Long partyId, Integer authBookType);
}
\ No newline at end of file
......@@ -152,7 +152,7 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
Long bookId = authBookInfo.getBookId();
Long adviserId = authBookInfo.getAdviserId();
//校验用户是否已经授权过
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId, authBookType);
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId, authBookType,null,null);
if (isHaveAuth) {
return BookStatusEnum.CodeUseTypeEnum.RIGHT.value;
}
......@@ -196,7 +196,7 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
return false;
}
//校验用户是否已经授权过
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId,null);
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId,null,null,null);
return !isHaveAuth;
}
......@@ -367,7 +367,7 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
return;
}
// 查询使用码的使用情况
Map<Long, List<BookAuthUserDTO>> authUserMap = bookAuthUserBiz.getByAuthCodeIds(authCodeIds);
Map<Long, List<BookAuthUserDTO>> authUserMap = bookAuthUserBiz.getByAuthCodeIds(authCodeIds,null);
for (BookAuthCodeDTO bookAuthCodeDTO : recordList) {
bookAuthCodeDTO.setBookAuthUserList(authUserMap.getOrDefault(bookAuthCodeDTO.getId(), Lists.newArrayList()));
}
......
......@@ -27,6 +27,7 @@ import com.pcloud.book.copyright.entity.BookAuthInfo;
import com.pcloud.book.copyright.entity.BookExportRecord;
import com.pcloud.book.copyright.enums.AuthBookTypeEnum;
import com.pcloud.book.copyright.tools.CopyrightTools;
import com.pcloud.book.copyright.vo.AuthOpenVO;
import com.pcloud.book.copyright.vo.BookAuthCodeUserVO;
import com.pcloud.book.copyright.vo.BookAuthInfoAndServesVO;
import com.pcloud.book.copyright.vo.BookAuthInfoVO;
......@@ -64,6 +65,8 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.util.ObjectUtil;
/**
* @author lily
* @date 2018/12/3 11:39
......@@ -287,7 +290,8 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
}
@ParamLog("发送站内信")
private void sendLetter(Long adviserId, String bookName, String url, String commitTime) {
@Override
public void sendLetter(Long adviserId, String bookName, String url, String commitTime) {
SendNotifyDto sendNotifyDto = new SendNotifyDto();
sendNotifyDto.setCreatedTime(new Date());
JSONObject content = new JSONObject();
......@@ -663,4 +667,35 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
bookAuthInfo.setIsGroupBook(1);
}
}
@Override
public void setBookCodeAuth(AuthOpenVO authOpenVO, Long adviserId) {
if(ObjectUtil.hasEmpty(authOpenVO,authOpenVO.getBookId(),authOpenVO.getChannelId())){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "缺少参数");
}
BookAuthInfoVO bookAuthInfoVO = bookAuthInfoDao.getInfoByBook(authOpenVO.getBookId(), authOpenVO.getChannelId(), adviserId,
authOpenVO.getAuthBookType());
BookAuthInfo bookAuthInfo = new BookAuthInfo();
bookAuthInfo.setBookId(authOpenVO.getBookId());
bookAuthInfo.setChannelId(authOpenVO.getChannelId());
bookAuthInfo.setAuthType(2);
if (bookAuthInfoVO == null) {
this.setAuthBookType(bookAuthInfo, authOpenVO.getAuthBookType());
bookAuthInfo.setAdviserId(adviserId);
try {
bookAuthInfoDao.insert(bookAuthInfo);
} catch (DataIntegrityViolationException e) {
LOGGER.error("您已经设置过这本图书!"+e.getMessage(), e);
throw new BookBizException(BookBizException.DB_DML_FAIL, "您已经设置过这本图书!");
}
} else {
bookAuthInfo.setId(bookAuthInfoVO.getId());
bookAuthInfo.setAdviserId(adviserId);
bookAuthInfoDao.updateBaseInfo(bookAuthInfo);
}
Integer authBookType = authOpenVO.getAuthBookType() == null ? 0 : authOpenVO.getAuthBookType();
String key = CopyrightConstants.BOOK_AUTH_INFO + bookAuthInfo.getBookId() + "-" + bookAuthInfo.getChannelId() + "-" + adviserId + "-" + authBookType;
BookAuthInfoVO bookAuth = bookAuthInfoDao.getInfoByBook(authOpenVO.getBookId(), authOpenVO.getChannelId(), adviserId, authOpenVO.getAuthBookType());
JedisClusterUtils.setJson(key, bookAuth);
}
}
......@@ -180,9 +180,9 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
@Override
@ParamLog("校验用户是否已经授权")
public Boolean checkIsHaveAuth(Long bookId, Long channelId, Long adviserId, Long wechatUserId, Integer authBookType) {
public Boolean checkIsHaveAuth(Long bookId, Long channelId, Long adviserId, Long wechatUserId, Integer authBookType,Long sceneId,Long bookAuthCodeId) {
List<Long> wechatUserIdList = readerConsr.getAllUnionUser(wechatUserId);
return bookAuthUserDao.getIsHaveAuth(bookId, channelId, adviserId, wechatUserIdList, authBookType);
return bookAuthUserDao.getIsHaveAuth(bookId, channelId, adviserId, wechatUserIdList, authBookType,sceneId,bookAuthCodeId);
}
@Override
......@@ -216,7 +216,7 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
private Boolean checkIsHaveAuthWithServer(Long bookId, Long channelId, Long adviserId, Long wecharUserId, Long serverId) {
// 书类型指定为is_paper_book
Boolean isUserAuth = checkIsHaveAuth(bookId,channelId,adviserId,wecharUserId,0);
Boolean isUserAuth = checkIsHaveAuth(bookId,channelId,adviserId,wecharUserId,0,null,null);
if(isUserAuth){
List<Long> serverIds = new ArrayList<>();
serverIds.add(serverId);
......@@ -345,11 +345,11 @@ public class BookAuthUserBizImpl implements BookAuthUserBiz {
}
@Override
public Map<Long, List<BookAuthUserDTO>> getByAuthCodeIds(List<Long> authCodeIds) {
public Map<Long, List<BookAuthUserDTO>> getByAuthCodeIds(List<Long> authCodeIds,Long sceneId) {
if(CollectionUtils.isEmpty(authCodeIds)){
return new HashMap<>();
}
List<BookAuthUserDTO> bookAuthUserList = bookAuthUserDao.getByAuthCodeIds(authCodeIds);
List<BookAuthUserDTO> bookAuthUserList = bookAuthUserDao.getByAuthCodeIds(authCodeIds,sceneId);
if(CollectionUtils.isEmpty(bookAuthUserList)){
return new HashMap<>();
}
......
......@@ -51,11 +51,12 @@ public class BookExportRecordBizImpl implements BookExportRecordBiz {
}
@Override
public PageBeanNew<BookExportRecordDTO> getGenerateCodeHistory(Long bookId, Long adviserId, Long channelId, PageParam pageParam) {
public PageBeanNew<BookExportRecordDTO> getGenerateCodeHistory(Long bookId, Long adviserId, Long channelId,Long sceneId, PageParam pageParam) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("channelId",channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("sceneId",sceneId);
PageBeanNew<BookExportRecordDTO> pageBeanNew = bookExportRecordDao.listPageNew(pageParam, paramMap, "getGenerateCodeHistory");
if(pageBeanNew == null || CollectionUtils.isEmpty(pageBeanNew.getRecordList())){
......@@ -82,4 +83,9 @@ public class BookExportRecordBizImpl implements BookExportRecordBiz {
default: return "";
}
}
@Override
public String getExportUrl(Long bookId, Long channelId, Long adviserId, Long sceneId) {
return bookExportRecordDao.getExportUrl(bookId,channelId,adviserId,sceneId);
}
}
package com.pcloud.book.copyright.biz.impl;
import com.google.common.collect.Lists;
import com.alibaba.fastjson.JSONObject;
import com.pcloud.book.base.enums.BookStatusEnum;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.biz.BookBiz;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.book.dto.BookDto;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.consumer.common.ExportConsr;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.copyright.biz.BookAuthInfoBiz;
import com.pcloud.book.copyright.biz.BookAuthUserBiz;
import com.pcloud.book.copyright.biz.BookExportRecordBiz;
import com.pcloud.book.copyright.biz.BookSceneAuthBiz;
import com.pcloud.book.copyright.constants.CopyrightConstants;
import com.pcloud.book.copyright.dao.BookAuthUserDao;
import com.pcloud.book.copyright.dao.BookSceneAuthCodeDao;
import com.pcloud.book.copyright.dao.BookSceneAuthDao;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.dto.BookAuthUserDTO;
import com.pcloud.book.copyright.dto.DeleteAuthCodeDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeSearchDTO;
import com.pcloud.book.copyright.entity.BookAuthUser;
import com.pcloud.book.copyright.entity.BookExportRecord;
import com.pcloud.book.copyright.entity.BookSceneAuth;
import com.pcloud.book.copyright.entity.BookSceneAuthCode;
import com.pcloud.book.copyright.enums.AuthBookTypeEnum;
import com.pcloud.book.copyright.tools.CopyrightTools;
import com.pcloud.book.copyright.vo.BookAuthInfoVO;
import com.pcloud.book.copyright.vo.CheckAuthCodeVO;
import com.pcloud.book.copyright.vo.GenerateCodeVO;
import com.pcloud.book.copyright.vo.UseAuthCodeVO;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.channelcenter.qrcode.dto.QrcodeSceneDto;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.dto.SendNotifyDto;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.exceptions.ExportException;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.aliyun.OssUtils;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.json.JSONUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.readercenter.wechat.entity.WechatUser;
import com.pcloud.resourcecenter.base.exceptions.ResBizException;
import com.pcloud.settlementcenter.record.exceptions.RecordException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import static com.pcloud.book.util.common.ExcelUtils.getColumnTopStyle;
import static com.pcloud.book.util.common.ExcelUtils.getDataStyle;
/**
* 书籍二维码授权表(BookSceneAuth)表服务实现类
*
* @author makejava
* @since 2021-10-19 14:14:22
*/
@Service("bookSceneAuthBiz")
public class BookSceneAuthBizImpl implements BookSceneAuthBiz {
private static final Logger LOGGER = LoggerFactory.getLogger(BookSceneAuthBizImpl.class);
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(2);
@Autowired
private BookSceneAuthDao bookSceneAuthDao;
@Autowired
private BookSceneAuthCodeDao bookSceneAuthCodeDao;
@Autowired
private BookBiz bookBiz;
@Autowired
private BookAuthInfoBiz bookAuthInfoBiz;
@Autowired
private BookExportRecordBiz bookExportRecordBiz;
@Autowired
private QrcodeSceneConsr qrcodeSceneConsr;
@Autowired
private BookAuthUserBiz bookAuthUserBiz;
@Autowired
private BookAuthUserDao bookAuthUserDao;
@Autowired
private ReaderConsr readerConsr;
@Autowired
private MessageBiz messageBiz;
@Autowired
private ExportConsr exportConsr;
/**
* 自动创建授权码
*/
@Override
public void autoGenerateAuthCode(GenerateCodeVO generateCodeVO, Long adviserId) {
if (ObjectUtil.hasEmpty(generateCodeVO, generateCodeVO.getBookId(), generateCodeVO.getSceneId(), generateCodeVO.getCodeCount())) {
return;
}
Integer codeCount = generateCodeVO.getCodeCount();
Long bookId = generateCodeVO.getBookId();
Integer authBookType = generateCodeVO.getAuthBookType();
Long channelId = generateCodeVO.getChannelId();
Long sceneId = generateCodeVO.getSceneId();
String key = BookConstant.BOOK_AUTH_CODE_CACHE + "_" + generateCodeVO.getBookId() + "_" + channelId + "_" + adviserId + "_" + sceneId;
if (null != JedisClusterUtils.get(key)) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "本书有授权码正在生成中,请稍后再试!");
}
QrcodeSceneDto sceneDto = qrcodeSceneConsr.getById(sceneId);
if (null == sceneDto || null == sceneDto.getUrl()) {
return;
}
if (codeCount == null || codeCount == 0) {
return;
}
if (codeCount > 1000) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "单次生成数量不要超过1000!");
}
ThreadPoolUtils.EXPORT_THREAD_POOL.execute(() -> {
String commitTime = DateUtils.formatDate(new Date());
String num = "";
try {
JedisClusterUtils.set(key, codeCount.toString(), 60 * 60);
//获取批次号
Integer batchNum = bookSceneAuthCodeDao.getMaxBatchNum(bookId, channelId, sceneId, adviserId, authBookType);
num = String.format("%04d", batchNum);
//新增导出记录
insertExportRecord(bookId, channelId, adviserId, num, codeCount, sceneId);
//获取图书名称
BookDto bookDto = bookBiz.getBaseById(bookId);
if (bookDto == null) {
return;
}
//获取随机数
List<String> uuids = CopyrightTools.createShortUuidByCount(codeCount);
List<BookSceneAuthCode> bookAuthCodes = new ArrayList<>();
for (String uuid : uuids) {
BookSceneAuthCode bookAuthCode = new BookSceneAuthCode();
if (authBookType == null || AuthBookTypeEnum.PAPER_BOOK.value.equals(authBookType)) {
bookAuthCode.setIsPaperBook(1);
bookAuthCode.setIsGroupBook(0);
} else {
bookAuthCode.setIsPaperBook(0);
bookAuthCode.setIsGroupBook(1);
}
bookAuthCode.setAdviserId(adviserId);
bookAuthCode.setChannelId(channelId);
bookAuthCode.setBookId(bookId);
bookAuthCode.setAuthCode(uuid);
bookAuthCode.setFullCode(num + uuid);
bookAuthCode.setBatchNum(num);
bookAuthCode.setCreateType(0);
bookAuthCode.setCreatedUser(adviserId);
bookAuthCode.setSceneId(sceneId);
bookAuthCodes.add(bookAuthCode);
}
bookSceneAuthCodeDao.insert(bookAuthCodes);
String noticeUrl;
String zipUrl = CopyrightTools.generateQrcode4ZipNew(bookAuthCodes, bookDto.getBookName(), sceneDto.getUrl(), authBookType);
noticeUrl = zipUrl;
//发送站内信
bookAuthInfoBiz.sendLetter(adviserId, bookDto.getBookName(), noticeUrl, commitTime);
//新增导出记录
updateSuccessRecord(bookId, channelId, adviserId, num, noticeUrl, sceneId);
BookSceneAuth authSceneInfo = bookSceneAuthDao.getAuthSceneInfo(bookId, sceneId);
if (null == authSceneInfo) {
BookSceneAuth build = BookSceneAuth.builder().bookId(bookId).adviserId(adviserId).channelId(channelId).sceneId(sceneId)
.maxUserCount(2).createdUser(adviserId).build();
bookSceneAuthDao.insert(build);
}
//更新授权二维码到数据库
if (CollUtil.isNotEmpty(bookAuthCodes)) {
if (StrUtil.isNotBlank(bookAuthCodes.get(0).getQrcodeUrl())) {
bookSceneAuthCodeDao.batchUpdate(bookAuthCodes);
}
}
LOGGER.info("url" + noticeUrl);
} catch (Exception e) {
LOGGER.error("导出授权码失败" + e.getMessage(), e);
updateExportRecord(bookId, channelId, adviserId, num, BookStatusEnum.BookExportStatus.FAIL.value, sceneId); //TODO
} finally {
JedisClusterUtils.del(key);
}
});
}
private void updateExportRecord(Long bookId, Long channelId, Long adviserId, String num, Integer exportStatus,Long sceneId) {
if(StringUtil.isEmpty(num)) {
return;
}
BookExportRecord bookExportRecord = new BookExportRecord();
bookExportRecord.setBookId(bookId);
bookExportRecord.setAdviserId(adviserId);
bookExportRecord.setBatchNum(num);
bookExportRecord.setChannelId(channelId);
bookExportRecord.setLastModifiedUser(adviserId);
bookExportRecord.setExportStatus(exportStatus);
bookExportRecord.setSceneId(sceneId);
bookExportRecordBiz.updateRecordStatus(bookExportRecord);
}
private void updateSuccessRecord(Long bookId, Long channelId, Long adviserId, String num, String noticeUrl,Long sceneId) {
BookExportRecord bookExportRecord = new BookExportRecord();
bookExportRecord.setBookId(bookId);
bookExportRecord.setAdviserId(adviserId);
bookExportRecord.setChannelId(channelId);
bookExportRecord.setLastModifiedUser(adviserId);
bookExportRecord.setExportStatus(BookStatusEnum.BookExportStatus.SUCCESS.value);
bookExportRecord.setDownloadUrl(noticeUrl);
bookExportRecord.setBatchNum(num);
bookExportRecord.setSceneId(sceneId);
bookExportRecordBiz.updateRecord(bookExportRecord);
}
private void insertExportRecord(Long bookId, Long channelId, Long adviserId, String num, Integer codeCount, Long sceneId) {
BookExportRecord bookExportRecord = new BookExportRecord();
bookExportRecord.setBookId(bookId);
bookExportRecord.setAdviserId(adviserId);
bookExportRecord.setChannelId(channelId);
bookExportRecord.setBatchNum(num);
bookExportRecord.setCodeCount(codeCount);
bookExportRecord.setSceneId(sceneId);
bookExportRecordBiz.insertRecord(bookExportRecord);
}
@Override
public PageBeanNew<BookAuthCodeDTO> listSceneAuthCode(Long bookId, Long channelId, Long sceneId, String keyword, Integer state, Integer authBookType, Integer currentPage, Integer numPerPage, Long adviserId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("channelId",channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("keyword",StringUtil.isEmpty(keyword)?null:keyword);
paramMap.put("state",state);
paramMap.put("sceneId",sceneId);
if(null == authBookType || AuthBookTypeEnum.PAPER_BOOK.value.equals(authBookType)){
paramMap.put("isPaperBook", 1);
} else {
paramMap.put("isGroupBook", 1);
}
PageBeanNew<BookAuthCodeDTO> pageBeanNew = bookSceneAuthCodeDao.listPageNew(new PageParam(currentPage,numPerPage), paramMap, "listSceneAuthCode");
if(pageBeanNew == null || CollUtil.isEmpty(pageBeanNew.getRecordList())){
return new PageBeanNew<>(currentPage,numPerPage,null==pageBeanNew ? 0 : pageBeanNew.getTotalCount(),new ArrayList<>());
}
List<BookAuthCodeDTO> recordList = pageBeanNew.getRecordList();
// 填充
fillAuthUser(recordList,sceneId);
return pageBeanNew;
}
private void fillAuthUser(List<BookAuthCodeDTO> recordList,Long sceneId) {
List<Long> authCodeIds = recordList.stream().filter(x->null!=x.getUseCount() && x.getUseCount() > 0).map(x -> x.getId()).collect(Collectors.toList());
if(CollectionUtils.isEmpty(authCodeIds)){
return;
}
// 查询使用码的使用情况
Map<Long, List<BookAuthUserDTO>> authUserMap = bookAuthUserBiz.getByAuthCodeIds(authCodeIds,sceneId);
for (BookAuthCodeDTO bookAuthCodeDTO : recordList) {
bookAuthCodeDTO.setBookAuthUserList(authUserMap.getOrDefault(bookAuthCodeDTO.getId(), Lists.newArrayList()));
}
}
@Override
public void deleteSceneAuthCode(List<Long> ids) {
bookSceneAuthCodeDao.deleteSceneAuthCode(ids);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void clearNoUsedAuthCode(DeleteAuthCodeDTO deleteAuthCodeDTO, Long adviserId) {
List<Long> codeIds=bookSceneAuthCodeDao.getCodeIdList(deleteAuthCodeDTO.getBookId(),deleteAuthCodeDTO.getChannelId(),adviserId,deleteAuthCodeDTO.getKeyWord(), deleteAuthCodeDTO.getAuthBookType(),deleteAuthCodeDTO.getSceneId());
if(CollUtil.isEmpty(codeIds)){
return;
}
this.deleteSceneAuthCode(codeIds);
}
@Override
@Transactional(rollbackFor = Exception.class)
public CheckAuthCodeVO checkSceneAuthCode(UseAuthCodeVO useAuthCodeVO, Long channelId, Long wechatUserId) {
String code = useAuthCodeVO.getAuthCode();
if (StringUtils.isEmpty(code) || code.length() != 15) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "此码错误,请重新验证");
}
BookSceneAuthCode bookSceneAuthCode = bookSceneAuthCodeDao.getByCode(code);
CheckAuthCodeVO result=new CheckAuthCodeVO();
if(null==bookSceneAuthCode){
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value);
return result;
}
BookSceneAuth authSceneInfo = bookSceneAuthDao.getAuthSceneInfo(bookSceneAuthCode.getBookId(), bookSceneAuthCode.getSceneId());
if(null==authSceneInfo){
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value);
return result;
}
channelId=authSceneInfo.getChannelId();
BookAuthInfoVO authBookInfo = bookAuthInfoBiz.getAuthBookInfo(bookSceneAuthCode.getBookId(), channelId, bookSceneAuthCode.getAdviserId(), bookSceneAuthCode.getSceneId(), useAuthCodeVO.getAuthBookType());
if (authBookInfo == null || BookStatusEnum.NO_SET.value.equals(authBookInfo.getBookStatus())) {
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.RIGHT.value);
return result;
}
//校验用户是否已经授权过
Boolean isHaveAuth = bookAuthUserBiz.checkIsHaveAuth(bookSceneAuthCode.getBookId(), channelId, bookSceneAuthCode.getAdviserId(), wechatUserId, useAuthCodeVO.getAuthBookType(),bookSceneAuthCode.getSceneId(),bookSceneAuthCode.getId());
if (isHaveAuth) {
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.RIGHT.value);
return result;
}
//判断激活人数是否已经满了
Integer sceneAuthUserCount = bookAuthUserDao.getSceneAuthUserCount(bookSceneAuthCode.getBookId(), channelId, bookSceneAuthCode.getAdviserId(), useAuthCodeVO.getAuthBookType(), bookSceneAuthCode.getSceneId(),bookSceneAuthCode.getId());
if(null!=authSceneInfo.getMaxUserCount() && authSceneInfo.getMaxUserCount()<=sceneAuthUserCount){
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.FULL.value);
result.setTips(authSceneInfo.getFullUseTips());
return result;
}
//新增一条校验成功记录
addUserRecord(bookSceneAuthCode.getBookId(), channelId, bookSceneAuthCode.getAdviserId(), wechatUserId, useAuthCodeVO.getAuthBookType(),bookSceneAuthCode.getId(), bookSceneAuthCode.getSceneId());
//修改使用人数
bookSceneAuthCodeDao.updateUseCount(bookSceneAuthCode.getId());
result.setCodeUseStatus(BookStatusEnum.CodeUseTypeEnum.RIGHT.value);
return result;
}
private void addUserRecord(Long bookId, Long channelId, Long adviserId, Long wechatUserId, Integer authBookType,Long bookAuthCodeId, Long sceneId) {
BookAuthUser bookAuthUser = new BookAuthUser();
bookAuthUser.setBookId(bookId);
bookAuthUser.setChannelId(channelId);
bookAuthUser.setAdviserId(adviserId);
bookAuthUser.setWechatUserId(wechatUserId);
bookAuthUser.setAuthCode(BookStatusEnum.AuthCodeTypeEnum.BY_CODE.value);
bookAuthUser.setBookAuthCodeId(bookAuthCodeId);
bookAuthUser.setSceneId(sceneId);
bookAuthUser.setBookAuthType(2);
WechatUser wechatUser = readerConsr.getWechatUser(wechatUserId);
bookAuthUser.setProvince(wechatUser == null || StringUtil.isEmpty(wechatUser.getWechatUserProvince()) ? "未知" : wechatUser.getWechatUserProvince());
bookAuthUser.setCity(wechatUser == null || StringUtil.isEmpty(wechatUser.getWechatUserCity()) ? "未知" : wechatUser.getWechatUserCity());
if(authBookType == null || AuthBookTypeEnum.PAPER_BOOK.value.equals(authBookType)) {
bookAuthUser.setIsPaperBook(1);
bookAuthUser.setIsGroupBook(0);
} else {
bookAuthUser.setIsGroupBook(1);
bookAuthUser.setIsPaperBook(0);
}
bookAuthUserBiz.insert(bookAuthUser);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void setBookCodeAuth(BookSceneAuth bookSceneAuth, Long adviserId) {
if(ObjectUtil.hasEmpty(bookSceneAuth,bookSceneAuth.getBookId(),bookSceneAuth.getSceneId())){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "缺少参数");
}
BookSceneAuth authSceneInfo = bookSceneAuthDao.getAuthSceneInfo(bookSceneAuth.getBookId(), bookSceneAuth.getSceneId());
if(null==authSceneInfo){
BookSceneAuth build = BookSceneAuth.builder().bookId(bookSceneAuth.getBookId()).adviserId(adviserId).channelId(bookSceneAuth.getChannelId()).sceneId(bookSceneAuth.getSceneId())
.maxUserCount(null!=bookSceneAuth.getMaxUserCount() ? bookSceneAuth.getMaxUserCount() : 2).fullUseTips(bookSceneAuth.getFullUseTips()).createdUser(adviserId).build();
bookSceneAuthDao.insert(build);
}else{
authSceneInfo.setMaxUserCount(bookSceneAuth.getMaxUserCount());
authSceneInfo.setFullUseTips(bookSceneAuth.getFullUseTips());
bookSceneAuthDao.update(authSceneInfo);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveSceneAuthInfo(List<BookSceneAuth> list, Long adviserId) {
if(CollUtil.isEmpty(list)){
return;
}
Long bookId = list.get(0).getBookId();
List<Long> sceneIds = list.stream().map(a -> a.getSceneId()).collect(Collectors.toList());
List<BookSceneAuth> authSceneIds = bookSceneAuthDao.getAuthSceneIds(bookId, sceneIds);
Map<Long, Long> authSceneMap =CollUtil.isEmpty(authSceneIds) ? new HashMap<>() : authSceneIds.stream().collect(Collectors.toMap(a -> a.getSceneId(), a -> a.getId(), (k1, k2) -> k2));
List<BookSceneAuth> insertList=new ArrayList<>();
List<BookSceneAuth> updateList=new ArrayList<>();
for (BookSceneAuth bookSceneAuth : list) {
bookSceneAuth.setAdviserId(adviserId);
bookSceneAuth.setCreatedUser(adviserId);
if(CollUtil.isNotEmpty(authSceneMap) && authSceneMap.containsKey(bookSceneAuth.getSceneId())){
bookSceneAuth.setId(authSceneMap.get(bookSceneAuth.getSceneId()));
updateList.add(bookSceneAuth);
}else{
insertList.add(bookSceneAuth);
}
}
if(CollUtil.isNotEmpty(insertList)){
bookSceneAuthDao.insert(insertList);
}
if(CollUtil.isNotEmpty(updateList)){
bookSceneAuthDao.batchUpdate(updateList);
}
}
@Override
public List<SceneAuthCodeResponseDTO> getSceneAuthInfo(SceneAuthCodeSearchDTO dto) {
if(ObjectUtil.hasEmpty(dto,dto.getBookId()) || CollUtil.isEmpty(dto.getSceneIds())){
return null;
}
List<SceneAuthCodeResponseDTO> result=new ArrayList<>();
List<BookSceneAuth> authSceneIds = bookSceneAuthDao.getAuthSceneIds(dto.getBookId(), dto.getSceneIds());
Map<Long, BookSceneAuth> authMap = CollUtil.isEmpty(authSceneIds) ? new HashMap<>() : authSceneIds.stream().collect(Collectors.toMap(a -> a.getSceneId(), Function.identity(), (k1, k2) -> k2));
List<SceneAuthCodeResponseDTO> codeCount = bookSceneAuthCodeDao.getCodeCount(dto.getBookId(), dto.getSceneIds());
Map<Long, Integer> codeCountMap = CollUtil.isEmpty(codeCount) ? new HashMap<>() : codeCount.stream().collect(Collectors.toMap(a -> a.getSceneId(), a->a.getCounts(), (k1, k2) -> k2));
SceneAuthCodeResponseDTO sceneAuthCodeResponseDTO;
for (Long sceneId : dto.getSceneIds()) {
sceneAuthCodeResponseDTO=new SceneAuthCodeResponseDTO();
sceneAuthCodeResponseDTO.setSceneId(sceneId);
if(CollUtil.isNotEmpty(authMap) && authMap.containsKey(sceneId)){
BookSceneAuth bookSceneAuth = authMap.get(sceneId);
if(null!=bookSceneAuth){
sceneAuthCodeResponseDTO.setFullUseTips(bookSceneAuth.getFullUseTips());
sceneAuthCodeResponseDTO.setMaxUserCount(bookSceneAuth.getMaxUserCount());
}
}
if(CollUtil.isNotEmpty(codeCountMap) && codeCountMap.containsKey(sceneId)){
sceneAuthCodeResponseDTO.setCounts(codeCountMap.get(sceneId));
}
result.add(sceneAuthCodeResponseDTO);
}
return result;
}
@Override
public Map<String, Object> exportSceneAuthCode(Long bookId, String codeIds, Long channelId, Long sceneId,Long status, String systemCode, Long partyId, Integer authBookType) {
//获取书的基本信息
BookDto bookDto = bookBiz.getBaseById(bookId);
if (null == bookDto || null == bookDto.getBookId()){
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "授权码所对应的书不存在");
}
QrcodeSceneDto qrcodeSceneDto = qrcodeSceneConsr.getById(sceneId);
if(null==qrcodeSceneDto){
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "授权码所对应的二维码不存在");
}
//表名
String title = "《" + bookDto.getBookName() + "》" + qrcodeSceneDto.getSceneName()+"的授权码";
String[] rowsName = {"序号", "完整授权码", "生成方式", "状态", "创建时间"};
String fileUrl = "";
String finalTitle = title;
//不管是全部导出还是导出部分,都使用异步处理
if (status == 0) {
EXECUTOR_SERVICE.execute(() -> {
String filePath = this.exportAllFreeCode(finalTitle, rowsName, bookId, channelId, partyId, authBookType,sceneId);
//发送站内信
SendNotifyDto sendNotifyDto = new SendNotifyDto();
sendNotifyDto.setCreatedTime(new Date());
JSONObject content = new JSONObject();
content.put("commitTime", DateUtils.getSysDateTimeString());
content.put("type", StringUtil.addBracket(bookDto.getBookName()));
sendNotifyDto.setNotifyContent(content.toJSONString());
sendNotifyDto.setToId(partyId);
sendNotifyDto.setFromId(partyId);
sendNotifyDto.setSystemCode(systemCode);
sendNotifyDto.setTypeCode("genuine_qrcord_download");
sendNotifyDto.setFileName(bookDto.getBookName());
sendNotifyDto.setResourceId(filePath);
messageBiz.sendLetter(sendNotifyDto);
});
} else if (status == 1) {
EXECUTOR_SERVICE.execute(() -> {
String filePath = this.exportFreeCodeSelected(finalTitle, rowsName, codeIds);
//发送站内信
SendNotifyDto sendNotifyDto = new SendNotifyDto();
sendNotifyDto.setCreatedTime(new Date());
Map<String, String> map = new HashMap<>();
map.put("commitTime", DateUtils.getSysDateTimeString());
map.put("type", StringUtil.addBracket(bookDto.getBookName()));
String content = JSONUtils.toJsonString(map);
sendNotifyDto.setNotifyContent(content);
sendNotifyDto.setFileName(finalTitle);
sendNotifyDto.setFromId(partyId);
sendNotifyDto.setToId(partyId);
sendNotifyDto.setSystemCode(systemCode);
sendNotifyDto.setTypeCode("genuine_qrcord_download");
sendNotifyDto.setFileName(bookDto.getBookName());
sendNotifyDto.setResourceId(filePath);
messageBiz.sendLetter(sendNotifyDto);
});
}
Map<String, Object> returnInfo = new HashMap<>();
returnInfo.put("fileUrl", fileUrl);
returnInfo.put("fileName", title);
return returnInfo;
}
private String exportAllFreeCode(String title, String[] rowsName, Long bookId, Long channelId, Long partyId, Integer authBookType,Long sceneId) {
SXSSFWorkbook wb = new SXSSFWorkbook(200);
int columnNum = rowsName.length;
int rowIndex = 0;
SXSSFRow row;
SXSSFCell cell;
//设置表头样式
CellStyle headerStyle = getColumnTopStyle(wb);
SXSSFSheet sheet = wb.createSheet();
row = sheet.createRow(rowIndex);
cell = row.createCell(0);
//合并前两行
sheet.addMergedRegion(new CellRangeAddress(rowIndex, ++rowIndex, 0, columnNum - 1));
cell.setCellStyle(headerStyle);
cell.setCellValue(title);
//设置属性
row = sheet.createRow(++rowIndex);
for (int i = 0; i < rowsName.length; ++i) {
sheet.setColumnWidth(i, 20 * 256);
cell = row.createCell(i);
cell.setCellStyle(headerStyle);
cell.setCellValue(rowsName[i]);
}
//设置数据样式
CellStyle dataStyle = getDataStyle(wb);
dataStyle.setAlignment(HorizontalAlignment.CENTER);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("bookId", bookId);
paramMap.put("channelId", channelId);
paramMap.put("adviserId", partyId);
if(authBookType == null || AuthBookTypeEnum.PAPER_BOOK.value.equals(authBookType)) {
paramMap.put("isPaperBook", 1);
} else {
paramMap.put("isGroupBook", 1);
}
paramMap.put("sceneId",sceneId);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int k = 1;
//分批导出
for (int j = 0; true; j++) {
paramMap.put("currentPage", j * 500);
paramMap.put("numPerPage", 500);
List<BookAuthCodeDTO> bookAuthCodeDtos = bookSceneAuthCodeDao.getBookSceneAuthCodeList(paramMap);
if (!ListUtils.isEmpty(bookAuthCodeDtos)) {
for (BookAuthCodeDTO bookAuthCodeDTO : bookAuthCodeDtos) {
SXSSFRow srow = sheet.createRow(++rowIndex);
SXSSFCell cell0 = srow.createCell(0);
cell0.setCellStyle(dataStyle);
cell0.setCellValue(k++);
SXSSFCell cell2 = srow.createCell(1);
cell2.setCellStyle(dataStyle);
cell2.setCellValue(bookAuthCodeDTO.getFullCode());
SXSSFCell cell3 = srow.createCell(2);
cell3.setCellStyle(dataStyle);
CopyrightConstants.CreateType createType = CopyrightConstants.CreateType.CRATE_TYPE_MAP.get(bookAuthCodeDTO.getCreateType());
cell3.setCellValue(null == createType ? "-" : createType.getName());
SXSSFCell cell4 = srow.createCell(3);
cell4.setCellStyle(dataStyle);
cell4.setCellValue(bookAuthCodeDTO.getUseCount() > 0 ? "已使用" : "未使用");
SXSSFCell cell5 = srow.createCell(4);
cell5.setCellStyle(dataStyle);
cell5.setCellValue(bookAuthCodeDTO.getCreatedDate() != null ? df.format(bookAuthCodeDTO.getCreatedDate()) : "");
}
}
if (bookAuthCodeDtos.size() < 500) {
break;
}
bookAuthCodeDtos.clear();
}
//上传文件
String fileUrl = "";
try {
String UID = UUID.randomUUID().toString();
String path = UID + ".xlsx";
FileOutputStream fileOut = new FileOutputStream(path);
wb.write(fileOut);
fileOut.flush();
fileOut.close();
wb.close();
UploadResultInfo uploadResultInfo = OssUtils.uploadLocalFile(path, "xlsx");
fileUrl = uploadResultInfo.getUrl();
LOGGER.info("=======fileUrl==========" + OssUtils.urlAddKeyLong(fileUrl));
new File(path).delete();
} catch (FileNotFoundException e) {
LOGGER.error("临时文件Excel路径找不到" + e.getMessage(), e);
throw new ExportException(RecordException.ERROR, "导出Excel失败");
} catch (IOException e) {
LOGGER.error("生成临时文件Excel异常" + e.getMessage(), e);
throw new ExportException(RecordException.ERROR, "导出Excel失败");
}
return fileUrl;
}
private String exportFreeCodeSelected(String title, String[] rowsName, String codeIds){
//导出选中的
List<String> rowsNameList = Arrays.asList(rowsName);
List<Object[]> dataList = new ArrayList<>();
String fileUrl = "";
if (!StringUtils.isBlank(codeIds)) {
//切割CodeIds
String[] codeId = codeIds.split(",");
//根据购物码id查询购物码信息
for (int i = 0; i < codeId.length; i++) {
BookSceneAuthCode bookAuthCode = bookSceneAuthCodeDao.getById(Long.parseLong(codeId[i]));
if (null == bookAuthCode) {
throw new ResBizException(ResBizException.PARAM_IS_ERROR, "授权码不存在");
}
Object[] objs = new Object[rowsNameList.size()];
objs[0] = i + 1;
//objs[1] = bookAuthCode.getAuthCode();
objs[1] = bookAuthCode.getFullCode();
CopyrightConstants.CreateType createType = CopyrightConstants.CreateType.CRATE_TYPE_MAP.get(bookAuthCode.getCreateType());
objs[2] = null == createType ? "-" : createType.getName();
objs[3] = (null!=bookAuthCode.getUseCount() && bookAuthCode.getUseCount() > 0) ? "已使用" : "未使用";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
objs[4] = bookAuthCode.getCreatedDate() != null ? df.format(bookAuthCode.getCreatedDate()) : "";
dataList.add(objs);
fileUrl = exportConsr.exportExcel(title, rowsName, dataList);
}
} else {
throw new ResBizException(ResBizException.PARAM_IS_ERROR, "授权码不存在");
}
return fileUrl;
}
}
\ No newline at end of file
......@@ -22,6 +22,8 @@ public interface BookAuthUserDao extends BaseDao<BookAuthUser> {
*/
BookAuthCodeUserVO getAuthUserCount(Long bookId, Long channelId, Long adviserId, Integer authBookType);
Integer getSceneAuthUserCount(Long bookId, Long channelId, Long adviserId, Integer authBookType,Long sceneId,Long codeId);
/**
* 30天趋势图
*/
......@@ -36,7 +38,7 @@ public interface BookAuthUserDao extends BaseDao<BookAuthUser> {
/**
* 校验是否已经授权
*/
Boolean getIsHaveAuth(Long bookId, Long channelId, Long adviserId, List<Long> wechatUserIdList, Integer authBookType);
Boolean getIsHaveAuth(Long bookId, Long channelId, Long adviserId, List<Long> wechatUserIdList, Integer authBookType,Long sceneId,Long bookAuthCodeId);
/**
* 根据月份获取授权用户信息
......@@ -71,5 +73,5 @@ public interface BookAuthUserDao extends BaseDao<BookAuthUser> {
/**
* 获取使用授权码的用户
*/
List<BookAuthUserDTO> getByAuthCodeIds(List<Long> authCodeIds);
List<BookAuthUserDTO> getByAuthCodeIds(List<Long> authCodeIds,Long sceneId);
}
......@@ -28,4 +28,9 @@ public interface BookExportRecordDao extends BaseDao<BookExportRecord> {
* 处理导出
*/
void handleExportFail();
/**
* 获取最后一次导出的地址
*/
String getExportUrl(Long bookId, Long channelId, Long adviserId,Long sceneId);
}
package com.pcloud.book.copyright.dao;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.entity.BookSceneAuthCode;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
import java.util.Map;
/**
* 书籍二维码授权码记录表(BookSceneAuthCode)表数据库访问层
*
* @author makejava
* @since 2021-10-19 14:14:47
*/
public interface BookSceneAuthCodeDao extends BaseDao<BookSceneAuthCode> {
Integer getMaxBatchNum(Long bookId, Long channelId,Long sceneId, Long adviserId, Integer authBookType);
void deleteSceneAuthCode(List<Long> ids);
List<Long> getCodeIdList(Long bookId, Long channelId, Long adviserId, String keyWord, Integer authBookType, Long sceneId);
BookSceneAuthCode getByCode(String code);
void updateUseCount(Long id);
List<SceneAuthCodeResponseDTO> getCodeCount(Long bookId, List<Long> sceneIds);
void batchUpdate(List<BookSceneAuthCode> list);
List<BookAuthCodeDTO> getBookSceneAuthCodeList(Map<String, Object> paramMap);
}
\ No newline at end of file
package com.pcloud.book.copyright.dao;
import com.pcloud.book.copyright.entity.BookSceneAuth;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
/**
* 书籍二维码授权表(BookSceneAuth)表数据库访问层
*
* @author makejava
* @since 2021-10-19 14:14:22
*/
public interface BookSceneAuthDao extends BaseDao<BookSceneAuth> {
BookSceneAuth getAuthSceneInfo(Long bookId, Long sceneId);
List<BookSceneAuth> getAuthSceneIds(Long bookId, List<Long> sceneIds);
void batchUpdate(List<BookSceneAuth> updateList);
}
\ No newline at end of file
......@@ -41,6 +41,22 @@ public class BookAuthUserDaoImpl extends BaseDaoImpl<BookAuthUser> implements Bo
}
@Override
public Integer getSceneAuthUserCount(Long bookId, Long channelId, Long adviserId, Integer authBookType,Long sceneId,Long bookAuthCodeId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("bookId", bookId);
paramMap.put("channelId", channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("sceneId",sceneId);
paramMap.put("bookAuthCodeId",bookAuthCodeId);
if(authBookType == null || authBookType.equals(0)) {
paramMap.put("isPaperBook", 1);
} else {
paramMap.put("isGroupBook", 1);
}
return this.getSqlSession().selectOne(this.getStatement("getSceneAuthUserCount"), paramMap);
}
@Override
public List<ThirtyDayCountVO> listThirtyDay(Map<String, Object> paramMap) {
return this.getSqlSession().selectList(this.getStatement("listThirtyDay"), paramMap);
}
......@@ -51,11 +67,13 @@ public class BookAuthUserDaoImpl extends BaseDaoImpl<BookAuthUser> implements Bo
}
@Override
public Boolean getIsHaveAuth(Long bookId, Long channelId, Long adviserId, List<Long> wechatUserIdList, Integer authBookType) {
public Boolean getIsHaveAuth(Long bookId, Long channelId, Long adviserId, List<Long> wechatUserIdList, Integer authBookType,Long sceneId,Long bookAuthCodeId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("bookId", bookId);
paramMap.put("channelId", channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("sceneId",sceneId);
paramMap.put("bookAuthCodeId",bookAuthCodeId);
paramMap.put("wechatUserIdList",wechatUserIdList);
if(authBookType == null || authBookType.equals(0)) {
paramMap.put("isPaperBook", 1);
......@@ -119,7 +137,10 @@ public class BookAuthUserDaoImpl extends BaseDaoImpl<BookAuthUser> implements Bo
}
@Override
public List<BookAuthUserDTO> getByAuthCodeIds(List<Long> authCodeIds) {
return this.getSessionTemplate().selectList(this.getStatement("getByAuthCodeIds"), authCodeIds);
public List<BookAuthUserDTO> getByAuthCodeIds(List<Long> authCodeIds,Long sceneId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("authCodeIds", authCodeIds);
paramMap.put("sceneId", sceneId);
return this.getSessionTemplate().selectList(this.getStatement("getByAuthCodeIds"), paramMap);
}
}
......@@ -38,4 +38,14 @@ public class BookExportRecordDaoImpl extends BaseDaoImpl<BookExportRecord> imple
public void handleExportFail() {
this.getSqlSession().update(this.getStatement("handleExportFail"));
}
@Override
public String getExportUrl(Long bookId, Long channelId, Long adviserId, Long sceneId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("channelId",channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("sceneId",sceneId);
return this.getSqlSession().selectOne(this.getStatement("getExportUrl"), paramMap);
}
}
package com.pcloud.book.copyright.dao.impl;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.entity.BookSceneAuthCode;
import com.pcloud.book.copyright.dao.BookSceneAuthCodeDao;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 书籍二维码授权码记录表(BookSceneAuthCode)表数据库访问层
*
* @author makejava
* @since 2021-10-19 14:14:47
*/
@Repository("bookSceneAuthCodeDaoImpl")
public class BookSceneAuthCodeDaoImpl extends BaseDaoImpl<BookSceneAuthCode> implements BookSceneAuthCodeDao {
@Override
public Integer getMaxBatchNum(Long bookId, Long channelId, Long sceneId, Long adviserId, Integer authBookType) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("channelId",channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("sceneId",sceneId);
if(authBookType == null || authBookType.equals(0)) {
paramMap.put("isPaperBook", 1);
} else {
paramMap.put("isGroupBook", 1);
}
return this.getSqlSession().selectOne(this.getStatement("getMaxBatchNum"), paramMap);
}
@Override
public void deleteSceneAuthCode(List<Long> ids) {
this.getSqlSession().delete(this.getStatement("deleteSceneAuthCode"), ids);
}
@Override
public List<Long> getCodeIdList(Long bookId, Long channelId, Long adviserId, String keyWord, Integer authBookType, Long sceneId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("channelId",channelId);
paramMap.put("adviserId",adviserId);
paramMap.put("keyword",keyWord);
paramMap.put("sceneId",sceneId);
if(authBookType == null || authBookType.equals(0)) {
paramMap.put("isPaperBook", 1);
} else {
paramMap.put("isGroupBook", 1);
}
return this.getSqlSession().selectList(this.getStatement("getCodeIdList"), paramMap);
}
@Override
public BookSceneAuthCode getByCode(String code) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("code",code);
return this.getSqlSession().selectOne(this.getStatement("getByCode"), paramMap);
}
@Override
public void updateUseCount(Long id) {
this.getSqlSession().update(this.getStatement("updateUseCount"), id);
}
@Override
public List<SceneAuthCodeResponseDTO> getCodeCount(Long bookId, List<Long> sceneIds) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("sceneIds",sceneIds);
return this.getSqlSession().selectList(this.getStatement("getCodeCount"), paramMap);
}
@Override
public void batchUpdate(List<BookSceneAuthCode> list) {
this.getSqlSession().update(this.getStatement("batchUpdate"), list);
}
@Override
public List<BookAuthCodeDTO> getBookSceneAuthCodeList(Map<String, Object> paramMap) {
return this.getSqlSession().selectList(this.getStatement("getBookSceneAuthCodeList"), paramMap);
}
}
\ No newline at end of file
package com.pcloud.book.copyright.dao.impl;
import com.pcloud.book.copyright.entity.BookSceneAuth;
import com.pcloud.book.copyright.dao.BookSceneAuthDao;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 书籍二维码授权表(BookSceneAuth)表数据库访问层
*
* @author makejava
* @since 2021-10-19 14:14:22
*/
@Repository("bookSceneAuthDaoImpl")
public class BookSceneAuthDaoImpl extends BaseDaoImpl<BookSceneAuth> implements BookSceneAuthDao {
@Override
public BookSceneAuth getAuthSceneInfo(Long bookId, Long sceneId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("sceneId",sceneId);
return this.getSqlSession().selectOne(this.getStatement("getAuthSceneInfo"), paramMap);
}
@Override
public List<BookSceneAuth> getAuthSceneIds(Long bookId, List<Long> sceneIds) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("bookId",bookId);
paramMap.put("sceneIds",sceneIds);
return this.getSqlSession().selectList(this.getStatement("getAuthSceneIds"), paramMap);
}
@Override
public void batchUpdate(List<BookSceneAuth> list) {
this.getSqlSession().update(this.getStatement("batchUpdate"), list);
}
}
\ No newline at end of file
......@@ -17,5 +17,9 @@ public class DeleteAuthCodeDTO {
@ApiModelProperty("书刊类型")
private Integer authBookType;
@ApiModelProperty("二维码id")
private Long sceneId;
}
......@@ -74,4 +74,7 @@ public class BookAuthInfo extends BaseEntity {
@ApiModelProperty("打开支付功能;0:关闭;1:开启;")
private Integer openPay;
@ApiModelProperty("授权类型(1-旧版-二维码+授权码,2-升级,二维码)")
private Integer authType;
}
......@@ -63,6 +63,28 @@ public class BookAuthUser extends BaseEntity {
@ApiModelProperty("授权码id")
private Long bookAuthCodeId;
@ApiModelProperty("二维码id")
private Long sceneId;
@ApiModelProperty("授权类型(1-旧版-二维码+授权码,2-升级,二维码)")
private Integer bookAuthType;
public Long getSceneId() {
return sceneId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
public Integer getBookAuthType() {
return bookAuthType;
}
public void setBookAuthType(Integer bookAuthType) {
this.bookAuthType = bookAuthType;
}
@Override
public Long getId() {
return id;
......
......@@ -53,4 +53,7 @@ public class BookExportRecord extends BaseEntity {
@ApiModelProperty("导出格式")
private Integer isHaveBarCode;
@ApiModelProperty("二维码id")
private Long sceneId;
}
package com.pcloud.book.copyright.entity;
import java.util.Date;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 书籍二维码授权表(BookSceneAuth)实体类
*
* @author makejava
* @since 2021-10-19 14:14:22
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BookSceneAuth extends BaseEntity {
private static final long serialVersionUID = 208406932124753490L;
@ApiModelProperty("主键标识")
private Long id;
@ApiModelProperty("图书标识")
private Long bookId;
@ApiModelProperty("二维码id")
private Long sceneId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("编辑标识")
private Long adviserId;
@ApiModelProperty("最多激活人数")
private Integer maxUserCount;
@ApiModelProperty("激活次数用完后提示")
private String fullUseTips;
@ApiModelProperty("创建人")
private Long createdUser;
@ApiModelProperty("创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
\ No newline at end of file
package com.pcloud.book.copyright.entity;
import java.util.Date;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 书籍二维码授权码记录表(BookSceneAuthCode)实体类
*
* @author makejava
* @since 2021-10-19 14:14:47
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BookSceneAuthCode extends BaseEntity {
private static final long serialVersionUID = 501026115036847009L;
@ApiModelProperty("主键标识")
private Long id;
@ApiModelProperty("图书标识")
private Long bookId;
@ApiModelProperty("二维码id")
private Long sceneId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("编辑标识")
private Long adviserId;
@ApiModelProperty("授权码")
private String authCode;
@ApiModelProperty("批次号")
private String batchNum;
@ApiModelProperty("完整校验码")
private String fullCode;
@ApiModelProperty("使用次数")
private Integer useCount;
@ApiModelProperty("创建方式(0-自动/1-手动)")
private Integer createType;
@ApiModelProperty("创建人")
private Long createdUser;
@ApiModelProperty("创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createdDate;
@ApiModelProperty("最后修改人")
private Long lastModifiedUser;
@ApiModelProperty("最后更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date lastModifiedDate;
@ApiModelProperty("是否是现代纸书")
private Integer isPaperBook;
@ApiModelProperty("是否是社群书")
private Integer isGroupBook;
private String url;
private String qrcodeUrl;
}
\ No newline at end of file
......@@ -3,16 +3,21 @@ package com.pcloud.book.copyright.facade.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.copyright.biz.BookAuthCodeBiz;
import com.pcloud.book.copyright.biz.BookExportRecordBiz;
import com.pcloud.book.copyright.biz.BookSceneAuthBiz;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.dto.BookExportRecordDTO;
import com.pcloud.book.copyright.dto.DeleteAuthCodeDTO;
import com.pcloud.book.copyright.entity.BookExportRecord;
import com.pcloud.book.copyright.facade.BookAuthCodeFacade;
import com.pcloud.book.copyright.vo.AuthOpenVO;
import com.pcloud.book.copyright.vo.CheckAuthCodeVO;
import com.pcloud.book.copyright.vo.CheckCodeParam;
import com.pcloud.book.copyright.vo.CheckIsAuthServeParam;
import com.pcloud.book.copyright.vo.CodeUseStatusVO;
import com.pcloud.book.copyright.vo.FileVO;
import com.pcloud.book.copyright.vo.GenerateCodeVO;
import com.pcloud.book.copyright.vo.ImportRecordVO;
import com.pcloud.book.copyright.vo.UseAuthCodeVO;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew;
......@@ -35,9 +40,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
/**
* @author lily
* @date 2018/11/29 16:59
......@@ -52,6 +60,9 @@ public class BookAuthCodeFacadeImpl implements BookAuthCodeFacade {
@Autowired
private BookExportRecordBiz bookExportRecordBiz;
@Autowired
private BookSceneAuthBiz bookSceneAuthBiz;
@Override
@RequestMapping(value = "checkCode", method = RequestMethod.POST)
public ResponseDto<CodeUseStatusVO> checkCode(@CookieValue("userInfo") String userInfo, @RequestBody CheckCodeParam checkCodeParam) throws PermissionException, BizException {
......@@ -175,11 +186,112 @@ public class BookAuthCodeFacadeImpl implements BookAuthCodeFacade {
public ResponseDto<?> getGenerateCodeHistory(@RequestHeader("token")String token,
@RequestParam(required = false, value ="bookId") Long bookId,
@RequestParam(required = false, value ="channelId") Long channelId,
@RequestParam(required = false, value ="sceneId") Long sceneId,
@RequestParam(required = false,value = "currentPage")Integer currentPage,
@RequestParam(required = false,value = "numPerPage")Integer numPerPage) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
PageParam pageParam = new PageParam(currentPage,numPerPage);
PageBeanNew<BookExportRecordDTO> result=bookExportRecordBiz.getGenerateCodeHistory(bookId,adviserId,channelId,pageParam);
PageBeanNew<BookExportRecordDTO> result=bookExportRecordBiz.getGenerateCodeHistory(bookId,adviserId,channelId,sceneId,pageParam);
return new ResponseDto<>(result);
}
/**
* 新版二维码自动生成版权保护二维码
*/
@PostMapping("autoGenerateAuthCode")
public ResponseDto<?> autoGenerateAuthCode(@RequestHeader("token") String token, @RequestBody GenerateCodeVO generateCodeVO) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
bookSceneAuthBiz.autoGenerateAuthCode(generateCodeVO, adviserId);
return new ResponseDto<>();
}
/**
* 二维码下授权码列表
*/
@GetMapping("listSceneAuthCode")
public ResponseDto<?> listSceneAuthCode(@RequestHeader("token") String token,
@RequestParam(required = false, value ="bookId") Long bookId,
@RequestParam(required = false, value ="channelId") Long channelId,
@RequestParam(required = false, value ="sceneId") Long sceneId,
@RequestParam(required = false,value = "keyword")String keyword,
@RequestParam(required = false,value = "state")Integer state,
@RequestParam(required = false,value = "authBookType")Integer authBookType,
@RequestParam(required = false,value = "currentPage")Integer currentPage,
@RequestParam(required = false,value = "numPerPage")Integer numPerPage
) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
PageBeanNew<BookAuthCodeDTO> result=bookSceneAuthBiz.listSceneAuthCode(bookId,channelId,sceneId,keyword,state,authBookType,currentPage,numPerPage, adviserId);
return new ResponseDto<>(result);
}
/**
* 批量删除正版授权码
* @param token
* @param ids
* @return
* @throws PermissionException
* @throws BizException
*/
@PostMapping("deleteSceneAuthCode")
public ResponseDto<?> deleteSceneAuthCode(@RequestHeader String token,
@RequestBody List<Long> ids) throws PermissionException, BizException {
if(ListUtils.isEmpty(ids)){
return new ResponseDto<>();
}
bookSceneAuthBiz.deleteSceneAuthCode(ids);
return new ResponseDto<>();
}
/**
*一键删除未使用的授权码
*/
@PostMapping("clearNoUsedAuthCode")
public ResponseDto<?> clearNoUsedAuthCode(@RequestHeader("token")String token,
@RequestBody DeleteAuthCodeDTO deleteAuthCodeDTO) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
if(null==deleteAuthCodeDTO || null == deleteAuthCodeDTO.getBookId() || null == deleteAuthCodeDTO.getChannelId() || null==deleteAuthCodeDTO.getSceneId()){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"参数有误!");
}
bookSceneAuthBiz.clearNoUsedAuthCode(deleteAuthCodeDTO,adviserId);
return new ResponseDto<>();
}
/**
* 升级用户扫描授权码之后
*/
@PostMapping("checkSceneAuthCode")
public ResponseDto<?> checkSceneAuthCode(@CookieValue("userInfo") String userInfo, @RequestBody UseAuthCodeVO useAuthCodeVO) throws PermissionException, BizException {
if(null==userInfo || null==useAuthCodeVO.getAuthCode()){
throw new BookBizException(BookBizException.PARAM_IS_ERROR,"参数有误!");
}
Long channelId = useAuthCodeVO.getChannelId();
if(channelId == null){
channelId = Cookie.getId(userInfo, Cookie._CHANNEL_ID);
}
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
CheckAuthCodeVO codeUseStatus = bookSceneAuthBiz.checkSceneAuthCode(useAuthCodeVO, channelId, wechatUserId);
return new ResponseDto<>(codeUseStatus);
}
/**
* 导出选中授权码
*/
@RequestMapping(value = "/exportSceneAuthCode", method = RequestMethod.GET)
public ResponseDto<?> exportSceneAuthCode(@RequestHeader("token") String token,
@RequestParam(required = false, value ="bookId") Long bookId,
@RequestParam(required = false, value ="codeIds") String codeIds,
@RequestParam(required = false, value ="channelId") Long channelId,
@RequestParam(required = false, value ="sceneId") Long sceneId,
@RequestParam(required = false, value ="status") Long status,
@RequestParam(required = false,value = "authBookType")Integer authBookType)
throws PermissionException, JsonParseException, BizException {
String systemCode = (String) SessionUtil.getVlaue(token, SessionUtil.SYSTEM_CODE);
Long partyId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
//校验参数
if (null == status || null == bookId || null == channelId) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数错误");
}
Map<String, Object> map = bookSceneAuthBiz.exportSceneAuthCode(bookId,codeIds, channelId,sceneId, status, systemCode, partyId, authBookType);
return new ResponseDto<>(map);
}
}
package com.pcloud.book.copyright.facade.impl;
import com.pcloud.book.copyright.biz.BookAuthInfoBiz;
import com.pcloud.book.copyright.biz.BookSceneAuthBiz;
import com.pcloud.book.copyright.entity.BookSceneAuth;
import com.pcloud.book.copyright.facade.BookAuthInfoFacade;
import com.pcloud.book.copyright.vo.AuthOpenVO;
import com.pcloud.book.copyright.vo.BookAuthInfoAndServesVO;
import com.pcloud.book.copyright.vo.BookAuthInfoVO;
import com.pcloud.book.copyright.vo.BookAuthInfoWechatVO;
......@@ -29,6 +32,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author lily
* @date 2018/12/3 10:58
......@@ -39,6 +44,8 @@ public class BookAuthInfoFacadeImpl implements BookAuthInfoFacade {
@Autowired
private BookAuthInfoBiz bookAuthInfoBiz;
@Autowired
private BookSceneAuthBiz bookSceneAuthBiz;
@Override
@PostMapping("setBookAuthOpen")
......@@ -132,4 +139,28 @@ public class BookAuthInfoFacadeImpl implements BookAuthInfoFacade {
Boolean isCanExport = bookAuthInfoBiz.isHaveExport(bookId, channelId, adviserId);
return new ResponseDto<>(isCanExport == null ? false : isCanExport);
}
@ApiOperation("升级版权保护")
@PostMapping("setBookCodeAuth")
public ResponseDto<?> setBookCodeAuth(@RequestHeader("token") String token, @RequestBody AuthOpenVO authOpenVO) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
bookAuthInfoBiz.setBookCodeAuth(authOpenVO, adviserId);
return new ResponseDto<>();
}
@ApiOperation("修改二维码授权信息")
@PostMapping("updateSceneAuthInfo")
public ResponseDto<?> updateSceneAuthInfo(@RequestHeader("token") String token, @RequestBody BookSceneAuth bookSceneAuth) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
bookSceneAuthBiz.setBookCodeAuth(bookSceneAuth, adviserId);
return new ResponseDto<>();
}
@ApiOperation("保存二维码授权信息")
@PostMapping("saveSceneAuthInfo")
public ResponseDto<?> saveSceneAuthInfo(@RequestHeader("token") String token, @RequestBody List<BookSceneAuth> list) throws PermissionException, BizException {
Long adviserId = (Long) SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
bookSceneAuthBiz.saveSceneAuthInfo(list, adviserId);
return new ResponseDto<>();
}
}
......@@ -95,7 +95,7 @@ public class BookAuthUserFacadeImpl implements BookAuthUserFacade {
channelId = Cookie.getId(userInfo, Cookie._CHANNEL_ID);
}
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
Boolean result = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId, 1);
Boolean result = bookAuthUserBiz.checkIsHaveAuth(bookId, channelId, adviserId, wechatUserId, 1,null,null);
return new ResponseDto<>(result);
}
......
......@@ -2,9 +2,12 @@ package com.pcloud.book.copyright.service.impl;
import com.pcloud.book.copyright.biz.BookAuthInfoBiz;
import com.pcloud.book.copyright.biz.BookAuthUserBiz;
import com.pcloud.book.copyright.biz.BookSceneAuthBiz;
import com.pcloud.book.copyright.dto.BookAuthInfoCountDTO;
import com.pcloud.book.copyright.dto.BookAuthTotalCountDTO;
import com.pcloud.book.copyright.dto.CheckUserAuthDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO;
import com.pcloud.book.copyright.dto.SceneAuthCodeSearchDTO;
import com.pcloud.book.copyright.service.BookAuthInfoService;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
......@@ -31,6 +34,8 @@ public class BookAuthInfoServiceImpl implements BookAuthInfoService {
private BookAuthInfoBiz bookAuthInfoBiz;
@Autowired
private BookAuthUserBiz bookAuthUserBiz;
@Autowired
private BookSceneAuthBiz bookSceneAuthBiz;
@Override
@RequestMapping(value = "/getBookAuthPrice", method = RequestMethod.GET)
......@@ -73,4 +78,9 @@ public class BookAuthInfoServiceImpl implements BookAuthInfoService {
@RequestParam("channelId")Long channelId, @RequestParam("adviserId")Long adviserId) throws BizException {
return ResponseHandleUtil.toResponse(bookAuthInfoBiz.getBookAuthPrice(bookId, channelId, adviserId, 1));
}
@Override
public ResponseEntity<ResponseDto<List<SceneAuthCodeResponseDTO>>> getSceneAuthInfo(SceneAuthCodeSearchDTO sceneAuthCodeSearchDTO) throws BizException {
return ResponseHandleUtil.toResponse(bookSceneAuthBiz.getSceneAuthInfo(sceneAuthCodeSearchDTO));
}
}
......@@ -10,6 +10,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.copyright.dto.DateDTO;
import com.pcloud.book.copyright.entity.BookAuthCode;
import com.pcloud.book.copyright.entity.BookSceneAuthCode;
import com.pcloud.common.constant.OSConstant;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.enums.ImageTypeEnum;
......@@ -18,6 +19,7 @@ import com.pcloud.common.exceptions.FileException;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.FileUtils;
import com.pcloud.common.utils.LocalDateUtils;
import com.pcloud.common.utils.QrcodeUtils;
import com.pcloud.common.utils.UUIDUitl;
import com.pcloud.common.utils.aliyun.OssUtils;
import com.pcloud.common.utils.zip.CompressUtils;
......@@ -223,6 +225,68 @@ public class CopyrightTools {
return uploadResultInfo == null ? null : uploadResultInfo.getUrl();
}
/**
* 生成二维码
* @param bookAuthCodes
* @param fileName
* @param sceneUrl
* @return
*/
public static String generateQrcode4ZipNew(List<BookSceneAuthCode> bookAuthCodes, String fileName, String sceneUrl,Integer authBookType) {
fileName = FileUtils.formatName(fileName);
String tempZipName = fileName + "_" + LocalDateUtils.getYmdhmss();
String zipFilePath = ZIP_FILE_PATH + tempZipName + ".zip";
String fileFolderPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(fileFolderPath);
UploadResultInfo uploadResultInfo;
try {
for (BookSceneAuthCode bookAuthCode : bookAuthCodes) {
LOGGER.info("【二维码】generateQrcode4Zip,<START>.[url]=" + bookAuthCode);
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0); // 设置白边
try {
String content=sceneUrl+"?authCode="+bookAuthCode.getFullCode()+"&authBookType="+authBookType;
// 生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 430,
430, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for(int x=0;x<width;x++){
for(int y=0;y<height;y++){
bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
// paintQrcodeText(bufferedImage, bookAuthCode.getFullCode());
File file = new File(fileFolderPath + "/" + bookAuthCode.getFullCode() + ".png");
ImageIO.write(bufferedImage, ImageTypeEnum.PNG.value, file);
String qrcodeUrl = QrcodeUtils.uploadImage(bufferedImage);
bookAuthCode.setUrl(content);
bookAuthCode.setQrcodeUrl(qrcodeUrl);
} catch (Exception e) {
LOGGER.error("【二维码】创建二维码失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "创建二维码失败");
}
}
// 检查压缩包临时文件夹是否存在,不存在就创建
FileUtils.isDir(ZIP_FILE_PATH);
CompressUtils.zip(fileFolderPath, zipFilePath);
// 上传文件到服务器中
uploadResultInfo = OssUtils.uploadLocalFile4CustomName(zipFilePath, fileName);
} catch (Exception e) {
LOGGER.error("【压缩】压缩失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.ZIP_ERROR, "压缩失败!");
} finally {
// 删除产生的文件
FileUtils.deleteDirectory(fileFolderPath);
FileUtils.deleteFile(zipFilePath);
}
return uploadResultInfo == null ? null : uploadResultInfo.getUrl();
}
public static String uploadImage(BufferedImage image) throws BizException {
UploadResultInfo uploadResultInfo = null;
......
package com.pcloud.book.copyright.vo;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 升级书刊二维保护
*/
@Data
@ApiModel
public class AuthOpenVO implements Serializable {
@ApiModelProperty("图书标识")
private Long bookId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("书刊类型:0-现代纸书 1-社群书")
private Integer authBookType;
}
package com.pcloud.book.copyright.vo;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 升级书刊二维保护,扫码之后
*/
@Data
@ApiModel
public class CheckAuthCodeVO implements Serializable {
@ApiModelProperty("码使用后状态")
private Integer codeUseStatus;
@ApiModelProperty("提示")
private String tips;
}
package com.pcloud.book.copyright.vo;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 升级书刊二维码自动生成保护二维码
*/
@Data
@ApiModel
public class GenerateCodeVO implements Serializable {
@ApiModelProperty("图书标识")
private Long bookId;
@ApiModelProperty("二维码id")
private Long sceneId;
@ApiModelProperty("运营标识")
private Long channelId;
@ApiModelProperty("书刊类型:0-现代纸书 1-社群书")
private Integer authBookType;
@ApiModelProperty("生成授权码个数")
private Integer codeCount;
}
......@@ -50,6 +50,17 @@ public class HaveSetAuthBook implements Serializable {
@ApiModelProperty("是否有使用过的授权码")
private Boolean haveUsedAuthCode;
@ApiModelProperty("授权类型(1-旧版-二维码+授权码,2-升级,二维码)")
private Integer authType;
public Integer getAuthType() {
return authType;
}
public void setAuthType(Integer authType) {
this.authType = authType;
}
public Long getBookId() {
return bookId;
}
......
package com.pcloud.book.copyright.vo;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 升级书刊二维保护
*/
@Data
@ApiModel
public class UseAuthCodeVO implements Serializable {
private String authCode;
@ApiModelProperty("运营标识")
private Long channelId;
private Integer authBookType;
}
......@@ -731,7 +731,7 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
if (new BigDecimal(0).compareTo(classify.getPrice()) < 0) {
//校验用户是否正版授权
Boolean isAuth = bookAuthUserBiz.checkIsHaveAuth(classify.getBookId(), classify.getChannelId(), classify.getCreateUser(), wechatUserId, 1);
Boolean isAuth = bookAuthUserBiz.checkIsHaveAuth(classify.getBookId(), classify.getChannelId(), classify.getCreateUser(), wechatUserId, 1,null,null);
if(!isAuth) {
//校验用户是否购买
Boolean isBuy = bookClassifyBuyRecordDao.checkUserBuy(wechatUserId, classifyId);
......
......@@ -20,13 +20,13 @@
<insert id="insert" useGeneratedKeys="true" parameterType="bookAuthInfo">
INSERT INTO BOOK_AUTH_INFO(
BOOK_ID, CHANNEL_ID,ADVISER_ID,PRICE,CODE_USE_COUNT,BUY_URL,CHECK_TYPE, CREATED_USER, CREATED_DATE,LAST_MODIFIED_DATE,OPEN_TIME,
is_paper_book, is_group_book, is_authorized_pay, open_pay
is_paper_book, is_group_book, is_authorized_pay, open_pay,auth_type
)
VALUES
(#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},
#{price}, #{codeUseCount,jdbcType=BIGINT}, #{buyUrl}, #{checkType},
#{adviserId,jdbcType=BIGINT}, NOW(), NOW(), NOW(),
#{isPaperBook}, #{isGroupBook}, IFNULL(#{isAuthorizedPay},0), IFNULL(#{openPay},1))
#{isPaperBook}, #{isGroupBook}, IFNULL(#{isAuthorizedPay},0), IFNULL(#{openPay},1),IFNULL(#{authType},1))
</insert>
<select id="getInfoByBook" resultMap="BookAuthInfoMap" parameterType="map">
......@@ -73,7 +73,8 @@
B.COVER_IMG coverImg,
B.SERIAL_NUMBER serialNumber,
A.IS_MAIN_EDITOR isMainEditor,
I.book_status bookStatus
I.book_status bookStatus,
I.auth_type authType
FROM
BOOK_AUTH_INFO I
INNER JOIN BOOK_ADVISER A ON A.BOOK_ID = I.BOOK_ID AND A.CHANNEL_ID = I.CHANNEL_ID AND A.CREATED_USER = I.ADVISER_ID AND A.IS_DELETE = 0
......@@ -271,6 +272,9 @@
<if test="openPay != null">
open_pay = #{openPay},
</if>
<if test="authType != null">
auth_type = #{authType},
</if>
LAST_MODIFIED_DATE = NOW()
WHERE
ID = #{id}
......
......@@ -4,10 +4,12 @@
<insert id="insert" useGeneratedKeys="true" parameterType="bookAuthUser">
INSERT INTO BOOK_AUTH_USER(
BOOK_ID, CHANNEL_ID,ADVISER_ID,WECHAT_USER_ID,MONTHS,province,city,IS_AUTH_CODE, CREATED_DATE,CREATED_USER, CREATED_TIME, is_paper_book, is_group_book, book_auth_code_id)
BOOK_ID, CHANNEL_ID,ADVISER_ID,WECHAT_USER_ID,MONTHS,province,city,IS_AUTH_CODE, CREATED_DATE,CREATED_USER, CREATED_TIME,
is_paper_book, is_group_book, book_auth_code_id,scene_id,book_auth_type)
VALUES
(#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},
#{wechatUserId}, #{months}, #{province}, #{city}, #{isAuthCode},NOW(), #{adviserId}, NOW(), #{isPaperBook}, #{isGroupBook}, #{bookAuthCodeId})
#{wechatUserId}, #{months}, #{province}, #{city}, #{isAuthCode},NOW(), #{adviserId}, NOW(), #{isPaperBook}, #{isGroupBook}, #{bookAuthCodeId}
,#{sceneId},ifnull(#{bookAuthType},1))
</insert>
<select id="getAuthUserCount" resultType="bookAuthCodeUserVO" parameterType="map">
......@@ -32,6 +34,33 @@
</if>
</select>
<select id="getSceneAuthUserCount" resultType="Integer" parameterType="map">
SELECT
ifnull(COUNT(1),0)
FROM
BOOK_AUTH_USER
WHERE
BOOK_ID = #{bookId, jdbcType=BIGINT}
AND
CHANNEL_ID = #{channelId, jdbcType=BIGINT}
AND
ADVISER_ID = #{adviserId, jdbcType=BIGINT}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
<if test="bookAuthCodeId!=null">
and book_auth_code_id=#{bookAuthCodeId}
</if>
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
</if>
<if test="isGroupBook!=null">
AND
is_group_book = #{isGroupBook}
</if>
</select>
<select id="getAuthUserCountByMonth" resultType="bookAuthCodeUserVO" parameterType="map">
SELECT
COUNT(1) totalCount,
......@@ -66,6 +95,12 @@
<foreach collection="wechatUserIdList" open="(" close=")" item="item" separator="," index="index">
#{item}
</foreach>
<if test="sceneId!=null">
and scene_id=#{sceneId}
</if>
<if test="bookAuthCodeId!=null">
and book_auth_code_id=#{bookAuthCodeId}
</if>
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
......@@ -232,16 +267,22 @@
LIMIT 1
</select>
<select id="getByAuthCodeIds" resultType="com.pcloud.book.copyright.dto.BookAuthUserDTO">
<select id="getByAuthCodeIds" parameterType="map" resultType="com.pcloud.book.copyright.dto.BookAuthUserDTO">
SELECT
id, is_auth_code isAuthCode, created_time createdTime, wechat_user_id wechatUserId, book_auth_code_id bookAuthCodeId
FROM
BOOK_AUTH_USER
WHERE is_auth_code = 0
AND book_auth_code_id IN
<foreach collection="list" item="item" open="(" close=")" separator=",">
<foreach collection="authCodeIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
<!-- <if test="sceneId ==null">
and (book_auth_type=1 or book_auth_type is null)
</if>-->
</select>
</mapper>
......@@ -4,10 +4,10 @@
<insert id="insert" useGeneratedKeys="true" parameterType="bookExportRecord">
INSERT INTO BOOK_EXPORT_RECORD(
BOOK_ID, CHANNEL_ID,ADVISER_ID, BATCH_NUM, CREATED_USER, CREATED_DATE,code_count,is_have_bar_code)
BOOK_ID, CHANNEL_ID,ADVISER_ID, BATCH_NUM, CREATED_USER, CREATED_DATE,code_count,is_have_bar_code,scene_id)
VALUES
(#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},#{batchNum},
#{adviserId}, NOW(),#{codeCount},#{isHaveBarCode})
#{adviserId}, NOW(),#{codeCount},#{isHaveBarCode},#{sceneId})
</insert>
<update id="updateRecordStatus" parameterType="bookAuthInfo" flushCache="true">
......@@ -18,6 +18,9 @@
LAST_MODIFIED_USER = #{lastModifiedUser}
WHERE
BOOK_ID = #{bookId} AND CHANNEL_ID = #{channelId} AND ADVISER_ID = #{adviserId} AND BATCH_NUM = #{batchNum}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
</update>
<update id="updateRecord" parameterType="bookAuthInfo" flushCache="true">
......@@ -29,8 +32,22 @@
LAST_MODIFIED_USER = #{lastModifiedUser}
WHERE
BOOK_ID = #{bookId} AND CHANNEL_ID = #{channelId} AND ADVISER_ID = #{adviserId} AND BATCH_NUM = #{batchNum}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
</update>
<select id="getExportUrl" parameterType="map" resultType="String">
select download_url
from BOOK_EXPORT_RECORD
WHERE
BOOK_ID = #{bookId} AND CHANNEL_ID = #{channelId} AND ADVISER_ID = #{adviserId}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
order by id desc limit 1
</select>
<select id="isHaveExport" resultType="Boolean" parameterType="map">
SELECT
COUNT(1)
......@@ -63,6 +80,9 @@
book_id = #{bookId}
AND channel_id = #{channelId}
AND adviser_id = #{adviserId}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
order by created_date desc
</select>
......
<?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.copyright.dao.impl.BookSceneAuthDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.copyright.entity.BookSceneAuth">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="book_id" property="bookId" jdbcType="INTEGER"/>
<result column="scene_id" property="sceneId" jdbcType="INTEGER"/>
<result column="channel_id" property="channelId" jdbcType="INTEGER"/>
<result column="adviser_id" property="adviserId" jdbcType="INTEGER"/>
<result column="max_user_count" property="maxUserCount" jdbcType="INTEGER"/>
<result column="full_use_tips" property="fullUseTips" jdbcType="VARCHAR"/>
<result column="created_user" property="createdUser" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, book_id, scene_id, channel_id, adviser_id, max_user_count, full_use_tips, created_user, create_time, update_time
</sql>
<select id="getById" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM book_scene_auth
WHERE id = #{id}
</select>
<select id="getList" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM book_scene_auth
</select>
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO book_scene_auth(
book_id,
scene_id,
channel_id,
adviser_id,
max_user_count,
full_use_tips,
created_user,
create_time,
update_time
) VALUES (
#{bookId, jdbcType=INTEGER},
#{sceneId, jdbcType=INTEGER},
#{channelId, jdbcType=INTEGER},
#{adviserId, jdbcType=INTEGER},
#{maxUserCount, jdbcType=INTEGER},
#{fullUseTips, jdbcType=VARCHAR},
#{createdUser, jdbcType=INTEGER},
#{createTime, jdbcType=TIMESTAMP},
#{updateTime, jdbcType=TIMESTAMP}
)
</insert>
<insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO book_scene_auth (
book_id,
scene_id,
channel_id,
adviser_id,
max_user_count,
full_use_tips,
created_user,
create_time,
update_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.bookId, jdbcType=INTEGER},
#{item.sceneId, jdbcType=INTEGER},
#{item.channelId, jdbcType=INTEGER},
#{item.adviserId, jdbcType=INTEGER},
#{item.maxUserCount, jdbcType=INTEGER},
#{item.fullUseTips, jdbcType=VARCHAR},
#{item.createdUser, jdbcType=INTEGER},
#{item.createTime, jdbcType=TIMESTAMP},
#{item.updateTime, jdbcType=TIMESTAMP}
)
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
UPDATE book_scene_auth
<set>
<if test="bookId != null">
book_id = #{bookId},
</if>
<if test="sceneId != null">
scene_id = #{sceneId},
</if>
<if test="channelId != null">
channel_id = #{channelId},
</if>
<if test="adviserId != null">
adviser_id = #{adviserId},
</if>
<if test="maxUserCount != null">
max_user_count = #{maxUserCount},
</if>
<if test="fullUseTips != null and fullUseTips != ''">
full_use_tips = #{fullUseTips},
</if>
<if test="createdUser != null">
created_user = #{createdUser},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
</set>
WHERE id = #{id}
</update>
<update id="batchUpdate" parameterType="list">
<foreach collection="list" index="index" item="item" separator=";">
UPDATE book_scene_auth
<set>
<if test="item.maxUserCount != null">
max_user_count = #{item.maxUserCount},
</if>
<if test="item.fullUseTips != null and item.fullUseTips != ''">
full_use_tips = #{item.fullUseTips},
</if>
update_time = now(),
</set>
WHERE id = #{item.id}
</foreach>
</update>
<!--通过主键删除-->
<delete id="deleteById">
DELETE FROM book_scene_auth WHERE id = #{id}
</delete>
<select id="getAuthSceneInfo" parameterType="map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from book_scene_auth
where book_id=#{bookId}
and scene_id=#{sceneId}
limit 1
</select>
<select id="getAuthSceneIds" parameterType="map" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from book_scene_auth
where book_id=#{bookId}
<if test="sceneIds!=null and sceneIds.size()>0">
and scene_id in
<foreach collection="sceneIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</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.copyright.dao.impl.BookSceneAuthCodeDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.copyright.entity.BookSceneAuthCode">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="book_id" property="bookId" jdbcType="INTEGER"/>
<result column="scene_id" property="sceneId" jdbcType="INTEGER"/>
<result column="channel_id" property="channelId" jdbcType="INTEGER"/>
<result column="adviser_id" property="adviserId" jdbcType="INTEGER"/>
<result column="auth_code" property="authCode" jdbcType="CHAR"/>
<result column="batch_num" property="batchNum" jdbcType="CHAR"/>
<result column="full_code" property="fullCode" jdbcType="CHAR"/>
<result column="use_count" property="useCount" jdbcType="INTEGER"/>
<result column="create_type" property="createType" jdbcType="INTEGER"/>
<result column="created_user" property="createdUser" jdbcType="INTEGER"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="last_modified_user" property="lastModifiedUser" jdbcType="INTEGER"/>
<result column="last_modified_date" property="lastModifiedDate" jdbcType="TIMESTAMP"/>
<result column="is_paper_book" property="isPaperBook" jdbcType="INTEGER"/>
<result column="is_group_book" property="isGroupBook" jdbcType="INTEGER"/>
<result column="url" property="url" jdbcType="CHAR"/>
<result column="qrcode_url" property="qrcodeUrl" jdbcType="CHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, book_id, scene_id, channel_id, adviser_id, auth_code, batch_num, full_code, use_count, create_type, created_user, created_date, last_modified_user, last_modified_date, is_paper_book, is_group_book,url,qrcode_url
</sql>
<select id="getById" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM book_scene_auth_code
WHERE id = #{id}
</select>
<select id="getList" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM book_scene_auth_code
</select>
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO book_scene_auth_code(
book_id,
scene_id,
channel_id,
adviser_id,
auth_code,
batch_num,
full_code,
use_count,
create_type,
created_user,
created_date,
last_modified_user,
last_modified_date,
is_paper_book,
is_group_book
) VALUES (
#{bookId, jdbcType=INTEGER},
#{sceneId, jdbcType=INTEGER},
#{channelId, jdbcType=INTEGER},
#{adviserId, jdbcType=INTEGER},
#{authCode, jdbcType=CHAR},
#{batchNum, jdbcType=CHAR},
#{fullCode, jdbcType=CHAR},
0,
#{createType, jdbcType=INTEGER},
#{createdUser, jdbcType=INTEGER},
now(),
#{lastModifiedUser, jdbcType=INTEGER},
now(),
#{isPaperBook, jdbcType=INTEGER},
#{isGroupBook, jdbcType=INTEGER}
)
</insert>
<insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO book_scene_auth_code (
book_id,
scene_id,
channel_id,
adviser_id,
auth_code,
batch_num,
full_code,
use_count,
create_type,
created_user,
created_date,
last_modified_user,
last_modified_date,
is_paper_book,
is_group_book
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.bookId, jdbcType=INTEGER},
#{item.sceneId, jdbcType=INTEGER},
#{item.channelId, jdbcType=INTEGER},
#{item.adviserId, jdbcType=INTEGER},
#{item.authCode, jdbcType=CHAR},
#{item.batchNum, jdbcType=CHAR},
#{item.fullCode, jdbcType=CHAR},
0,
#{item.createType, jdbcType=INTEGER},
#{item.createdUser, jdbcType=INTEGER},
now(),
#{item.lastModifiedUser, jdbcType=INTEGER},
now(),
#{item.isPaperBook, jdbcType=INTEGER},
#{item.isGroupBook, jdbcType=INTEGER}
)
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
UPDATE book_scene_auth_code
<set>
<if test="bookId != null">
book_id = #{bookId},
</if>
<if test="sceneId != null">
scene_id = #{sceneId},
</if>
<if test="channelId != null">
channel_id = #{channelId},
</if>
<if test="adviserId != null">
adviser_id = #{adviserId},
</if>
<if test="authCode != null and authCode != ''">
auth_code = #{authCode},
</if>
<if test="batchNum != null and batchNum != ''">
batch_num = #{batchNum},
</if>
<if test="fullCode != null and fullCode != ''">
full_code = #{fullCode},
</if>
<if test="useCount != null">
use_count = #{useCount},
</if>
<if test="createType != null">
create_type = #{createType},
</if>
<if test="createdUser != null">
created_user = #{createdUser},
</if>
<if test="createdDate != null">
created_date = #{createdDate},
</if>
<if test="lastModifiedUser != null">
last_modified_user = #{lastModifiedUser},
</if>
<if test="lastModifiedDate != null">
last_modified_date = #{lastModifiedDate},
</if>
<if test="isPaperBook != null">
is_paper_book = #{isPaperBook},
</if>
<if test="isGroupBook != null">
is_group_book = #{isGroupBook},
</if>
</set>
WHERE id = #{id}
</update>
<update id="batchUpdate" parameterType="list">
<foreach collection="list" index="index" item="item" separator=";">
UPDATE book_scene_auth_code
<set>
<if test="item.url != null">
url = #{item.url},
</if>
<if test="item.qrcodeUrl != null">
qrcode_url = #{item.qrcodeUrl},
</if>
</set>
WHERE id = #{item.id}
</foreach>
</update>
<!--通过主键删除-->
<delete id="deleteById">
DELETE FROM book_scene_auth_code WHERE id = #{id}
</delete>
<select id="getMaxBatchNum" resultType="Integer" parameterType="map">
SELECT
IFNULL(max(batch_num), 0)+1
FROM
book_scene_auth_code
WHERE
BOOK_ID = #{bookId}
AND
CHANNEL_ID = #{channelId}
AND
ADVISER_ID = #{adviserId}
and scene_id=#{sceneId}
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
</if>
<if test="isGroupBook!=null">
AND
is_group_book = #{isGroupBook}
</if>
</select>
<select id="listSceneAuthCode" parameterType="map" resultType="com.pcloud.book.copyright.dto.BookAuthCodeDTO">
SELECT
id id,
book_id bookId,
channel_id channelId,
adviser_id adviserId,
auth_code authCode,
batch_num batchNum,
full_code fullCode,
use_count useCount,
create_type createType,
created_date createdDate,
qrcode_url qrcodeUrl
FROM
book_scene_auth_code
WHERE
book_id = #{bookId}
AND channel_id = #{channelId}
AND adviser_id = #{adviserId}
and scene_id=#{sceneId}
<if test="keyword != null">
AND full_code LIKE CONCAT('%', #{keyword}, '%')
</if>
<if test="state != null">
<choose>
<when test="state == 0">
and use_count = 0
</when>
<otherwise>
and use_count > 0
</otherwise>
</choose>
</if>
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
</if>
<if test="isGroupBook!=null">
AND
is_group_book = #{isGroupBook}
</if>
order by created_date desc
</select>
<delete id="deleteSceneAuthCode" parameterType="list">
DELETE FROM book_scene_auth_code
WHERE id in
<foreach collection="list" open="(" item="item" close=")" separator=",">
${item}
</foreach>
AND use_count = 0
</delete>
<select id="getCodeIdList" parameterType="map" resultType="Long">
SELECT
id
FROM
book_scene_auth_code
WHERE
book_id = #{bookId}
AND channel_id = #{channelId}
AND adviser_id = #{adviserId}
and scene_id=#{sceneId}
and use_count = 0
<if test="keyword != null">
AND full_code LIKE CONCAT('%', #{keyword}, '%')
</if>
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
</if>
<if test="isGroupBook!=null">
AND
is_group_book = #{isGroupBook}
</if>
</select>
<select id="getByCode" parameterType="map" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM book_scene_auth_code
WHERE full_code = #{code}
limit 1
</select>
<update id="updateUseCount" parameterType="Long">
UPDATE book_scene_auth_code
SET
use_count = ifnull(use_count,0) + 1,
LAST_MODIFIED_DATE = NOW()
WHERE
id = #{id}
</update>
<select id="getCodeCount" parameterType="map" resultType="com.pcloud.book.copyright.dto.SceneAuthCodeResponseDTO">
select
scene_id sceneId,
ifnull(count(1),0) counts
from book_scene_auth_code
where book_id=#{bookId}
<if test="sceneIds!=null and sceneIds.size()>0">
and scene_id in
<foreach collection="sceneIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
group by scene_id
</select>
<select id="getBookSceneAuthCodeList" parameterType="map" resultType="com.pcloud.book.copyright.dto.BookAuthCodeDTO">
select
book_id bookId,
channel_id channelId,
adviser_id adviserId,
create_type createType,
auth_code authCode,
batch_num batchNum,
full_code fullCode,
ifnull(use_count,0) useCount,
created_date createdDate
from book_scene_auth_code
where book_id= #{bookId,jdbcType=BIGINT} and channel_id = #{channelId} and adviser_id = #{adviserId}
<if test="sceneId !=null">
and scene_id=#{sceneId}
</if>
<if test="isPaperBook != null">
AND
is_paper_book = #{isPaperBook}
</if>
<if test="isGroupBook!=null">
AND
is_group_book = #{isGroupBook}
</if>
LIMIT #{currentPage},#{numPerPage}
</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