tijian_jichuang/Code/SOH.BLL.Host/QianTaiBLL.cs

816 lines
32 KiB
C#
Raw Normal View History

2025-02-20 11:54:48 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EAS.Services;
using SOH.Data;
using SOH.Entities;
using SOH.Entities.DTO;
using EAS.Data.ORM;
using EAS.Data.Linq;
using EAS.Data.Access;
using System.Data;
namespace SOH.BLL
{
[ServiceBind(typeof(IQianTai))]
[ServiceObject("前台业务")]
public class QianTaiBLL : IQianTai
{
public Data.OperationResult gettmstate(string tm)
{
///////////////////////throw new NotImplementedException();
OperationResult or = new OperationResult();
using (var db = new DbEntities())
{
//select * from t_jjxb where tm=1020150226 and jjx=0 and ysfbz=0
int itm = int.Parse(tm);
if (db.t_jjxbs.Where(t => t.tm == itm && t.jjx == 0 && t.ysfbz == 0).Any())
{
or.State = 2;
or.Message = "当前客户有未收费的加项不能回收!";
return or;
}
//select tmztz,hyh,xm,xb,nl,hyzk,sfzh,csrq,image from t_ttgzb where tm=1020150226
var gr = db.t_grgzbs.Where(t => t.tm == itm);
var tt = db.t_ttgzbs.Where(t => t.tm == itm);
// if(gr.Any())
bool grb = gr.Any();
bool ttb = tt.Any();
dto_gzb gzb = null;
if (grb || ttb)
{
if (grb)
{
gzb = gr.Select(t => new dto_gzb { tm = itm, tmztz = t.tmztz, hyh = t.hyh, xm = t.xm, xb = t.xb, nl = t.nl, hyzk = t.hyzk, sfzh = t.sfzh, csrq = t.csrq, lx = 1 }).First();
}
if (ttb)
{
gzb = tt.Select(t => new dto_gzb
{
tm = itm,
tmztz = t.tmztz,
hyh = t.hyh,
xm = t.xm,
xb = t.xb,
nl = t.nl,
hyzk = t.hyzk,
sfzh = t.sfzh,
csrq = t.csrq,
image = t.image,
lx = 2,
ygbh = t.ygh,
ygbm = t.ssbm,
ygdh = t.tel
}).First();
}
}
else
{
or.State = 3;
or.Message = "当前条码不存在!";
return or;
}
if (gzb.tmztz == 3)
{
or.State = 2;
or.Message = "当前客户有未收费的加项不能回收!";
return or;
}
if (gzb.tmztz == 2)
{
or.State = 1;
or.Message = "当前条码可以回收!";
or.Tag = Newtonsoft.Json.JsonConvert.SerializeObject(gzb);
return or;
}
if (gzb.tmztz == 4 || gzb.tmztz == 5)
{
or.State = 4;
or.Message = "当前体检人员已经交本!";
or.Tag = Newtonsoft.Json.JsonConvert.SerializeObject(gzb);
return or;
}
or.State = 0;
or.Message = "条码其他状态,不能回收!";
}
return or;
}
class zt
{
public short bm { get; set; }
public string ztz { get; set; }
}
List<zt> zts = new List<zt>();
public string gettjxmbytm(string tm)
{
zts.Add(new zt { bm = 0, ztz = "未检查" });
zts.Add(new zt { bm = 1, ztz = "临时保存" });
zts.Add(new zt { bm = 2, ztz = "放弃" });
zts.Add(new zt { bm = 3, ztz = "带查" });
zts.Add(new zt { bm = 4, ztz = "完成" });
//throw new NotImplementedException();
//select * from t_tempdjxm,t_zhxm where tm=216184 and t_zhxm.zhbm=t_tempdjxm.zhbm and t_zhxm.jclb<>2 order by ztz,t_Tempdjxm.ksbm
using (var db = new DbEntities())
{
int itm = int.Parse(tm.Trim());
var tjcxm = db.t_tempdjxms.Where(t => t.tm == itm);//.Join(db.t_zhxms, t => t.zhbm, p => p.zhbm, (o, p) => { });
var tzhxm = db.t_zhxms.Where(t => t.jclb != 2).OrderBy(t => t.xssx);
var ts = tjcxm.Join(tzhxm, t => t.zhbm, p => p.zhbm, (a, b) => new { b.zhmc, a.ztz }).ToList();
var tr = ts.Join(zts, t => t.ztz, p => p.bm, (t, p) => new { t.ztz, t.zhmc, ztzs = p.ztz }).ToList();
return Newtonsoft.Json.JsonConvert.SerializeObject(tr);
}
//return null;
}
public OperationResult tijianshouchehuishou(string tm, string czy, short fddm)
{
//throw new NotImplementedException();
OperationResult or = new OperationResult();
using (var db = new DbEntities())
{
var tran = db.CreateTransaction();
try
{
int itm = int.Parse(tm.Trim());
var djxm = db.t_tempdjxms.Where(t => t.tm == itm);
var zhxm = db.t_zhxms.Join(djxm, t => t.zhbm, p => p.zhbm, (t, p) => new { t, p }).ToList();
zhxm.ForEach(t =>
{
if (t.p.ztz == 0)
{
t.p.upflag = 1;
t.p.ztz = 2;
db.t_tempdjxms.Update(t.p);
db.t_fqs.Delete(fq => fq.tm == itm && fq.zhbm == t.p.zhbm && fq.fddm == fddm);
t_fq fqm = new t_fq { tm = itm, czy = czy, fddm = fddm, zhbm = t.p.zhbm };
db.t_fqs.Insert(fqm);
}
else if (t.p.ztz == 1 && t.t.jclb != 1)
{
t.p.ztz = 4;
t.p.upflag = 1;
db.t_tempdjxms.Update(t.p);
}
});
bool all4 = false;
if (db.t_tempdjxms.Where(t => t.tm == itm && t.ztz != 4 && t.ztz != 2).Join(db.t_zhxms, t => t.zhbm, p => p.zhbm, (a, b) => new { b }).Where(t => t.b.jclb != 2).Count() == 0)
{
all4 = true;
}
var gr = db.t_grgzbs.FirstOrDefault(t => t.tm == itm);
var tt = db.t_ttgzbs.FirstOrDefault(t => t.tm == itm);
if (all4)
{
//db.t_tempdjxms.Update(t => t.tm == itm, t => new t_tempdjxm {tm=t.tm, });
if (gr != null)
{
gr.dyrq = new DateTime(1900, 1, 1);
gr.tmztz = 5;
db.t_grgzbs.Update(gr);
}
else if (tt != null)
{
tt.dyrq = new DateTime(1900, 1, 1);
tt.tmztz = 5;
db.t_ttgzbs.Update(tt);
}
else
{
tran.Rollback();
or.State = 0;
or.Message = "在团检记录和个检记录里都找不到当前条码";
}
}
else
{
if (gr != null)
{
gr.dyrq = new DateTime(1900, 1, 1);
gr.tmztz = 4;
db.t_grgzbs.Update(gr);
}
else if (tt != null)
{
tt.dyrq = new DateTime(1900, 1, 1);
tt.tmztz = 4;
db.t_ttgzbs.Update(tt);
}
else
{
tran.Rollback();
or.State = 0;
or.Message = "在团检记录和个检记录里都找不到当前条码";
}
}
tran.Commit();
}
catch (System.Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = ex.Message;
return or;
}
}
or.State = 1;
or.Message = "体检手册回收成功!";
return or;
}
public OperationResult chexiaohuishou(dto_gzb cx_gzb)
{
//throw new NotImplementedException();
OperationResult or = new OperationResult();
using (var db = new DbEntities())
{
var tran = db.CreateTransaction();
try
{
if (cx_gzb.lx == 1)
{
// db.t_grgzbs.Update(t => t.tm == cx_gzb.tm, t => new t_grgzb
// {
// tm=t.tm,
// xm=t.xm,
// tcbm=t.tcbm,
//
// });
var gr = db.t_grgzbs.FirstOrDefault(t => t.tm == cx_gzb.tm);
if (gr == null)
{
or.State = 0;
or.Message = "没有找到当前条码!";
tran.Rollback();
return or;
}
gr.tmztz = 2;
gr.upflag = 1;
gr.dyrq = new DateTime(1900, 1, 1);
db.t_grgzbs.Update(gr);
}
else if (cx_gzb.lx == 2)
{
var tt = db.t_ttgzbs.FirstOrDefault(t => t.tm == cx_gzb.tm);
if (tt == null)
{
or.State = 0;
or.Message = "没有找到当前条码!";
tran.Rollback();
return or;
}
tt.tmztz = 2;
tt.dyrq = new DateTime(1900, 1, 1);
tt.upflag = 1;
db.t_ttgzbs.Update(tt);
}
//db.OrmAccessor.DataAccessor.Query()
var hzfx = db.t_hzfxs.FirstOrDefault(t => t.tm == cx_gzb.tm);
if (hzfx != null)
{
hzfx.zt = 0;
hzfx.shtg = 0;
hzfx.upflag = 1;
db.t_hzfxs.Update(hzfx);
}
db.t_fqs.Delete(t => t.tm == cx_gzb.tm);
db.DataAccessor.Execute("update t_tempdjxm set ztz=0,upflag=1 where ztz=2 and tm=" + cx_gzb.tm);
db.DataAccessor.Execute("delete from t_jjdtx where tm=" + cx_gzb.tm);
tran.Commit();
}
catch (System.Exception ex)
{
or.State = 0;
or.Message = ex.Message;
tran.Rollback();
return or;
}
}
or.State = 1;
or.Message = "操作成功!";
return or;
}
#region
/// <summary>
/// 根据条码查询个检和团检中存在的客户相关信息
/// </summary>
/// <param name="tm"></param>
/// <returns></returns>
public Entities.DTO.dto_gzb GetInfoByTm(int tm)
{
using (DbEntities db = new DbEntities())
{
bool ifgr = tm.ToString("0000000000").StartsWith("1");
//以0开头的tm是个人的
if (!ifgr) //个人体检
{
var data1 = from a in db.t_grgzbs
join b in db.t_tcs on a.tcbm equals b.tcbm
where a.tm == tm
select new Entities.DTO.dto_gzb
{
tmztz = a.tmztz,
hyh = a.hyh,
xm = a.xm,
xb = a.xb,
nl = a.nl,
hyzk = a.hyzk,
sfzh = a.sfzh,
csrq = a.csrq,
tm = a.tm,
lx = 1, //类型1个人
//ygbh=a. ,
//ygbm=a. ,
ygdh = a.dh,
tcbm = a.tcbm,
tcmc = b.tcmc,
tczl = a.tczl,
jxgzfbj = 1,
fddm = a.fddm,
gzfbj = 1
//khmc=a.
};
if (data1.Any())
{
return data1.First();
}
else
{
return null;
}
}
else //团体体检
{
var data2 = from a in db.t_ttgzbs
join b in db.t_htfzbs on a.htfzbm equals b.htfzbm
where a.tm == tm
select new Entities.DTO.dto_gzb
{
tmztz = a.tmztz,
hyh = a.hyh,
xm = a.xm,
xb = a.xb,
nl = a.nl,
hyzk = a.hyzk,
sfzh = a.sfzh,
csrq = a.csrq,
tm = a.tm,
lx = 2, //类型2团检
//ygbh=a. ,
//ygbm=a. ,
ygdh = a.tel,
tcbm = a.htfzbm,
tcmc = b.htfzmc,
jxzl = b.jxzl,
jxgzfbj = b.jxgzfbj,
//tczl=,
//khmc=a.
fddm = a.fddm,
gzfbj = b.gzfbj
};
if (data2.Any())
{
return data2.First();
}
else
{
return null;
}
}
}
}
/// <summary>
/// 获取已交费的组合项目,根据加减项进行增减
/// </summary>
public List<dto_zhxm> GetZhxm_YJF_JJX(int tm)
{
using (DbEntities db = new DbEntities())
{
var data = from a in db.t_tempdjxms
join b in db.t_zhxms on a.zhbm equals b.zhbm
where a.tm == tm
select new dto_zhxm
{
zhmc = b.zhmc,
zhbm = a.zhbm,
jg = b.jg_v
};
if (data.Any())
{
return data.ToList();
}
else
{
return null;
}
}
}
/// <summary>
/// 临时加项业务处理
/// </summary>
/// <param name="jffs">交费方式0公费1自费</param>
/// <param name="ldl">加项集合</param>
/// <param name="lx">类型1个人 2团体</param>
/// <param name="tm">条码</param>
/// <param name="uname">操作员</param>
/// <returns></returns>
public OperationResult LSJX(List<dto_lsjx> ldl, int tm, short jffs, short lx, short fddm, string uname,string isOpen)
{
OperationResult or = new OperationResult();
//个检自费、团检自费
//更新t_grgzb 或者 t_ttgzb表中的tmztz
//插入 t_jjxb
//团检公费
//插入t_jjxb
//插入t_tempdjxm
using (DbEntities db = new DbEntities())
{
DateTime rq = DateTime.Now;
int zje = 0;
if (ldl == null)
{
or.State = 0;
or.Message = "没有加项信息";
return or;
}
else
{
var tran = db.CreateTransaction(); //事务声明
try
{
#region
int c = ldl.Count;
BasicBll bb = new BasicBll();
int xh = bb.GetMax("dbo.jjx", c);
for (int i = 0; i < ldl.Count; i++)
{
dto_lsjx dl = ldl[i];
//jjxb插入
t_jjxb tj = new t_jjxb();
tj.xh = xh;
xh++;
tj.tm = tm;
tj.zhbm = dl.zhbm;
tj.jjx = 0;
if (jffs == 1)
{
tj.ysfbz = 0;
//公费(团检) jjxlx=0, 自费个检团检jjxlx=1
tj.jjxlx = 1;
}
else
{
tj.ysfbz = 1;
tj.jjxlx = 0;
}
tj.zl = dl.zl;
tj.jjxje = dl.jg;
tj.jglx = 1;
tj.czy = uname;
tj.fddm = fddm;
db.t_jjxbs.Insert(tj);
zje += dl.zhj; //折后价算总金额
////加项医生记录
//if (dl.jyysbm != null && dl.jyysbm != 0)
//{
t_jxysjl jxysjl = new t_jxysjl();
jxysjl.tm = tm;
jxysjl.zhbm = dl.zhbm;
jxysjl.ysbm = dl.jyysbm;
jxysjl.upflag = 1;
jxysjl.fddm = fddm;
jxysjl.rq = rq;
jxysjl.ywdb = dl.jyys;
db.t_jxysjls.Insert(jxysjl);
//db.t_jxysjls.Delete(jxysjl);
//}
if (jffs == 0) //团检公费t_tempdjxm表中插入信息
{
t_tempdjxm tt = new t_tempdjxm();
tt.tm = tm;
tt.zhbm = dl.zhbm;
tt.ksbm = dl.ksbm;
tt.djrq = rq;
tt.ztz = 0; //
tt.fddm = fddm;
db.t_tempdjxms.Insert(tt);
}
}
string sql1 = "update t_tempdjxm set ztz=4 ,upflag=1 from t_tempdjxm,t_zhxm " +
" where t_tempdjxm.zhbm=t_zhxm.zhbm and t_zhxm.jclb=2 and tm=" + tm;
db.DataAccessor.Execute(sql1);
string sql2 = "";
if (lx == 1) //个人
{
sql2 = "update t_grgzb set tmztz=3,upflag=1, czjjxbj=1 where tm=" + tm;
db.DataAccessor.Execute(sql2);
}
else //团体
{
if (jffs == 1) //加项自费
{
sql2 = "update t_ttgzb set tmztz=3,upflag=1, czjjxbj=1 where tm=" + tm;
db.DataAccessor.Execute(sql2);
}
else //加项公费
{
sql2 = "update t_ttgzb set tmztz=2,upflag=1, czjjxbj=1, tjzje=tjzje+" + zje + " where tm=" + tm;
db.DataAccessor.Execute(sql2);
tran.Commit();
or.State = 1;
or.Message = "临时加项成功!";
if (isOpen == "1")
{
string ksname = PaiDuiJiaoHaoBLL.sendPaiduixinxi(tm);
if (!string.IsNullOrEmpty(ksname))
{
or.Message += "\r\n请到" + ksname + "体检";
}
}
return or;
}
}
tran.Commit();
or.State = 1;
or.Message = "临时加项成功";
return or;
#endregion
}
catch (Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = (ex.InnerException ?? ex).Message;
return or;
}
}
}
}
#endregion
public OperationResult IfExistGJBySFZH(string sfzh, short fddm)
{
//根据身份证号查询是否有在体检的信息
//tmztz在-2 到8之间的数值不可在此登记
OperationResult or = new OperationResult();
using (DbEntities db = new DbEntities())
{
//首先判断是否有团检信息
/*
var data2 = from a in db.t_ttgzbs where a.fddm==fddm&&a.sfzh == sfzh&&a.tmztz>=-2&&a.tmztz<9
select a;
if (data2.Any()) //团检
{
or.State = 0;
or.Message = "团检人员请到团检进行登记";
return or;
}*/
var data = from a in db.t_grgzbs
where a.fddm == fddm && a.sfzh == sfzh && a.tmztz >= -2 && a.tmztz < 9
select a;
if (data.Any())
{
//个人登记有了,进行提示
or.State = 0;
var data1 = data.Where(t => t.tmztz == -2);
if (data1.Any())
{
or.Message = "待查人员请到待查人员管理中登记";
return or;
}
else
{
var data4 = data.Where(t => t.tmztz == -1);
if (data4.Any())
{
or.Message = "预约人员请到预约处进行登记";
return or;
}
}
}
or.State = 1;
or.Message = "可以登记";
return or;
}
}
public OperationResult IfExistTJBySFZH(string sfzh, short fddm)
{
//根据身份证号查询是否有在体检的信息
//tmztz在-2 到8之间的数值不可在此登记
OperationResult or = new OperationResult();
using (DbEntities db = new DbEntities())
{
//首先判断是否有团检信息
/*
var data2 = from a in db.t_ttgzbs where a.fddm==fddm&&a.sfzh == sfzh&&a.tmztz>=-2&&a.tmztz<9
select a;
if (data2.Any()) //团检
{
or.State = 0;
or.Message = "团检人员请到团检进行登记";
return or;
}*/
var data = from a in db.t_ttgzbs
where a.fddm == fddm && a.sfzh == sfzh && a.tmztz >= -2 && a.tmztz < 9
select a;
if (data.Any())
{
//个人登记有了,进行提示
or.State = 0;
var data1 = data.Where(t => t.tmztz == -2);
if (data1.Any())
{
or.Message = "待查人员请到待查人员管理中登记";
return or;
}
else
{
var data4 = data.Where(t => t.tmztz == -1);
if (data4.Any())
{
or.Message = "预约人员请到预约处进行登记";
return or;
}
}
}
or.State = 1;
or.Message = "可以登记";
return or;
}
}
public OperationResult IfExistTJBySFZH2(string sfzh, short fddm)
{
OperationResult or = new OperationResult();
using (DbEntities db = new DbEntities())
{
var data = from a in db.t_ttgzbs
where a.fddm == fddm && a.sfzh == sfzh && a.tmztz == 0
select a;
if (!data.Any())
{
or.State = 0;
or.Message = "身份证信息未查询到客户记录";
return or;
}
t_ttgzb tt = data.First();
or.State = 1;
or.Message = tt.tm.ToString();
return or;
}
}
public t_tc GetTcBytcbm(short tcbm)
{
using (var db = new DbEntities())
{
var data = from t in db.t_tcs
where t.tcbm == tcbm
select t;
return data.First();
}
}
public string gettjxx(DateTime tjrq, string tm)
{
int itm = 0;
int.TryParse(tm, out itm);
//throw new NotImplementedException();
using (var db = new DbEntities())
{
var tt = db.t_ttgzbs.Where(t => true);
if (tm == "")
{
tt = tt.Where(t => t.tjrq > tjrq && t.tjrq < tjrq.AddDays(1));
}
else
{
tt = tt.Where(t => t.tm == itm);
}
var gr = db.t_grgzbs.Where(t => true);
if (tm == "")
{
gr = gr.Where(t => t.tjrq > tjrq && t.tjrq < tjrq.AddDays(1));
}
else
{
gr = gr.Where(t => t.tm == itm);
}
var ltt = tt.Select(t => new dto_gzb { tm = t.tm, csrq = t.csrq, xm = t.xm, xb = t.xb, lx = 1, tjrq = t.tjrq, nl = t.nl, hyzk = t.hyzk, hyh = t.hyh }).ToList();
var lgr = gr.Select(t => new dto_gzb { tm = t.tm, csrq = t.csrq, xm = t.xm, xb = t.xb, lx = 2, tjrq = t.tjrq, nl = t.nl, hyzk = t.hyzk, hyh = t.hyh }).ToList();
ltt = ltt.Concat(lgr).ToList();
return Newtonsoft.Json.JsonConvert.SerializeObject(ltt);
}
}
public OperationResult sqxg(int tm, int ksbm)
{
// throw new NotImplementedException();
OperationResult or = new OperationResult();
using (var db = new DbEntities())
{
DbTransaction tran = db.CreateTransaction();
try
{
var tjztz = 0;
if (tm.ToString("0000000000").StartsWith("1"))
{
var tt = db.t_ttgzbs.FirstOrDefault(t => t.tm == tm);
tjztz = tt.tmztz;
}
else
{
var gr = db.t_grgzbs.FirstOrDefault(t => t.tm == tm);
tjztz = gr.tmztz;
}
if (tjztz < 6)
{
var zhxm = db.t_zhxms.Join(db.t_zhxmmxs.Join(db.t_jcxms.Where(t => t.ksbm == ksbm), t => t.xmbm, p => p.jcxmbm, (t, p) => t), t => t.zhbm, p => p.zhbm, (t, p) => t).Distinct();
var tjxms = db.t_tempdjxms.Where(t => t.tm == tm).Join(zhxm, t => t.zhbm, p => p.zhbm, (t, p) => t).ToList();
tjxms.ForEach(t =>
{
t.ztz = 1;
db.t_tempdjxms.Update(t);
});
if (tm.ToString("0000000000").StartsWith("1"))
{
var tt = db.t_ttgzbs.FirstOrDefault(t => t.tm == tm);
tt.tmztz = 4;
db.t_ttgzbs.Update(tt);
}
else
{
var gr = db.t_grgzbs.FirstOrDefault(t => t.tm == tm);
gr.tmztz = 4;
db.t_grgzbs.Update(gr);
}
tran.Commit();
}
else
{
or.State = 1;
or.Message = "授权失败:客人进入汇总阶段,禁止修改体检结果,请与管理员联系。";
return or;
}
}
catch (Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = ex.Message;
return or;
}
or.State = 1;
or.Message = "授权成功!";
return or;
}
}
}
}