192 lines
6.9 KiB
C#
192 lines
6.9 KiB
C#
using DOAN.Admin.WebApi.Filters;
|
||
using DOAN.Model;
|
||
using DOAN.Model.BZFM;
|
||
using DOAN.Model.BZFM.Dto;
|
||
using DOAN.Model.System;
|
||
using DOAN.Model.System.Dto;
|
||
using DOAN.Service.BZFM;
|
||
using DOAN.Service.BZFM.IBZFMService;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using MiniExcelLibs;
|
||
using System.Linq;
|
||
using System.Collections.Generic;
|
||
|
||
//创建时间:2025-12-25
|
||
namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||
{
|
||
/// <summary>
|
||
/// 物料表
|
||
/// </summary>
|
||
[Verify]
|
||
[Route("mes/productionMaterial/MmMaterial")]
|
||
public class MmMaterialController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 物料表接口
|
||
/// </summary>
|
||
private readonly IMmMaterialService _MmMaterialService;
|
||
|
||
public MmMaterialController(IMmMaterialService MmMaterialService)
|
||
{
|
||
_MmMaterialService = MmMaterialService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询物料表列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:list")]
|
||
public IActionResult QueryMmMaterial([FromQuery] MmMaterialQueryDto parm)
|
||
{
|
||
var response = _MmMaterialService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查询物料表详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{Id}")]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:query")]
|
||
public IActionResult GetMmMaterial(int Id)
|
||
{
|
||
var response = _MmMaterialService.GetInfo(Id);
|
||
|
||
var info = response.Adapt<MmMaterialDto>();
|
||
return SUCCESS(info);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加物料表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:add")]
|
||
[Log(Title = "物料表", BusinessType = BusinessType.INSERT)]
|
||
public IActionResult AddMmMaterial([FromBody] MmMaterialDto parm)
|
||
{
|
||
var modal = parm.Adapt<MmMaterial>().ToCreate(HttpContext);
|
||
|
||
var response = _MmMaterialService.AddMmMaterial(modal);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新物料表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:edit")]
|
||
[Log(Title = "物料表", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateMmMaterial([FromBody] MmMaterialDto parm)
|
||
{
|
||
var modal = parm.Adapt<MmMaterial>().ToUpdate(HttpContext);
|
||
var response = _MmMaterialService.UpdateMmMaterial(modal);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除物料表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("delete/{ids}")]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:delete")]
|
||
[Log(Title = "物料表", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult DeleteMmMaterial([FromRoute]string ids)
|
||
{
|
||
var idArr = Tools.SplitAndConvert<int>(ids);
|
||
|
||
return ToResponse(_MmMaterialService.Delete(idArr));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取物料表类别下拉框
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("GetMmMaterialCategoryOptions")]
|
||
[AllowAnonymous]
|
||
public IActionResult GetMmMaterialCategoryOptions([FromBody] MmMaterialCategoryDto parm)
|
||
{
|
||
var response = _MmMaterialService.GetMmMaterialCategoryOptions(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导入
|
||
/// </summary>
|
||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||
/// <returns></returns>
|
||
[HttpPost("importData")]
|
||
[Log(Title = "物料清单导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:import")]
|
||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||
{
|
||
List<MmMaterialExcelDto> material = new();
|
||
using (var stream = formFile.OpenReadStream())
|
||
{
|
||
material = stream.Query<MmMaterialExcelDto>(startCell: "A2").ToList();
|
||
}
|
||
|
||
return SUCCESS(_MmMaterialService.Importmaterial(material));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下载物料导入模板
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("importTemplate")]
|
||
[Log(Title = "物料模板", BusinessType = BusinessType.EXPORT)]
|
||
[AllowAnonymous]
|
||
public IActionResult ImportTemplateExcel()
|
||
{
|
||
// create an empty sample list of export DTO to generate header row
|
||
var sample = new List<MmMaterialExcelDto>();
|
||
var result = DownloadImportTemplate(sample, "material");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 物料清单导出
|
||
/// </summary>
|
||
/// <param name="material"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("export")]
|
||
[Log(Title = "物料清单导出", BusinessType = BusinessType.EXPORT)]
|
||
[ActionPermissionFilter(Permission = "mmmaterial:export")]
|
||
public IActionResult MaterialExport([FromQuery] MmMaterialQueryDto material)
|
||
{
|
||
var list = _MmMaterialService.SelectMaterialList(material, new PagerInfo(1, 10000));
|
||
|
||
var data = (list?.Result ?? new List<MmMaterial>());
|
||
|
||
// Build list of dictionaries to control column titles and format dates
|
||
var exportList = data.Select(x => new Dictionary<string, object>
|
||
{
|
||
["id"] = x.Id,
|
||
["物料标号"] = x.Type,
|
||
["物料编码"] = x.MaterialCode,
|
||
["物料名称"] = x.MaterialName,
|
||
["规格"] = x.Specification,
|
||
["物料分类编码"] = x.CategoryCode,
|
||
["物料分类名称"] = x.CategoryName,
|
||
["计量单位"] = x.Unit,
|
||
["供应商编码"] = x.SupplierCode,
|
||
["供应商名称"] = x.SupplierName,
|
||
["安全库存"] = x.SafetyStock,
|
||
["状态"] = x.Status,
|
||
["创建时间"] = x.CreatedTime.HasValue ? x.CreatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty,
|
||
["更新时间"] = x.UpdatedTime.HasValue ? x.UpdatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty,
|
||
["描述"] = x.Description
|
||
}).ToList();
|
||
|
||
var result = ExportExcelMini(exportList, "material", "物料清单");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
}
|
||
} |