tijian_tieying/web/dccdc.DAL/InfectionCheckDal.cs

130 lines
4.6 KiB
C#
Raw Permalink Normal View History

2025-02-20 12:14:39 +08:00
using Dapper;
using dccdc.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace dccdc.DAL
{
public class InfectionCheckDal
{
public int checkToday(string user_id)
{
string SQL = string.Format("select count(*) from dccdc.dbo.infection_check where user_id={0} and check_date=CONVERT(varchar(10),GETDATE(),120)", user_id);
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int i = conn.ExecuteScalar<int>(SQL);
return i;
}
catch (Exception ex)
{
return 0;
}
}
}
public object SaveData(InfectionCheckModel model)
{
string sql = @"Insert Into infection_check(user_id,state,check_date,create_time)
Values (@user_id,@state,@check_date,@create_time)";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, model);
if (result > 0)
return new { State = 1, Message = "签到成功!" };
else
return new { State = 0, Message = "签到失败!" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public List<InfectionCheckModel> GetAllDataList(string user_id)
{
string sql = "select isnull(c.state,0) as state,DATEPART(dd,d.date) as check_date from dccdc.dbo.infection_check c right join dccdc.dbo.infection_date d on c.check_date=d.date and c.user_id=" + user_id+" where d.year=DATENAME(YYYY,GETDATE()) and d.month=DATENAME(MM,GETDATE())";
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sql====================" + sql);
try {
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<InfectionCheckModel>(sql).ToList();
}
}
catch (Exception ex) {
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("message====================" + ex.Message);
return new List<InfectionCheckModel>();
}
}
public int getCheckSum(string user_id)
{
string SQL = string.Format("select count(*) from dccdc.dbo.infection_check where user_id={0} and check_state=0 ", user_id);
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int i = conn.ExecuteScalar<int>(SQL);
return i;
}
catch (Exception ex)
{
return 0;
}
}
}
public bool updateCheckState(string user_id,int days)
{
string sql = @"update infection_check set check_state = 1 where id in (select TOP(@days) id from infection_check where user_id = @user_id And check_state = 0 order by create_time)";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, new { @user_id = user_id, @days = days });
if (result > 0)
return true;
else
return false;
}
catch (Exception ex)
{
return false;
}
}
}
public bool updateTodayCheckState(string user_id)
{
string sql = @"update infection_check set check_state = 1 where user_id = @user_id And check_state = 0 and check_date=CONVERT(varchar(10),GETDATE(),120)";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, new { @user_id = user_id});
if (result > 0)
return true;
else
return false;
}
catch (Exception ex)
{
return false;
}
}
}
}
}