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

288 lines
9.4 KiB
C#

using Dapper;
using dccdc.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dccdc.DAL
{
public class InfectionOpenUserDal
{
public void updateOpenUserInfection(InfectionOpenUserModel ou)
{
//throw new NotImplementedException();
try
{
//throw new NotImplementedException();
string sql = "select count(1) from infection_open_user where openid='" + ou.openid + "'";
using (var conn = CommHelper.GetSqlConnection())
{
var c = conn.ExecuteScalar<int>(sql);
if (c > 0)
{
sql = @"UPDATE [infection_open_user]
SET [openid] = @openid
,[nickname] = @nickname
,[sex] = @sex
,[city] = @city
,[country] = @country
,[province] = @province
,[language] = @language
,[headimgurl] = @headimgurl
,[subscribe_time] = @subscribe_time
,[remark] = @remark
,[subscribe] = @subscribe
WHERE openid=@openid";
}
else
{
sql = @"INSERT INTO [dbo].[infection_open_user]
([openid]
,[nickname]
,[sex]
,[city]
,[country]
,[province]
,[language]
,[headimgurl]
,[subscribe_time]
,[remark]
,[subscribe]
,[recommendold])
VALUES
(@openid
,@nickname
,@sex
,@city
,@country
,@province
,@language
,@headimgurl
,@subscribe_time
,@remark
,@subscribe
,@recommendold)
";
}
conn.Execute(sql, ou);
}
}
catch (System.Exception ex)
{
throw ex;
}
}
public void updateRemarkInfection(string openid, string remark)
{
//throw new NotImplementedException();
try
{
using (var conn = CommHelper.GetSqlConnection())
{
string sql = @"UPDATE [infection_open_user] SET [remark] = @remark WHERE openid=@openid";
conn.Execute(sql, new { openid = openid, remark = remark });
}
}
catch (System.Exception ex)
{
throw ex;
}
}
public int remarkGZInfection(string openid, string bz)
{
//throw new NotImplementedException();
string sql = "update infection_open_user set remark=@bz where openid=@openid";
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Execute(sql, new { openid = openid, bz = bz });
}
}
public List<InfectionOpenUserModel> getGZListInfection(string nc, string bz, int page, int pagesize)
{
//throw new NotImplementedException();
string sql = "select *,row_number() over(order by id) as rownum," +
"ISNULL (( SELECT CASE WHEN info.id IS NULL THEN '0'ELSE '1'END " +
"FROM infection_open_user_info info WHERE info.user_id = u.id ),'0')AS stateUser" +
" from infection_open_user u where 1=1";
if (!string.IsNullOrEmpty(nc))
{
sql += " and nickname like @nc";
}
if (!string.IsNullOrEmpty(bz))
{
sql += " and remark like @bz";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Query<InfectionOpenUserModel>(sql, new { nc = "%" + nc + "%", bz = "%" + bz + "%" }).ToList();
}
}
public int getGZCountInfection(string nc, string bz)
{
string sql = "select count(1) from infection_open_user where 1=1";
if (!string.IsNullOrEmpty(nc))
{
sql += " and nickname like @nc";
}
if (!string.IsNullOrEmpty(bz))
{
sql += " and remark like @bz";
}
using (var conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { nc = "%" + nc + "%", bz = "%" + bz + "%" });
}
}
public List<InfectionOpenUserModel> GetDataByOpenid(string openid)
{
string sql = string.Format("Select * From infection_open_user Where openid = '{0}'", openid);
List<InfectionOpenUserModel> models;
try
{
using (var conn = CommHelper.GetSqlConnection())
{
models = conn.Query<InfectionOpenUserModel>(sql).ToList();
}
}
catch
{
models = null;
}
return models;
}
public int updateAdminById(string id, string type, string oaId)
{
//throw new NotImplementedException();
int s = int.Parse(oaId);
if(s > 0)
{
if(type == "0")
{
oaId = "0";
}
string sql = "update infection_open_user set type=@type, oa_id=@oa_id where id=@id";
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Execute(sql, new { id = id, type = type, oa_id = oaId });
}
}
else
{
string sql = "update infection_open_user set type=@type where id=@id";
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Execute(sql, new { id = id, type = type });
}
}
}
public string GetTypeByID(string id)
{
string returnValue = string.Empty;
string sql = string.Format("Select * From infection_open_user Where id = {0}", id);
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
List<InfectionOpenUserModel> models = conn.Query<Models.InfectionOpenUserModel>(sql).ToList();
if (models.Count > 0 && models != null)
{
for (int i = 0; i < models.Count; i++)
{
returnValue = models[i].type.ToString();
break;
}
}
}
return returnValue;
}
public InfectionOpenUserModel GetDataByID(string id)
{
string sql = string.Format("Select * From infection_open_user Where id = {0}", id);
InfectionOpenUserModel model = new InfectionOpenUserModel();
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
model = conn.QueryFirst<Models.InfectionOpenUserModel>(sql);
}
return model;
}
public int updateUserStateById(int id)
{
string sql = "update infection_open_user set state=3 where id=@id";
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Execute(sql, new { id = id});
}
}
public int checkUserIdent(string ident, string user_id)
{
string sql = "select count(*) from infection_open_user_info where ident=@ident ";
if (!string.IsNullOrEmpty(user_id))
{
sql = sql + " and user_id <> @user_id";
}
using (var conn = CommHelper.GetSqlConnection())
{
return conn.QueryFirst<int>(sql, new { ident = ident, user_id = user_id });
}
}
//已做问卷(月)
public int getMonthOne()
{
string sql = "select count(*) from infection_question_record where DATEDIFF(m,create_time,GETDATE())=0 ";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
//未做问卷(月)
public int getMonthTwo()
{
string sql = "select count(i.id) from infection_open_user_info i left join infection_open_user u on i.user_id=u.id where u.state<3 and DATEDIFF(m,i.create_time,GETDATE())=0";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
//已做问卷(总)
public int getAllOne()
{
string sql = "select count(*) from infection_open_user where state>=3 ";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
//未做问卷(总)
public int getAllTwo()
{
string sql = "select count(*) from infection_open_user where state<3 ";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
}
}