168 lines
6.1 KiB
C#
168 lines
6.1 KiB
C#
using System;
|
||
using SqlSugar;
|
||
using Infrastructure.Attribute;
|
||
using Infrastructure.Extensions;
|
||
using ZR.Model;
|
||
using ZR.Model.Dto;
|
||
using ZR.Model.Business;
|
||
using ZR.Repository;
|
||
using ZR.Service.Business.IBusinessService;
|
||
using System.Linq;
|
||
using System.Globalization;
|
||
using ZR.Model.mes.carouselBoard;
|
||
using ZR.Model.MES.pro;
|
||
|
||
namespace ZR.Service.Business
|
||
{
|
||
/// <summary>
|
||
/// bi大屏-清洗后数据-工单表Service业务层处理
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(IBiDwdWorkorderService), ServiceLifetime = LifeTime.Transient)]
|
||
public class BiDwdWorkorderService : BaseService<BiDwdWorkorder>, IBiDwdWorkorderService
|
||
{
|
||
/// <summary>
|
||
/// 查询bi大屏-清洗后数据-工单表列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public PagedInfo<BiDwdWorkorderDto> GetList(BiDwdWorkorderQueryDto parm)
|
||
{
|
||
var predicate = Expressionable.Create<BiDwdWorkorder>();
|
||
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.ToPage<BiDwdWorkorder, BiDwdWorkorderDto>(parm);
|
||
|
||
return response;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
public BiDwdWorkorder GetInfo(int Id)
|
||
{
|
||
var response = Queryable()
|
||
.Where(x => x.Id == Id)
|
||
.First();
|
||
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加bi大屏-清洗后数据-工单表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public BiDwdWorkorder AddBiDwdWorkorder(BiDwdWorkorder model)
|
||
{
|
||
return Context.Insertable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改bi大屏-清洗后数据-工单表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public int UpdateBiDwdWorkorder(BiDwdWorkorder model)
|
||
{
|
||
//var response = Update(w => w.Id == model.Id, it => new BiDwdWorkorder()
|
||
//{
|
||
// GenerationTime = model.GenerationTime,
|
||
// WorkOrder = model.WorkOrder,
|
||
// PartNumber = model.PartNumber,
|
||
// BlankNumber = model.BlankNumber,
|
||
// Colour = model.Colour,
|
||
// Specification = model.Specification,
|
||
// Description = model.Description,
|
||
// VehicleNumber = model.VehicleNumber,
|
||
// HangNumber = model.HangNumber,
|
||
// PreviousNumber = model.PreviousNumber,
|
||
// CylinderNumber = model.CylinderNumber,
|
||
// Sort = model.Sort,
|
||
// Remark1 = model.Remark1,
|
||
// Remark2 = model.Remark2,
|
||
//});
|
||
//return response;
|
||
return Update(model, true);
|
||
}
|
||
|
||
public int GenerateDataByDateTime(BiDwdWorkorderQueryDto parm)
|
||
{
|
||
try
|
||
{
|
||
Context.Ado.BeginTran();
|
||
DateTime dateTime = parm.GenerationTime;
|
||
// 清空旧记录
|
||
DeleteDataByDateTime(parm);
|
||
// 生成新纪录
|
||
int currentYear = dateTime.Year;
|
||
|
||
// 计算当前是本年的第几周(周一为一周的开始)
|
||
int currentWeek = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(
|
||
dateTime,
|
||
CalendarWeekRule.FirstFourDayWeek,
|
||
DayOfWeek.Monday
|
||
);
|
||
|
||
// 计算当前是星期几(1-7,周一=1,周日=7)
|
||
int currentDay = (int)dateTime.DayOfWeek;
|
||
if (currentDay == 0) // 如果是周日
|
||
{
|
||
currentDay = 7;
|
||
}
|
||
|
||
List<BiDwdWorkorder> GenerationData = Context
|
||
.Queryable<ProWorkorder_v2>()
|
||
.Where(it => it.Remark3 == "是") // 只获取有效的工单
|
||
.Where(it => it.Year == currentYear) // 筛选当前年份
|
||
.Where(it => it.Week == currentWeek) // 筛选当前周
|
||
.Where(it => it.Date == currentDay) // 筛选当前日
|
||
.OrderBy(it => it.Sort) // 按序号排序
|
||
.Select(it => new BiDwdWorkorder
|
||
{
|
||
GenerationTime = dateTime,
|
||
BlankNumber = it.BlankNumber, // 毛坯号
|
||
PartNumber = it.FinishedPartNumber, // 成品零件号
|
||
Description = it.ProductDescription, // 产品描述
|
||
Colour = it.Colour, // 颜色
|
||
Specification = it.Specifications, // 规格
|
||
VehicleNumber = it.VehicleNumber, // 车数
|
||
PreviousNumber = it.PreviousNumber, // 上件数
|
||
CylinderNumber = it.CylinderNumber, // 双组号缸号
|
||
Remark1 = it.Remark1, // 备注1
|
||
Remark2 = it.Remark2, // 备注2
|
||
Sort = it.Sort, // 序号
|
||
WorkOrder = it.ClientWorkorder, // 客户工单号
|
||
})
|
||
.ToList();
|
||
int result = Context.Insertable(GenerationData).ExecuteCommand();
|
||
Context.Ado.CommitTran();
|
||
return result;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
Context.Ado.RollbackTran();
|
||
throw;
|
||
}
|
||
|
||
}
|
||
|
||
public int DeleteDataByDateTime(BiDwdWorkorderQueryDto parm)
|
||
{
|
||
return Context.Deleteable<BiDwdWorkorder>().Where(it=>it.GenerationTime == parm.GenerationTime).ExecuteCommand();
|
||
}
|
||
|
||
public (string, object, object) Import(List<BiDwdWorkorder> list)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public List<BiDwdWorkorderDto> GetListByDate(BiDwdWorkorderQueryDto parm)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
} |