Ejemplo n.º 1
0
 public IActionResult InitData(InitDataViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var trans = dbContext.Database.BeginTransaction())
         {
             try
             {
                 var roles     = JsonConvert.DeserializeObject <List <Role> >(GetFileContents("role.json"));
                 var menus     = JsonConvert.DeserializeObject <List <Menu> >(GetFileContents("menu.json"));
                 var menu_role = JsonConvert.DeserializeObject <List <MenuRole> >(GetFileContents("menu-role.json"));
                 var User      = new User
                 {
                     Id       = "1",
                     FullName = "Quản trị hệ thống",
                     Email    = model.AdminEmail,
                     UserName = model.AdminUsername,
                     Password = Security.EncryptPassword(model.AdminPassword),
                     Gender   = (int)Gender.Male,
                     UserRole = roles.Select(p => new UserRole
                     {
                         Id     = Guid.NewGuid().ToString(),
                         RoleId = p.Id,
                         UserId = "1"
                     }).ToList()
                 };
                 dbContext.Roles.AddRange(roles);
                 dbContext.Users.Add(User);
                 dbContext.Menus.AddRange(menus);
                 dbContext.MenuRoles.AddRange(menu_role);
                 dbContext.SiteSettings.Add(new SiteSetting
                 {
                     Id        = Guid.NewGuid().ToString(),
                     PageEmail = model.AdminEmail,
                     PageTitle = model.PageName
                 });
                 dbContext.SaveChanges();
                 trans.Commit();
             }
             catch (Exception)
             {
                 trans.Rollback();
             }
         }
     }
     return(View());
 }
Ejemplo n.º 2
0
 public JsonResult InitInsuranceData(InitDataViewModel model)
 {
     _insuranceService.InitInsuranceData(model);
     return(Json(ResponseViewModelUtils.Sueecss()));
 }
Ejemplo n.º 3
0
 public JsonResult InitPayrollData(InitDataViewModel model)
 {
     _payrollService.InitPayrollData(model);
     return(Json(ResponseViewModelUtils.Sueecss()));
 }
Ejemplo n.º 4
0
        public void InitInsuranceData(InitDataViewModel initData)
        {
            InsCase   insCase = _dbContext.Get <InsCase>(initData.CaseUid);
            InsRecord iRecord = _dbContext.Get <InsRecord>(initData.RecordUid);

            string where = " InsYM='" + iRecord.InsYM + "' and InsCaseUid='" + iRecord.CaseUid + "' and InsmentTimes=" + iRecord.InsCount;
            var colList = _dbContext.Columns(insCase.TableName);
            //基础列和 特性列
            List <FapColumn> baseCols = colList.Where(c => (c.IsDefaultCol == 1 || c.ColProperty == "3") && c.ColName != "Id" && c.ColName != "Fid").ToList();
            string           pCols    = string.Join(",", baseCols.Select(c => c.ColName));

            if (initData.ReservedItems.IsPresent())
            {
                pCols += "," + initData.ReservedItems;
            }
            pCols = pCols.ReplaceIgnoreCase("InsYM", "'" + initData.InitYm + "' as InsYM");

            //检查当月是否有发送记录
            DynamicParameters param = new DynamicParameters();

            param.Add("InsYM", initData.InitYm);
            param.Add("CaseUid", initData.CaseUid);
            var records = _dbContext.QueryWhere <InsRecord>(" InsYM=@InsYM and CaseUid=@CaseUid", param);
            int pcount  = 1;

            if (records.Any())
            {
                var existRecord = records.FirstOrDefault(r => r.InsFlag == 0);
                if (existRecord == null)
                {
                    pcount = records.Max(r => r.InsCount) + 1;
                    //添加发放记录
                    InsRecord newRecord = new InsRecord();
                    newRecord.CaseUid  = insCase.Fid;
                    newRecord.InsCount = pcount;
                    newRecord.InsYM    = initData.InitYm;
                    newRecord.InsFlag  = 0;
                    _dbContext.Insert(newRecord);
                }
                else
                {
                    pcount = existRecord.InsCount;
                }
            }
            else
            {
                //添加发放记录
                InsRecord newRecord = new InsRecord();
                newRecord.CaseUid  = insCase.Fid;
                newRecord.InsCount = pcount;
                newRecord.InsYM    = initData.InitYm;
                newRecord.InsFlag  = 0;
                _dbContext.Insert(newRecord);
            }
            pCols = pCols.ReplaceIgnoreCase("InsmentTimes", pcount.ToString() + " as InsmentTimes");
            pCols = pCols.ReplaceIgnoreCase("InsConfirm", "0 as InsConfirm");
            string sql      = $"select {pCols} from InsCenter where {where}";
            var    pastData = _dbContext.QueryOriSql(sql);
            IList <FapDynamicObject> listCase = new List <FapDynamicObject>();

            foreach (var pd in pastData)
            {
                var dicPd            = pd as IDictionary <string, object>;
                FapDynamicObject fdo = new FapDynamicObject(_dbContext.Columns(insCase.TableName));
                foreach (var key in dicPd.Keys)
                {
                    fdo.SetValue(key, dicPd[key]);
                }
                listCase.Add(fdo);
            }
            _dbContext.ExecuteOriginal($"truncate table {insCase.TableName}");
            _dbContext.InsertDynamicDataBatchSql(listCase);

            //更新工资套
            insCase.InsYM    = initData.InitYm;
            insCase.InsCount = pcount;
            insCase.InsFlag  = 0;
            _dbContext.Update(insCase);
        }