Browse Source

后台内容管理开发

master
Jackwang 4 years ago
parent
commit
afa0162d51
  1. 15
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/controller/ModuleTypeController.java
  2. 33
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/controller/NoticeController.java
  3. 10
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/dao/ModuleTypeDao.java
  4. 9
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/dao/NoticeDao.java
  5. 9
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/entity/NoticeEntity.java
  6. 7
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/feign/AdminFeignClient.java
  7. 5
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/feign/fallback/AdminFeignClientFallback.java
  8. 11
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/ModuleTypeService.java
  9. 18
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/NoticeService.java
  10. 89
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/impl/ModuleTypeServiceImpl.java
  11. 74
      epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/impl/NoticeServiceImpl.java
  12. 8
      epdc-cloud-news/src/main/resources/mapper/ModuleTypeDao.xml
  13. 16
      epdc-cloud-news/src/main/resources/mapper/NoticeDao.xml

15
epdc-cloud-news/src/main/java/com/elink/esua/epdc/controller/ModuleTypeController.java

@ -25,6 +25,7 @@ import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.dto.ModuleOption;
import com.elink.esua.epdc.dto.ModuleTypeCategoryDTO;
import com.elink.esua.epdc.dto.ModuleTypeDTO;
import com.elink.esua.epdc.excel.ModuleTypeExcel;
@ -106,4 +107,18 @@ public class ModuleTypeController {
return new Result<List<ModuleTypeCategoryDTO>>().ok(list);
}
/**
* @describe: 根据用户角色获取栏目信息
* @author wangtong
* @date 2021/8/10 14:38
* @params [pid]
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.ModuleOption>
*/
@GetMapping("getModuleListByRole")
public Result<ModuleOption> getModuleListByRole( ) {
ModuleOption moduleOption = moduleTypeService.getModuleListByRole();
return new Result().ok(moduleOption);
}
}

33
epdc-cloud-news/src/main/java/com/elink/esua/epdc/controller/NoticeController.java

@ -23,8 +23,8 @@ import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.commons.tools.validator.AssertUtils;
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.dto.NoticeDTO;
import com.elink.esua.epdc.excel.NoticeExcel;
import com.elink.esua.epdc.service.NoticeService;
@ -111,4 +111,35 @@ public class NoticeController {
return new Result();
}
/**
* @describe: 后台管理-内容发布
* @author wangtong
* @date 2021/8/11 10:25
* @params [dto]
* @return com.elink.esua.epdc.commons.tools.utils.Result
*/
@PostMapping("saveOrUpContent")
public Result saveContent(@RequestBody NoticeDTO dto) {
return noticeService.saveOrUpContent(dto);
}
@PutMapping("saveOrUpContent")
public Result updateContent(@RequestBody NoticeDTO dto) {
return noticeService.saveOrUpContent(dto);
}
/**
* @describe: 后台管理-内容列表
* @author wangtong
* @date 2021/8/11 10:50
* @params [params]
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.commons.tools.page.PageData<com.elink.esua.epdc.dto.ModuleTypeDTO>>
*/
@GetMapping("modulePage")
public Result<PageData<NoticeDTO>> modulePage(@RequestParam Map<String, Object> params){
PageData<NoticeDTO> page = noticeService.modulePage(params);
return new Result<PageData<NoticeDTO>>().ok(page);
}
}

10
epdc-cloud-news/src/main/java/com/elink/esua/epdc/dao/ModuleTypeDao.java

@ -18,6 +18,7 @@
package com.elink.esua.epdc.dao;
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import com.elink.esua.epdc.dto.ModuleOptionDTO;
import com.elink.esua.epdc.entity.ModuleTypeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -44,4 +45,13 @@ public interface ModuleTypeDao extends BaseDao<ModuleTypeEntity> {
List<ModuleTypeEntity> getList(HashMap<Object, Object> params);
ModuleTypeEntity selectInfoById(@Param("id") String id);
/**
* @describe: 根据角色id查询所对应栏目
* @author wangtong
* @date 2021/8/10 16:42
* @params [roleIStrings]
* @return java.util.List<com.elink.esua.epdc.dto.ModuleOptionDTO>
*/
List<ModuleOptionDTO> getModuleListByRole(@Param("roleIStrings") String roleIStrings);
}

9
epdc-cloud-news/src/main/java/com/elink/esua/epdc/dao/NoticeDao.java

@ -109,4 +109,13 @@ public interface NoticeDao extends BaseDao<NoticeEntity> {
* @since 2020/3/7 1:20
*/
void updateDeptNameByDeptId(String newDeptName, Long deptId);
/**
* @describe: 后台管理-内容列表
* @author wangtong
* @date 2021/8/11 11:01
* @params [params]
* @return java.util.List<com.elink.esua.epdc.dto.ModuleTypeDTO>
*/
List<NoticeDTO> getModulePageList(Map<String, Object> params);
}

9
epdc-cloud-news/src/main/java/com/elink/esua/epdc/entity/NoticeEntity.java

@ -104,9 +104,14 @@ public class NoticeEntity extends BaseEpdcEntity {
private String extendFlag;
/**
* 类别编码
* 栏目ID
*/
private String typeCode;
private String typeId;
/**
* 所有栏目id
*/
private String allTypeId;
/**
* 置顶标识 0-1-

7
epdc-cloud-news/src/main/java/com/elink/esua/epdc/feign/AdminFeignClient.java

@ -15,7 +15,9 @@ import java.util.List;
* @email yujintao@elink-cn.com
* @date 2019/9/5 14:44
*/
@FeignClient(name = ServiceConstant.EPDC_ADMIN_SERVER, fallback = AdminFeignClientFallback.class)
@FeignClient(name = ServiceConstant.EPDC_ADMIN_SERVER, fallback = AdminFeignClientFallback.class
,url = "http://127.0.0.1:9092"
)
public interface AdminFeignClient {
/**
@ -51,4 +53,7 @@ public interface AdminFeignClient {
*/
@GetMapping("sys/optimize/deptScope/listByTypeKey/{userId}")
Result<List<Long>> getUserDeptScope(@PathVariable("userId") Long userId, String... typeKeys);
@GetMapping("sys/role/getRoleStringIdsByUserId/{userId}")
Result<String> getRoleStringIdsByUserId(@PathVariable("userId")Long userId);
}

5
epdc-cloud-news/src/main/java/com/elink/esua/epdc/feign/fallback/AdminFeignClientFallback.java

@ -31,4 +31,9 @@ public class AdminFeignClientFallback implements AdminFeignClient {
public Result<List<Long>> getUserDeptScope(Long userId, String... typeKeys) {
return ModuleUtils.feignConError(ServiceConstant.EPDC_ADMIN_SERVER, "getUserDeptScope", typeKeys);
}
@Override
public Result<String> getRoleStringIdsByUserId(Long userId) {
return ModuleUtils.feignConError(ServiceConstant.EPDC_ADMIN_SERVER, "getRoleStringIdsByUserId", userId);
}
}

11
epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/ModuleTypeService.java

@ -19,6 +19,7 @@ package com.elink.esua.epdc.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.dto.ModuleOption;
import com.elink.esua.epdc.dto.ModuleTypeCategoryDTO;
import com.elink.esua.epdc.dto.ModuleTypeDTO;
import com.elink.esua.epdc.entity.ModuleTypeEntity;
@ -103,4 +104,14 @@ public interface ModuleTypeService extends BaseService<ModuleTypeEntity> {
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.util.List<CategoryDTO>>
*/
List<ModuleTypeCategoryDTO> getList(HashMap<Object, Object> params);
/**
* @describe: 根据用户角色获取栏目信息
* @author wangtong
* @date 2021/8/10 14:38
* @params [pid]
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.ModuleOption>
*/
ModuleOption getModuleListByRole( );
}

18
epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/NoticeService.java

@ -159,4 +159,22 @@ public interface NoticeService extends BaseService<NoticeEntity> {
* @since 2020/3/7 1:23
*/
void modifyOrganizationInfo(OrganizationModifyDTO dto);
/**
* @describe: 后台管理-内容发布
* @author wangtong
* @date 2021/8/11 10:25
* @params [dto]
* @return com.elink.esua.epdc.commons.tools.utils.Result
*/
Result saveOrUpContent(NoticeDTO dto);
/**
* @describe: 后台管理-内容列表
* @author wangtong
* @date 2021/8/11 10:50
* @params [params]
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.commons.tools.page.PageData<com.elink.esua.epdc.dto.ModuleTypeDTO>>
*/
PageData<NoticeDTO> modulePage(Map<String, Object> params);
}

89
epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/impl/ModuleTypeServiceImpl.java

@ -17,6 +17,8 @@
package com.elink.esua.epdc.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
@ -24,14 +26,20 @@ import com.elink.esua.epdc.commons.tools.constant.Constant;
import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.commons.tools.exception.RenException;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.commons.tools.utils.TreeUtils;
import com.elink.esua.epdc.dao.ModuleTypeDao;
import com.elink.esua.epdc.dto.ModuleOption;
import com.elink.esua.epdc.dto.ModuleOptionDTO;
import com.elink.esua.epdc.dto.ModuleTypeCategoryDTO;
import com.elink.esua.epdc.dto.ModuleTypeDTO;
import com.elink.esua.epdc.entity.ModuleTypeEntity;
import com.elink.esua.epdc.feign.AdminFeignClient;
import com.elink.esua.epdc.redis.ModuleTypeRedis;
import com.elink.esua.epdc.service.ModuleTypeService;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -51,6 +59,9 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module
@Autowired
private ModuleTypeRedis moduleTypeRedis;
@Autowired
private AdminFeignClient adminFeignClient;
@Override
public PageData<ModuleTypeDTO> page(Map<String, Object> params) {
IPage<ModuleTypeEntity> page = baseDao.selectPage(
@ -184,4 +195,82 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module
return TreeUtils.build(dtoList);
}
@Override
public ModuleOption getModuleListByRole( ) {
Result<String> roleResult = adminFeignClient.getRoleStringIdsByUserId(SecurityUser.getUserId());
if (!roleResult.success()) {
throw new RenException("获取用户角色失败");
}
List<ModuleOptionDTO> deptList = baseDao.getModuleListByRole(roleResult.getData());
JSONObject node;
JSONArray headNodes = new JSONArray();
for (ModuleOptionDTO deptItemDto : deptList) {
if (deptItemDto.getPid().longValue() == 0) {
node = new JSONObject();
node.put("value", deptItemDto.getId());
node.put("label", deptItemDto.getLabel());
headNodes.add(node);
}
}
// 用于存放所有父级节点
JSONArray parent;
parent = headNodes;
// 用于存放所有子级节点
JSONArray allChildren = new JSONArray();
JSONArray children;
// 用于存放单个子级节点
JSONObject childNode;
// 存放其余未处理的类别(节点)
List<ModuleOptionDTO> others = this.getOtherDept(deptList, parent);
while (!others.isEmpty()) {
for (int i = 0; i < parent.size(); i++) {
node = parent.getJSONObject(i);
children = new JSONArray();
for (ModuleOptionDTO categoryTreeDto : others) {
if (categoryTreeDto.getPid().equals(node.get("value"))) {
childNode = new JSONObject();
childNode.put("value", categoryTreeDto.getId());
childNode.put("label", categoryTreeDto.getLabel());
children.add(childNode);
allChildren.add(childNode);
}
}
if (!children.isEmpty()) {
node.put("children", children);
}
}
parent = allChildren;
others = this.getOtherDept(others, parent);
}
//存放到redis中
ModuleOption option = new ModuleOption();
option.setModuleOptions(headNodes);
return option;
}
List<ModuleOptionDTO> getOtherDept(List<ModuleOptionDTO> deptList, JSONArray parent) {
List<Long> already = Lists.newArrayList();
for (int i = 0; i < parent.size(); i++) {
already.add((Long) parent.getJSONObject(i).get("value"));
}
List<ModuleOptionDTO> others = Lists.newArrayList();
for (ModuleOptionDTO categoryTreeDto : deptList) {
Long categoryTreeDtoId = categoryTreeDto.getId();
if (!already.contains(categoryTreeDtoId)) {
others.add(categoryTreeDto);
}
}
return others;
}
}

74
epdc-cloud-news/src/main/java/com/elink/esua/epdc/service/impl/NoticeServiceImpl.java

@ -72,8 +72,9 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
public PageData<NoticeDTO> page(Map<String, Object> params) {
String noticeTitle = (String) params.get("noticeTitle");
params.put("noticeTitle", noticeTitle.trim());
QueryWrapper<NoticeEntity> wrapper = this.getWrapper(params);
// .eq(FieldConstant.CREATED_BY, SecurityUser.getUserId());
QueryWrapper<NoticeEntity> wrapper = this.getWrapper(params)
.eq(FieldConstant.CREATED_BY, SecurityUser.getUserId())
.isNull("type_id");
IPage<NoticeEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
@ -117,6 +118,11 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
public NoticeDTO get(String id) {
NoticeEntity entity = baseDao.selectById(id);
NoticeDTO dto = ConvertUtils.sourceToTarget(entity, NoticeDTO.class);
if(StringUtils.isNotBlank(entity.getTypeId())){
String[] ids = entity.getAllTypeId().split(",");
List<String> moduleTypes = Arrays.asList(ids);
dto.setAllTypeId(moduleTypes);
}
/*if(StringUtils.isNotBlank(dto.getAllDeptIds())){
String[] idsShow = dto.getAllDeptIds().split(",");
List<String> ids = Arrays.asList(idsShow);
@ -244,6 +250,70 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity>
baseDao.updateDeptNameByDeptId(dto.getNewDeptName(), dto.getDeptId());
}
@Override
public Result saveOrUpContent(NoticeDTO dto) {
saveContentOrUpdate(dto);
return new Result().ok("");
}
/**
* @describe: 后台内容管理-新增/更新
* @author wangtong
* @date 2021/8/11 14:19
* @params []
* @return void
*/
private void saveContentOrUpdate(NoticeDTO dto){
UserDetail user = SecurityUser.getUser();
// 通知所属部门(发布者所在部门)
Long noticeDeptId = user.getDeptId();
dto.setCreatorName(user.getRealName());
NoticeEntity entity = ConvertUtils.sourceToTarget(dto, NoticeEntity.class);
entity.setDeptId(noticeDeptId);
entity.setDeptName(user.getDeptName());
entity.setAllTypeId(StringUtils.join(dto.getAllTypeId(), ","));
// 塞入全部部门ids,names
Result<ParentAndAllDeptDTO> parentResult = adminFeignClient.getParentAndAllDept(String.valueOf(noticeDeptId));
if (!parentResult.success() || parentResult.getData() == null) {
throw new RenException("获取用户部门信息失败");
} else {
ParentAndAllDeptDTO deptDTO = parentResult.getData();
entity.setAllDeptIds(deptDTO.getAllDeptIds());
entity.setAllDeptNames(deptDTO.getAllDeptNames());
entity.setParentDeptIds(deptDTO.getParentDeptIds());
entity.setParentDeptNames(deptDTO.getParentDeptNames());
}
List<Long> noticeGridList = NewsUtils.getAllGridId(dto.getAllDeptIdsShow());
boolean isSave = true;
if (StringUtils.isNotBlank(dto.getId())) {
isSave = false;
}
if (isSave) {
entity.setReadingAmount(NumConstant.ZERO);
insert(entity);
} else {
entity.setUpdatedBy(user.getRealName());
entity.setUpdatedTime(new Date());
this.baseDao.updateNoticeById(entity);
noticeDepartmentService.deleteByNoticeId(entity.getId());
}
this.noticeDepartmentService.save(entity.getId(), noticeGridList);
}
@Override
public PageData<NoticeDTO> modulePage(Map<String, Object> params) {
params.put("createdBy", SecurityUser.getUserId());
IPage<NoticeDTO> page = getPage(params);
List<NoticeDTO> list = baseDao.getModulePageList(params);
return new PageData<>(list, page.getTotal());
}
/**
*
* 组织机构信息处理

8
epdc-cloud-news/src/main/resources/mapper/ModuleTypeDao.xml

@ -27,6 +27,14 @@
select t1.*,(select t2.type_name from epdc_module_type t2 where t2.id=t1.pid)parentName from epdc_module_type t1
where t1.id = #{id} and t1.del_flag = 0
</select>
<select id="getModuleListByRole" resultType="com.elink.esua.epdc.dto.ModuleOptionDTO">
select t1.id,t1.pid,t1.id as value,t1.type_name as label
from epdc_module_type t1
left join epdc_role_module rm on rm.MODULE_ID=t1.id
where t1.del_flag = 0
and FIND_IN_SET(rm.ROLE_ID,#{roleIStrings})
order by t1.sort asc
</select>
</mapper>

16
epdc-cloud-news/src/main/resources/mapper/NoticeDao.xml

@ -51,7 +51,9 @@
updated_by = #{updatedBy},
updated_time = #{updatedTime},
dept_id=#{deptId},
dept_name=#{deptName}
dept_name=#{deptName},
TOP_FLAG=#{topFlag},
NOTICE_UP_DOWN_STATE=#{noticeUpDownState}
WHERE id = #{id} AND del_flag = '0'
</update>
@ -94,5 +96,17 @@
<update id="updateDeptNameByDeptId">
UPDATE epdc_notice SET DEPT_NAME = #{newDeptName}, UPDATED_TIME = NOW() WHERE DEPT_ID = #{deptId}
</update>
<select id="getModulePageList" resultType="com.elink.esua.epdc.dto.NoticeDTO">
SELECT en.*,mt.type_name
FROM `epdc_notice` en
left join epdc_module_type mt on mt.id=en.TYPE_ID
where en.CREATED_BY=#{createdBy}
and en.DEL_FLAG='0'
<if test="noticeTitle != null and noticeTitle !=''">
AND en.NOTICE_TITLE like '%${noticeTitle}%'
</if>
and en.type_id is not null
order by en.CREATED_TIME desc
</select>
</mapper>
Loading…
Cancel
Save