Blame view

sys/Hh.Mes.Service/WebService/Material/MaterialCallService.cs 8.82 KB
1
2
using Hh.Mes.Common.config;
using Hh.Mes.Common.log;
赖素文 authored
3
4
5
6
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
7
using NPOI.SS.Formula.Functions;
HuXiYu authored
8
using Org.BouncyCastle.Crypto;
赖素文 authored
9
10
11
12
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
HuXiYu authored
13
using System.Linq;
赖素文 authored
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
using System.Text;
using System.Threading.Tasks;

namespace Hh.Mes.Service.Material
{
    public class MaterialCallService : RepositorySqlSugar<dynamic>
    {
        /// <summary>
        /// 物料呼叫,需求库位
        /// </summary>
        /// <returns></returns>
        public Task<DataSet> GetSelectData()
        {
            string sql = @" SELECT t1.code, srmCode   FROM [dbo].[base_location] t1 WHERE type = 'A' OR type = 'B'
                            select WorkshopId, WorkshopCode, LineCode, LineName, Id  from Line";

            return base.Context.Ado.GetDataSetAllAsync(sql);
        }

        /// <summary>
        /// 获取物料
        /// </summary>
        public Response GetMaterialList(PageReq pageReq, base_material entity)
        {
            var result = new Response();
            string orderBy = (pageReq == null || string.IsNullOrEmpty(pageReq.field)) ? " id desc" : $"{pageReq.field} {pageReq.order} ";
            string sqlWhere = SqlMateriaWhere(entity);
            var stringBuilder = new StringBuilder();
            //页码,页数
            //Exel ture 不分页
            if (!entity.Exel && pageReq != null)
            {
                stringBuilder.Append("declare @pageIndex int,@pageSize int,@offset int");
                stringBuilder.AppendLine($"  select @pageIndex={pageReq.page}, @pageSize={pageReq.limit}, @offset=(@pageIndex - 1) * @pageSize");
            }
50
            stringBuilder.AppendLine($@" select t3.quantityRate, t2.mtTypeName materialtypeName,t1.*  
赖素文 authored
51
                                         from base_material t1 with(nolock)
赖素文 authored
52
                                         left join base_material_type t2 with(nolock) on t1.MtTypeCode=t2.mtTypeCode  
53
                                         left join base_material_rate t3   with(nolock) on t1.materialCode=t3.materialCode  
赖素文 authored
54
55
56
57
58
59
60
                                         where {sqlWhere} order by {orderBy} ");

            //Exel ture 不分页
            if (!entity.Exel)
            {
                stringBuilder.AppendLine("  offset @offset row fetch next @pageSize row only ");
                stringBuilder.Append($@" select rowTotal= count(*) from base_material t1 with(nolock)
赖素文 authored
61
                                         left join base_material_type t2 with(nolock) on t1.MtTypeCode=t2.mtTypeCode  where {sqlWhere}");
赖素文 authored
62
63
64
65
66
67
            }

            var parameters = new List<SugarParameter>(){
                new SugarParameter("@mtTypeCode",entity.mtTypeCode),
                new SugarParameter("@materialName",entity.materialName),
                new SugarParameter("@materialCode",entity.materialCode),
68
69
                new SugarParameter("@codeOrName",entity.codeOrName),
                new SugarParameter("@plmeId",entity.plmeId)
赖素文 authored
70
71
72
73
74
75
76
77
78
79
80
81
            };

            var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString(), parameters);
            result.Result = ds.Tables[0];
            result.Count = entity.Exel ? (int)result.Result.Rows.Count : (int)ds.Tables[1].Rows[0]["rowTotal"];
            return result;
        }

        public string SqlMateriaWhere(base_material model)
        {
            var stringBuilder = new StringBuilder();
            stringBuilder.Append(" 1=1 ");
82
83
84
85
            if (!string.IsNullOrEmpty(model.plmeId))
            {
                stringBuilder.Append(" and t1.plmeId=@plmeId ");
            }
赖素文 authored
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
            if (!string.IsNullOrEmpty(model.mtTypeCode))
            {
                stringBuilder.Append(" and  t1.mtTypeCode = @mtTypeCode ");
            }
            if (!string.IsNullOrEmpty(model.materialName))
            {
                stringBuilder.Append(" and  t1.materialName like '%'+@materialName+'%' ");
            }
            if (!string.IsNullOrEmpty(model.materialCode))
            {
                stringBuilder.Append(" and  t1.materialCode like '%'+@materialCode+'%' ");
            }
            //下拉弹出搜索框
            if (!string.IsNullOrEmpty(model.codeOrName))
            {
                stringBuilder.Append($" and  (t1.materialCode like '%'+@codeOrName+'%' or  t1.materialName like '%'+@codeOrName+'%' )   ");
            }
            return stringBuilder.ToString();
        }
赖素文 authored
107
108
109
110
111
        public dynamic Ins(base_material entity)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new Response();
赖素文 authored
112
                entity.keys = Guid.NewGuid();
113
                entity.createBy = sysWebUser.Account;
赖素文 authored
114
                entity.createTime = DateTime.Now;
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

                var rate = new base_material_rate
                {
                    materialCode = entity.materialCode,
                    materialName = entity.materialName,
                    mtClassify = entity.mtClassify,
                    unitCode = entity.unitCode,
                    specifications = entity.specifications,
                    materialKeys = entity.keys,
                    quantityRate = 1,

                    createBy = sysWebUser?.Account,
                    createTime = DateTime.Now
                };
130
131
132
                Context.Insertable(entity).AddQueue();
                Context.Insertable(rate).AddQueue();
                Context.SaveQueues();
赖素文 authored
133
134
135
136
137
138
                return response;
            });
        }
赖素文 authored
139
        /// <summary>
赖素文 authored
140
        /// 更新 物料
赖素文 authored
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        /// </summary>
        public dynamic Upd(base_material model)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                model.updateBy = sysWebUser?.Account;
                model.updateTime = DateTime.Now;
                response.Status = Context.Updateable(model).Where(u => u.id == model.id).ExecuteCommand() > 0;
                if (!response.Status) response.Message = "更新失败";
                return response;
            });
        }
HuXiYu authored
155
156
157
158
159
        /// <summary>
        /// 删除 物料
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
160
        public dynamic DelByIds(Guid[] ids)
HuXiYu authored
161
162
163
164
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new Response();
165
166
167
168
169
170
171
172
173

               var materialCodeList= Context.Queryable<base_material>().Where(x => ids.Contains(x.keys)).Select(x=>x.materialCode).ToList();

                Context.Deleteable<base_material>(t => ids.Contains(t.keys)).AddQueue();

                Context.Deleteable<base_material_rate>(t => materialCodeList.Contains(t.materialCode)).AddQueue();

                Context.SaveQueues();
HuXiYu authored
174
175
176
                return response;
            });
        }
赖素文 authored
177
178
179
180
181
182
183
184
185
186
187
188
189


        /// <summary>
        /// 左侧列表  
        /// </summary>
        public DataTable GetTreeList()
        {
            string sql = @"select t1.id,name=t1.mtTypeName ,  t1.mtTypeCode ,t1.keys,parentId=t1.parentTypeId		     
						   from base_material_type t1";
            var dt = base.Context.Ado.GetDataTable(sql);
            return dt == null || dt.Rows.Count == 0 ? null : dt;
        }
HuXiYu authored
190
191
192
193
194
195
196
197
198
199
        /// <summary>
        /// 编辑 物料比例表数据
        /// </summary>
        public dynamic EditRate(base_material_rate model)
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                model.updateBy = sysWebUser?.Account;
                model.updateTime = DateTime.Now;
200
                response.Status = Context.Updateable(model)
201
202
                                         .UpdateColumns(t => new { t.oprSequenceCode, t.quantityRate })
                                         .Where(u => u.id == model.id).ExecuteCommand() > 0;
HuXiYu authored
203
204
205
206
207
208
209
210
211
                if (!response.Status) response.Message = "更新失败";
                return response;
            });
        }

        /// <summary>
        /// 查找比率数据
        /// </summary>
        /// <returns></returns>
212
        public dynamic GetMaterialRateByCode(Guid materialKeys)
HuXiYu authored
213
214
215
216
217
        {
            var response = new Response();
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var result = base.Context.Queryable<base_material_rate>()
218
                                 .Where(x => x.materialKeys == materialKeys).ToList();
HuXiYu authored
219
220
221
222
223
                response.Result = result;
                return response;
            });
        }
224
225
226
227
228
229
230

        public string GetMaterialUrl()
        {
            var urlDic = "UrlMaterialUpCict" + ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend1;
            var url = GetDictionaryDictValue(urlDic, "GetUrl");
            return url + "api/Upstream/Mes/V1/MaterialUpCict";
        }
赖素文 authored
231
232
    }
}