Bladeren bron

优化代码

Your Name 2 jaren geleden
bovenliggende
commit
fe623ab80e

+ 23 - 8
service-store/src/main/java/com/java110/store/cmd/resourceStore/ListAllocationStorehouseApplysCmd.java

@@ -2,6 +2,7 @@ package com.java110.store.cmd.resourceStore;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.CmdContextUtils;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
@@ -11,6 +12,7 @@ import com.java110.intf.community.IMenuInnerServiceSMO;
 import com.java110.intf.store.IAllocationStorehouseApplyInnerServiceSMO;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -43,14 +45,7 @@ public class ListAllocationStorehouseApplysCmd extends Cmd {
     public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
         AllocationStorehouseApplyDto allocationStorehouseApplyDto = BeanConvertUtil.covertBean(reqJson, AllocationStorehouseApplyDto.class);
         //调拨记录(调拨记录所有权限查看所有数据)
-        String userId = reqJson.getString("userId");
-        BasePrivilegeDto basePrivilegeDto = new BasePrivilegeDto();
-        basePrivilegeDto.setResource("/viewlistAllocationStorehouses");
-        basePrivilegeDto.setUserId(userId);
-        List<Map> privileges = menuInnerServiceSMOImpl.checkUserHasResource(basePrivilegeDto);
-        if (privileges.size() == 0) {
-            allocationStorehouseApplyDto.setStartUserId(userId);
-        }
+        privilegeControl(context, allocationStorehouseApplyDto);
         int count = allocationStorehouseApplyInnerServiceSMOImpl.queryAllocationStorehouseApplysCount(allocationStorehouseApplyDto);
 
         List<AllocationStorehouseApplyDto> allocationStorehouseApplyDtos = null;
@@ -67,4 +62,24 @@ public class ListAllocationStorehouseApplysCmd extends Cmd {
 
         context.setResponseEntity(responseEntity);
     }
+
+    /**
+     * 权限控制
+     *
+     * @param context
+     * @param allocationStorehouseApplyDto
+     */
+    private void privilegeControl(ICmdDataFlowContext context, AllocationStorehouseApplyDto allocationStorehouseApplyDto) {
+        if (!StringUtil.isEmpty(allocationStorehouseApplyDto.getApplyId())) { //单个信息查询时不做控制
+            return;
+        }
+        String userId = CmdContextUtils.getUserId(context);
+        BasePrivilegeDto basePrivilegeDto = new BasePrivilegeDto();
+        basePrivilegeDto.setResource("/viewlistAllocationStorehouses");
+        basePrivilegeDto.setUserId(userId);
+        List<Map> privileges = menuInnerServiceSMOImpl.checkUserHasResource(basePrivilegeDto);
+        if (privileges.size() == 0) {
+            allocationStorehouseApplyDto.setStartUserId(userId);
+        }
+    }
 }