zhanghonglin
6 天以前 8f9b9411ca279670bd85fcfa7763987295ed9abf
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac.Core;
using Newtonsoft.Json;
using Quartz;
using WIDESEA_Common.FillingEnum;
using WIDESEA_DTO.Basic;
using WIDESEA_Model.Models.Basic;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO.MES;
using WIDESEAWCS_QuartzJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class UpstreamJob : JobBase, IJob
    {
 
        private readonly IRepository<Dt_FillingOrder_Hty> _FillingHtyRepository;
 
        //mes校验码
        private static string mesVerification = "";
        //秒
        private static int shijian = 0;
 
        public UpstreamJob(IRepository<Dt_FillingOrder_Hty> fillingHtyRepository)
        {
            _FillingHtyRepository = fillingHtyRepository;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                //一天获取一次校验码
                Thread.Sleep(1000);
                shijian = shijian -1;
                string mes = AppSettings.Get("MSE");
                if (!string.IsNullOrEmpty(mes))
                {
                    Reports reports = new Reports();
                    //获取MES校验码
                    if (shijian <= 0)
                    {
                        User user = new User();
                        Return s = JsonConvert.DeserializeObject<Return>(HttpHelper.Post($"{mes}/Account/Check/", user.Serialize()));
                        if (s.code.Equals("200"))
                        {
                            mesVerification = s.message;
                            shijian = 86400;
                            LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{"获取mes校验码成功" + s.message}" });
                        }
                        else
                        {
                            LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{"获取mes校验码失败" + JsonConvert.SerializeObject(s)}" });
                        }
                    }
 
                    //查询二维码
                    Dt_FillingOrder_Hty FillingOrder = _FillingHtyRepository.QueryFirst(x => x.BarStatus == (int)FillingStatusEnum.ExecuteCompleted);
                    if (FillingOrder != null && !mesVerification.Equals(""))
                    {
                        reports.report.Qty = FillingOrder.BarNum;
                        reports.report.DispatchID = FillingOrder.WorkID + "";
                        reports.barcodeSN.Add(new barcodeSN());
                        reports.barcodeSN[0].Barcode = FillingOrder.BarCode;
                        reports.barcodeSN[0].BatchNum = int.Parse(FillingOrder.batchNum);
                        reports.barcodeSN[0].Id = FillingOrder.BarCodeID;
                        reports.barcodeSN[0].MaterialId = FillingOrder.ArticleNumID;
                        reports.barcodeSN[0].Quantity = (int)FillingOrder.BarNum;
                        reports.barcodeSN[0].DispatchId = FillingOrder.WorkID;
                        reports.barcodeSN[0].BarcodeType = 0;
 
                        var headers = new Dictionary<string, string>();
                        headers.Add("token", mesVerification);
                        Return k = JsonConvert.DeserializeObject<Return>(HttpHelper.Post($"{mes}/Task/SaveReportRaw/", reports.Serialize(), "application/json", headers));
 
                        string zhi = JsonConvert.SerializeObject(reports);
                        LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{"发送二维码:" + zhi + "//"}" });
 
                        //修改状态
                        if (k.code.Equals("200"))
                        {
                            FillingOrder.BarStatus = (int)FillingStatusEnum.Send;
                            _FillingHtyRepository.UpdateData(FillingOrder);
                            LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{"修改二维码ID:" + FillingOrder.Id + "//"}" });
                        }
                    }
                    else
                    {
                        //LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{"没有可上报的二维码或无校验码"}" });
                    }
                }
 
            }
            catch (Exception ex)
            {
                //写入日志
                LogLock.OutLogAOP("上游系统日志", new string[] { "上游系统", $"{ex.Message}" });
            }
 
            return Task.CompletedTask;
        }
    }
}