DAL_DZKJ_TaskExecutionStatistics.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. namespace LYFZ.WeixinServiceDate.DAL
  8. {
  9. public class DAL_DZKJ_TaskExecutionStatistics : BaseDataOperate
  10. {
  11. public DAL_DZKJ_TaskExecutionStatistics()
  12. {
  13. this.TableFieldNameString = "";
  14. }
  15. #region 属性和字段
  16. string _tableName = "tb_DZKJ_TaskExecutionStatistics";
  17. /// <summary>
  18. /// 获取数据表名
  19. /// </summary>
  20. public override string TableName
  21. {
  22. get { return _tableName; }
  23. set { this._tableName = value; }
  24. }
  25. /// <summary>
  26. /// 获取当前新的数据表模型对象
  27. /// </summary>
  28. public override object ObjModel
  29. {
  30. get
  31. {
  32. return this.CurrentModel;
  33. }
  34. }
  35. /// <summary>
  36. /// 获取当前新的MOdel
  37. /// </summary>
  38. public Model.Model_DZKJ_TaskExecutionStatistics CurrentModel
  39. {
  40. get { return new Model.Model_DZKJ_TaskExecutionStatistics(); }
  41. }
  42. string _tableFieldNameString = "";
  43. /// <summary>
  44. /// 数据表字段名数组
  45. /// </summary>
  46. public override string TableFieldNameString
  47. {
  48. get { return this._tableFieldNameString; }
  49. set { this._tableFieldNameString = value; }
  50. }
  51. #endregion
  52. #region 检查记录
  53. //基类已经实现
  54. #endregion
  55. #region 增加数据
  56. /// <summary>
  57. /// 增加一条数据
  58. /// </summary>
  59. /// <param name="model">Model对象</param>
  60. /// <returns></returns>
  61. public bool Add(Model.Model_DZKJ_TaskExecutionStatistics model)
  62. {
  63. return base.Add(model);
  64. }
  65. /// <summary>
  66. /// 增加一条数据
  67. /// </summary>
  68. /// <param name="model">Model对象</param>
  69. /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
  70. /// <returns></returns>
  71. public bool Add(Model.Model_DZKJ_TaskExecutionStatistics model, string overlookFieldList = "ID")
  72. {
  73. return base.Add(model, overlookFieldList);
  74. }
  75. #endregion
  76. #region 删除数据
  77. /// <summary>
  78. /// 删除数据
  79. /// </summary>
  80. /// <param name="model"></param>
  81. /// <returns></returns>
  82. public bool Delete(Model.Model_DZKJ_TaskExecutionStatistics model)
  83. {
  84. return base.Delete(model.ID);
  85. }
  86. #endregion
  87. #region 更新数据
  88. /// <summary>
  89. /// 更新一条数据
  90. /// </summary>
  91. public bool Update(Model.Model_DZKJ_TaskExecutionStatistics model)
  92. {
  93. return base.Update(model);
  94. }
  95. /// <summary>
  96. /// 根据筛选字段和SQL筛选运算符号更新数据
  97. /// </summary>
  98. /// <param name="model">Model对象</param>
  99. /// <param name="filterFieldName">筛选字段名称</param>
  100. /// <param name="operators">SQL筛选运算符号</param>
  101. /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
  102. /// <returns></returns>
  103. public bool Update(Model.Model_DZKJ_TaskExecutionStatistics model, string filterFieldName = "ID", string operators = "=", string overlookFieldList = "ID")
  104. {
  105. return base.Update(model, filterFieldName, operators, overlookFieldList);
  106. }
  107. #endregion
  108. #region 查询数据
  109. /// <summary>
  110. /// 得到一个对象实体
  111. /// </summary>
  112. public Model.Model_DZKJ_TaskExecutionStatistics GetModel(long ID)
  113. {
  114. return DataRowToModel(GetDataRow(ID));
  115. }
  116. /// <summary>
  117. /// 得到一个对象实体
  118. /// </summary>
  119. /// <param name="row"></param>
  120. /// <returns></returns>
  121. public Model.Model_DZKJ_TaskExecutionStatistics DataRowToModel(DataRow row)
  122. {
  123. return DataRowToModelObject(row) as Model.Model_DZKJ_TaskExecutionStatistics;
  124. }
  125. public bool UpdateLatestLoginTime(string Account, string ip, string LatestLoginTime)
  126. {
  127. string updateSql = "update [tb_DZKJ_CustomerAccount] set ip='" + ip + "',LatestLoginTime='" + LatestLoginTime + "' where Account='" + Account + "'";
  128. if (LYFZ.Helper.SQLHelper.ExecuteSql(updateSql) > 0)
  129. {
  130. return true;
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. }
  137. /// <summary>
  138. /// 获取点赞科技爆客系统功能执行统计
  139. /// </summary>
  140. /// <param name="type"></param>
  141. /// <param name="time"></param>
  142. /// <param name="keyword"></param>
  143. /// <returns></returns>
  144. public DataTable GetTaskExecutionStatisticDataTable(int type, DateTime time, string keyword)
  145. {
  146. try
  147. {
  148. string ExecutionTimeString = "";
  149. switch (type)
  150. {
  151. case 0:
  152. ExecutionTimeString = "ExecutionTime>='" + Convert.ToDateTime(time.Year + "-01-01").ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + Convert.ToDateTime(time.Year + "-01-01").AddYears(1).ToString("yyyy-MM-dd") + "'";
  153. break;
  154. case 1:
  155. ExecutionTimeString = "ExecutionTime>='" + Convert.ToDateTime(time.ToString("yyyy-MM") + "-01").ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + Convert.ToDateTime(time.ToString("yyyy-MM") + "-01").AddMonths(1).ToString("yyyy-MM-dd") + "'";
  156. break;
  157. case 2:
  158. ExecutionTimeString = "ExecutionTime>='" + time.ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + time.AddDays(1).ToString("yyyy-MM-dd") + "'";
  159. break;
  160. default:
  161. ExecutionTimeString = "ExecutionTime>='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "'";
  162. break;
  163. }
  164. string whereString = "";
  165. if (!string.IsNullOrEmpty(keyword.Trim()))
  166. {
  167. whereString = "where [tb_DZKJ_CustomerAccount].Account like '%" + keyword + "%' or [CompanyName] like '%" + keyword + "%'";
  168. }
  169. string sql = " with t as"
  170. + " ("
  171. + " SELECT [Account]"
  172. + " ,sum([ExecutionCount]) as ExecutionCount "
  173. + " FROM [dbo].[tb_DZKJ_TaskExecutionStatistics] "
  174. + " where " + ExecutionTimeString + " "
  175. + " group by [Account]"
  176. + " )"
  177. + " select top 5000 [CompanyName],[tb_DZKJ_CustomerAccount].Account,ManagerProgramVersion,SmallEifVersion,ExecutionCount "
  178. + " from [tb_DZKJ_CustomerAccount] "
  179. + " left join "
  180. + " t on [tb_DZKJ_CustomerAccount].Account=t.Account "
  181. + whereString + " order by ExecutionCount desc";
  182. return LYFZ.Helper.SQLHelper.Query(sql).Tables[0];
  183. }
  184. catch {
  185. return null;
  186. }
  187. }
  188. public DataTable GetTaskExecutionOneDataTable(int type, DateTime time, string Account = "")
  189. {
  190. try
  191. {
  192. string ExecutionTimeString = "";
  193. switch (type)
  194. {
  195. case 0:
  196. ExecutionTimeString = " and (ExecutionTime>='" + Convert.ToDateTime(time.Year + "-01-01").ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + Convert.ToDateTime(time.Year + "-01-01").AddYears(1).ToString("yyyy-MM-dd") + "')";
  197. break;
  198. case 1:
  199. ExecutionTimeString = " and (ExecutionTime>='" + Convert.ToDateTime(time.ToString("yyyy-MM") + "-01").ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + Convert.ToDateTime(time.ToString("yyyy-MM") + "-01").AddMonths(1).ToString("yyyy-MM-dd") + "')";
  200. break;
  201. case 2:
  202. ExecutionTimeString = " and (ExecutionTime>='" + time.ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + time.AddDays(1).ToString("yyyy-MM-dd") + "')";
  203. break;
  204. default:
  205. ExecutionTimeString = " and (ExecutionTime>='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "')";
  206. break;
  207. }
  208. string sql = "with t as"
  209. + " ("
  210. + " SELECT "
  211. + " max([Account]) as Account "
  212. + " ,MAX(Features) as Features "
  213. + " ,sum([ExecutionCount]) as ExecutionCount "
  214. + " FROM [dbo].[tb_DZKJ_TaskExecutionStatistics] "
  215. + " where [Account]='" + Account + "' " + ExecutionTimeString+" "
  216. + " group by GroupType "
  217. + " ) "
  218. + " select Account,Features,ExecutionCount "
  219. + " from t "
  220. + " order by ExecutionCount desc ";
  221. return LYFZ.Helper.SQLHelper.Query(sql).Tables[0];
  222. }
  223. catch
  224. {
  225. return null;
  226. }
  227. }
  228. #endregion
  229. /// <summary>
  230. /// 更新点赞营销功能使用次数统计
  231. /// </summary>
  232. /// <param name="_Account"></param>
  233. /// <param name="_Features"></param>
  234. /// <returns></returns>
  235. public static int UpdateTaskExecutionStatistics(string _Account, string _Features)
  236. {
  237. /*
  238. Declare @return_value nvarchar(50)
  239. EXEC @return_value = [dbo].[PROCE_UpdateTaskExecutionStatistics]
  240. @ID = 3,
  241. @DayKey = N'md512345655553',
  242. @Account = N'test',
  243. @Features = N'转发朋友圈',
  244. @GroupType = N'md333333'
  245. */
  246. try
  247. {
  248. SqlParameter[] parameters = {
  249. new SqlParameter("@ID", SqlDbType.BigInt),
  250. new SqlParameter("@DayKey" , SqlDbType.VarChar , 50),
  251. new SqlParameter("@Account", SqlDbType.VarChar , 50 ),
  252. new SqlParameter("@Features", SqlDbType.VarChar, 100),
  253. new SqlParameter("@GroupType", SqlDbType.VarChar , 50 )
  254. };
  255. long _ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId();
  256. string _DayKey = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(_Account.Trim() + _Features.Trim() + DateTime.Now.ToString("yyyy-MM-dd"));
  257. string _GroupType = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(_Account.Trim() + _Features.Trim());
  258. parameters[0].Value = _ID;
  259. parameters[1].Value = _DayKey;
  260. parameters[2].Value = _Account.Trim();
  261. parameters[3].Value = _Features.Trim();
  262. parameters[4].Value = _GroupType;
  263. int retRowCount = 0;
  264. LYFZ.Helper.SQLHelper.RunProcedure("PROCE_UpdateTaskExecutionStatistics", parameters, out retRowCount);
  265. return retRowCount;
  266. }
  267. catch {
  268. return 0;
  269. }
  270. }
  271. /// <summary>
  272. /// 获取任务执行次数
  273. /// </summary>
  274. /// <param name="_Account"></param>
  275. /// <param name="t"></param>
  276. /// <returns></returns>
  277. public static DataTable GetTaskExecutionStatistics(string _Account, DateTime t)
  278. {
  279. try
  280. {
  281. string sql = "select max([Features]) as Features,sum([ExecutionCount]) as ExecutionCount from [tb_DZKJ_TaskExecutionStatistics] "
  282. + " where Account='" + _Account + "' and (ExecutionTime>='" + t.ToString("yyyy-MM-dd") + "' and ExecutionTime <'" + t.AddDays(1).ToString("yyyy-MM-dd") + "')"
  283. + " group by GroupType";
  284. DataSet ds = LYFZ.Helper.SQLHelper.Query(sql);
  285. return ds.Tables[0];
  286. }
  287. catch {
  288. return null;
  289. }
  290. }
  291. #region 数据分页
  292. //基类已实现相关方法
  293. #endregion
  294. }
  295. }