260 lines
9.2 KiB
C#
260 lines
9.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Dapper;
|
|
using dccdc.Models;
|
|
|
|
namespace dccdc.DAL
|
|
{
|
|
public class ExamGroupMaintainDal
|
|
{
|
|
public int getCount(string key)
|
|
{
|
|
string sql = "select count(1) from dbo.exam_group_maintain where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and team_name like @team_name";
|
|
}
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.ExecuteScalar<int>(sql, new { team_name = "%" + key + "%" });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据小组名称获取体检小组列表
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="pagesize"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> getList(int page, int pagesize, string key)
|
|
{
|
|
//throw new NotImplementedException();
|
|
string sql = "select *,row_number() over(order by id desc) as rownum from exam_group_maintain where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and team_name like @team_name";
|
|
}
|
|
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<Models.ExamGroupMaintainModel>(sql, new { team_name = "%" + key + "%" }).ToList();
|
|
}
|
|
}
|
|
|
|
public object save(ExamGroupMaintainModel ct, ERPUser user)
|
|
{
|
|
//throw new NotImplementedException();
|
|
ct.creator = user.TrueName;
|
|
ct.create_time = DateTime.Now.ToString("yyyy-MM-dd");
|
|
string sql = "";
|
|
if (ct.id == 0)
|
|
{
|
|
sql = @"INSERT INTO [dbo].[exam_group_maintain]
|
|
([up_level]
|
|
,[team_name]
|
|
,[is_review]
|
|
,[weight]
|
|
,[is_collect]
|
|
,[status]
|
|
,[creator]
|
|
,[create_time])
|
|
VALUES
|
|
(@up_level
|
|
,@team_name
|
|
,@is_review
|
|
,@weight
|
|
,@is_collect
|
|
,@status
|
|
,@creator
|
|
,@create_time)
|
|
";
|
|
}
|
|
else
|
|
{
|
|
sql = @"UPDATE [dbo].[exam_group_maintain]
|
|
SET [up_level] = @up_level
|
|
,[team_name] = @team_name
|
|
,[is_review] = @is_review
|
|
,[weight] = @weight
|
|
,[is_collect] = @is_collect
|
|
,[status] = @status
|
|
WHERE id=@id
|
|
";
|
|
}
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, ct);
|
|
if (c > 0)
|
|
{
|
|
return new { State = 1, Message = "保存成功!" };
|
|
}
|
|
else
|
|
{
|
|
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据小组id查询小组
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and id=@id";
|
|
}
|
|
return conn.Query<Models.ExamGroupMaintainModel>("select * from exam_group_maintain where 1=1" + param, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 正式数据用 status=是
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetAllListTrue(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and id=@id";
|
|
}
|
|
return conn.Query<Models.ExamGroupMaintainModel>("select * from exam_group_maintain where status='是' " + param, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 正式数据用 status=是
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetAllListTrueOrderByCount()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"select *,GroupCount from exam_group_maintain g
|
|
left join (
|
|
select exam_group_maintain_id,count(1) as GroupCount from examination_process group by exam_group_maintain_id
|
|
) t
|
|
ON g.id = t.exam_group_maintain_id
|
|
where g.status='是' order by t.GroupCount desc";
|
|
|
|
return conn.Query<Models.ExamGroupMaintainModel>(sql).ToList();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 正式数据用 status=是
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetAllListJY(string is_collect)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (is_collect != "")
|
|
{
|
|
param = " and is_collect=@is_collect";
|
|
}
|
|
return conn.Query<Models.ExamGroupMaintainModel>("select * from exam_group_maintain where status='是' " + param, new { @is_collect = is_collect }).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取不合格项的小组列表
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetGroupList(string id)
|
|
{
|
|
string sql = "select b.* from exam_group_maintain b left join exam_project_maintain a on a.exam_group_maintain_id=b.id\r\nwhere 1=1 and a.project_id in \r\n(select project_id from professionalExam_project_result where person_id=@id and qualified='不合格') ";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<Models.ExamGroupMaintainModel>(sql, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据personid获取其体检小组列表
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetGroupListByPersonId(string id)
|
|
{
|
|
string sql = "select distinct b.* from exam_group_maintain b left join exam_project_maintain a on a.exam_group_maintain_id=b.id\r\nwhere 1=1 and a.project_id in \r\n(select project_id from professionalExam_project_result where person_id=@id ) ";
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<Models.ExamGroupMaintainModel>(sql, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据小组名称模糊查询
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <returns></returns>
|
|
public List<ExamGroupMaintainModel> GetAllListByName(string name)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (name != "")
|
|
{
|
|
param = " and team_name like @name";
|
|
}
|
|
return conn.Query<Models.ExamGroupMaintainModel>("select * from exam_group_maintain where 1=1" + param, new { name = "%" + name + "%" }).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id删除体检小组
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public object del(string id)
|
|
{
|
|
string sql = @"delete exam_group_maintain where id=@id";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, new { id = id });
|
|
if (c > 0)
|
|
{
|
|
return new { State = 1, Message = "操作成功!" };
|
|
}
|
|
else
|
|
{
|
|
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|