123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using DllEapEntity.Onsemi;
- using DllSocketFile;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace DllEapDal.OFILM
- {
- public class OfilmProgramDal
- {
- private IDatabase CurrDb;
- private IConfiguration Configuration;
- private string mesApiPrefix;
- private ILogger logger;
- public OfilmProgramDal(IDatabase db)
- {
- CurrDb = db;
- }
- public OfilmProgramDal(IDatabase db, IConfiguration configuration,
- ILogger logger)
- {
- CurrDb = db;
- this.Configuration = configuration;
- this.mesApiPrefix = Configuration["mesurl:url"];
- this.logger = logger;
- }
- /// <summary>
- /// 获取程序列表
- /// </summary>
- /// <param name="macId"></param>
- /// <param name="proName"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public IEnumerable<OnsemiProgramDto> GetProgramPaths(int macId, string proName, ref string errorinfo)
- {
- var machine = CurrDb.FindEntityFor<Machine>(macId);
- var uploadedPros = CurrDb.FindListForCondition<BusinessFileRelation>($" and c.UploadMacID={machine.ID}", ref errorinfo);
- if (machine.MModeCode == "ADT7900DUO")
- {
- string reError = "";
- var res = new MacOrderSendDal(this.CurrDb).SendOrder(machine, 7, 19, "S7F19", ref reError);
- if (proName != null && proName.Length > 0)
- {
- res = res.Where(v => v.FContent.Contains(proName)).ToList();
- }
- return res.Where(v => v.FContent.Trim().Length > 0).Select(v =>
- {
- var fileOrgName = Regex.Match(v.FContent, @"(?<=\\).*").Value;
- return new OnsemiProgramDto()
- {
- Name = fileOrgName,
- Path = v.FContent,
- State = uploadedPros.Any(t => t.FileOrgName == fileOrgName) ? "已上传" : "未上传"
- };
- });
- };
- IEnumerable<OnsemiProgramDto> pros = null;
- var socketFile = new SocketFile();
- IEnumerable<string> fileNames = null;
- var customer = AppConfigurtaionServices.Configuration["Client"];
- if (customer.ToUpper() == "OFILM")
- {
- fileNames = socketFile.GetMacFileList(machine, proName, ref errorinfo);
- if (fileNames != null && fileNames.Count() > 0)
- {
- pros = fileNames.Select(c => new OnsemiProgramDto
- {
- Path = c,
- Name = c,
- State = uploadedPros.Any(t => t.FileOrgName == c) ? "已上传" : "未上传"
- });
- }
- }
- else if (customer.ToUpper() == "TRS")
- {
- var dtos = socketFile.GetMacFileListForTRS(machine, proName, ref errorinfo);
- if (dtos != null && dtos.Count() > 0)
- {
- pros = dtos.Select(c => new OnsemiProgramDto
- {
- Path = c.Path,
- Name = c.Name,
- State = uploadedPros.Any(t => t.FileOrgName == c.Name) ? "已上传" : "未上传"
- });
- }
- }
- else
- {
- var dtos = socketFile.GetMacFileListForTRS(machine, proName, ref errorinfo);
- if (dtos != null && dtos.Count() > 0)
- {
- pros = dtos.Select(c => new OnsemiProgramDto
- {
- Path = c.Path,
- Name = c.Name,
- State = uploadedPros.Any(t => t.FileOrgName == c.Name) ? "已上传" : "未上传"
- });
- }
- }
- return pros;
- }
- public int Upload(int macId, string proPath, string proName, string userCode, ref string errorinfo)
- {
- var machine = CurrDb.FindEntityFor<Machine>(macId);
- //if (machine.MModeCode == "ADT7900DUO")
- //{
- // // ADT7900程序上传
- // return new Adt7900ProgramDal(this.CurrDb, this.logger).UploadProgram(machine, proName, proPath, userCode);
- //}
- var socketFile = new SocketFile();
- var customer = AppConfigurtaionServices.Configuration["Client"];
- if (customer.ToUpper() == "OFILM")
- {
- var flag = socketFile.UploadFile(machine, proName, ref errorinfo);
- if (flag == null)
- return -1;
- CallMesuploadRecipe(machine.FCode, proName, flag.Version, ref errorinfo);
- }
- else
- {
- var flag = socketFile.UploadForTRS(machine, proName, proPath, ref errorinfo);
- if (flag == null)
- return -1;
- }
- return 1;
- }
- private int CallMesuploadRecipe(string maccode, string programname, int version, ref string errorinfo)
- {
- try
- {
- //处理程序名称,传给MES的程序名称不能含.RCP扩展名称
- if (programname.Length > 4)
- {
- string extname = programname.Substring(programname.Length - 4, 4);
- if (extname == ".rcp")
- programname = programname.Substring(0, programname.Length - 4);
- }
- string actionName = "uploadRecipe";
- string fullUrl = mesApiPrefix + actionName;
- IDictionary<string, string> dic = new Dictionary<string, string>();
- dic.Add("equipmentID", maccode);
- dic.Add("recipeName", programname);
- dic.Add("version", version.ToString());
- var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
- string logText = $"调用MES上传程序接口:{fullUrl},传入的参数:{JsonConvert.SerializeObject(dic)}," +
- $"接收到的值为:{JsonConvert.SerializeObject(response)}";
- this.logger.LogError(logText);
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.ToString();
- return -1;
- }
- }
- }
- }
|