新增农户功能升级:身份证OCR/OSS上传、头像采集、同名村检测、Region热度排序及表单体验优化
- Region 表新增热度列,热门省份优先显示 - 区县下拉按地级市分组、已录区县优先、支持全省搜索 - 组选择内置一组至二十组 - 银行卡号独立行+粗体预览,开户行独立行 - 新增农户类型:农户/个体户/合作社/经营集体/公司 - 身份证正反面支持高拍仪/摄像头OCR与手机扫码上传,附件存本地/OSS - 新增农户头像采集组件(摄像头/本地上传),预留人脸识别收购扩展 - 同名村弹窗提醒(防选错乡镇) - 编辑窗体禁止遮罩/Esc误关,整体加宽适配高频操作 - 修复二维码局域网手机无法访问(监听0.0.0.0、局域网IP识别、Vite代理兜底)
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using AgriculturalPlatform.Api.Data;
|
||||
using AgriculturalPlatform.Api.Dtos;
|
||||
using AgriculturalPlatform.Api.Models;
|
||||
using AgriculturalPlatform.Api.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AgriculturalPlatform.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/orgs")]
|
||||
[Authorize]
|
||||
public class OrgsController(AppDbContext db, DataScopeService scope, CurrentUserService currentUser) : ControllerBase
|
||||
{
|
||||
/// <summary>组织列表(按数据权限过滤)</summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> List(string? type, string? keyword)
|
||||
{
|
||||
var visible = await scope.GetVisibleOrgIdsAsync(currentUser.Get());
|
||||
var query = db.Organizations.Include(o => o.Parent).AsQueryable();
|
||||
if (visible is not null)
|
||||
query = query.Where(o => visible.Contains(o.Id));
|
||||
if (!string.IsNullOrWhiteSpace(type) && Enum.TryParse<OrgType>(type, out var orgType))
|
||||
query = query.Where(o => o.Type == orgType);
|
||||
if (!string.IsNullOrWhiteSpace(keyword))
|
||||
query = query.Where(o => o.Name.Contains(keyword) || o.ContactPerson.Contains(keyword) || o.Phone.Contains(keyword));
|
||||
|
||||
var items = await query.OrderBy(o => o.Type).ThenBy(o => o.Id).ToListAsync();
|
||||
return Ok(items.ToDtos());
|
||||
}
|
||||
|
||||
/// <summary>组织详情</summary>
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<ActionResult<OrgDto>> Get(int id)
|
||||
{
|
||||
var org = await db.Organizations.Include(o => o.Parent).FirstOrDefaultAsync(o => o.Id == id);
|
||||
if (org is null) return NotFound();
|
||||
return Ok(org.ToDto());
|
||||
}
|
||||
|
||||
/// <summary>新增组织</summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<OrgDto>> Create(OrgSaveRequest req)
|
||||
{
|
||||
if (!Enum.TryParse<OrgType>(req.Type, out var orgType))
|
||||
return BadRequest(new { message = "组织类型不正确" });
|
||||
|
||||
var org = new Organization
|
||||
{
|
||||
Type = orgType,
|
||||
Name = req.Name,
|
||||
ParentId = req.ParentId,
|
||||
ContactPerson = req.ContactPerson,
|
||||
Phone = req.Phone,
|
||||
Address = req.Address,
|
||||
TaxNo = req.TaxNo,
|
||||
IsActive = req.IsActive
|
||||
};
|
||||
db.Organizations.Add(org);
|
||||
await db.SaveChangesAsync();
|
||||
return Ok((await db.Organizations.Include(o => o.Parent).FirstAsync(o => o.Id == org.Id)).ToDto());
|
||||
}
|
||||
|
||||
/// <summary>修改组织</summary>
|
||||
[HttpPut("{id:int}")]
|
||||
public async Task<ActionResult<OrgDto>> Update(int id, OrgSaveRequest req)
|
||||
{
|
||||
var org = await db.Organizations.FindAsync(id);
|
||||
if (org is null) return NotFound();
|
||||
if (Enum.TryParse<OrgType>(req.Type, out var orgType)) org.Type = orgType;
|
||||
org.Name = req.Name;
|
||||
org.ParentId = req.ParentId;
|
||||
org.ContactPerson = req.ContactPerson;
|
||||
org.Phone = req.Phone;
|
||||
org.Address = req.Address;
|
||||
org.TaxNo = req.TaxNo;
|
||||
org.IsActive = req.IsActive;
|
||||
await db.SaveChangesAsync();
|
||||
return Ok((await db.Organizations.Include(o => o.Parent).FirstAsync(o => o.Id == org.Id)).ToDto());
|
||||
}
|
||||
|
||||
/// <summary>删除组织(存在关联时禁止删除)</summary>
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var org = await db.Organizations.FindAsync(id);
|
||||
if (org is null) return NotFound();
|
||||
if (await db.Organizations.AnyAsync(o => o.ParentId == id))
|
||||
return BadRequest(new { message = "该组织下存在下级组织,无法删除" });
|
||||
if (await db.PurchaseOrders.AnyAsync(p => p.PurchaserOrgId == id))
|
||||
return BadRequest(new { message = "该组织已有收购业务,无法删除" });
|
||||
if (await db.Users.AnyAsync(u => u.OrgId == id))
|
||||
return BadRequest(new { message = "该组织下存在用户,无法删除" });
|
||||
|
||||
db.Organizations.Remove(org);
|
||||
await db.SaveChangesAsync();
|
||||
return Ok(new { message = "删除成功" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user