359 lines
13 KiB
C#
359 lines
13 KiB
C#
using CYQ.Data.Cache;
|
|
using Microsoft.SqlServer.Server;
|
|
using Newtonsoft.Json;
|
|
using Song.Entities;
|
|
using Song.ServiceInterfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Dynamic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Contexts;
|
|
using System.Web;
|
|
using System.Web.Configuration;
|
|
using Taurus.Core;
|
|
using Taurus.Mvc;
|
|
using Taurus.Mvc.Attr;
|
|
using WeiSha.Common;
|
|
|
|
namespace PeiXun.Controllers.BasicInfo
|
|
{
|
|
public class ExamAPIController : Controller
|
|
{
|
|
[HttpGet]
|
|
[Token]
|
|
public void AA()
|
|
{
|
|
string id = Query<string>("id");
|
|
|
|
Write(id);
|
|
//Context.Response.Write(id);
|
|
}
|
|
|
|
//近期的考试(我的考试)
|
|
[Token]
|
|
[HttpGet]
|
|
public void FutureExamList()
|
|
{
|
|
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
|
|
//学员登录id
|
|
int stid = emp.Ac_ID;
|
|
|
|
//近期要开展的考试(从今天开始)
|
|
DateTime start = DateTime.Now.Date;
|
|
List<Song.Entities.Examination> todaylate = Business.Do<IExamination>().GetSelfExam(stid, start, null);
|
|
|
|
foreach (Examination e in todaylate)
|
|
{
|
|
e.Paper = getTestPaper(e.Tp_Id);
|
|
|
|
e.SubjectPath = getSubjectPath(e.Sbj_ID);
|
|
|
|
}
|
|
|
|
dynamic obj = new ExpandoObject();
|
|
obj.code = 1;
|
|
obj.msg = "success";
|
|
obj.data = todaylate;
|
|
|
|
Write(JsonConvert.SerializeObject(obj));
|
|
|
|
}
|
|
|
|
//所有考试
|
|
[Token]
|
|
[HttpGet]
|
|
public void ExamsList()
|
|
{
|
|
int size = Query<int>("size");
|
|
if (size == 0) size = 10;//默认10
|
|
int index = Query<int>("index");
|
|
if (index == 0) index = 1;//默认1
|
|
|
|
int sum = 0;
|
|
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
|
|
//学员登录Org_ID
|
|
int org_ID = emp.Org_ID;
|
|
|
|
List<Examination> exams = Business.Do<IExamination>().GetPager(org_ID, null, null, true, "", size, index, out sum).ToList();
|
|
foreach (Song.Entities.Examination exam in exams)
|
|
{
|
|
exam.Exam_Intro = WeiSha.Common.HTML.ClearTag(exam.Exam_Intro);
|
|
//场次
|
|
List<Examination> eList = setExamItem(exam.Exam_UID);
|
|
foreach (Examination e in eList)
|
|
{
|
|
e.GroupName = getGroupType(e.Exam_UID, e.Exam_GroupType);
|
|
e.Paper = getTestPaper(e.Tp_Id);
|
|
e.SubjectPath = getSubjectPath(e.Sbj_ID);
|
|
}
|
|
|
|
//场次
|
|
exam.ExaminationList = eList;
|
|
}
|
|
//总页数
|
|
int pageSum = (int)Math.Ceiling((double)sum / (double)size);
|
|
int[] pageAmount = new int[pageSum];
|
|
for (int i = 0; i < pageAmount.Length; i++)
|
|
pageAmount[i] = i + 1;
|
|
|
|
dynamic obj = new ExpandoObject();
|
|
obj.code = 1;
|
|
obj.msg = "success";
|
|
obj.pageIndex = index;
|
|
obj.pageSum = pageSum;
|
|
obj.pageAmount = pageAmount;
|
|
obj.pageSize = size;
|
|
|
|
obj.data = exams;
|
|
|
|
Write(JsonConvert.SerializeObject(obj));
|
|
|
|
}
|
|
|
|
//考试回顾
|
|
[Token]
|
|
[HttpGet]
|
|
public void ExamResult()
|
|
{
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
|
|
//学员id
|
|
int acID = emp.Ac_ID;
|
|
|
|
int count = 0;
|
|
Song.Entities.ExamResults[] results = null;
|
|
results = Business.Do<IExamination>().GetAttendPager(acID, -1, -1, null, int.MaxValue, 1, out count);
|
|
List<ExamResults> resultList = new List<ExamResults>();
|
|
resultList = results.ToList();
|
|
|
|
foreach (ExamResults result in resultList)
|
|
{
|
|
result.exam = getExam(result.Exam_ID);
|
|
result.Paper = getTestPaper(result.Tp_Id);
|
|
}
|
|
|
|
dynamic obj = new ExpandoObject();
|
|
obj.code = 1;
|
|
obj.msg = "success";
|
|
|
|
obj.data = resultList;
|
|
|
|
Write(JsonConvert.SerializeObject(obj));
|
|
}
|
|
|
|
[Token]
|
|
[HttpGet]
|
|
public void ExamReportFile()
|
|
{
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts student = cache.Get<Song.Entities.Accounts>(token);
|
|
|
|
|
|
FastReport.Report webReport = new FastReport.Report(); // 创建报表对象
|
|
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
FastReport.Export.Image.ImageExport pdf = new FastReport.Export.Image.ImageExport();
|
|
DataTable dt = new DataTable(); //JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(new xgDal().getJYSQD(int.Parse(id))));
|
|
dt.Columns.Add("name");
|
|
dt.Columns.Add("rq");
|
|
dt.Columns.Add("date_year");
|
|
dt.Columns.Add("sfzh");
|
|
dt.Columns.Add("zsbh");
|
|
dt.Columns.Add("jg");
|
|
dt.Columns.Add("type");
|
|
|
|
|
|
string id = Query<string>("id");
|
|
Song.Entities.ExamResults exr = Business.Do<IExamination>().ResultSingle(int.Parse(id));
|
|
|
|
DataRow dr = dt.NewRow();
|
|
dt.Rows.Add(dr);
|
|
dr["name"] = student.Ac_Name;
|
|
dr["rq"] = exr.Exr_CalcTime.ToString("yyyy年MM月dd日");
|
|
dr["date_year"] = DateTime.Now.Year;
|
|
dr["sfzh"] = student.Ac_IDCardNumber;
|
|
dr["zsbh"] = "DZZYJKPXPT" + exr.Exr_CalcTime.ToString("yyyyMMdd") + exr.Exr_ID.ToString("000000");
|
|
dr["jg"] = student.Ac_QyName;
|
|
if (student.Ac_Type == "main")
|
|
{
|
|
dr["type"] = "用人单位主要负责人";
|
|
webReport.Load(Server.MapPath("~/Download/") + "manager.frx");//调用报表
|
|
}
|
|
else if (student.Ac_Type == "manager")
|
|
{
|
|
dr["type"] = "职业卫生管理人员";
|
|
webReport.Load(Server.MapPath("~/Download/") + "manager.frx");//调用报表
|
|
}
|
|
else
|
|
{
|
|
webReport.Load(Server.MapPath("~/Download/") + "worker.frx");//调用报表
|
|
}
|
|
webReport.RegisterData(dt, "bg"); //传递数据
|
|
webReport.Prepare();
|
|
webReport.Export(pdf, ms);
|
|
webReport.Dispose();
|
|
|
|
|
|
|
|
string base64String = Convert.ToBase64String(ms.ToArray());
|
|
|
|
Write("data:image/Jpeg;base64," + base64String);
|
|
return;
|
|
|
|
|
|
HttpContext.Current.Response.ContentType = "image/JPEG";
|
|
//Response.ContentType = "application/octet-stream";
|
|
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + student.Ac_Name+ "证书" + exr.Exr_ID.ToString().PadLeft(12,'0')+".jpg");
|
|
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
|
|
HttpContext.Current.Response.Flush();
|
|
HttpContext.Current.Response.End();
|
|
//return File(ms, "image/jpeg");
|
|
|
|
}
|
|
|
|
//参加考试URL
|
|
[Token]
|
|
[HttpGet]
|
|
public void GetExamURL()
|
|
{
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts student = cache.Get<Song.Entities.Accounts>(token);
|
|
//Exam_id
|
|
string examId = Query<string>("examid");
|
|
|
|
//主站的域名跟目录。后期需要用户所在城市动态获取二级域名.
|
|
string maiHost = ConfigurationManager.AppSettings["mainhost"];
|
|
|
|
string domain =ConfigurationManager.AppSettings["sso_domain"];
|
|
string gotourl = $"/mobile/examing.ashx?id={examId}";
|
|
string url = $"{maiHost}/api/sso.ashx?appid=app&user={student.Ac_AccName}&name={student.Ac_Name}&pw={student.Ac_Pw}&domain={domain}&action=login&return=json&goto={gotourl}";
|
|
|
|
dynamic obj = new ExpandoObject();
|
|
obj.code = 1;
|
|
obj.msg = "success";
|
|
|
|
obj.data = url;
|
|
|
|
Write(JsonConvert.SerializeObject(obj));
|
|
}
|
|
//考试预览URL
|
|
[Token]
|
|
[HttpGet]
|
|
public void GetExamReviewURL()
|
|
{
|
|
string token = Query<string>("token").TrimStart("xyl:".ToCharArray());
|
|
DistributedCache cache = DistributedCache.Instance;
|
|
Song.Entities.Accounts student = cache.Get<Song.Entities.Accounts>(token);
|
|
//Exam_id
|
|
string examId = Query<string>("examid");
|
|
|
|
//主站的域名跟目录。后期需要用户所在城市动态获取二级域名.
|
|
string maiHost = ConfigurationManager.AppSettings["mainhost"];
|
|
|
|
string domain =ConfigurationManager.AppSettings["sso_domain"];
|
|
string gotourl = $"/mobile/ExamReview.ashx?id={examId}";
|
|
string url = $"{maiHost}/api/sso.ashx?appid=app&user={student.Ac_AccName}&name={student.Ac_Name}&pw={student.Ac_Pw}&domain={domain}&action=login&return=json&goto={gotourl}";
|
|
|
|
dynamic obj = new ExpandoObject();
|
|
obj.code = 1;
|
|
obj.msg = "success";
|
|
|
|
obj.data = url;
|
|
|
|
Write(JsonConvert.SerializeObject(obj));
|
|
}
|
|
|
|
|
|
#region 公共函数
|
|
|
|
/// <summary>
|
|
/// 获取参考人员类型
|
|
/// </summary>
|
|
/// <param name="para"></param>
|
|
/// <returns></returns>
|
|
protected string getGroupType(string uid,int type)
|
|
{
|
|
if (type == 1) return "全体学员";
|
|
if (type == 2)
|
|
{
|
|
Song.Entities.StudentSort[] sts = Business.Do<IExamination>().GroupForStudentSort(uid);
|
|
string strDep = "";
|
|
for (int i = 0; i < sts.Length; i++)
|
|
{
|
|
strDep += sts[i].Sts_Name;
|
|
if (i < sts.Length - 1) strDep += ",";
|
|
}
|
|
return strDep;
|
|
}
|
|
return "";
|
|
}
|
|
/// <summary>
|
|
/// 绑定考试场次的列表
|
|
/// </summary>
|
|
private List<Examination> setExamItem(string uid)
|
|
{
|
|
Song.Entities.Examination[] ans = Business.Do<IExamination>().ExamItem(uid);
|
|
for (int i = 0; i < ans.Length; i++)
|
|
{
|
|
DateTime examDate = ans[i].Exam_Date < DateTime.Now.AddYears(-100) ? DateTime.Now : (DateTime)ans[i].Exam_Date;
|
|
ans[i].Exam_Date = examDate.AddYears(100) < DateTime.Now ? DateTime.Now : examDate;
|
|
}
|
|
return ans.ToList();
|
|
}
|
|
/// <summary>
|
|
/// 获取考试的试卷信息
|
|
/// </summary>
|
|
/// <param name="para"></param>
|
|
/// <returns></returns>
|
|
protected Song.Entities.TestPaper getTestPaper(int tpid)
|
|
{
|
|
Song.Entities.TestPaper tp = Business.Do<ITestPaper>().PagerSingle(tpid);
|
|
return tp;
|
|
}
|
|
/// <summary>
|
|
/// 获取考试信息
|
|
/// </summary>
|
|
/// <param name="para"></param>
|
|
/// <returns></returns>
|
|
protected Song.Entities.Examination getExam(int examid)
|
|
{
|
|
Song.Entities.Examination exam = Business.Do<IExamination>().ExamSingle(examid);
|
|
return exam;
|
|
}
|
|
/// <summary>
|
|
/// 获取当前专业的上级专业
|
|
/// </summary>
|
|
/// <param name="para"></param>
|
|
/// <returns></returns>
|
|
protected string getSubjectPath(int sbjid)
|
|
{
|
|
string sbjstr = "";
|
|
Song.Entities.Subject s = Business.Do<ISubject>().SubjectSingle(sbjid);
|
|
if (s != null)
|
|
{
|
|
sbjstr += s.Sbj_Name;
|
|
while (s.Sbj_PID != 0)
|
|
{
|
|
s = Business.Do<ISubject>().SubjectSingle(s.Sbj_PID);
|
|
if (s == null) break;
|
|
sbjstr = s.Sbj_Name + " >> " + sbjstr;
|
|
}
|
|
}
|
|
return sbjstr;
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
} |