コード例 #1
0
ファイル: HomeController.cs プロジェクト: wpmyj/FakeService
        public string AddSchedul(JObject data)
        {
            var res = new SchedulResponse
            {
                success = true
            };

            try
            {
                var model      = Request.Form["requestInstitution"].ToString();
                var req        = JsonConvert.DeserializeObject <SchedulRequest>(model);
                var dept       = _context.科室信息.FirstOrDefault(p => p.deptCode == req.DeptId);
                var doctor     = _context.医生介绍.FirstOrDefault(p => p.doctCode == req.DoctorId);
                var scheduleId = DateTimeCore.Now.ToString("yyyyMMddhhmmss");
                var date       = DateTime.Parse(req.Date);
                var schedule   = new 排班信息
                {
                    hospitalId     = req.HosId,
                    regType        = req.TypeId,
                    deptCode       = req.DeptId,
                    deptName       = dept?.deptName,
                    doctCode       = req.DoctorId,
                    doctName       = doctor?.doctName,
                    doctTech       = doctor.doctIntro,
                    hosRegType     = req.TypeId,
                    medDate        = date.ToString("yyyy-MM-dd"),
                    medAmPm        = req.AMPMId,
                    parentDeptCode = dept.parentDeptCode,
                    parentDeptName = dept.parentDeptName,
                    scheduleId     = scheduleId,
                    regAmount      = "1000",
                };
                _context.排班信息.Add(schedule);
                var resource = new 号源明细
                {
                    hospitalId = req.HosId,
                    isEnable   = "1",
                    scheduleId = scheduleId,
                };

                if (req.AMPMId == "1")//全天
                {
                    var smallerTime = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
                    var BigerstTime = new DateTime(date.Year, date.Month, date.Day, 23, 0, 0);
                    while (DateTime.Compare(BigerstTime, smallerTime) > 0)
                    {
                        resource.appoNo     = Guid.NewGuid().ToString();
                        resource.medBegtime = smallerTime.ToString("yyyy-MM-dd HH:mm:ss");
                        resource.medEndtime = smallerTime.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss");
                        _context.号源明细.Add(resource);
                        smallerTime = smallerTime.AddMinutes(30);
                        _context.SaveChanges();
                    }
                }
                else if (req.AMPMId == "2")//上午
                {
                    var smallerTime = new DateTime(date.Year, date.Month, date.Day, 8, 0, 0);
                    var BigerstTime = new DateTime(date.Year, date.Month, date.Day, 11, 30, 0);
                    while (DateTime.Compare(BigerstTime, smallerTime) > 0)
                    {
                        resource.appoNo     = Guid.NewGuid().ToString();
                        resource.medBegtime = smallerTime.ToString("yyyy-MM-dd HH:mm:ss");
                        resource.medEndtime = smallerTime.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss");
                        _context.号源明细.Add(resource);
                        smallerTime = smallerTime.AddMinutes(30);
                        _context.SaveChanges();
                    }
                }
                else
                {
                    var smallerTime = new DateTime(date.Year, date.Month, date.Day, 13, 0, 0);
                    var BigerstTime = new DateTime(date.Year, date.Month, date.Day, 17, 30, 0);
                    while (DateTime.Compare(BigerstTime, smallerTime) > 0)
                    {
                        resource.appoNo     = Guid.NewGuid().ToString();
                        resource.medBegtime = smallerTime.ToString("yyyy-MM-dd HH:mm:ss");
                        resource.medEndtime = smallerTime.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss");
                        _context.号源明细.Add(resource);
                        smallerTime = smallerTime.AddMinutes(30);
                        _context.SaveChanges();
                    }
                }
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                res.success = false;
                res.msg     = $"服务端异常:{e.Message}";
                throw;
            }

            return(JsonConvert.SerializeObject(res));
        }
コード例 #2
0
        public override GatewayResponse Process(JObject req, MyDBContext context)
        {
            var res = new res预约挂号();

            try
            {
                var  model          = req.ToObject <req预约挂号>();
                号源明细 registration号源 = context.号源明细.FirstOrDefault(p => p.scheduleId == model.scheduleId);
                if (string.IsNullOrEmpty(model.scheduleId))
                {
                    res.success = false;
                    res.msg     = $"排班ID不能为空";
                    return(res);
                }
                if (model.regMode == "1")
                {
                    if (string.IsNullOrEmpty(model.appoNo))
                    {
                        res.success = false;
                        res.msg     = $"号源No不能为空";
                        return(res);
                    }
                    var app = context.号源明细.FirstOrDefault(p => p.appoNo == model.appoNo);
                    if (app != null)
                    {
                        app.isEnable = "0";
                    }
                }
                else
                {
                    if (registration号源 == null)
                    {
                        res.success = false;
                        res.msg     = $"号源已经挂完";
                        return(res);
                    }
                    TimeSpan flag = new TimeSpan(24, 0, 0);
                    foreach (var item in context.号源明细.Where(p => p.scheduleId == model.scheduleId && p.isEnable == "1"))
                    {
                        if (DateTime.Parse(item.medBegtime) > DateTime.Now &&
                            (DateTime.Parse(item.medBegtime) - DateTime.Now < flag))
                        {
                            registration号源 = item;
                            flag           = DateTime.Parse(item.medBegtime) - DateTime.Now;
                        }
                    }
                    context.号源明细.FirstOrDefault(p => p.appoNo == registration号源.appoNo).isEnable = "0";
                    if (model.tradeMode == "OC")
                    {
                        var balance = context.病人信息.FirstOrDefault(p => p.patientId == model.patientId).accBalance;
                        if ((double.Parse(balance) - double.Parse(model.cash)) < 0)
                        {
                            res.success = false;
                            res.msg     = $"余额不足";
                            return(res);
                        }
                        context.病人信息.FirstOrDefault(p => p.patientId == model.patientId).accBalance = (double.Parse(balance) - (double.Parse(model.cash))).ToString();
                    }
                }

                var newData = new 挂号预约记录
                {
                    regNo      = DateTimeCore.Now.ToString("yyyyMMddhhmmss"),
                    appoNo     = model.regMode == "1" ? model.appoNo : registration号源.appoNo,
                    scheduleId = model.scheduleId,
                    patientId  = model.patientId,
                    tradeTime  = model.tradeTime,
                    medDate    = model.regMode == "1" ? model.medDate : DateTime.Parse(registration号源.medBegtime).Date.ToString(),
                    medTime    = model.regMode == "1" ? model.medTime : DateTime.Parse(registration号源.medBegtime).ToString("hh:mm:ss"),
                    medAmPm    = model.regMode == "1" ? model.medAmPm : DateTimeCore.Now.Hour <= 12 ? "1" : "2",
                    hospCode   = model.hospCode,
                    hospName   = null,
                    deptName   = model.deptName,
                    doctName   = model.doctName,
                    address    = null,
                    appoFrom   = null,
                    regFee     = model.cash,
                    treatFee   = null,
                    regAmount  = model.cash,
                    status     = model.regMode == "1" ? "0" : "1",//0 已预约,1 已挂号,2 已取消,3 已过期,4 已停诊,5 已退号
                    orderNo    = null,
                    doctCode   = model.doctCode,
                    deptCode   = model.deptCode,
                    payStatus  = model.regMode == "1" ? "100" : "200",
                    lockId     = model.lockId,
                    hospitalId = model.hospitalId
                };
                context.挂号预约记录.Add(newData);
                context.SaveChanges();
                res.success = true;
                res.data    = new DataModels.挂号结果
                {
                    address   = "二楼202",
                    appoNo    = model.regMode == "1" ? model.appoNo : registration号源.appoNo,
                    deptName  = model.deptName,
                    doctName  = model.doctCode,
                    regFee    = model.cash,
                    treatFee  = null,
                    regAmount = model.cash,
                    orderNo   = null,
                    medDate   = model.medDate,
                };
            }
            catch (Exception ex)
            {
                res.success = false;
                res.msg     = $"{exMsg}预约挂号失败:{ex.Message}";
            }
            return(res);
        }