You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/JobAutoCreateFee/JobBcEdiReply.cs

160 lines
6.2 KiB
C#

3 years ago
using log4net;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using JobAutoCreateFee.Model;
using System.IO;
namespace JobCreateFee
{
public class JobBcEdiReply : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobBcEdiReply));
public void Execute(IJobExecutionContext context)
{
log.Debug($"Execute开始");
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string BcPath = context.JobDetail.JobDataMap.GetString("BcPath");
string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BcTmp");
//string BcPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BcPath");
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
string[] files = Directory.GetFiles(BcPath);
if (files.Length > 0)
{
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
string pathtxt = File.ReadAllText(file);
var opList = pathtxt.Split('\'');
var MBLNO = "";
var EDISTATUS = "";
log.Debug($"文件名"+ fileInfo.Name);
foreach (var opstr in opList)
{
if (opstr.Length >= 10)
{
log.Debug($"" + opstr);
var head = opstr.TrimStart().Substring(0, 3);
if (head == "UCM")
{
log.Debug($"UCM" + opstr);
var headlist = opstr.Split('+');
var fieldcount = 0;
foreach (var str in headlist)
{
log.Debug($"UCMstr" + str);
if (fieldcount == 1)
{
MBLNO = str;
log.Debug($"业务编号:" + MBLNO);
}
fieldcount = fieldcount + 1;
}
}
}
}
if (!string.IsNullOrEmpty(MBLNO))
{
log.Debug($"业务编号:" + MBLNO);
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
string sql = " update t_op_seae set 订舱状态='已接收' where 业务编号='" + MBLNO + "'";
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
dbcon.Close();
}
File.Copy(file, Path.Combine(tempPath, fileInfo.Name));
File.Delete(file);
}
//foreach (var opstr in opList)
//{
// if (opstr.Length >= 3) {
// var head = opstr.Substring(0, 3);
// if (head == "BGM") {
// var headlist = opstr.Split('+');
// var fieldcount = 0;
// foreach (var str in headlist)
// {
// if (fieldcount == 2) {
// MBLNO = str;
// }
// if (fieldcount == 4)
// {
// EDISTATUS = str;
// }
// fieldcount = fieldcount + 1;
// }
// }
// }
//}
//if (!string.IsNullOrEmpty(MBLNO) && !string.IsNullOrEmpty(EDISTATUS)) {
// log.Debug($"提单号" + MBLNO+" 订舱状态:"+ EDISTATUS);
// var bcstatus = "";
// if (EDISTATUS.Trim() == "AP") {
// bcstatus = "已订舱";
// } else if (EDISTATUS.Trim() == "CA")
// {
// bcstatus = "条件接受";
// }
// else if (EDISTATUS.Trim() == "RE")
// {
// bcstatus = "拒绝";
// }
// using (SqlConnection dbcon = new SqlConnection(connStr))
// {
// dbcon.Open();
// string sql = " update t_op_seae set 订舱状态='"+ bcstatus + "' where 主提单号='"+MBLNO+"'";
// SqlCommand cmd = new SqlCommand(sql, dbcon);
// cmd.ExecuteNonQuery();
// dbcon.Close();
// }
// File.Copy(file, Path.Combine(tempPath, fileInfo.Name));
// File.Delete(file);
//}
}
}
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
}
}