|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Linq;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2023-03-06 12:18
- /// 描 述:心里预约功能
- /// </summary>
- public class PsychologyInfoService : RepositoryFactory
- {
-
- #region 获取数据
-
- /// <summary>
- /// 获取列表数据
- /// </summary>
- /// <param name="queryJson">条件参数</param>
- /// <returns></returns>
- public IEnumerable<PsychologyInfoEntity> GetList(string queryJson)
- {
- try
- {
- //参考写法
- //var queryParam = queryJson.ToJObject();
- // 虚拟参数
- //var dp = new DynamicParameters(new { });
- //dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
-
- var strSql = new StringBuilder();
- strSql.Append(" SELECT t.*,p.ReplyContent,p.Url as Urls,p.ReplyUser,p.ReplyTime,s.StuName,s.deptNo,s.majorno,s.classno,s.GenderNo,s.IdentityCardNo,s.IsSingle FROM PsychologyInfo t ");
- strSql.Append(" left join PsychologyReplyInfo p on p.PsychologyInfoid = t.id ");
- strSql.Append(" left join StuInfoBasic s on s.StuNo = t.StuNo ");
- strSql.Append(" where 1=1");
-
- return this.BaseRepository("CollegeMIS").FindList<PsychologyInfoEntity>(strSql.ToString());
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取列表分页数据
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="queryJson">条件参数</param>
- /// <returns></returns>
- public IEnumerable<PsychologyInfoEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var db = this.BaseRepository().getDbConnection().Database;
- var strSql = new StringBuilder();
- strSql.Append(" SELECT t.*,p.ReplyContent,p.Url as Urls,p.ReplyUser,p.ReplyTime,l.F_RealName FROM PsychologyInfo t ");
- strSql.Append(" left join PsychologyReplyInfo p on p.PsychologyInfoid=t.id and p.ReplyType = 2");
- strSql.Append($" left join {db}.dbo.LR_Base_User l on l.F_account =p.ReplyUser ");
- strSql.Append(" where 1=1 ");
- var queryParam = queryJson.ToJObject();
- var dp = new DynamicParameters(new { });
- if (!queryParam["StuNo"].IsEmpty())
- {
- dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
- strSql.Append(" AND t.StuNo = @StuNo ");
- }
- if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
- {
- dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
- dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
- strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
- }
- return this.BaseRepository("CollegeMIS").FindList<PsychologyInfoEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public PsychologyInfoEntity GetEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<PsychologyInfoEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 学生查看
- /// </summary>
- /// <param name="keyValue"></param>
- /// <returns></returns>
- public PsychologyInfoEntity GetEntityForView(string keyValue)
- {
- try
- {
- var db = this.BaseRepository().getDbConnection().Database;
- var strSql = new StringBuilder();
- strSql.Append(" SELECT t.*,p.ReplyContent,p.Url as Urls,p.ReplyUser,p.ReplyTime,l.F_RealName FROM PsychologyInfo t ");
- strSql.Append(" left join PsychologyReplyInfo p on p.PsychologyInfoid=t.id and p.ReplyType = 2");
- strSql.Append($" left join {db}.dbo.LR_Base_User l on l.F_account =p.ReplyUser ");
- strSql.Append($" where t.Id='{keyValue}' ");
- return this.BaseRepository("CollegeMIS").FindList<PsychologyInfoEntity>(strSql.ToString()).FirstOrDefault();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- try
- {
- this.BaseRepository("CollegeMIS").Delete<PsychologyInfoEntity>(t => t.Id == keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- /// </summary>
- public void SaveEntity(string keyValue, PsychologyInfoEntity entity)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- this.BaseRepository("CollegeMIS").Update(entity);
- }
- else
- {
- entity.Create();
- this.BaseRepository("CollegeMIS").Insert(entity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 提交实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void SubmitEntity(string keyValue)
- {
- var db = this.BaseRepository("CollegeMIS").BeginTrans();
- try
- {
- var entity = db.FindEntity<PsychologyInfoEntity>(keyValue);
- entity.State = 2;
- db.Update(entity);
- //添加回复表数据
- db.ExecuteBySql(@"INSERT INTO PsychologyReplyInfo(Id, PsychologyInfoId, State, ReplyContent, ReplyType, Url, ReplyUser, ReplyTime, CreateTime)
- VALUES('" + Guid.NewGuid().ToString() + "', '" + keyValue + "', '2', '', '', '', '',NUll, '" + DateTime.Now + "') ");
-
- //添加消息提醒阅读表数据
- var account = LoginUserInfo.Get().account;
- //查询当前学生辅导员
- var classinfo = db.FindList<ClassInfoEntity>($"select t.* from classinfo t join StuInfoBasic stu on t.classno=stu.ClassNo and stu.StuNo='{account}'").FirstOrDefault();
- if (classinfo != null && !string.IsNullOrEmpty(classinfo.ClassTutorNo))
- {
- PsychologyReadInfo model = new PsychologyReadInfo();
- model.Create();
- model.PsychologyInfoId = keyValue;
- model.State = entity.State;
- model.Account = classinfo.ClassTutorNo;
- model.Description = "教师";
- db.Insert(model);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- }
- }
|