Exemplo n.º 1
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns>返回列表</returns>
        public DataTable GetList(Pagination pagination, string queryJson, string authType, Operator user)
        {
            DatabaseType dataTye = DatabaseType.Oracle;

            #region 查表
            pagination.p_kid         = "a.id";
            pagination.p_fields      = @"a.flowdeptname,a.flowname,a.flowrolename,a.flowdept,a.investigatestate,a.workdeptid,a.engineeringid,a.flowid,b.outtransferuseraccount,b.intransferuseraccount,
                                    a.workdepttype,a.workdeptname,a.applynumber,a.createdate,a.applystate,a.workplace,a.workcontent,a.workuserids,a.workareaname,a.workareacode,
                                    a.workstarttime,a.workendtime,a.applyusername,a.applydeptname,a.createuserid,a.createuserdeptcode,nvl(a.conditionstate,0) conditionstate,
                                    a.createuserorgcode,a.flowremark,a.specialtytype,'' as approveuserid,'' as approveusername,'' as approveuseraccount,case when a.applystate='3' and (a.conditionstate='0' or a.conditionstate is null) then '1' else '0' end appconditionstate";
            pagination.p_tablename   = " bis_firewater a left join (select recid,flowid,outtransferuseraccount,intransferuseraccount,row_number()  over(partition by recid,flowid order by createdate desc) as num from BIS_TRANSFERRECORD where disable=0) b on a.id=b.recid and a.flowid=b.flowid and b.num=1";
            pagination.conditionJson = " 1=1 ";
            if (!string.IsNullOrEmpty(authType))
            {
                //配置的部门拥有特殊查看权限
                string specialDeptId  = new DataItemDetailService().GetItemValue(user.OrganizeId, "FireDept");
                var    IsHrdl         = new DataItemDetailService().GetItemValue("IsOpenPassword");
                string isAllDataRange = dataitemdetailservice.GetEnableItemValue("HighRiskWorkDataRange"); //特殊标记,高风险作业模块是否看全厂数据
                if (!string.IsNullOrEmpty(specialDeptId) && specialDeptId.Contains(user.DeptId) || IsHrdl == "true" || !string.IsNullOrWhiteSpace(isAllDataRange))
                {
                    pagination.conditionJson += " and a.createuserorgcode='" + user.OrganizeCode + "'";
                }
                else
                {
                    switch (authType)
                    {
                    case "1":
                        pagination.conditionJson += " and a.applyuserid='" + user.UserId + "'";
                        break;

                    case "2":
                        pagination.conditionJson += " and a.workdeptid='" + user.DeptId + "'";
                        break;

                    case "3":    //本子部门
                        pagination.conditionJson += string.Format(" and ((a.workdeptid in(select departmentid from base_department where encode like '{0}%'))  or (a.engineeringid in(select id from epg_outsouringengineer a where a.engineerletdeptid = '{1}')))", user.DeptCode, user.DeptId);
                        break;

                    case "4":
                        pagination.conditionJson += " and a.createuserorgcode='" + user.OrganizeCode + "'";
                        break;

                    case "app":
                        if (user.RoleName.Contains("公司") || user.RoleName.Contains("厂级"))
                        {
                            pagination.conditionJson += " and a.createuserorgcode='" + user.OrganizeCode + "'";
                        }
                        else
                        {
                            pagination.conditionJson += string.Format(" and ((a.workdeptid in(select departmentid from base_department where encode like '{0}%'))  or (a.engineeringid in(select id from epg_outsouringengineer a where a.engineerletdeptid = '{1}')))", user.DeptCode, user.DeptId);
                        }
                        break;
                    }
                }
            }
            else
            {
                pagination.conditionJson += " and 0=1";
            }
            #endregion

            #region  筛选条件
            var queryParam = JObject.Parse(queryJson);
            //查询条件
            if (!queryParam["applynumber"].IsEmpty())//申请编号
            {
                pagination.conditionJson += string.Format(" and applynumber like '%{0}%'", queryParam["applynumber"].ToString());
            }
            //查询条件
            if (!queryParam["status"].IsEmpty())//许可状态
            {
                pagination.conditionJson += string.Format(" and applystate='{0}'", queryParam["status"].ToString());
            }
            //时间选择
            if (!queryParam["st"].IsEmpty())//开始时间
            {
                string from = queryParam["st"].ToString().Trim();
                pagination.conditionJson += string.Format(" and workstarttime>=to_date('{0}','yyyy-mm-dd')", from);
            }
            if (!queryParam["et"].IsEmpty())//结束时间
            {
                string to = Convert.ToDateTime(queryParam["et"].ToString().Trim()).AddDays(1).ToString("yyyy-MM-dd");
                pagination.conditionJson += string.Format(" and workendtime<=to_date('{0}','yyyy-mm-dd')", to);
            }
            if (!queryParam["workdept"].IsEmpty() && !queryParam["workdeptid"].IsEmpty())//使用消防水单位
            {
                pagination.conditionJson += string.Format(" and ((workdeptcode in(select encode from base_department where encode like '{0}%'))  or (engineeringid in(select id from epg_outsouringengineer a where a.engineerletdeptid = '{1}')))", queryParam["workdept"].ToString(), queryParam["workdeptid"].ToString());
            }
            //查询条件
            if (!queryParam["workdeptcode"].IsEmpty())//使用消防水单位code
            {
                pagination.conditionJson += string.Format(" and workdeptcode='{0}'", queryParam["workdeptcode"].ToString());
            }
            if (!queryParam["viewrange"].IsEmpty())
            {
                //本人
                if (queryParam["viewrange"].ToString().ToLower() == "self")
                {
                    pagination.conditionJson += string.Format(" and a.applyuserid='{0}'", user.UserId);
                }
                else if (queryParam["viewrange"].ToString().ToLower() == "selfaudit")
                {
                    string    strCondition = " and a.applystate ='1'";
                    DataTable dt           = BaseRepository().FindTable("select " + pagination.p_kid + "," + pagination.p_fields + " from " + pagination.p_tablename + " where " + pagination.conditionJson + strCondition);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string executedept = string.Empty;
                        highriskcommonapplyservice.GetExecutedept(dt.Rows[i]["workdepttype"].ToString(), dt.Rows[i]["workdeptid"].ToString(), dt.Rows[i]["engineeringid"].ToString(), out executedept);
                        string createdetpid           = departmentservice.GetEntityByCode(dt.Rows[i]["createuserdeptcode"].ToString()).IsEmpty() ? "" : departmentservice.GetEntityByCode(dt.Rows[i]["createuserdeptcode"].ToString()).DepartmentId;
                        string outsouringengineerdept = string.Empty;
                        highriskcommonapplyservice.GetOutsouringengineerDept(dt.Rows[i]["workdeptid"].ToString(), out outsouringengineerdept);
                        string str = manypowercheckservice.GetApproveUserAccount(dt.Rows[i]["flowid"].ToString(), dt.Rows[i]["id"].ToString(), "", dt.Rows[i]["specialtytype"].ToString(), executedept, outsouringengineerdept, createdetpid, "", "");
                        dt.Rows[i]["approveuseraccount"] = str;
                    }
                    string[] applyids = dt.Select(" (outtransferuseraccount is null or outtransferuseraccount not like '%" + user.Account + ",%') and (approveuseraccount like '%" + user.Account + ",%' or intransferuseraccount like '%" + user.Account + ",%')").AsEnumerable().Select(d => d.Field <string>("id")).ToArray();

                    pagination.conditionJson += string.Format(" and a.id in ('{0}') {1}", string.Join("','", applyids), strCondition);
                }
                else
                {
                    //排除其他人申请保存的数据
                    pagination.conditionJson += string.Format("  and a.id  not in(select id from bis_firewater where applystate='0' and  applyuserid!='{0}')", user.UserId);
                }
            }
            #endregion
            DataTable data = this.BaseRepository().FindTableByProcPager(pagination, dataTye);
            for (int i = 0; i < data.Rows.Count; i++)
            {
                string executedept = string.Empty;
                highriskcommonapplyservice.GetExecutedept(data.Rows[i]["workdepttype"].ToString(), data.Rows[i]["workdeptid"].ToString(), data.Rows[i]["engineeringid"].ToString(), out executedept);                                            //获取执行部门
                string createdetpid           = departmentservice.GetEntityByCode(data.Rows[i]["createuserdeptcode"].ToString()).IsEmpty() ? "" : departmentservice.GetEntityByCode(data.Rows[i]["createuserdeptcode"].ToString()).DepartmentId; //获取创建部门
                string outsouringengineerdept = string.Empty;
                highriskcommonapplyservice.GetOutsouringengineerDept(data.Rows[i]["workdeptid"].ToString(), out outsouringengineerdept);
                string   str = manypowercheckservice.GetApproveUserAccount(data.Rows[i]["flowid"].ToString(), data.Rows[i]["id"].ToString(), "", data.Rows[i]["specialtytype"].ToString(), executedept, outsouringengineerdept, createdetpid, "", "");
                string   outtransferuseraccount     = data.Rows[i]["outtransferuseraccount"].IsEmpty() ? "" : data.Rows[i]["outtransferuseraccount"].ToString(); //转交申请人
                string   intransferuseraccount      = data.Rows[i]["intransferuseraccount"].IsEmpty() ? "" : data.Rows[i]["intransferuseraccount"].ToString();   //转交接收人
                string[] outtransferuseraccountlist = outtransferuseraccount.Split(',');
                string[] intransferuseraccountlist  = intransferuseraccount.Split(',');
                foreach (var item in intransferuseraccountlist)
                {
                    if (!item.IsEmpty() && !str.Contains(item + ","))
                    {
                        str += (item + ",");//将转交接收人加入审核账号中
                    }
                }
                foreach (var item in outtransferuseraccountlist)
                {
                    if (!item.IsEmpty() && str.Contains(item + ","))
                    {
                        str = str.Replace(item + ",", "");//将转交申请人从审核账号中移除
                    }
                }
                data.Rows[i]["approveuseraccount"] = str;
                DataTable dtuser    = userservice.GetUserTable(str.Split(','));
                string[]  usernames = dtuser.AsEnumerable().Select(d => d.Field <string>("realname")).ToArray();
                data.Rows[i]["approveusername"] = usernames.Length > 0 ? string.Join(",", usernames) : "";
            }
            return(data);
        }