192 lines
7.1 KiB
C#
192 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Web;
|
|
using System.Web.SessionState;
|
|
using System.Web.UI.HtmlControls;
|
|
using Dapper;
|
|
using Dapper.Contrib.Extensions;
|
|
|
|
namespace abbott_2024_event.BackEnd.api
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// importTestBaby 的摘要描述
|
|
/// </summary>
|
|
public class importTestBaby : IHttpHandler
|
|
{
|
|
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/plain";
|
|
context.Response.Write("Hello World");
|
|
|
|
string line_uid = "U648c5f8a6eb8bcc39291136c8f522106";
|
|
string baby_uid = "";
|
|
string baby_name = "十年女寶寶";
|
|
string babyData_sexual = "F";
|
|
string babyData_birthday = "2025/4/11";
|
|
|
|
if (baby_uid == "") {
|
|
baby_uid = globalClass.CreateRandomCode(10);
|
|
}
|
|
|
|
babyData tmpBaby = new babyData();
|
|
tmpBaby.babyData_uid = baby_uid;
|
|
tmpBaby.babyData_name = baby_name;
|
|
tmpBaby.babyData_sexual = babyData_sexual;
|
|
tmpBaby.babyData_birthday = Convert.ToDateTime(babyData_birthday);
|
|
tmpBaby.babyData_createdate = DateTime.Now;
|
|
tmpBaby.babyData_bindedLine = "Y";
|
|
tmpBaby.babyData_bindeddate = DateTime.Now;
|
|
tmpBaby.babyData_lastTestDate = DateTime.Now;
|
|
tmpBaby.line_uid = line_uid;
|
|
|
|
DateTime tmpDate = Convert.ToDateTime(babyData_birthday);
|
|
DateTime endDate = tmpDate.AddYears(10);
|
|
|
|
lenHeiTable minLenHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_percent = 3 and lenHeiTable_month = @lenHeiTable_month and lenHeiTable_sexual = @lenHeiTable_sexual", new { lenHeiTable_month = 0, lenHeiTable_sexual = babyData_sexual });
|
|
|
|
double minHeight = 42.5;
|
|
double maxHeight = 0.0;
|
|
|
|
while (tmpDate <= endDate)
|
|
{
|
|
int intmonth = globalClass.MonthDiff(tmpBaby.babyData_birthday, tmpDate);
|
|
|
|
int thisMonth = tmpDate.Month;
|
|
int thisYear = tmpDate.Year;
|
|
int nextMonth = tmpDate.AddDays(1).Month;
|
|
int nextYear = tmpDate.AddDays(1).Year;
|
|
|
|
string lastMonth = "N";
|
|
string lastYear = "N";
|
|
string newsest = "N";
|
|
|
|
if (thisMonth != nextMonth)
|
|
{
|
|
lastMonth = "Y";
|
|
}
|
|
|
|
if (thisYear != nextYear) {
|
|
lastYear = "Y";
|
|
}
|
|
|
|
if (tmpDate.ToString("yyyy/MM/dd") == endDate.ToString("yyyy/MM/dd"))
|
|
{
|
|
lastMonth = "Y";
|
|
lastYear = "Y";
|
|
newsest = "Y";
|
|
}
|
|
|
|
lenHeiTable maxLenHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_percent = 85 and lenHeiTable_month = @lenHeiTable_month and lenHeiTable_sexual = @lenHeiTable_sexual", new { lenHeiTable_month = intmonth, lenHeiTable_sexual = babyData_sexual });
|
|
|
|
maxHeight = maxLenHei.lenHeiTable_maxVal;
|
|
|
|
|
|
|
|
int intMin = (int)(minHeight * 10);
|
|
int intMax = (int)(maxHeight * 10);
|
|
|
|
if (intmonth <= 12) {
|
|
if (intMax - intMin > 3)
|
|
{
|
|
intMax = intMin + 3;
|
|
}
|
|
}
|
|
|
|
if (intmonth > 12 && intmonth <= 36)
|
|
{
|
|
if (intMax - intMin > 3)
|
|
{
|
|
intMax = intMin + 3;
|
|
}
|
|
}
|
|
|
|
if (intmonth > 36 && intmonth <= 72)
|
|
{
|
|
if (intMax - intMin > 4)
|
|
{
|
|
intMax = intMin + 4;
|
|
}
|
|
}
|
|
|
|
if (intmonth > 72 && intmonth <= 90)
|
|
{
|
|
if (intMax - intMin > 3)
|
|
{
|
|
intMax = intMin + 3;
|
|
}
|
|
}
|
|
|
|
if (intmonth > 90 )
|
|
{
|
|
if (intMax - intMin > 5)
|
|
{
|
|
intMax = intMin + 5;
|
|
}
|
|
}
|
|
|
|
Random rnd = new Random();
|
|
|
|
if (intMax < intMin) {
|
|
intMax = intMin + 1;
|
|
}
|
|
|
|
int getHei = rnd.Next(intMin, intMax);
|
|
|
|
double getHeight = (double)getHei / 10;
|
|
|
|
minHeight = getHeight;
|
|
|
|
babyRec objRec = new babyRec();
|
|
|
|
objRec.babyData_uid = baby_uid;
|
|
objRec.line_uid = line_uid;
|
|
objRec.babyRec_uid = globalClass.CreateRandomCode(16);
|
|
objRec.babyRec_key = globalClass.CreateRandomCode(16);
|
|
objRec.babyRec_recdate = tmpDate;
|
|
objRec.babyRec_recYear = tmpDate.Year;
|
|
objRec.babyRec_recMonth = tmpDate.Month;
|
|
objRec.babyRec_recDay = tmpDate.Day;
|
|
objRec.babyRec_height = getHeight;
|
|
objRec.babyRec_dayLastRec = "Y";
|
|
objRec.babyRec_monthLastRec = lastMonth;
|
|
objRec.babyRec_yearLastRec = lastYear;
|
|
objRec.babyRec_months = intmonth;
|
|
objRec.babyRec_yearMonthStr = globalClass.YearMonthDiff(tmpBaby.babyData_birthday, objRec.babyRec_recdate);
|
|
objRec.babyRec_yearMonthStr = globalClass.YearMonthDiff(tmpBaby.babyData_birthday, objRec.babyRec_recdate);
|
|
objRec.utm_source = "test";
|
|
objRec.utm_medium = "test";
|
|
objRec.utm_campaign = "test";
|
|
objRec.utm_term = "test";
|
|
objRec.utm_content = "test";
|
|
|
|
lenHeiTable objLenHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_minVal <= @height1 and lenHeiTable_maxVal > @height2 ", new { gender = tmpBaby.babyData_sexual, month = objRec.babyRec_months, height1 = getHeight, height2 = getHeight });
|
|
lenHeiTable objMidHei = conn.QueryFirstOrDefault<lenHeiTable>("select * from lenHeiTable where lenHeiTable_sexual = @gender and lenHeiTable_month = @month and lenHeiTable_percent = 50", new { gender = tmpBaby.babyData_sexual, month = objRec.babyRec_months });
|
|
|
|
objRec.babyRec_inpercent = objLenHei.lenHeiTable_percent;
|
|
objRec.babyRec_middleHeight = objMidHei.lenHeiTable_maxVal;
|
|
objRec.babyRec_newestRec = newsest;
|
|
|
|
conn.Insert(objRec);
|
|
|
|
tmpDate = tmpDate.AddDays(1);
|
|
|
|
}
|
|
|
|
conn.Insert(tmpBaby);
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |