Merge remote-tracking branch 'origin/master'

This commit is contained in:
wangliwen 2022-04-27 16:53:12 +08:00
commit f7eff75ad7
10 changed files with 211 additions and 81 deletions

View File

@ -20,9 +20,19 @@ public interface ResourceDao extends BaseDao<ResourceEntity> {
Integer deleteByIds(@Param("ids") List<Long> idList);
List<ResourceDTO> selectWithAttrs(@Param("dto") ResourceDTO resourceDTO);
List<ResourceDTO> selectWithAttrs(@Param("dto") ResourceDTO resourceDTO,
@Param("orderField") String orderField,
@Param("orderType") String orderType);
List<Map> selectTypeCount(Long deptId);
List<ResourceDTO> selectMostPopular(Map<String, Object> selectMap);
ResourceDTO selectDTOById(Long id);
List<ResourceDTO> selectDTOPage(@Param("dto")ResourceDTO resourceDTO,
@Param("pageNum") Integer pageNum,
@Param("pageSize") Integer pageSize,
@Param("orderField")String orderField,
@Param("orderType") String orderType);
}

View File

@ -77,10 +77,14 @@ public class ResourceDTO implements Serializable {
private String deptName;
@ApiModelProperty(value = "收藏标志")
private String isCollect;
@ApiModelProperty(value = "收藏量")
private Integer collectCount;
@ApiModelProperty(value = "评分")
private Long score;
@ApiModelProperty(value = "申请结果")
private String applyState;
@ApiModelProperty(value = "申请量")
private String applyCount;
@ApiModelProperty(value = "属性信息")

View File

@ -1,6 +1,5 @@
package io.renren.modules.resource.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -17,10 +16,11 @@ import io.renren.modules.resource.dto.ResourceDTO;
import io.renren.modules.resource.entity.AttrEntity;
import io.renren.modules.resource.entity.ResourceEntity;
import io.renren.modules.resource.service.ResourceService;
import io.renren.modules.resourceCar.dao.ResourceCarDao;
import io.renren.modules.resourceCollection.dao.ResourceCollectionDao;
import io.renren.modules.resourceScore.dao.ResourceScoreDao;
import io.renren.modules.security.user.SecurityUser;
import io.renren.modules.security.user.UserDetail;
import io.renren.modules.sys.dto.SysDeptDTO;
import io.renren.modules.sys.service.SysDeptService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -41,10 +41,16 @@ import java.util.Map;
public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEntity, ResourceDTO> implements ResourceService {
@Autowired
private SysDeptService sysDeptService;
private ResourceDao resourceDao;
@Autowired
private ResourceDao resourceDao;
private ResourceScoreDao resourceScoreDao;
@Autowired
private ResourceCollectionDao resourceCollectionDao;
@Autowired
private ResourceCarDao resourceCarDao;
@Autowired
private AttrDao attrDao;
@ -91,7 +97,11 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
JSONArray jsonArray = jsonObject.getJSONArray("ids");
List<Long> idList = jsonArray.toJavaList(Long.class);
resourceDao.deleteByIds(idList);
//将所有能力相关表的删除标志都置为1
attrDao.delete4Resource(idList);
resourceCarDao.delete4Resource(idList);
resourceScoreDao.delete4Resource(idList);
resourceCollectionDao.delete4Resource(idList);
}
@Override
@ -112,15 +122,9 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override
public ResourceDTO selectWithAttrs(Long id) {
ResourceDTO resourceDTO = new ResourceDTO();
ResourceEntity resourceEntity = resourceDao.selectById(id);
BeanUtils.copyProperties(resourceEntity, resourceDTO);
SysDeptDTO data = sysDeptService.get(resourceDTO.getDeptId());
if (ObjectUtil.isNotNull(data)) {
resourceDTO.setNote1(data.getName());
}
ResourceDTO resourceDTO = resourceDao.selectDTOById(id);
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
wrapper.eq("data_resource_id", resourceEntity.getId())
wrapper.eq("data_resource_id", id)
.eq("del_f lag", 0);
List<AttrEntity> attrEntities = attrDao.selectList(wrapper);
resourceDTO.setInfoList(attrEntities);
@ -134,32 +138,18 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
Integer pageNum = jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize");
//默认按上架时间降序排列
String orderField = StringUtils.isNotBlank(jsonObject.getString("orderField")) ? "create_time" : jsonObject.getString("orderField");
String orderType = StringUtils.isNotBlank(jsonObject.getString("orderType")) ? "DESC" : jsonObject.getString("orderType");
boolean orderASC = /*orderType.equals("ASC") ? true : */false;
String orderField = StringUtils.isBlank(jsonObject.getString("orderField")) ? "total" : jsonObject.getString("orderField");
String orderType = StringUtils.isBlank(jsonObject.getString("orderType")) ? "DESC" : jsonObject.getString("orderType");
Page<ResourceDTO> resultPage = new Page<>(pageNum, pageSize);
if (resourceDTO.getInfoList().isEmpty()) {
Page<ResourceEntity> page = new Page(pageNum, pageSize);
QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("del_flag", 0)
.like(StringUtils.isNotBlank(resourceDTO.getName()), "name", resourceDTO.getName())
.eq(ObjectUtil.isNotNull(resourceDTO.getDistrictId()), "district_id", resourceDTO.getDistrictId())
.eq(ObjectUtil.isNotNull(resourceDTO.getDeptId()), "dept_id", resourceDTO.getDeptId())
.eq("type", resourceDTO.getType())
.orderBy(true, orderASC, orderField);
Page<ResourceEntity> entityPage = resourceDao.selectPage(page, queryWrapper);
ArrayList<ResourceDTO> list = new ArrayList<>();
entityPage.getRecords().forEach(item -> {
ResourceDTO dto = new ResourceDTO();
BeanUtils.copyProperties(item, dto);
dto.setInfoList(this.selectAttrsByResourceId(dto.getId()));
list.add(dto);
List<ResourceDTO> resourceDTOS = resourceDao.selectDTOPage(resourceDTO, (pageNum - 1)* pageSize, pageSize, orderField, orderType);
resourceDTOS.forEach(item -> {
item.setInfoList(this.selectAttrsByResourceId(item.getId()));
});
resultPage.setRecords(list);
resultPage.setTotal(page.getTotal());
resultPage.setRecords(resourceDTOS);
resultPage.setTotal(resourceDao.selectDTOPage(resourceDTO, 1, 100000, orderField, orderType).size());
} else {
List<ResourceDTO> resourceDTOS = resourceDao.selectWithAttrs(resourceDTO);
List<ResourceDTO> resourceDTOS = resourceDao.selectWithAttrs(resourceDTO , orderField, orderType);
int j = Math.min(pageNum * pageSize, resourceDTOS.size());
if (resourceDTOS.isEmpty()) {
resultPage.setRecords(null);

View File

@ -23,4 +23,6 @@ public interface ResourceCarDao extends BaseDao<ResourceCarEntity> {
List<ResourceCarDTO> selectPageWithResource(@Param("params") Map<String, Object> params,
@Param("pageNum") Integer pageNum,
@Param("pageSize") Integer pageSize);
Integer delete4Resource(@Param("resourceIds") List<Long> idList);
}

View File

@ -23,4 +23,6 @@ public interface ResourceCollectionDao extends BaseDao<ResourceCollectionEntity>
List<ResourceCollectionDTO> selectPageWithResource(@Param("params") Map<String, Object> params,
@Param("pageNum") Integer pageNum,
@Param("pageSize") Integer pageSize);
Integer delete4Resource(@Param("resourceIds") List<Long> idList);
}

View File

@ -5,6 +5,8 @@ import io.renren.modules.resourceScore.entity.ResourceScoreEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 能力评分表
*
@ -15,4 +17,6 @@ import org.apache.ibatis.annotations.Param;
public interface ResourceScoreDao extends BaseDao<ResourceScoreEntity> {
Integer deleteByIds(@Param("ids") Long[] ids);
Integer delete4Resource(@Param("resourceIds") List<Long> idList);
}

View File

@ -60,9 +60,12 @@
<result property="note4" column="note4"/>
<result property="note5" column="note5"/>
<!-- 自定义字段 -->
<result property="deptName" column="dept_name"/>
<result property="isCollect" column="is_collect"/>
<result property="deptName" column="deptName"/>
<result property="isCollect" column="isCollect"/>
<result property="collectCount" column="collectCount"/>
<result property="score" column="score"/>
<result property="applyState" column="applyState"/>
<result property="applyCount" column="applyCount"/>
<collection property="infoList" javaType="List" ofType="attrEntity">
<result property="id" column="id"/>
<result property="dataResourceId" column="data_resource_id"/>
@ -82,11 +85,11 @@
</resultMap>
<update id="deleteByIds">
update tb_data_resource
set del_flag = 1,
update_date = now()
where 1 = 1
and id in
UPDATE tb_data_resource
SET del_flag = 1,
update_date = NOW()
WHERE 1 = 1
AND id IN
<foreach collection="ids" item="item" open="(" separator="," close=")">
#{item}
</foreach>
@ -94,27 +97,42 @@
<select id="selectWithAttrs" resultMap="resourceDTO">
SELECT
r.*,
a.*
tdr.*,
tda.*,
IFNULL(trs.score, 0 ) AS "score",
IFNULL(taa.applyCount, 0 ) AS "applyCount",
IFNULL(trc.collectCount, 0) AS "collectCount",
IFNULL(sd.name, '暂无部门信息') AS "deptName",
IFNULL(trc2.isCollect, 'false') AS "isCollect",
(IFNULL(tdr.visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(taa.applyCount, 0)+ IFNULL(trc.collectCount, 0)) AS total
FROM
tb_data_resource r,
tb_data_attr a
tb_data_resource tdr
LEFT JOIN tb_data_attr tda ON tdr.id = tda.data_resource_id
LEFT JOIN ( SELECT resource_id, AVG(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id
LEFT JOIN ( SELECT resource_id, user_id, ( CASE COUNT( id ) WHEN 1 THEN 'true' ELSE 'false' END ) AS "isCollect" FROM tb_resource_collection WHERE
1 = 1
AND del_flag = 0
AND user_id = #{dto.creator}
GROUP BY resource_id
) trc2 ON tdr.id = trc2.resource_id
LEFT JOIN sys_dept sd ON tdr.dept_id = sd.id
WHERE 1 = 1
AND r.id = a.data_resource_id
AND r.type = #{dto.type}
AND r.del_flag = 0
AND tdr.type = #{dto.type}
AND tdr.del_flag = 0
<if test="dto.name != null and dto.name != ''" >
AND r.name like CONCAT('%',#{dto.name},'%')
AND tdr.name like CONCAT('%',#{dto.name},'%')
</if>
<if test="dto.districtId != null and dto.districtId != ''" >
AND r.district_id = #{dto.districtId}
AND tdr.district_id = #{dto.districtId}
</if>
<if test="dto.deptId != null and dto.deptId != ''" >
AND r.dept_id = #{deptId}
AND tdr.dept_id = #{dto.deptId}
</if>
<if test="dto.infoList.size > 0">
AND
a.data_resource_id IN (
tda.data_resource_id IN (
SELECT data_resource_id
FROM (
SELECT tb.data_resource_id
@ -127,36 +145,38 @@
</foreach>) tb
GROUP BY tb.data_resource_id
HAVING COUNT( tb.data_resource_id ) = ${dto.infoList.size}
ORDER BY tb.data_resource_id ASC
) tmp
)
</if>
ORDER BY ${orderField} ${orderType}
</select>
<select id="selectTypeCount" resultType="java.util.Map">
select type, count(id) as "count"
from tb_data_resource
where 1 = 1
and del_flag = 0
SELECT
type,
count(id) AS "count"
FROM tb_data_resource
WHERE 1 = 1
AND del_flag = 0
<if test="deptId != null and deptId != ''">
and dept_id = #{deptId}
AND dept_id = #{deptId}
</if>
group by type
order by type
GROUP BY type
ORDER BY type
</select>
<select id="selectMostPopular" resultType="io.renren.modules.resource.dto.ResourceDTO">
SELECT
tdr.*,
trs.score,
taa.applyCount,
trc.collectCount,
(IFNULL(visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(applyCount,0)+ IFNULL(collectCount,0)) as total
IFNULL(trs.score, 0 ) AS "score",
IFNULL(taa.applyCount, 0 ) AS "applyCount",
IFNULL(trc.collectCount, 0) AS "collectCount",
(IFNULL(visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(applyCount,0)+ IFNULL(collectCount,0)) AS total
FROM
tb_data_resource tdr
LEFT JOIN ( SELECT resource_id, SUM(score) AS "score" FROM tb_resource_score WHERE 1 = 1 and del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 and del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 and del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id
LEFT JOIN ( SELECT resource_id, SUM(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id
WHERE
1 = 1
AND tdr.del_flag = 0
@ -169,4 +189,69 @@
ORDER BY ${orderFiled} ${orderType}
LIMIT ${pageNum}, ${pageSize}
</select>
<select id="selectDTOById" resultType="io.renren.modules.resource.dto.ResourceDTO">
SELECT
tdr.*,
tda.*,
IFNULL(trs.score, 0 ) AS "score",
IFNULL(taa.applyCount, 0 ) AS "applyCount",
IFNULL(trc.collectCount, 0) AS "collectCount",
sd.name as "deptName",
IFNULL(trc2.isCollect, 'false') AS "isCollect",
IFNULL(taa2.applyState, 'false') AS "applyState"
FROM
tb_data_resource tdr
LEFT JOIN tb_data_attr tda ON tdr.id = tda.data_resource_id
LEFT JOIN ( SELECT resource_id, AVG(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id
LEFT JOIN ( SELECT resource_id, user_id, ( CASE COUNT( id ) WHEN 1 THEN 'true' ELSE 'false' END ) AS "isCollect" FROM tb_resource_collection WHERE
1 = 1 AND del_flag = 0 AND user_id = #{dto.creator}
GROUP BY resource_id) trc2 ON tdr.id = trc2.resource_id
LEFT JOIN ( SELECT resource_id, user_id, ( CASE approve_status WHEN '通过' THEN 'true' ELSE 'false' END ) AS "applyState" FROM t_ability_application WHERE
1 = 1 AND del_flag = 0 AND user_id = #{dto.creator}
GROUP BY resource_id) taa2 ON tdr.id = taa2.resource_id
LEFT JOIN sys_dept sd ON tdr.dept_id = sd.id
WHERE 1 = 1
AND tdr.del_flag = 0
AND tdr.id = #{id}
</select>
<select id="selectDTOPage" resultType="io.renren.modules.resource.dto.ResourceDTO">
SELECT
tdr.*,
IFNULL(trs.score, 0 ) AS "score",
IFNULL(taa.applyCount, 0 ) AS "applyCount",
IFNULL(trc.collectCount, 0) AS "collectCount",
sd.name AS "deptName",
IFNULL(trc2.isCollect, 'false') AS "isCollect",
IFNULL(taa2.applyState, 'false') AS "applyState",
(IFNULL(visits / 100, 0) + IFNULL(trs.score, 0) + IFNULL(applyCount,0)+ IFNULL(collectCount,0)) AS total
FROM
tb_data_resource tdr
LEFT JOIN ( SELECT resource_id, AVG(score) AS "score" FROM tb_resource_score WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trs ON tdr.id = trs.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "applyCount" FROM t_ability_application WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) taa ON tdr.id = taa.resource_id
LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 AND del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id
LEFT JOIN ( SELECT resource_id, user_id, ( CASE COUNT( id ) WHEN 1 THEN 'true' ELSE 'false' END ) AS "isCollect" FROM tb_resource_collection WHERE
1 = 1 AND del_flag = 0 AND user_id = #{dto.creator}
GROUP BY resource_id) trc2 ON tdr.id = trc2.resource_id
LEFT JOIN ( SELECT resource_id, user_id, ( CASE approve_status WHEN '通过' THEN 'true' ELSE 'false' END ) AS "applyState" FROM t_ability_application WHERE
1 = 1 AND del_flag = 0 AND user_id = #{dto.creator}
GROUP BY id) taa2 ON tdr.id = taa2.resource_id
LEFT JOIN sys_dept sd ON tdr.dept_id = sd.id
WHERE 1 = 1
AND tdr.del_flag = 0
<if test="dto.name != null and dto.name != ''" >
AND tdr.name LIKE CONCAT('%',#{dto.name},'%')
</if>
<if test="dto.type != null and dto.type != ''" >
AND tdr.type = #{dto.type}
</if>
<if test="dto.districtId != null and dto.districtId != ''" >
AND tdr.district_id = #{dto.districtId}
</if>
ORDER BY ${orderField} ${orderType}
LIMIT ${pageNum}, ${pageSize}
</select>
</mapper>

View File

@ -30,6 +30,17 @@
</foreach>
</update>
<update id="delete4Resource">
update tb_resource_car
set del_flag = 1,
update_date = now()
where 1 = 1
and resource_id in
<foreach collection="resourceIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
<select id="selectPageWithResource" resultType="io.renren.modules.resourceCar.dto.ResourceCarDTO">
select trc.*
from tb_resource_car trc

View File

@ -30,6 +30,17 @@
</foreach>
</update>
<update id="delete4Resource">
update tb_resource_collection
set del_flag = 1,
update_date = now()
where 1 = 1
and resource_id in
<foreach collection="resourceIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
<select id="selectPageWithResource" resultType="io.renren.modules.resourceCollection.dto.ResourceCollectionDTO">
select trc.*
from tb_resource_collection trc

View File

@ -32,4 +32,15 @@
</foreach>
</update>
<update id="delete4Resource">
update tb_resource_score
set del_flag = 1,
update_date = now()
where 1 = 1
and resource_id in
<foreach collection="resourceIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
</mapper>