Platform upgrade: login auth fix, OCR/OSS upload, system menus and dicts, weather dashboard, weighing and invoice modules
This commit is contained in:
@@ -57,14 +57,87 @@ public static class DbSeeder
|
||||
stationWest.ParentId = company.Id;
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 角色(RBAC) ----------
|
||||
var roleAdmin = new SysRole { Name = "超级管理员", Code = "super_admin", Description = "系统内置:拥有全部权限", IsSystem = true, CreatedAt = now };
|
||||
var roleCompany = new SysRole { Name = "公司管理员", Code = "company_admin", Description = "管理本公司及下属收购站业务", IsSystem = true, CreatedAt = now };
|
||||
var roleStation = new SysRole { Name = "收购站员工", Code = "station_staff", Description = "负责过磅称重、收购单录入", IsSystem = true, CreatedAt = now };
|
||||
var roleIndividual = new SysRole { Name = "收购个体", Code = "individual", Description = "个体收购户", IsSystem = true, CreatedAt = now };
|
||||
db.SysRoles.AddRange(roleAdmin, roleCompany, roleStation, roleIndividual);
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 菜单/权限(RBAC 资源,Path 与前端路由一致) ----------
|
||||
var menus = new List<SysMenu>
|
||||
{
|
||||
// 首页
|
||||
new() { Name = "首页", Path = "/home", Component = "views/Home.vue", Icon = "HomeFilled", Type = "menu", Permission = "home:view", Sort = 1, CreatedAt = now },
|
||||
// 收购业务
|
||||
new() { Name = "收购业务", Path = "/weighing", Icon = "Van", Type = "directory", Sort = 2, CreatedAt = now },
|
||||
new() { Name = "过磅称重", Path = "/weighing", Component = "views/weighing/WeighingList.vue", Icon = "Odometer", Type = "menu", Permission = "weighing:list", Sort = 1, CreatedAt = now },
|
||||
new() { Name = "触摸屏过磅", Path = "/weighing/touch", Component = "views/weighing/WeighingTouch.vue", Icon = "Iphone", Type = "menu", Permission = "weighing:touch", Sort = 2, CreatedAt = now },
|
||||
new() { Name = "电子支付", Path = "/payments", Component = "views/payments/PaymentList.vue", Icon = "Wallet", Type = "menu", Permission = "payment:list", Sort = 3, CreatedAt = now },
|
||||
new() { Name = "反向开票", Path = "/invoices", Component = "views/invoices/InvoiceList.vue", Icon = "Tickets", Type = "menu", Permission = "invoice:list", Sort = 4, CreatedAt = now },
|
||||
// 基础资料
|
||||
new() { Name = "基础资料", Path = "/base", Icon = "FolderOpened", Type = "directory", Sort = 3, CreatedAt = now },
|
||||
new() { Name = "农户管理", Path = "/farmers", Component = "views/farmers/FarmerList.vue", Icon = "User", Type = "menu", Permission = "farmer:list", Sort = 1, CreatedAt = now },
|
||||
new() { Name = "品种管理", Path = "/products", Component = "views/products/ProductList.vue", Icon = "Goods", Type = "menu", Permission = "product:list", Sort = 2, CreatedAt = now },
|
||||
// 统计报表
|
||||
new() { Name = "统计报表", Path = "/reports", Icon = "DataAnalysis", Type = "directory", Sort = 4, CreatedAt = now },
|
||||
new() { Name = "收购报表", Path = "/reports/purchase", Component = "views/reports/ReportPurchase.vue", Icon = "TrendCharts", Type = "menu", Permission = "report:purchase", Sort = 1, CreatedAt = now },
|
||||
new() { Name = "付款报表", Path = "/reports/payment", Component = "views/reports/ReportPayment.vue", Icon = "Money", Type = "menu", Permission = "report:payment", Sort = 2, CreatedAt = now },
|
||||
new() { Name = "开票报表", Path = "/reports/invoice", Component = "views/reports/ReportInvoice.vue", Icon = "Document", Type = "menu", Permission = "report:invoice", Sort = 3, CreatedAt = now },
|
||||
// 系统管理
|
||||
new() { Name = "系统管理", Path = "/system", Icon = "Setting", Type = "directory", Sort = 5, CreatedAt = now },
|
||||
new() { Name = "组织管理", Path = "/orgs", Component = "views/orgs/OrgList.vue", Icon = "OfficeBuilding", Type = "menu", Permission = "system:org:list", Sort = 1, CreatedAt = now },
|
||||
new() { Name = "用户管理", Path = "/users", Component = "views/users/UserList.vue", Icon = "Avatar", Type = "menu", Permission = "system:user:list", Sort = 2, CreatedAt = now },
|
||||
new() { Name = "角色权限", Path = "/system/roles", Component = "views/system/RoleList.vue", Icon = "UserFilled", Type = "menu", Permission = "system:role:list", Sort = 3, CreatedAt = now },
|
||||
new() { Name = "菜单管理", Path = "/system/menus", Component = "views/system/MenuList.vue", Icon = "Menu", Type = "menu", Permission = "system:menu:list", Sort = 4, CreatedAt = now },
|
||||
new() { Name = "数据字典", Path = "/system/dicts", Component = "views/system/DictList.vue", Icon = "Notebook", Type = "menu", Permission = "system:dict:list", Sort = 5, CreatedAt = now },
|
||||
// 通知公告
|
||||
new() { Name = "通知公告", Path = "/notify", Icon = "Bell", Type = "directory", Sort = 6, CreatedAt = now },
|
||||
new() { Name = "公告管理", Path = "/notify/announcements", Component = "views/notify/AnnouncementList.vue", Icon = "Bell", Type = "menu", Permission = "announcement:list", Sort = 1, CreatedAt = now },
|
||||
// 关于
|
||||
new() { Name = "关于系统", Path = "/about", Component = "views/about/About.vue", Icon = "InfoFilled", Type = "menu", Permission = "about:view", Sort = 7, CreatedAt = now },
|
||||
};
|
||||
db.SysMenus.AddRange(menus);
|
||||
db.SaveChanges();
|
||||
|
||||
// 目录菜单的父级关系(按路径匹配;目录路径与子菜单路径相同时以 Type 区分)
|
||||
SetChild(menus, "/weighing", "/weighing");
|
||||
SetChild(menus, "/weighing/touch", "/weighing");
|
||||
SetChild(menus, "/payments", "/weighing");
|
||||
SetChild(menus, "/invoices", "/weighing");
|
||||
SetChild(menus, "/farmers", "/base");
|
||||
SetChild(menus, "/products", "/base");
|
||||
SetChild(menus, "/reports/purchase", "/reports");
|
||||
SetChild(menus, "/reports/payment", "/reports");
|
||||
SetChild(menus, "/reports/invoice", "/reports");
|
||||
SetChild(menus, "/orgs", "/system");
|
||||
SetChild(menus, "/users", "/system");
|
||||
SetChild(menus, "/system/roles", "/system");
|
||||
SetChild(menus, "/system/menus", "/system");
|
||||
SetChild(menus, "/system/dicts", "/system");
|
||||
SetChild(menus, "/notify/announcements", "/notify");
|
||||
db.SaveChanges();
|
||||
|
||||
// 给超级管理员分配全部菜单;收购站员工分配常用菜单
|
||||
var allMenuIds = menus.Select(m => m.Id).ToArray();
|
||||
db.SysRoleMenus.AddRange(allMenuIds.Select(mid => new SysRoleMenu { RoleId = roleAdmin.Id, MenuId = mid }));
|
||||
var stationMenuIds = menus.Where(m => m.Type == "menu" && m.Permission is "home:view" or "weighing:list" or "weighing:touch" or "farmer:list" or "about:view").Select(m => m.Id);
|
||||
db.SysRoleMenus.AddRange(stationMenuIds.Select(mid => new SysRoleMenu { RoleId = roleStation.Id, MenuId = mid }));
|
||||
|
||||
// 公司管理员:除系统管理外的全部业务菜单
|
||||
var companyMenuIds = menus.Where(m => m.Type == "menu" && !m.Permission.StartsWith("system:")).Select(m => m.Id);
|
||||
db.SysRoleMenus.AddRange(companyMenuIds.Select(mid => new SysRoleMenu { RoleId = roleCompany.Id, MenuId = mid }));
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 用户(默认密码均为 123456) ----------
|
||||
var users = new List<User>
|
||||
{
|
||||
new() { Username = "admin", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "系统管理员", Phone = "13800000000", Role = UserRole.SuperAdmin, CreatedAt = now },
|
||||
new() { Username = "company", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "王建国", Phone = "13800000001", Role = UserRole.CompanyAdmin, OrgId = company.Id, CreatedAt = now },
|
||||
new() { Username = "station1", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "李强", Phone = "13800000002", Role = UserRole.StationStaff, OrgId = stationEast.Id, CreatedAt = now },
|
||||
new() { Username = "station2", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "赵敏", Phone = "13800000003", Role = UserRole.StationStaff, OrgId = stationWest.Id, CreatedAt = now },
|
||||
new() { Username = "individual", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "张伟", Phone = "13800000004", Role = UserRole.Individual, OrgId = individual.Id, CreatedAt = now }
|
||||
new() { Username = "admin", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "系统管理员", Phone = "13800000000", Role = UserRole.SuperAdmin, RoleId = roleAdmin.Id, CreatedAt = now },
|
||||
new() { Username = "company", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "王建国", Phone = "13800000001", Role = UserRole.CompanyAdmin, RoleId = roleCompany.Id, OrgId = company.Id, CreatedAt = now },
|
||||
new() { Username = "station1", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "李强", Phone = "13800000002", Role = UserRole.StationStaff, RoleId = roleStation.Id, OrgId = stationEast.Id, CreatedAt = now },
|
||||
new() { Username = "station2", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "赵敏", Phone = "13800000003", Role = UserRole.StationStaff, RoleId = roleStation.Id, OrgId = stationWest.Id, CreatedAt = now },
|
||||
new() { Username = "individual", PasswordHash = BCrypt.Net.BCrypt.HashPassword("123456"), RealName = "张伟", Phone = "13800000004", Role = UserRole.Individual, RoleId = roleIndividual.Id, OrgId = individual.Id, CreatedAt = now }
|
||||
};
|
||||
db.Users.AddRange(users);
|
||||
db.SaveChanges();
|
||||
@@ -146,6 +219,75 @@ public static class DbSeeder
|
||||
db.PurchaseOrders.AddRange(orders);
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 数据字典(收购等级 / 价格类型 / 票据格式 / 公告类型) ----------
|
||||
var dicts = new List<SysDict>
|
||||
{
|
||||
new() { Name = "收购等级", Code = "purchase_grade", Remark = "收购单磅次等级", IsSystem = true, Sort = 1, CreatedAt = now,
|
||||
Items =
|
||||
{
|
||||
new() { Label = "一等", Value = "一等", IsDefault = true, Sort = 1 },
|
||||
new() { Label = "二等", Value = "二等", Sort = 2 },
|
||||
new() { Label = "三等", Value = "三等", Sort = 3 },
|
||||
new() { Label = "级外", Value = "级外", Sort = 4 },
|
||||
}
|
||||
},
|
||||
new() { Name = "价格类型", Code = "price_type", Remark = "过磅计价方式", IsSystem = true, Sort = 2, CreatedAt = now,
|
||||
Items =
|
||||
{
|
||||
new() { Label = "固定价格", Value = "Fixed", Ext = "按产品默认价", IsDefault = true, Sort = 1 },
|
||||
new() { Label = "现场议价", Value = "Manual", Ext = "与农户协商价", Sort = 2 },
|
||||
new() { Label = "价格区间", Value = "Range", Ext = "区间内浮动价", Sort = 3 },
|
||||
}
|
||||
},
|
||||
new() { Name = "票据格式", Code = "receipt_format", Remark = "小票/票据打印格式", IsSystem = true, Sort = 3, CreatedAt = now,
|
||||
Items =
|
||||
{
|
||||
new() { Label = "58mm 热敏小票", Value = "thermal_58", Ext = "58mm", IsDefault = true, Sort = 1 },
|
||||
new() { Label = "80mm 热敏小票", Value = "thermal_80", Ext = "80mm", Sort = 2 },
|
||||
new() { Label = "三等分针式票据", Value = "dotmatrix_3part", Ext = "241mm×139.7mm/联", Sort = 3 },
|
||||
new() { Label = "A5 激光打印", Value = "laser_a5", Ext = "A5", Sort = 4 },
|
||||
}
|
||||
},
|
||||
new() { Name = "公告类型", Code = "announcement_type", Remark = "通知公告类型", IsSystem = true, Sort = 4, CreatedAt = now,
|
||||
Items =
|
||||
{
|
||||
new() { Label = "通知", Value = "notice", Sort = 1 },
|
||||
new() { Label = "公告", Value = "announce", Sort = 2 },
|
||||
new() { Label = "价格行情", Value = "price", Sort = 3 },
|
||||
new() { Label = "政策法规", Value = "policy", Sort = 4 },
|
||||
}
|
||||
},
|
||||
new() { Name = "系统图标", Code = "system_logo", Remark = "主标题系统图标,可选大部分农产品图标", IsSystem = true, Sort = 5, CreatedAt = now,
|
||||
Items =
|
||||
{
|
||||
new() { Label = "苹果", Value = "Apple", IsDefault = true, Sort = 1 },
|
||||
new() { Label = "葡萄", Value = "Grape", Sort = 2 },
|
||||
new() { Label = "西瓜", Value = "Watermelon", Sort = 3 },
|
||||
new() { Label = "樱桃", Value = "Cherry", Sort = 4 },
|
||||
new() { Label = "梨", Value = "Pear", Sort = 5 },
|
||||
new() { Label = "桃", Value = "Peach", Sort = 6 },
|
||||
new() { Label = "橙子", Value = "Orange", Sort = 7 },
|
||||
new() { Label = "农作物", Value = "Food", Sort = 8 },
|
||||
new() { Label = "时蔬", Value = "Dish", Sort = 9 },
|
||||
new() { Label = "牛奶", Value = "Milk", Sort = 10 },
|
||||
new() { Label = "冰淇淋", Value = "IceCream", Sort = 11 },
|
||||
new() { Label = "生鲜礼盒", Value = "TakeawayBox", Sort = 12 },
|
||||
}
|
||||
},
|
||||
};
|
||||
db.SysDicts.AddRange(dicts);
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 通知公告(演示数据) ----------
|
||||
var announcements = new List<Announcement>
|
||||
{
|
||||
new() { Title = "欢迎使用农易富农产品收购交易平台", Content = "系统已完成升级,新增数据字典、角色权限、通知公告等功能。默认账号 admin / 123456。", Type = "announce", IsPinned = true, PublisherId = users[0].Id, PublishedAt = now, CreatedAt = now },
|
||||
new() { Title = "关于2026年夏季收购价格调整的通知", Content = "自8月15日起,一等品收购价调整为每公斤3.6元,请各收购站及时更新价格配置。", Type = "price", PublisherId = users[0].Id, PublishedAt = now.AddHours(-3), CreatedAt = now.AddHours(-3) },
|
||||
new() { Title = "电子秤串口连接使用说明", Content = "请在收购单新建界面点击电子秤区域连接串口,支持标准ASCII输出协议(如 ST,GS,+00123.45kg)。无串口设备时可使用手动输入模式。", Type = "notice", PublisherId = users[0].Id, PublishedAt = now.AddDays(-1), CreatedAt = now.AddDays(-1) },
|
||||
};
|
||||
db.Announcements.AddRange(announcements);
|
||||
db.SaveChanges();
|
||||
|
||||
// ---------- 历史付款(对应部分订单) ----------
|
||||
var payOrders = orders.Where(o => o.Status == PurchaseStatus.Completed)
|
||||
.OrderBy(o => o.CreatedAt).Take(120).ToList();
|
||||
@@ -192,4 +334,12 @@ public static class DbSeeder
|
||||
db.Invoices.AddRange(invoices);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
private static void SetChild(List<SysMenu> menus, string childPath, string parentPath)
|
||||
{
|
||||
var parent = menus.FirstOrDefault(m => m.Type == "directory" && m.Path == parentPath);
|
||||
if (parent is null) return;
|
||||
foreach (var child in menus.Where(m => m.Type != "directory" && m.Path == childPath && m.ParentId == null))
|
||||
child.ParentId = parent.Id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user