Commit da50c977 by 阮思源

Merge branch 'feat-youhua' into 'master'

接口优化

See merge request rays/pcloud-book!500
parents dddc4adf b0c52e3b
......@@ -28,6 +28,7 @@ import com.pcloud.book.push.dao.SelfPushItemDao;
import com.pcloud.book.push.dao.SelfPushUserDao;
import com.pcloud.book.push.dto.SelfPushAddParamDTO;
import com.pcloud.book.push.dto.SelfPushRecordDTO;
import com.pcloud.book.push.dto.UserCountAndPushDTO;
import com.pcloud.book.push.entity.SelfPush;
import com.pcloud.book.push.entity.SelfPushItem;
import com.pcloud.book.push.entity.SelfPushUser;
......@@ -530,11 +531,8 @@ public class SelfPushBizImpl implements SelfPushBiz {
}else{
dto.setRealSendTime(DateUtils.formatDate(dto.getSendTime(),"yyyy-MM-dd HH:mm:ss"));
}
List<SelfPushItem> selfPushItemList = selfPushItemDao.getByPushId(dto.getPushId());
this.fillItem(selfPushItemList);
dto.setSelfPushItemList(selfPushItemList);
}
fillPushItemsAndBookName(pageBeanNew.getRecordList());
List<String> wxIds = pageBeanNew.getRecordList().stream().filter(s -> !StringUtil.isEmpty(s.getAltId())).map(SelfPushRecordDTO::getAltId).distinct().collect(Collectors.toList());
Map<String, GroupUserDTO> robotMap = new HashMap<>();
Map<String, RobotClassifyDTO> robotClassifyDTOMap =new HashMap<>();
......@@ -555,8 +553,6 @@ public class SelfPushBizImpl implements SelfPushBiz {
}
}
for (SelfPushRecordDTO dto : pageBeanNew.getRecordList()) {
Integer userCount = selfPushUserDao.getCountByPushId(dto.getPushId());
dto.setUserCount(userCount);
if (!MapUtils.isEmpty(robotMap) && !StringUtil.isEmpty(dto.getAltId()) && robotMap.containsKey(dto.getAltId())) {
GroupUserDTO userDTO = robotMap.get(dto.getAltId());
dto.setRobotName(userDTO.getNickName());
......@@ -567,10 +563,6 @@ public class SelfPushBizImpl implements SelfPushBiz {
dto.setClassifyName(null!=robotClassifyDTO?robotClassifyDTO.getClassifyName():null);
dto.setUniqueNumber(null!=robotClassifyDTO?robotClassifyDTO.getUniqueNumber():null);
}
if (null != dto.getBookGroupId()){
BookGroupDTO bookGroupDTO = bookGroupDao.getBookBaseInfoById(dto.getBookGroupId());
dto.setBookName(bookGroupDTO.getBookName());
}
if (!StringUtil.isEmpty(dto.getAltId())){//平台端登录账号
if (dto.getCreateUser() == 0L){
dto.setUserName("pcloud");
......@@ -583,6 +575,42 @@ public class SelfPushBizImpl implements SelfPushBiz {
return pageBeanNew;
}
private void fillPushItemsAndBookName(List<SelfPushRecordDTO> recordList) {
List<Long> pushIds=new ArrayList<>();
List<Long> bookGroupIds=new ArrayList<>();
for (SelfPushRecordDTO dto:recordList) {
if (null != dto.getBookGroupId()&&!bookGroupIds.contains(dto.getBookGroupId())){
bookGroupIds.add(dto.getBookGroupId());
}
if (null != dto.getPushId()&&!pushIds.contains(dto.getPushId())){
pushIds.add(dto.getPushId());
}
}
Map<Long,List<SelfPushItem>> itemMap=new HashMap<>();
Map<Long,String> bookNameMap=new HashMap<>();
Map<Long,Integer> userCountMap=new HashMap<>();
if (!ListUtils.isEmpty(pushIds)){
List<SelfPushItem> selfPushItemList = selfPushItemDao.getByPushIds(pushIds);
this.fillItem(selfPushItemList);
itemMap=selfPushItemList.stream().collect(Collectors.groupingBy(SelfPushItem::getPushId));
List<UserCountAndPushDTO> userCountList = selfPushUserDao.getCountByPushIds(pushIds);
for (UserCountAndPushDTO userCountAndPushDTO:userCountList){
userCountMap.put(userCountAndPushDTO.getPushId(),userCountAndPushDTO.getUserCount());
}
}
if (!ListUtils.isEmpty(bookGroupIds)){
List<BookGroupDTO> infos = bookGroupDao.getBookBaseInfoByIds(bookGroupIds);
for (BookGroupDTO bookGroupDTO:infos){
bookNameMap.put(bookGroupDTO.getId(),bookGroupDTO.getBookName());
}
}
for (SelfPushRecordDTO dto:recordList) {
dto.setSelfPushItemList(itemMap.get(dto.getPushId()));
dto.setBookName(bookNameMap.get(dto.getBookGroupId()));
dto.setUserCount(userCountMap.get(dto.getPushId()));
}
}
private void fillItem(List<SelfPushItem> list) {
if (ListUtils.isEmpty(list)){
return;
......
......@@ -30,4 +30,6 @@ public interface SelfPushItemDao extends BaseDao<SelfPushItem>{
public void deleteByPushId(Long pushId);
Integer getStatusByPushId(Long pushId);
List<SelfPushItem> getByPushIds(List<Long> pushIds);
}
package com.pcloud.book.push.dao;
import com.pcloud.book.push.dto.UserCountAndPushDTO;
import com.pcloud.book.push.entity.SelfPushUser;
import com.pcloud.common.core.dao.BaseDao;
......@@ -28,4 +29,6 @@ public interface SelfPushUserDao extends BaseDao<SelfPushUser>{
List<String> getUserIdListByPushId(Long pushId);
public void deleteByPushId(Long pushId);
List<UserCountAndPushDTO> getCountByPushIds(List<Long> pushIds);
}
......@@ -43,4 +43,11 @@ public class SelfPushItemDaoImpl extends BaseDaoImpl<SelfPushItem> implements Se
map.put("pushId", pushId);
return getSessionTemplate().selectOne(getStatement("getStatusByPushId"), map);
}
@Override
public List<SelfPushItem> getByPushIds(List<Long> pushIds) {
Map<String, Object> map = new HashMap<>();
map.put("pushIds", pushIds);
return getSessionTemplate().selectList(getStatement("getByPushIds"), map);
}
}
package com.pcloud.book.push.dao.impl;
import com.pcloud.book.push.dao.SelfPushUserDao;
import com.pcloud.book.push.dto.UserCountAndPushDTO;
import com.pcloud.book.push.entity.SelfPushUser;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @描述:
......@@ -31,4 +34,11 @@ public class SelfPushUserDaoImpl extends BaseDaoImpl<SelfPushUser>implements Sel
public void deleteByPushId(Long pushId) {
getSessionTemplate().delete(getStatement("deleteByPushId"), pushId);
}
@Override
public List<UserCountAndPushDTO> getCountByPushIds(List<Long> pushIds) {
Map<String, Object> map = new HashMap<>();
map.put("pushIds", pushIds);
return getSessionTemplate().selectList(getStatement("getCountByPushIds"), map);
}
}
package com.pcloud.book.push.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class UserCountAndPushDTO {
@ApiModelProperty("群发id")
private Long pushId;
@ApiModelProperty("数量")
private Integer userCount;
}
......@@ -175,4 +175,13 @@
group by push_id
</select>
<select id="getByPushIds" parameterType="map" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM self_push_item
WHERE push_id in
<foreach collection="pushIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
</select>
</mapper>
\ No newline at end of file
......@@ -72,4 +72,18 @@
WHERE push_id = #{pushId}
</delete>
<select id="getCountByPushIds" resultType="com.pcloud.book.push.dto.UserCountAndPushDTO" parameterType="map">
SELECT
COUNT(1) userCount,
push_id pushId
FROM
self_push_user
WHERE
push_id in
<foreach collection="pushIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
group by push_id
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment