class ArrangementManagementServiceImpl implements ArrangementManagementService {

    @Override
    public CommonResult listArrangementRules(Integer departmentId){
        JSONObject returnJson = new JSONObject();

        List<HashMap> arrangementRuleList = arrangementRuleMapper.listArrangementRulesByDepartmentId(departmentId);
        // JSON格式 v2.0
//        returnJson = formatJson(returnJson, arrangementRuleList);
//         JSON格式 v1.0
        HashMap<Integer, List<HashMap>> arrangementRules = new HashMap<>();// <规则id， 内容>
        for(HashMap arrangementRule : arrangementRuleList){
            Long idLong = (Long)arrangementRule.get("id");
            Integer id = new Integer(String.valueOf(idLong));
            List<HashMap> info;
            if(!arrangementRules.containsKey(id))
                info = new ArrayList<>();
            else
                info = arrangementRules.get(id);
            arrangementRule.remove("id");
            arrangementRule.remove("departmentId");
            Byte levelId = Byte.valueOf(String.valueOf(arrangementRule.get("registrationLevelId")));
            arrangementRule.put("registrationLevel", ConstantMap.convert("挂号级别", levelId));
            arrangementRule.remove("registrationLevelId");
            Byte positionId = Byte.valueOf(String.valueOf(arrangementRule.get("titleId")));
            arrangementRule.put("title", ConstantMap.convert("职称", positionId));
            arrangementRule.remove("titleId");
            arrangementRule.put("isValid", getStatusStr((Boolean)arrangementRule.get("isValid")));

            info.add(arrangementRule);
            arrangementRules.put(id, info);
        }
        //JSON格式
        JSONArray jsonArray = new JSONArray();
        for(Map.Entry<Integer, List<HashMap>> entry: arrangementRules.entrySet()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ruleId", entry.getKey());
            jsonObject.put("ruleName", entry.getValue().get(0).get("ruleName"));
            Integer adminId = (Integer)entry.getValue().get(0).get("adminId");
            jsonObject.put("adminName", roleMapper.getUserNameByRoleId(adminId));
            jsonObject = formatJson(jsonObject, entry.getValue());
            jsonArray.add(jsonObject);
        }
        returnJson.put("arrangementRules", jsonArray);
        return CommonResult.success(returnJson);
    }

}