소스 검색

菜单和撤回功能

shiqian 4 년 전
부모
커밋
e71ad5e366

+ 11 - 11
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysMenuServiceImpl.java

@@ -140,7 +140,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
         SysMenu menu = selectMenuById(menuId);
         List<SysMenu> menus = menuMapper.selectMenuList(new SysMenu());
         List<SysMenu> sysMenus = recChildList(menus, menu, tempList);
-        return ObjectUtils.filter(sysMenus, menu1 -> SysMenu.BUTTON.equals(menu1.getMenuType()));
+//        return ObjectUtils.filter(sysMenus, menu1 -> SysMenu.BUTTON.equals(menu1.getMenuType()));
+        return sysMenus;
     }
 
     private List<SysMenu> recChildList(List<SysMenu> menus, SysMenu menu, List<SysMenu> tempList) {
@@ -520,7 +521,11 @@ public class SysMenuServiceImpl implements ISysMenuService {
     private void recursionFn(List<SysMenu> list, SysMenu t) {
         // 得到子节点列表
         List<SysMenu> childList = getChildList(list, t);
-        t.setChildren(childList);
+        if (isNotEmpty(childList)) {
+            List<SysMenu> filter = filter(childList, menu -> !SysMenu.BUTTON.equals(menu.getMenuType()));
+            t.setChildren(filter);
+        }
+
         for (SysMenu tChild : childList) {
             if (hasChild(list, tChild)) {
                 recursionFn(list, tChild);
@@ -670,25 +675,20 @@ public class SysMenuServiceImpl implements ISysMenuService {
      */
     @Override
     public List<SysMenu> listTreeByRoleId(Long roleId) {
-        List<SysMenu> roleMenus = menuMapper.listTreeByRoleId(roleId);
-
         SysMenu con = new SysMenu();
         // 0 为可用的
         con.setStatus("0");
+        // 0 为可见的
+        con.setVisible("0");
         List<SysMenu> allMenus = selectMenuListAll(con);
 
-        List<Long> roleMenuIdList = map(roleMenus, SysMenu::getId);
-        List<SysMenu> parentMenus = Lists.newArrayListWithCapacity(16);
-
-        // 把roleMenus对应的所有的爹parentMenus找到
-        recGetParent(allMenus, roleMenus, parentMenus);
+        List<SysMenu> parentMenus = filter(allMenus, menu->SysMenu.DICTIONARY.equals(menu.getMenuType()));
 
         // 递归,把孩子放进父亲的怀抱
         for (SysMenu parentMenu : parentMenus) {
-            recursionFn(parentMenus, parentMenu);
+            recursionFn(allMenus, parentMenu);
         }
 
-        // 把不在roleMenus中的去除掉
         return filter(parentMenus, menu -> isNotEmpty(menu.getChildren()));
     }
 

+ 1 - 1
boman-modules/boman-system/src/main/resources/mapper/system/SysMenuMapper.xml

@@ -178,7 +178,7 @@
 		FROM
 			sys_menu m
 				LEFT JOIN sys_role_menu rm ON m.id = rm.menu_id
-		WHERE m.status = '0'
+		WHERE m.status = '0' AND m.visible = '0'
 		<if test="roleId != null and roleId != ''">
 			and rm.role_id = #{roleId}
 		</if>

+ 45 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/MessageController.java

@@ -0,0 +1,45 @@
+package com.boman.web.core.controller;
+
+import com.boman.domain.dto.AjaxResult;
+import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
+import com.boman.web.core.service.message.MessageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * @author shiqian
+ * @Date: 2021/07/08/
+ */
+@RestController
+@RequestMapping("/message")
+public class MessageController {
+
+    @Resource
+    private MessageService service;
+
+    /**
+     * 功能描述: 撤回
+     *
+     * @param id id
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @GetMapping("withdraw/{id}")
+    public AjaxResult withdraw(@PathVariable("id") Long id) {
+        boolean withdraw = service.withdraw(id);
+        return withdraw ? AjaxResult.success("撤回成功") : AjaxResult.error("撤回失败");
+    }
+
+    /**
+     * 功能描述: 可以下载:超过30分钟 true,不能下载:30分钟以内 false
+     *
+     * @param id id
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @GetMapping("canDownload/{id}")
+    public AjaxResult canDownload(@PathVariable("id") Long id) {
+        boolean withdraw = service.canDownload(id);
+        return withdraw ? AjaxResult.success("可以下载") : AjaxResult.error("无法下载");
+    }
+}

+ 34 - 2
boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/BomanMessageReceiveServiceImpl.java

@@ -4,15 +4,17 @@ import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.*;
 import java.util.List;
 
-import static com.boman.common.core.utils.obj.ObjectUtils.ifNullSetEmpty;
-import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
 
 /**
  * @author tjf
@@ -21,8 +23,15 @@ import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
 @Service
 public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveService{
 
+    private static final String BOMAN_MESSAGE_RECEIVE = "boman_message_receive";
+    private static final String STATUS = "status";
+    private static final String MESSAGE_ID = "message_id";
+    private static final String DELETED = "D";
+
     @Autowired
     private IBaseSelectService selectService;
+    @Resource
+    private ICommonService commonService;
 
     /**
      * 根据发文id查询出该发文所选人员名称和部门
@@ -91,4 +100,27 @@ public class BomanMessageReceiveServiceImpl implements IBomanMessageReceiveServi
         map.put("todayReceipt", todayReceipt);
         return AjaxResult.success(map);
     }
+
+    /**
+     * 功能描述: 根据messageId撤回消息
+     *
+     * @param messageId messageId
+     * @return int
+     */
+    @Override
+    public int withdrawByMessageId(Long messageId) {
+        requireNonNull(messageId, "撤回时, 发文id为空");
+        UpdateDto dto = new UpdateDto();
+        dto.setTableName(BOMAN_MESSAGE_RECEIVE);
+
+        JSONObject commitData = new JSONObject();
+        commitData.put(STATUS, DELETED);
+
+        JSONObject condition = new JSONObject();
+        condition.put(MESSAGE_ID, messageId);
+
+        dto.setCommitData(commitData);
+        dto.setCondition(condition);
+        return commonService.update(dto);
+    }
 }

+ 8 - 0
boman-web-core/src/main/java/com/boman/web/core/service/bomanMessageReceive/IBomanMessageReceiveService.java

@@ -21,4 +21,12 @@ public interface IBomanMessageReceiveService {
      * @return
      */
     AjaxResult getIndexInfo(String userId);
+
+    /**
+     * 功能描述: 根据messageId撤回消息
+     *
+     * @param messageId messageId
+     * @return int
+     */
+    int withdrawByMessageId(Long messageId);
 }

+ 24 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageService.java

@@ -0,0 +1,24 @@
+package com.boman.web.core.service.message;
+
+/**
+ * @author shiqian
+ * @date 2021年07月08日 13:56
+ **/
+public interface MessageService {
+
+    /**
+     * 功能描述: 撤回
+     *
+     * @param id id
+     * @return java.lang.String
+     */
+    boolean withdraw(Long id);
+
+    /*
+     * 功能描述: 超过30分钟true,否则false
+     *
+     * @param id id
+     * @return boolean
+     */
+    boolean canDownload(Long id);
+}

+ 100 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageServiceImpl.java

@@ -0,0 +1,100 @@
+package com.boman.web.core.service.message;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.service.bomanMessageReceive.BomanMessageReceiveServiceImpl;
+import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
+import com.boman.web.core.service.common.ICommonService;
+import com.boman.web.core.utils.AuthUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+
+import java.sql.Timestamp;
+
+import static com.boman.common.core.utils.number.NumberUtils.eqZero;
+import static com.boman.common.core.utils.number.NumberUtils.gtZero;
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
+
+/**
+ * @author shiqian
+ * @date 2021年07月08日 13:56
+ **/
+@Service
+public class MessageServiceImpl implements MessageService {
+
+    private static final String BOMAN_MESSAGE_PK = "id";
+    private static final String BOMAN_MESSAGE = "boman_message";
+    private static final String CREATE_TIME = "create_time";
+    private static final String MESSAGE_SITUATION = "message_situation";
+    /*** 已撤回 ***/
+    private static final String WITHDRAW_CODE = "5";
+    /*** 默认30分钟 ***/
+    private static final int DEFAULT_TIME_OUT = 30;
+
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(MessageServiceImpl.class);
+
+    @Resource
+    private ICommonService commonService;
+    @Resource
+    private IBomanMessageReceiveService receiveService;
+
+    /**
+     * 功能描述: 撤回
+     *
+     * @param id id
+     * @return java.lang.String
+     */
+    @Override
+    @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
+    public boolean withdraw(Long id) {
+        requireNonNull(id, "撤回时, 发文id为空");
+        JSONObject message = commonService.getById(BOMAN_MESSAGE, id);
+        requireNonNull(message, "当前发文不存在, id = " + id);
+        long before = message.getTimestamp(CREATE_TIME).getTime();
+        long current = System.currentTimeMillis();
+        if ((current - before) / 1000 / 60 > DEFAULT_TIME_OUT) {
+            LOGGER.error("超过30分钟以上的发文无法撤回, 操作人:{}", AuthUtils.getLoginUser().getUsername());
+            throw new RuntimeException("超过30分钟以上的发文无法撤回");
+        }
+
+        // 修改主表
+        UpdateDto dto = new UpdateDto();
+        dto.setTableName(BOMAN_MESSAGE);
+        JSONObject commitData = new JSONObject();
+        commitData.put(MESSAGE_SITUATION, WITHDRAW_CODE);
+        JSONObject condition = new JSONObject();
+        condition.put(BOMAN_MESSAGE_PK, id);
+        dto.setCommitData(commitData);
+        dto.setCondition(condition);
+        int update = commonService.update(dto);
+        if (eqZero(update)) {
+            return false;
+        }
+
+        // 修改子表
+        int effective = receiveService.withdrawByMessageId(id);
+        return !eqZero(effective);
+    }
+
+    /*
+     * 功能描述: 超过30分钟true,否则false
+     *
+     * @param id id
+     * @return boolean
+     */
+    @Override
+    public boolean canDownload(Long id) {
+        requireNonNull(id, "撤回时, 发文id为空");
+        JSONObject message = commonService.getById(BOMAN_MESSAGE, id);
+        requireNonNull(message, "当前发文不存在, id = " + id);
+        long before = message.getTimestamp(CREATE_TIME).getTime();
+        long current = System.currentTimeMillis();
+        return ((current - before) / 1000 / 60) > DEFAULT_TIME_OUT;
+    }
+}