wx
2023-01-08 5399034accbccaeb2148337d585df379e70b368a
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using CommonHelper;
using GasolineBlend.Entity;
using GasolineBlend.Entity.ViewModel;
using Pissa.Service.DbService;
using Quartz.Util;
using SqlSugar;
 
namespace GasolineBlend.Controllers
{
    public class SysController : BaseController
    {
        private SysService _countryService = new SysService();
        private SysHotWordService _hotWordService = new SysHotWordService();
 
        /// <summary>
        /// 获取国家信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCountry()
        {
            var res = _countryService.GetListAsync(null, a => a.Sort, OrderByType.Asc, false).Result;
            return SuccessNoShow(data:res);
        }
 
        /// <summary>
        /// 获取主要国家信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCountryMain()
        {
            List<string> listNameCH = new List<string>();
            string[] strNameCh = {"中国", "美国", "欧盟", "日本", "韩国", "德国","法国","芬兰","意大利", "瑞典",  "挪威", "英国", "瑞士", "印度", "巴西" };
            listNameCH = strNameCh.ToList();
            var res = _countryService.GetListAsync(a=>listNameCH.Contains(a.NameCh), a => a.Sort, OrderByType.Asc, false).Result;
            return SuccessNoShow(data: res);
        }
 
        /// <summary>
        /// 获取字典信息
        /// </summary>
        /// <param name="dictCode"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetDictItems(string dictCode)
        {
            var res = _countryService.GetDictItems(dictCode);
            return SuccessNoShow(data: res);
        }
 
 
        /// <summary>
        /// 获取ipc
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="parentCode">父编码</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetIpcClass(int year = 2021, string parentCode = "")
        {
            var res = _countryService.GetIpcClass(year, parentCode);
            return SuccessNoShow(data: res);
        }
        /// <summary>
        /// 获取ipc树型结构
        /// </summary>
        /// <param name="param">条件</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetIpcClassTree(int year,string json)
        {
            var res = _countryService.GetIpcClassTree(year,json);
            return SuccessNoShow(data: res);
        }
 
        /// <summary>
        /// 获取cpc
        /// </summary>
        /// <param name="parentCode">父编码</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCpcClass(string parentCode = "")
        {
            var res = _countryService.GetCpcClass(parentCode);
            return SuccessNoShow(data: res);
        }
        /// <summary>
        /// 获取cpc
        /// </summary>
        /// <param name="json">条件</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCpcClassTree(string json)
        {
            var res = _countryService.GetCpcClassTree(json);
            return SuccessNoShow(data: res);
        }
        /// <summary>
        /// 获取产业分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetStraindustryTree(string json)
        {
            var res = _countryService.GetStraindustryTree(json);
            return SuccessNoShow(data: res);
        }
 
        /// <summary>
        /// 获取国民经济行业分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetEcoindustryTree(string json)
        {
            var res = _countryService.GetEcoindustryTree(json);
            return SuccessNoShow(data: res);
        }
 
        /// <summary>
        /// 获取轮播图
        /// </summary>
        /// <param name="isDisplay">是否展示</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCarouselImg(bool? isDisplay = null)
        {
            var res = _countryService.Context.Queryable<SysCarouselImg>()
                .WhereIF(isDisplay != null, a => a.IsDisplay == isDisplay)
                .OrderBy(a => a.Sort)
                .ToList();
            return SuccessNoShow(data: res);
        }
 
        /// <summary>
        /// 上传轮播图
        /// </summary>
        /// <param name="imgName"></param>
        /// <param name="sort"></param>
        /// <param name="isDisplay"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddCarouselImg(string imgName, int sort = 0, bool isDisplay = true)
        {
            //LogHelper.Error("文件名Test:"+imgName);
            if (HttpContext.Request.Files.Count == 0)
                return Error("上传文件的数量是0");
            var file = Request.Files[0];
            if (file == null)
                return Error("请上传图像文件");
            if (imgName.IsNullOrWhiteSpace())
                imgName = file.FileName;
            if (!Directory.Exists(Server.MapPath("/CarouselImg")))
                Directory.CreateDirectory(Server.MapPath("/CarouselImg"));
            string filePath = $"/CarouselImg/{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
            string absolutePath = Server.MapPath(filePath);
            file.SaveAs(absolutePath);
 
            var model = new SysCarouselImg()
            {
                Name = imgName,
                Sort = sort,
                IsDisplay = isDisplay,
                CreateUserId = OperatorProvider.Instance?.Current?.UserId??"0",
                Url = filePath
            };
            var res = _countryService.Context.Insertable(model).ExecuteReturnIdentity();
            return Success(data: res);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="imgName"></param>
        /// <param name="sort"></param>
        /// <param name="isDisplay"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult UpdateCarouselImg(int id,string imgName, int? sort = null, bool? isDisplay = null)
        {
            var res = _countryService.Context.Updateable<SysCarouselImg>()
                .SetColumns(a => new SysCarouselImg() { UpdateTime = DateTime.Now})
                .SetColumnsIF(!string.IsNullOrWhiteSpace(imgName),a=>a.Name==imgName)
                .SetColumnsIF(sort!=null,a=>a.Sort==(int)sort)
                .SetColumnsIF(isDisplay != null,a=>a.IsDisplay == (bool)isDisplay)
                .Where(a => a.Id == id)
                .ExecuteCommand();
            return Success();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DeleteCarouselImg(int id)
        {
            var img = _countryService.Context.Queryable<SysCarouselImg>()
                .Where(a => a.Id == id)
                .First();
            if (img == null)
                return Error("找不到该图片");
 
            var res = _countryService.Context.Deleteable<SysCarouselImg>()
                .Where(a => a.Id == id)
                .ExecuteCommand();
            System.IO.File.Delete(Server.MapPath(img.Url));
            return res > 0 ? Success() : Error();
        }
 
 
        /// <summary>
        /// 洛迦诺分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLoccn(string json)
        {
            var res = _countryService.GetLoccn(json);
            return SuccessNoShow(data: res);
        }
 
        #region SysHotwords
 
 
        [HttpPost]
        public async Task<ActionResult> AddHotWord(SysHotWord model)
        {
            model.CreateUserId = OperatorProvider.Instance?.Current?.UserId;
            var res = await _hotWordService.AddAsync(model);
            return Success();
        }
        [HttpPost]
        public async Task<ActionResult> DelHotWord(int id)
        {
            var res = await _hotWordService.DeleteAsync(a=>a.Id == id);
            return Success();
        }
        [HttpPost]
        public async Task<ActionResult> UpdateHotWord(SysHotWord model)
        {
            model.CreateUserId = OperatorProvider.Instance?.Current?.UserId;
            var res = await _hotWordService.UpdateAsync(model);
            return Success();
        }
        [HttpPost]
        public async Task<ActionResult> GetHotWordList()
        {
            var res = await _hotWordService.GetListAsync(null, a => a.Sort, OrderByType.Asc);
            return SuccessNoShow(data:res);
        }
 
        #endregion
    }
}