Commit 9ec670ff by 田超

Merge branch 'feature/1005111-back' into 'master'

feat: [1005111] 分享收藏

See merge request rays/pcloud-book!1375
parents 1f451baa fc329f81
...@@ -36,7 +36,7 @@ public interface ServeCollectBiz { ...@@ -36,7 +36,7 @@ public interface ServeCollectBiz {
* @param serveCollect 实例对象 * @param serveCollect 实例对象
* @return 主键 * @return 主键
*/ */
AppletTaskDTO insert(ServeCollect serveCollect); String insert(ServeCollect serveCollect);
/** /**
* 修改数据 * 修改数据
...@@ -123,4 +123,18 @@ public interface ServeCollectBiz { ...@@ -123,4 +123,18 @@ public interface ServeCollectBiz {
*/ */
void processingData2TypeCode(); void processingData2TypeCode();
/**
* 取消收藏
* @param serveCollect
*/
void cancel(ServeCollect serveCollect);
/**
* 获取收藏状态 true 收藏 false 未收藏
* @param wechatUserId
* @param serverId
* @param serveType
* @return
*/
Boolean getCollectState(Long wechatUserId, Long serverId, Integer serveType);
} }
\ No newline at end of file
...@@ -28,11 +28,14 @@ import com.pcloud.book.group.enums.AppAndProductTypeEnum; ...@@ -28,11 +28,14 @@ import com.pcloud.book.group.enums.AppAndProductTypeEnum;
import com.pcloud.book.group.tools.SendWeixinRequestTools; import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.util.common.ThreadPoolUtils; import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.book.util.common.YesOrNoEnums; import com.pcloud.book.util.common.YesOrNoEnums;
import com.pcloud.channelcenter.qrcode.dto.GroupQrcodeVO;
import com.pcloud.channelcenter.wechat.dto.AccountSettingDto; import com.pcloud.channelcenter.wechat.dto.AccountSettingDto;
import com.pcloud.channelcenter.wechat.entity.AccountSetting;
import com.pcloud.common.core.aspect.ParamLog; import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew; import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam; import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.BeanUtils;
import com.pcloud.common.utils.ListUtils; import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil; import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.string.StringUtil; import com.pcloud.common.utils.string.StringUtil;
...@@ -46,6 +49,7 @@ import com.pcloud.resourcecenter.product.dto.ProductTypeDto; ...@@ -46,6 +49,7 @@ import com.pcloud.resourcecenter.product.dto.ProductTypeDto;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
...@@ -88,6 +92,8 @@ public class ServeCollectBizImpl implements ServeCollectBiz { ...@@ -88,6 +92,8 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
private ReaderConsr readerConsr; private ReaderConsr readerConsr;
@Autowired @Autowired
private BookDao bookDao; private BookDao bookDao;
@Value("${operate_official_id}")
private Long operateOfficialId;
@Override @Override
...@@ -100,7 +106,7 @@ public class ServeCollectBizImpl implements ServeCollectBiz { ...@@ -100,7 +106,7 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
@ParamLog("查询多条数据") @ParamLog("查询多条数据")
public PageBeanNew getList(Long wechatUserId, Integer currentPage, Integer numPerPage, String typeCode, public PageBeanNew getList(Long wechatUserId, Integer currentPage, Integer numPerPage, String typeCode,
Long officialAccountsId) { Long officialAccountsId) {
List<Long> wechatUserIds = readerConsr.getRelateUserIdList(wechatUserId, officialAccountsId); List<Long> wechatUserIds = readerConsr.getAllUnionUser(wechatUserId);
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
paramMap.put("wechatUserIds", wechatUserIds); paramMap.put("wechatUserIds", wechatUserIds);
paramMap.put("typeCode",typeCode); paramMap.put("typeCode",typeCode);
...@@ -308,31 +314,26 @@ public class ServeCollectBizImpl implements ServeCollectBiz { ...@@ -308,31 +314,26 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
@Override @Override
@ParamLog("新增收藏") @ParamLog("新增收藏")
public AppletTaskDTO insert(ServeCollect serveCollect) { public String insert(ServeCollect serveCollect) {
paramCheck(serveCollect); paramCheck(serveCollect);
fillParam(serveCollect); fillParam(serveCollect);
AppletTaskDTO appletTaskDTO = new AppletTaskDTO(); List<Long> allUnionUserIds = readerConsr.getAllUnionUser(serveCollect.getWechatUserId());
ServeCollect collected = serveCollectDao.getCollectByUser(allUnionUserIds, serveCollect.getServeId(), serveCollect.getServeType());
if (null != collected) {
if (YesOrNoNumEnum.YES.getValue().equals(collected.getIsDelete())) {
//删除状态,则更新状态为收藏
collected.setIsDelete(YesOrNoNumEnum.NO.getValue());
serveCollectDao.update(collected);
}
} else {
//不存在则新增
if (StringUtil.isEmpty(serveCollect.getServeTypeName())) { if (StringUtil.isEmpty(serveCollect.getServeTypeName())) {
fillTypeCodeAndTypeName(Lists.newArrayList(serveCollect)); fillTypeCodeAndTypeName(Lists.newArrayList(serveCollect));
} }
serveCollectDao.insert(serveCollect); serveCollectDao.insert(serveCollect);
Integer taskCount = readerConsr.getTaskCount(serveCollect.getWechatUserId(), MoneyReceiveTypeEnum.COLLECTION.key);
Integer subtractTaskCount = RmallContants.COLLECTION_MONEY_TIMES - 1;
Integer isFinish = 0;
if (null != taskCount && subtractTaskCount.equals(taskCount)) {
isFinish = 1;
}
appletTaskDTO.setIsFinishTask(isFinish);
RMALL_SIGN_IN.execute(()->{
//收藏埋点
if (null == serveCollect.getIsDelete() || YesOrNoNumEnum.NO.getValue().equals(serveCollect.getIsDelete())){
RmallBookMoneyRecord rmallBookMoneyRecord = new RmallBookMoneyRecord();
rmallBookMoneyRecord.setWechatUserId(serveCollect.getWechatUserId());
rmallBookMoneyRecord.setRecordType(MoneyReceiveTypeEnum.COLLECTION.key);
rmallBookMoneyRecordService.insert(rmallBookMoneyRecord);
} }
}); AccountSetting appInfo = qrcodeSceneConsr.getAppInfo(operateOfficialId);
return appletTaskDTO; return null != appInfo ? appInfo.getQrcodeUrl() : "https://oss.5rs.me/oss/uploadfe/jpg/5962646df4abeb5ece0b7037be4f3e6a.jpg";
} }
private void fillParam(ServeCollect serveCollect) { private void fillParam(ServeCollect serveCollect) {
...@@ -414,7 +415,7 @@ public class ServeCollectBizImpl implements ServeCollectBiz { ...@@ -414,7 +415,7 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
LOGGER.error("[ServeCollectBizImpl.isCollected]参数为空,wechatUserId:{} serverId:{}",wechatUserId,serverId); LOGGER.error("[ServeCollectBizImpl.isCollected]参数为空,wechatUserId:{} serverId:{}",wechatUserId,serverId);
throw BizException.PARAM_IS_NULL; throw BizException.PARAM_IS_NULL;
} }
ServeCollectDTO collected = serveCollectDao.isCollected(wechatUserId, serverId); ServeCollectDTO collected = serveCollectDao.isCollected(wechatUserId, serverId, AppletRecordTypeEnum.NEWS.value);
if (null == collected){ if (null == collected){
ServeCollectDTO serveCollectDTO = new ServeCollectDTO(); ServeCollectDTO serveCollectDTO = new ServeCollectDTO();
serveCollectDTO.setIsCollected(0); serveCollectDTO.setIsCollected(0);
...@@ -545,6 +546,26 @@ public class ServeCollectBizImpl implements ServeCollectBiz { ...@@ -545,6 +546,26 @@ public class ServeCollectBizImpl implements ServeCollectBiz {
} }
} }
@Override
@ParamLog("取消收藏")
public void cancel(ServeCollect serveCollect) {
paramCheck(serveCollect);
List<Long> allUnionUserIds = readerConsr.getAllUnionUser(serveCollect.getWechatUserId());
List<ServeCollect> serveCollects = serveCollectDao.getCollectList(allUnionUserIds, serveCollect.getServeId(), serveCollect.getServeType(), null);
if (ListUtils.isEmpty(serveCollects)) {
return;
}
List<Long> ids = serveCollects.stream().map(e -> e.getId()).collect(Collectors.toList());
serveCollectDao.cancelCollect(ids);
}
@Override
public Boolean getCollectState(Long wechatUserId, Long serverId, Integer serveType) {
List<Long> allUnionUserIds = readerConsr.getAllUnionUser(wechatUserId);
List<ServeCollect> collectList = serveCollectDao.getCollectList(allUnionUserIds, serverId, serveType, YesOrNoNumEnum.NO.getValue());
return ListUtils.isEmpty(collectList) ? Boolean.FALSE : Boolean.TRUE;
}
private void fillTypeCodeAndTypeName(List<ServeCollect> recordList){ private void fillTypeCodeAndTypeName(List<ServeCollect> recordList){
List<Long> newsIdList = recordList.stream().filter(serveCollect -> AppletRecordTypeEnum.NEWS.value.equals(serveCollect.getServeType())). List<Long> newsIdList = recordList.stream().filter(serveCollect -> AppletRecordTypeEnum.NEWS.value.equals(serveCollect.getServeType())).
map(serveCollect -> serveCollect.getServeId()).collect(Collectors.toList()); map(serveCollect -> serveCollect.getServeId()).collect(Collectors.toList());
......
...@@ -31,7 +31,7 @@ public interface ServeCollectDao extends BaseDao<ServeCollect> { ...@@ -31,7 +31,7 @@ public interface ServeCollectDao extends BaseDao<ServeCollect> {
List<CollectionTypeNameAndCountDTO> getTypeNameAndCountByWechatId(List<Long> wechatUserIds ); List<CollectionTypeNameAndCountDTO> getTypeNameAndCountByWechatId(List<Long> wechatUserIds );
ServeCollectDTO isCollected(Long wechatUserId,Long serveId ); ServeCollectDTO isCollected(Long wechatUserId, Long serveId, Integer serveType);
List<CollectionTypeNameCodeClassifyVO> getDistinctTypeCode(); List<CollectionTypeNameCodeClassifyVO> getDistinctTypeCode();
...@@ -40,4 +40,8 @@ public interface ServeCollectDao extends BaseDao<ServeCollect> { ...@@ -40,4 +40,8 @@ public interface ServeCollectDao extends BaseDao<ServeCollect> {
List<ServeCollect> List2ProcessedData(); List<ServeCollect> List2ProcessedData();
void batchUpdate(List<ServeCollect> serveCollectList); void batchUpdate(List<ServeCollect> serveCollectList);
ServeCollect getCollectByUser(List<Long> wechatUserId, Long serveId, Integer serveType);
List<ServeCollect> getCollectList(List<Long> allUnionUserIds, Long serveId, Integer serveType, Integer isDelete);
} }
\ No newline at end of file
...@@ -48,10 +48,11 @@ public class ServeCollectDaoImpl extends BaseDaoImpl<ServeCollect> implements Se ...@@ -48,10 +48,11 @@ public class ServeCollectDaoImpl extends BaseDaoImpl<ServeCollect> implements Se
} }
@Override @Override
public ServeCollectDTO isCollected(Long wechatUserId, Long serveId) { public ServeCollectDTO isCollected(Long wechatUserId, Long serveId, Integer serveType) {
Map<String, Object> paraMap = new HashMap<>(); Map<String, Object> paraMap = new HashMap<>();
paraMap.put("wechatUserId",wechatUserId); paraMap.put("wechatUserId",wechatUserId);
paraMap.put("serveId",serveId); paraMap.put("serveId",serveId);
paraMap.put("serveType",serveType);
return getSessionTemplate().selectOne(getStatement("isCollected"),paraMap); return getSessionTemplate().selectOne(getStatement("isCollected"),paraMap);
} }
...@@ -76,6 +77,25 @@ public class ServeCollectDaoImpl extends BaseDaoImpl<ServeCollect> implements Se ...@@ -76,6 +77,25 @@ public class ServeCollectDaoImpl extends BaseDaoImpl<ServeCollect> implements Se
} }
@Override @Override
public ServeCollect getCollectByUser(List<Long> wechatUserIds, Long serveId, Integer serveType) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("wechatUserIds", wechatUserIds);
paramMap.put("serveId", serveId);
paramMap.put("serveType", serveType);
return getSessionTemplate().selectOne(getStatement("getCollectByUser"), paramMap);
}
@Override
public List<ServeCollect> getCollectList(List<Long> wechatUserIds, Long serveId, Integer serveType, Integer isDelete) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("wechatUserIds", wechatUserIds);
paramMap.put("serveId", serveId);
paramMap.put("serveType", serveType);
paramMap.put("isDelete", isDelete);
return getSessionTemplate().selectList(getStatement("getCollectList"), paramMap);
}
@Override
public List<Long> getAllCollect(List<Long> wechatUserIds,String typeCode) { public List<Long> getAllCollect(List<Long> wechatUserIds,String typeCode) {
Map<String, Object> paramMap = new HashMap<>(); Map<String, Object> paramMap = new HashMap<>();
paramMap.put("wechatUserIds",wechatUserIds); paramMap.put("wechatUserIds",wechatUserIds);
......
...@@ -75,6 +75,17 @@ public class ServeCollectFacade { ...@@ -75,6 +75,17 @@ public class ServeCollectFacade {
return new ResponseDto<>(serveCollectBiz.insert(serveCollect)); return new ResponseDto<>(serveCollectBiz.insert(serveCollect));
} }
@ApiOperation("取消收藏")
@PostMapping("cancel")
public ResponseDto<?> cancel(@CookieValue("userInfo") String userInfo, @RequestBody ServeCollect serveCollect)
throws BizException, PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
serveCollect.setWechatUserId(wechatUserId);
serveCollectBiz.cancel(serveCollect);
return new ResponseDto<>();
}
@ApiOperation("更新") @ApiOperation("更新")
@PostMapping("update") @PostMapping("update")
public ResponseDto<?> update(@CookieValue("userInfo") String userInfo, @RequestBody ServeCollect serveCollect) throws BizException, PermissionException { public ResponseDto<?> update(@CookieValue("userInfo") String userInfo, @RequestBody ServeCollect serveCollect) throws BizException, PermissionException {
...@@ -158,4 +169,13 @@ public class ServeCollectFacade { ...@@ -158,4 +169,13 @@ public class ServeCollectFacade {
serveCollectBiz.processingData2TypeCode(); serveCollectBiz.processingData2TypeCode();
return new ResponseDto<>(); return new ResponseDto<>();
} }
@ApiOperation("查询应用作品收藏状态")
@GetMapping("getCollectState")
public ResponseDto<?> getCollectState(@CookieValue("userInfo") String userInfo,
@RequestParam("serverId") Long serverId,
@RequestParam("serveType") Integer serveType) {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
return new ResponseDto<>(serveCollectBiz.getCollectState(wechatUserId, serverId, serveType));
}
} }
\ No newline at end of file
...@@ -103,16 +103,7 @@ ...@@ -103,16 +103,7 @@
#{bookId, jdbcType=BIGINT}, #{bookId, jdbcType=BIGINT},
#{adviserId, jdbcType=BIGINT}, #{adviserId, jdbcType=BIGINT},
#{channelId, jdbcType=BIGINT} #{channelId, jdbcType=BIGINT}
) on duplicate key )
update
update_time = now(),
collect_day = CURDATE(),
book_id =#{bookId, jdbcType=BIGINT},
adviser_id =#{adviserId, jdbcType=BIGINT},
channel_id =#{channelId, jdbcType=BIGINT}
<if test="isDelete != null">
, is_delete = #{isDelete}
</if>
</insert> </insert>
<insert id="batchInsert"> <insert id="batchInsert">
...@@ -325,6 +316,8 @@ ...@@ -325,6 +316,8 @@
and and
serve_id = #{serveId} serve_id = #{serveId}
and and
serve_type = #{serveType}
and
is_delete = 0 is_delete = 0
LIMIT 1 LIMIT 1
</select> </select>
...@@ -372,4 +365,42 @@ ...@@ -372,4 +365,42 @@
where id = #{item.id} where id = #{item.id}
</foreach> </foreach>
</update> </update>
<select id="getCollectByUser" parameterType="map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
serve_collect
where
wechat_user_id
in
<foreach collection="wechatUserIds" index="index" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
and
serve_id = #{serveId}
and
serve_type = #{serveType}
LIMIT 1
</select>
<select id="getCollectList" parameterType="map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
serve_collect
where
wechat_user_id
in
<foreach collection="wechatUserIds" index="index" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
and
serve_id = #{serveId}
and
serve_type = #{serveType}
<if test="isDelete != null">
and is_delete = #{isDelete}
</if>
</select>
</mapper> </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