package com.java110.user.cmd.user; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.java110.core.annotation.Java110Cmd; import com.java110.core.context.ICmdDataFlowContext; import com.java110.core.event.cmd.Cmd; import com.java110.core.event.cmd.CmdEvent; import com.java110.dto.store.StoreDto; import com.java110.intf.store.IStoreV1InnerServiceSMO; import com.java110.service.context.DataQuery; import com.java110.service.smo.IQueryServiceSMO; import com.java110.utils.exception.CmdException; import com.java110.utils.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @Java110Cmd(serviceCode = "user.queryAdminStaffPrivilege") public class QueryAdminStaffPrivilegeCmd extends Cmd { @Autowired private IStoreV1InnerServiceSMO storeV1InnerServiceSMOImpl; @Autowired private IQueryServiceSMO queryServiceSMOImpl; @Override public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { super.validateAdmin(context); } @Override public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { DataQuery dataQuery = new DataQuery(); dataQuery.setServiceCode("query.user.privilege"); JSONObject param = new JSONObject(); param.put("userId", reqJson.getString("staffId")); param.put("domain", StoreDto.STORE_TYPE_PROPERTY); dataQuery.setRequestParams(param); queryServiceSMOImpl.commonQueryService(dataQuery); ResponseEntity privilegeGroup = dataQuery.getResponseEntity(); if (privilegeGroup.getStatusCode() != HttpStatus.OK) { context.setResponseEntity(privilegeGroup); return ; } JSONObject resultObj = JSONObject.parseObject(privilegeGroup.getBody().toString()); JSONArray privileges = resultObj.getJSONArray("privileges"); JSONArray tmpPrivilegeArrays = new JSONArray(); JSONObject privilegeObj = null; for (int privilegeIndex = 0; privilegeIndex < privileges.size(); privilegeIndex++) { privilegeObj = privileges.getJSONObject(privilegeIndex); hasSameData(privilegeObj, tmpPrivilegeArrays); } JSONObject resObj = new JSONObject(); resObj.put("datas", privileges); context.setResponseEntity(new ResponseEntity(resObj.toJSONString(), HttpStatus.OK)); } private void hasSameData(JSONObject privilegeObj, JSONArray tmpPrivilegeArrays) { JSONObject tmpPrivilegeObj = null; for (int tmpPrivilegeIndex = 0; tmpPrivilegeIndex < tmpPrivilegeArrays.size(); tmpPrivilegeIndex++) { tmpPrivilegeObj = tmpPrivilegeArrays.getJSONObject(tmpPrivilegeIndex); if (privilegeObj.getString("pId").equals(tmpPrivilegeObj.getString("pId"))) { if (!StringUtil.isEmpty(privilegeObj.getString("pgId"))) { tmpPrivilegeArrays.remove(tmpPrivilegeIndex); tmpPrivilegeArrays.add(privilegeObj); } return; } } tmpPrivilegeArrays.add(privilegeObj); } }