169 lines
6.8 KiB
C#
169 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Web.SessionState;
|
|
using Dapper;
|
|
using Dapper.Contrib.Extensions;
|
|
using System.Data.SqlClient;
|
|
using System.IO.Compression;
|
|
|
|
namespace abbott_2024_event.BackEnd.api
|
|
{
|
|
/// <summary>
|
|
/// userList 的摘要描述
|
|
/// </summary>
|
|
public class userList : IHttpHandler
|
|
{
|
|
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
|
|
public authToken authToken;
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
result objRet = new result();
|
|
DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType());
|
|
context.Response.ContentType = "application/json;charset=utf-8";
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant();
|
|
if (!String.IsNullOrEmpty(acceptEncoding))
|
|
{
|
|
if (acceptEncoding.Contains("GZIP"))
|
|
{
|
|
//输出流头部GZIP压缩
|
|
context.Response.AppendHeader("Content-encoding", "gzip");
|
|
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
else if (acceptEncoding.Contains("DEFLATE"))
|
|
{
|
|
//输出流头部DEFLATE压缩
|
|
context.Response.AppendHeader("Content-encoding", "deflate");
|
|
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
}
|
|
|
|
authToken objAuth = new authToken();
|
|
|
|
if (!objAuth.user_isLogin)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string start = (context.Request["start"] == null) ? "" : context.Request["start"].ToString();
|
|
string end = (context.Request["end"] == null) ? "" : context.Request["end"].ToString();
|
|
string gender = (context.Request["gender"] == null) ? "" : context.Request["gender"].ToString();
|
|
string min_age = (context.Request["min_age"] == null) ? "" : context.Request["min_age"].ToString();
|
|
string max_age = (context.Request["max_age"] == null) ? "" : context.Request["max_age"].ToString();
|
|
|
|
DateTime dateStart;
|
|
DateTime dateEnd;
|
|
|
|
try {
|
|
dateStart = DateTime.Parse(start);
|
|
dateEnd = DateTime.Parse(end + " 23:59:59");
|
|
}
|
|
catch {
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0008";
|
|
objRet.message = "測驗記錄起訖日期有誤!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
if (gender != "%" && gender != "M" && gender != "F") {
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0009";
|
|
objRet.message = "性別代碼錯誤!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string filiterString = "";
|
|
|
|
filiterString += " Where babyData_bindedLine = 'Y' and babyRec_newestRec = 'Y' and babyRec_recdate >= '" + dateStart.ToString("yyyy/MM/dd") + "' and babyRec_recdate <= '" + dateEnd.ToString("yyyy/MM/dd HH:mm:ss") + "' ";
|
|
|
|
if (gender != "%") {
|
|
filiterString += " and babyData_sexual = '" + gender + "' ";
|
|
}
|
|
|
|
filiterString += " and babyRec_months >= " + (int.Parse(min_age) * 12).ToString() + " and babyRec_months <= " + (int.Parse(max_age) * 12).ToString();
|
|
|
|
List<babyDataRecView> babyDataRecViews = conn.Query<babyDataRecView>("select distinct line_uid, line_displayname from babyDataRecView " + filiterString + " ").ToList();
|
|
|
|
foreach (babyDataRecView view in babyDataRecViews) {
|
|
userData userData = new userData();
|
|
userData.line_uid = view.line_uid;
|
|
userData.line_displayName = view.line_displayName;
|
|
|
|
List<babyDataRecView> subViews = conn.Query<babyDataRecView>("select * from babyDataRecView " + filiterString + " and line_uid = @line_uid ", new { line_uid = view.line_uid }).ToList();
|
|
|
|
foreach (babyDataRecView subView in subViews) {
|
|
babyData babyData = new babyData();
|
|
babyData.baby_name = subView.babyData_name;
|
|
babyData.baby_gender = subView.babyData_sexual;
|
|
babyData.baby_birthday = subView.babyData_birthday.ToString("yyyy/MM/dd");
|
|
babyData.baby_age = subView.babyRec_yearMonthStr;
|
|
babyData.baby_months = subView.babyRec_months.ToString();
|
|
babyData.baby_height = subView.babyRec_height.ToString();
|
|
babyData.baby_testdate = subView.babyRec_recdate.ToString("yyyy/MM/dd");
|
|
babyData.baby_percent = subView.babyRec_inpercent;
|
|
|
|
userData.testdate = subView.babyRec_recdate.ToString("yyyy/MM/dd");
|
|
|
|
userData.babyDatas.Add(babyData);
|
|
|
|
}
|
|
|
|
objRet.datas.Add(userData);
|
|
|
|
|
|
}
|
|
|
|
objRet.ret = "yes";
|
|
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
|
|
}
|
|
public class result
|
|
{
|
|
public string ret = "no";
|
|
public string err_code = "0000";
|
|
public string message = "";
|
|
public List<userData> datas = new List<userData>();
|
|
}
|
|
|
|
public class userData
|
|
{
|
|
public string line_uid { get; set; } = "";
|
|
public string line_displayName { get; set; } = "";
|
|
public string testdate { get; set; } = "";
|
|
|
|
public List<babyData> babyDatas = new List<babyData>();
|
|
}
|
|
|
|
public class babyData {
|
|
public string baby_name { get; set; } = "";
|
|
public string baby_gender { get; set; } = "";
|
|
public string baby_birthday { get; set; } = "";
|
|
public string baby_age { get; set; } = "";
|
|
public string baby_months { get; set; } = "";
|
|
public string baby_testdate { get; set; } = "";
|
|
|
|
public string baby_height { get; set; } = "";
|
|
public double baby_percent { get; set; } = 0;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |