schangxiang@126.com
2025-05-07 7eb4eb64a854eae4f3f62f0dfc4e63427d7231b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using Ao.Lang;
using CMS.Extensions.Abp.AspNetCore.Mvc.Filters;
using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.MyTestEntityNames;
using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System.Reflection;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
 
namespace CMS.Plugin.PipeLineLems.Controller
{
    /// <summary>
    /// MyTestEntityName服务
    /// </summary>
    [ApiController]
    [TypeFilter(typeof(CMSLanguageFilter))]
    [TypeFilter(typeof(CMSUowActionFilter))]
    [TypeFilter(typeof(CMSAuditActionFilter))]
    [TypeFilter(typeof(CMSExceptionFilter))]
    [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")]
    public class MyTestEntityNameController : ControllerBase
    {
        private readonly IMyTestEntityNameAppService _mytestentitynameAppService;
 
        /// <summary>
        /// Initializes a new instance of the <see cref="MyTestEntityNameController"/> class.
        /// </summary>
        /// <param name="mytestentitynameAppService">The mytestentityname application service.</param>
        public MyTestEntityNameController(IMyTestEntityNameAppService mytestentitynameAppService)
        {
            _mytestentitynameAppService = mytestentitynameAppService;
        }
 
        /// <summary>
        /// 获取mytestentityname.
        /// </summary>
        /// <param name="id">标识符.</param>
        /// <returns></returns>
        [HttpGet]
        [Route("{id}")]
        public virtual Task<MyTestEntityNameDto> GetAsync(Guid id)
        {
            return _mytestentitynameAppService.GetAsync(id);
        }
 
        /// <summary>
        /// 获取mytestentityname的列表.
        /// </summary>
        /// <param name="input">输入.</param>
        /// <returns></returns>
        [HttpGet]
        public virtual Task<PagedResultDto<MyTestEntityNameDto>> GetListAsync([FromQuery] GetMyTestEntityNamesInput input)
        {
            return _mytestentitynameAppService.GetListAsync(input);
        }
 
        /// <summary>
        /// 创建mytestentityname.
        /// </summary>
        /// <param name="input">输入.</param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost]
        public virtual Task<MyTestEntityNameDto> CreateAsync(MyTestEntityNameCreateDto input)
        {
            return _mytestentitynameAppService.CreateAsync(input);
        }
 
        /// <summary>
        /// 更新mytestentityname.
        /// </summary>
        /// <param name="id">标识符.</param>
        /// <param name="input">输入.</param>
        /// <returns></returns>
        //[Authorize]
        [HttpPut]
        [Route("{id}")]
        public virtual Task<MyTestEntityNameDto> UpdateAsync(Guid id, MyTestEntityNameUpdateDto input)
        {
            return _mytestentitynameAppService.UpdateAsync(id, input);
        }
 
        /// <summary>
        /// 克隆MyTestEntityName.
        /// </summary>
        /// <param name="ids">Id集合.</param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost]
        [Route("Clone")]
        public virtual Task<List<MyTestEntityNameDto>> CloneAsync([FromBody] IEnumerable<Guid> ids)
        {
            return _mytestentitynameAppService.CloneAsync(ids);
        }
 
        /// <summary>
        /// 删除mytestentityname.
        /// </summary>
        /// <param name="id">标识符.</param>
        /// <returns></returns>
        //[Authorize]
        [HttpDelete]
        [Route("{id}")]
        public virtual Task DeleteAsync(Guid id)
        {
            return _mytestentitynameAppService.DeleteAsync(id);
        }
 
        /// <summary>
        /// 批量删除mytestentityname.
        /// </summary>
        /// <param name="ids">The ids.</param>
        /// <returns></returns>
        //[Authorize]
        [HttpDelete]
        public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids)
        {
            return _mytestentitynameAppService.DeleteManyAsync(ids);
        }
 
        /// <summary>
        /// 调整排序.
        /// </summary>
        /// <param name="id">标识符.</param>
        /// <returns></returns>
        [HttpPut]
        [Route("{id}/AdjustSort/{sort}")]
        public virtual Task AdjustSortAsync(Guid id, int sort)
        {
            return _mytestentitynameAppService.AdjustSortAsync(id, sort);
        }
 
        /// <summary>
        /// 导入mytestentityname.
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        [Route("Import")]
        public virtual async Task<IActionResult> ImportAsync(IFormFile file)
        {
            using var stream = new MemoryStream();
            await file.CopyToAsync(stream);
            stream.Seek(0L, SeekOrigin.Begin);
 
            var sheetNames = stream.GetSheetNames();
            var mytestentitynameRows = sheetNames.Contains("配置") ? MiniExcel.Query<MyTestEntityNamesImportModel.MyTestEntityNameImportModel>(stream, sheetName: "配置").ToList() : new();
 
            if (!mytestentitynameRows.Any())
            {
                throw new UserFriendlyException("请检查导入的表格");
            }
 
            await _mytestentitynameAppService.ImportAsync(new MyTestEntityNamesImportModel
            {
                MyTestEntityNames = mytestentitynameRows,
            });
 
            return Ok();
        }
 
        /// <summary>
        /// 导出mytestentityname.
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("Export")]
        public virtual async Task<IActionResult> ExportAsync([FromQuery] GetMyTestEntityNamesInput input)
        {
            input.MaxResultCount = int.MaxValue;
            var exportData = await _mytestentitynameAppService.ExportAsync(input);
            var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/MyTestEntityName导出模板.xlsx");
            if (!System.IO.File.Exists(templatePath))
            {
                templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/MyTestEntityName导出模板.xlsx");
            }
 
            var memoryStream = new MemoryStream();
            await memoryStream.SaveAsByTemplateAsync(templatePath, exportData.Sheets);
            memoryStream.Seek(0L, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportData.FileName}_{DateTime.Now:yyyyMMddhhmmss}.xlsx" };
        }
    }
}