yangle
2024-07-17 2eef7800f97ba845780c8eee1da191fff4b18d94
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers
{
    public class Gy_UnitConvertRateController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        const string ModCaption = "单位换算";
        public const string ModRightName = "Gy_UnitConvertRate";
        public const string ModRightNameDelete = ModRightName + "_Delete";  //删除
        public DataSet ds = new DataSet();
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
 
 
        #region 单位换算列表
        /// <summary>
        /// 获取单位换算列表信息
        /// </summary>
        /// <returns></returns>
        [Route("Gy_UnitConvertRateController/GetGy_UnitConvertRateList_Json")]
        [HttpGet]
        public object GetGy_UnitConvertRateList_Json(string sWhere, string HMaker, string OperationType)
        {
            try
            {
                //判断权限  1为直接列表模块打开  2为从其他模块跳转打开列表
                if (OperationType == "1")
                {
                    //判断权限
                    if (!DBUtility.ClsPub.Security_Log(ModRightName, 1, false, HMaker))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "您没有该模块权限,请与管理员联系!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                //返回列表信息
                ds = oCn.RunProcReturn("select * from h_v_Gy_UnitConvertRateList where " + sWhere + " order by HItemID desc", "h_v_Gy_UnitConvertRateList");
                List<object> columnNameList = new List<object>();
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));  //获取到DataColumn列对象的列名
                }
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "成功!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询列表信息失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 单位换算删除
        /// <summary>
        /// 删除单位换算
        /// </summary>
        /// <returns></returns>
        [Route("Gy_UnitConvertRateController/GetGy_UnitConvertRate_Delete_Json")]
        [HttpGet]
        public object GetGy_UnitConvertRate_Delete_Json(Int64 HItemID, string HMaker)
        {
            try
            {
                //判断权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameDelete, 1, false, HMaker))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "您没有该模块删除功能权限,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                oCn.BeginTran();
                //判断存在性
                ds = oCn.RunProcReturn("select HNumber,HName from Gy_UnitConvertRate with(nolock) where HItemID= " + HItemID.ToString(), "Gy_UnitConvertRate");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    oCn.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未查询到该单位换算,请刷新数据后重新选择!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    oCn.RunProc("Delete from Gy_UnitConvertRate where HItemID= " + HItemID.ToString(), ref DBUtility.ClsPub.sExeReturnInfo);
                    //写入日志
                    DBUtility.ClsPub.Add_Log("", "删除单位换算,代码:" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HNumber"]) + ",名称:" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HName"]), HMaker);
                    oCn.Commit();
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除单位换算成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "删除单位换算失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 单位换算批量同步
        /// <summary>
        /// 从金蝶云批量同步单位换算至本地表
        /// </summary>
        [Route("Gy_UnitConvertRateController/GetGy_UnitConvertRate_BatchSync_Json")]
        [HttpGet]
        public object GetGy_UnitConvertRate_BatchSync_Json()
        {
            try
            {
                //获取系统参数
                string sErrMsg = "";
                if (oSystemParameter.ShowBill(ref sErrMsg) == true)
                {
                    //系统参数是否为私有云模式,N为公有云模式,Y为私有云模式
                    //私有云模式,通过调用存储过程进行同步
                    if (oSystemParameter.omodel.WMS_CloudMode.ToUpper() == "Y")
                    {
                        ds = oCn.RunProcReturn("exec h_p_IFCLD_ERPDataToLocal_UnitConvertRate", "h_p_IFCLD_ERPDataToLocal_UnitConvertRate");
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "单位换算批量同步成功!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //公有云模式,通过调用WEBAPI方式进行同步
                    else if (oSystemParameter.omodel.WMS_CloudMode.ToUpper() == "N")
                    {
                        //判断金蝶云是否登录成功
                        var loginRet = InvokeHelper.Login();
                        var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                        //判断是否登录成功
                        if (isSuccess <= 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "批量同步失败,金蝶云登入不成功,请确认C盘配置文件所设置金蝶云对应网址、账套、登录用户、登录密码是否正确!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
 
                        var json = new
                        {
                            FormId = "BD_UNITCONVERTRATE",
                            FieldKeys = "FUNITCONVERTRATEID,FBILLNO,FMATERIALID,FUSEORGID,FCREATEORGID,FFORBIDSTATUS" +
                            ",FCURRENTUNITID,FDESTUNITID,FCONVERTTYPE,FCONVERTNUMERATOR,FCONVERTDENOMINATOR" +
                            ",FCREATORID,FCREATEDATE,FMODIFIERID,FMODIFYDATE,FAPPROVERID,FAPPROVEDATE,FFORBIDDERID,FFORBIDDATE",
                            FilterString = "",
                            OrderString = "",
                            TopRowCount = 0,
                            StartRow = 0,
                            Limit = 0
                        };
                        //查看 获取数据                    
                        var _result = InvokeHelper.Query("BD_UNITCONVERTRATE", JsonConvert.SerializeObject(json));
 
                        //反序列化
                        _result = _result.Replace("\"", "");
                        _result = _result.Replace("\n", "");
                        _result = _result.Replace(",[", "");
                        _result = _result.Replace("[", "");
                        string[] rows = _result.Split(new string[] { "]" }, StringSplitOptions.RemoveEmptyEntries); //以"]"分隔每一行并移除空行
                        string[,] arr = new string[rows.Length, rows[0].Split(',').Length]; //根据行和列数创建二维数组
                        for (int i = 0; i < rows.Length; i++) //遍历每一行
                        {
                            string[] cols = rows[i].Split(','); //以逗号分隔每一列
                            for (int j = 0; j < cols.Length; j++) //遍历每一列
                            {
                                arr[i, j] = cols[j]; //存入二维数组
                            }
                        }
 
                        oCn.BeginTran();
                        //清空单位换算表数据
                        oCn.RunProc("Delete from Gy_UnitConvertRate", ref DBUtility.ClsPub.sExeReturnInfo);
 
                        //输出二维数组
                        for (int i = 0; i < arr.GetLength(0); i++)
                        {
                            var subData = new
                            {
                                HItemID = DBUtility.ClsPub.isLong(arr[i, 0]),
                                HNumber = "",
                                HName = "",
                                HShortNumber = "",
                                HParentID = 0,
                                HLevel = 1,
                                HEndFlag = 1,
                                HStopflag = arr[i, 5].ToString() == "B" ? 1 : 0,
                                HRemark = "CLD-ERP导入",
                                HUseFlag = "已使用",
                                HUSEORGID = DBUtility.ClsPub.isLong(arr[i, 3]),
                                HCREATEORGID = DBUtility.ClsPub.isLong(arr[i, 4]),
                                HBILLNO = DBUtility.ClsPub.isStrNull(arr[i, 1]),
                                HMATERID = DBUtility.ClsPub.isLong(arr[i, 2]),
                                HCURRENTUNITID = DBUtility.ClsPub.isLong(arr[i, 6]),
                                HDESTUNITID = DBUtility.ClsPub.isLong(arr[i, 7]),
                                HCONVERTTYPE = DBUtility.ClsPub.isStrNull(arr[i, 8]),
                                HCONVERTNUMERATOR = DBUtility.ClsPub.isDoule(arr[i, 9]),
                                HCONVERTDENOMINATOR = DBUtility.ClsPub.isDoule(arr[i, 10]),
                                HFORBIDSTATUS = DBUtility.ClsPub.isStrNull(arr[i, 5]),
                                HUnitID = DBUtility.ClsPub.isLong(arr[i, 2] == "0" ? arr[i, 6] : "-1"),
                                HMakeEmp = DBUtility.ClsPub.isStrNull(arr[i, 11]),
                                HMakeTime = DBUtility.ClsPub.isDate(arr[i, 12]),
                                HCheckEmp = DBUtility.ClsPub.isStrNull(arr[i, 15]),
                                HCheckTime = DBUtility.ClsPub.isDate(arr[i, 16]),
                                HModifyEmp = DBUtility.ClsPub.isStrNull(arr[i, 13]),
                                HModifyTime = DBUtility.ClsPub.isDate(arr[i, 14]),
                                HStopEmp = DBUtility.ClsPub.isStrNull(arr[i, 17]),
                                HStopTime = DBUtility.ClsPub.isDate(arr[i, 18]),
                            };
 
                            //写入单位换算表数据
                            oCn.RunProc("set identity_insert Gy_UnitConvertRate on", ref DBUtility.ClsPub.sExeReturnInfo);
                            string sql = $@"Insert into Gy_UnitConvertRate 
                                    (HItemID,HNumber,HName,HShortNumber,HParentID,HLevel
                                    ,HEndFlag,HStopflag,HRemark,HUseFlag,HUSEORGID,HCREATEORGID
                                    ,HBILLNO,HMATERID,HCURRENTUNITID,HDESTUNITID,HCONVERTTYPE,HCONVERTNUMERATOR
                                    ,HCONVERTDENOMINATOR,HFORBIDSTATUS,HUnitID
                                    ,HMakeEmp,HMakeTime
                                    ,HCheckEmp,HCheckTime
                                    ,HModifyEmp,HModifyTime
                                    ,HStopEmp,HStopTime)
                                    Values({subData.HItemID},'{subData.HNumber}','{subData.HName}','{subData.HShortNumber}',{subData.HParentID},{subData.HLevel}
                                    ,{subData.HEndFlag},{subData.HStopflag},'{subData.HRemark}','{subData.HUseFlag}',{subData.HUSEORGID},{subData.HCREATEORGID}
                                    ,'{subData.HBILLNO}',{subData.HMATERID},{subData.HCURRENTUNITID},{subData.HDESTUNITID},{subData.HCONVERTTYPE},{subData.HCONVERTNUMERATOR}
                                    ,{subData.HCONVERTDENOMINATOR},'{subData.HFORBIDSTATUS}',{subData.HUnitID}
                                    ,'{subData.HMakeEmp}',case when '{subData.HMakeTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HMakeTime}' end
                                    ,'{subData.HCheckEmp}',case when '{subData.HCheckTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HCheckTime}' end
                                    ,'{subData.HModifyEmp}',case when '{subData.HModifyTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HModifyTime}' end
                                    ,'{subData.HStopEmp}',case when '{subData.HStopTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HStopTime}' end)";
                            oCn.RunProc(sql.Replace("\r\n", ""));
                            oCn.RunProc("set identity_insert Gy_UnitConvertRate off", ref DBUtility.ClsPub.sExeReturnInfo);
                        }
                        oCn.Commit();
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "单位换算批量同步成功!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "不支持批量同步功能!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单位换算批量同步失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        #endregion
 
    }
}