tijian_tieying/web/dccdc.DAL/OccupationExamSchemeMaintainDal.cs
2025-02-20 12:14:39 +08:00

289 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dccdc.Models;
using Dapper;
namespace dccdc.DAL
{
public class OccupationExamSchemeMaintainDal
{
public int GetSiteCount(string key,string fn)
{
string sql = "select count(1) from dbo.occupation_exam_scheme_maintain where scheme_type='企业'";
if (!string.IsNullOrEmpty(key))
{
sql += " and util_name like @util_name";
}
if (!string.IsNullOrEmpty(fn))
{
sql += " and scheme_name like @fn";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { util_name = "%" + key + "%", fn="%"+fn+"%" });
}
}
public OccupationExamSchemeMaintainModel GetModel(string id)
{
string sql = "select * from dbo.occupation_exam_scheme_maintain where id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
List<OccupationExamSchemeMaintainModel> al = conn.Query<OccupationExamSchemeMaintainModel>(sql, new { @id = id }).ToList();
return al.Any() ? al.First() : null;
}
}
/// <summary>
/// 根据公司名称获取所有企业体检方案
/// </summary>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <param name="key">公司名称</param>
/// <returns></returns>
public List<OccupationExamSchemeMaintainModel> GetSiteList(int page, int pagesize, string key,string fn)
{
string sql = "select *,row_number() over(order by id desc) as rownum from occupation_exam_scheme_maintain where scheme_type='企业'";
if (!string.IsNullOrEmpty(key))
{
sql += " and util_name like @util_name";
}
if (!string.IsNullOrEmpty(fn))
{
sql += " and scheme_name like @fn";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.OccupationExamSchemeMaintainModel>(sql, new { util_name = "%" + key + "%" ,fn="%"+fn+"%"}).ToList();
}
}
/// <summary>
/// 根据企业ID获取企业体检方案
/// </summary>
/// <returns></returns>
public List<OccupationExamSchemeMaintainModel> GetSiteList(string siteid)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from occupation_exam_scheme_maintain where scheme_type='企业' and util_id=@util_id";
return conn.Query<Models.OccupationExamSchemeMaintainModel>(sql, new { @util_id = siteid }).ToList();
}
}
public int GetTyCount(string key)
{
string sql = "select count(1) from dbo.occupation_exam_scheme_maintain where scheme_type='通用'";
if (!string.IsNullOrEmpty(key))
{
sql += " and util_name like @util_name";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { util_name = "%" + key + "%" });
}
}
/// <summary>
/// 根据公司名称获取通用体检方案列表
/// </summary>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <param name="key">公司名称</param>
/// <returns></returns>
public List<OccupationExamSchemeMaintainModel> GetTyList(int page, int pagesize, string key)
{
string sql = "select *,row_number() over(order by id desc) as rownum from occupation_exam_scheme_maintain where scheme_type='通用'";
if (!string.IsNullOrEmpty(key))
{
sql += " and util_name like @util_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.OccupationExamSchemeMaintainModel>(sql, new { util_name = "%" + key + "%" }).ToList();
}
}
/// <summary>
/// 根据类型获取体检方案
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public List<OccupationExamSchemeMaintainModel> GetListByType(string type)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from occupation_exam_scheme_maintain where scheme_type =@type";
return conn.Query<Models.OccupationExamSchemeMaintainModel>(sql, new { type = type }).ToList();
}
}
public bool Update(OccupationExamSchemeMaintainModel model)
{
string sql = @"UPDATE [occupation_exam_scheme_maintain]
SET [scheme_name] = @scheme_name
,[scheme_type] = @scheme_type
,[util_id] = @util_id
,[util_name] = @util_name
,[exam_type] = @exam_type
,[check_type_maintain_id] = @check_type_maintain_id
,[station_status] = @station_status
,[jobs_state_maintain_id] = @jobs_state_maintain_id
,[hazard_type_ids] = @hazard_type_ids
,[hazard_type_names] =@hazard_type_names
,[hazards] = @hazards
,[hazards_alias] = @hazards_alias
,[harmful_factors_maintain_id] = @harmful_factors_maintain_id
,[check_item_ids] = @check_item_ids
,[valid_start] = @valid_start
,[valid_end] = @valid_end
,[expense_name] = @expense_name
,[recievable_amount] = @recievable_amount
,[agreement_amount] = @agreement_amount
,[print_item_ids] = @print_item_ids
WHERE id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public bool Add(OccupationExamSchemeMaintainModel model)
{
string sql = @"INSERT INTO [occupation_exam_scheme_maintain]
([scheme_name]
,[scheme_type]
,[util_id]
,[util_name]
,[exam_type]
,[check_type_maintain_id]
,[station_status]
,[jobs_state_maintain_id]
,[hazard_type_ids]
,[hazard_type_names]
,[hazards]
,[hazards_alias]
,[harmful_factors_maintain_id]
,[check_item_ids]
,[valid_start]
,[valid_end]
,[expense_name]
,[recievable_amount]
,[agreement_amount]
,[print_item_ids])
VALUES
(@scheme_name
,@scheme_type
,@util_id
,@util_name
,@exam_type
,@check_type_maintain_id
,@station_status
,@jobs_state_maintain_id
,@hazard_type_ids
,@hazard_type_names
,@hazards
,@hazards_alias
,@harmful_factors_maintain_id
,@check_item_ids
,@valid_start
,@valid_end
,@expense_name
,@recievable_amount
,@agreement_amount
,@print_item_ids)";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public object Del(string id)
{
string sql = "delete occupation_exam_scheme_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 };
}
}
}
public object Clone(string id)
{
string sql = @"INSERT INTO occupation_exam_scheme_maintain ([scheme_name]
,[scheme_type]
,[util_id]
,[util_name]
,[exam_type]
,[check_type_maintain_id]
,[station_status]
,[jobs_state_maintain_id]
,[hazard_type_ids]
,[hazard_type_names]
,[hazards]
,[hazards_alias]
,[harmful_factors_maintain_id]
,[check_item_ids]
,[valid_start]
,[valid_end]
,[expense_name]
,[recievable_amount]
,[agreement_amount])
SELECT [scheme_name]+'复制'
,[scheme_type]
,[util_id]
,[util_name]
,[exam_type]
,[check_type_maintain_id]
,[station_status]
,[jobs_state_maintain_id]
,[hazard_type_ids]
,[hazard_type_names]
,[hazards]
,[hazards_alias]
,[harmful_factors_maintain_id]
,[check_item_ids]
,[valid_start]
,[valid_end]
,[expense_name]
,[recievable_amount]
,[agreement_amount] FROM occupation_exam_scheme_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 };
}
}
}
}
}