首页 新闻 搜索 专区 学院

急!求助c#代码改为java代码

0
悬赏园豆:50 [待解决问题]

c#部分
private string PackagePermissionSql(PermissionDepartmentDataModel permissionDepModel, string username)
{
string pemiSql = "";
if (permissionDepModel.suDepartmentId == null && (permissionDepModel.list == null || permissionDepModel.list.Count == 0))
{
//无速达部门也无授权部门,只能看自己接手的
pemiSql = $" and isnull(join_e.name,e.name)= '{username}'";
return pemiSql;
}

        //#####组装begin
        pemiSql = " and (";
        //授权部门
        List<string> pdsql_list = new List<string>();
        string pdsql_str = "";
        if (permissionDepModel.list != null && permissionDepModel.list.Count > 0)
        { 	
            foreach (var pdMode in permissionDepModel.list)
            {
                if (pdMode.suDepartmentId != null)
                {
                    pdsql_list.Add($" (isnull(ie.joindepartmentid,i.departmentid)={pdMode.suDepartmentId} {PackagePermissionAreaSql(pdMode.supervisor, permissionDepModel.areaIds)})");
                }
            }
            pdsql_str = $"({string.Join("or", pdsql_list.ToArray())})";
        }
        //当前部门
        if (permissionDepModel.	 != null)
        {
            pemiSql += $" (isnull(ie.joindepartmentid,i.departmentid)={permissionDepModel.suDepartmentId}{PackagePermissionAreaSql(permissionDepModel.supervisor, permissionDepModel.areaIds)})";
            if (!string.IsNullOrWhiteSpace(pdsql_str))
            {
                pemiSql += $" or {pdsql_str}";
            }
        }
        else
        {
            if (!string.IsNullOrWhiteSpace(pdsql_str))
            {
                pemiSql += $"{pdsql_str}";
            }
        }

        //包括自己接手的
        pemiSql += $" or isnull(join_e.name, e.name) = '{username}'";
        pemiSql += " )";
        //#####组装end

        return pemiSql;
    }

    /// <summary>
    /// 获取组装地区查询
    /// </summary>
    /// <param name="supervisor"></param>
    /// <param name="areaIds"></param>
    /// <returns></returns>
    private string PackagePermissionAreaSql(bool supervisor, List<string> areaIds)
    {
        string sql = "";
        if (!supervisor)
        {
            //不是主管,条件加上地区
            if (areaIds == null || areaIds.Count == 0)
            {
                sql += " and 1=2";
            }
            else
            {
                string areaIdsStr = string.Join(",", areaIds);
                sql += $" and ( t.provinceid in ({areaIdsStr}) or t.cityId in ({areaIdsStr}) or t.areaId in ({areaIdsStr}))";
            }
        }
        return sql;
    }

求组改为dao.xml文件中的sql语句,我改成以下那样,发现进行查询的时候程序出错了
-- 速达部门
<if test="model.suDepartmentId !=null and (model.list == null or model.list.size ==0 )">
-- 无速达部门也无授权部门,只能看自己接手的
and isnull(join_e.name,e.name)= #{model.username}
</if>

-- 授权部门
and (
<if test="model.list !=null and model.list.size != 0">
<foreach collection="model.list" item="item" index="index">
<if test="item.suDepartmentId !=null">
isnull(ie.joindepartmentid,i.departmentid)= #{item.suDepartmentId}
<if test="item.supervisor ==false">
-- 不是主管,条件加上地区
<if test="model.areaIds == null and model.areaIds.size ==0">
and 1=2
</if>
<if test="model.areaIds != null and model.areaIds.size !=0">
and ( t.provinceid in (#{model.areaIds}) or t.cityId in (#{model.areaIds}) or t.areaId in (#{model.areaIds}))
</if>
</if>
</if>

			</foreach>
		</if>
林jj的主页 林jj | 初学一级 | 园豆:152
提问于:2021-06-04 09:41
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册