| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Dynamic.Core;
- using System.Threading.Tasks;
- using Volo.Abp.Application.Dtos;
- using Volo.Abp.Domain.Repositories;
- using Business.Models;
- using Microsoft.AspNetCore.Authorization;
- using Business.Permissions;
- using XCZ;
- using Business.ResourceExamineManagement.Dto;
- using Bussiness.Model.MES.IC;
- using AutoMapper.Internal.Mappers;
- using Bussiness.Model.Tech;
- using Bussiness.Model.Production;
- using Business.Core.MongoDBHelper;
- using Business.Core.Utilities;
- using Hangfire.Storage.Monitoring;
- using Business.BookManagement.Dto;
- using Volo.Abp.ObjectMapping;
- using Volo.Abp.Application.Services;
- using ZstdSharp.Unsafe;
- using System.Transactions;
- namespace Business.ResourceExamineManagement
- {
- /// <summary>
- /// 资源检查
- /// </summary>
- //[Authorize(BusinessPermissions.ResourceExamine.Default)]
- public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
- {
- #region 服务
- /// <summary>
- /// 工艺路径
- /// </summary>
- private readonly IMongoDB<mes_technique> _mes_technique;
- /// <summary>
- /// 工艺关联工序
- /// </summary>
- private readonly IMongoDB<mes_tech_process> _mes_tech_process;
- /// <summary>
- /// 工作日历
- /// </summary>
- private readonly IMongoDB<mes_work_calendar> _mes_work_calendar;
- /// <summary>
- /// 工作日历明细
- /// </summary>
- private readonly IMongoDB<mes_work_calendar_list> _mes_work_calendar_list;
- /// <summary>
- /// 工艺工序关联工位
- /// </summary>
- private readonly IMongoDB<mes_tech_proc_workshop> _mes_tech_proc_workshop;
- /// <summary>
- /// 排程占用记录
- /// </summary>
- private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
- /// <summary>
- /// 物料详情
- /// </summary>
- private readonly IMongoDB<ic_item> _ic_item;
- private IRepository<ic_item, long> _mysql_ic_item;
- /// <summary>
- /// 物料BOM
- /// </summary>
- private readonly IMongoDB<ic_bom> _ic_bom;
- private IRepository<ic_bom, long> _mysql_ic_bom;
- /// <summary>
- /// 物料BOM明细
- /// </summary>
- private readonly IMongoDB<ic_bom_child> _ic_bom_child;
- /// <summary>
- /// 生产工单主表
- /// </summary>
- private readonly IMongoDB<mes_morder> _mes_morder;
- private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="icitem"></param>
- /// <param name="icbom"></param>
- public ResourceExamineAppService(
- IMongoDB<mes_technique> mes_technique,
- IMongoDB<ic_item> ic_item,
- IRepository<ic_item, long> mysql_ic_item,
- IRepository<ic_bom, long> mysql_ic_bom,
- IRepository<ic_bom_child, long> mysql_ic_bom_child,
- IMongoDB<ic_bom> ic_bom,
- IMongoDB<ic_bom_child> ic_bom_child,
- IMongoDB<mes_morder> mes_morder
- )
- {
- _mes_technique = mes_technique;
- _ic_item = ic_item;
- _mysql_ic_item = mysql_ic_item;
- _ic_bom = ic_bom;
- _mysql_ic_bom = mysql_ic_bom;
- _ic_bom_child = ic_bom_child;
- _mysql_ic_bom_child = mysql_ic_bom_child;
- _mes_morder = mes_morder;
- }
- /// <summary>
- /// 资源检查
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
- {
- ////多条插入
- //List<mes_technique> infos = new List<mes_technique>();
- //mes_technique info;
- //for (int i = 0; i < 3; i++)
- //{
- // info = new mes_technique();
- // info.GenerateNewId();
- // info.tech_name = "多条"+i;
- // info.level = i;
- // infos.Add(info);
- //}
- //await _mes_technique.InsertMany(infos);
- ////获取数据
- //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
- ////更新数据
- //info1.tech_name = "更新777";
- //await _mes_technique.UpdateOne(info1, info1.Id);
- throw new NotImplementedException();
- }
- /// <summary>
- /// 产能计算
- /// </summary>
- /// <param name="BomId">Bom主键</param>
- /// <param name="Quantity">需要数量</param>
- public async Task ProductiveExamine(long? BomId, int Quantity)
- {
- }
- /// <summary>
- /// 检查在制工单
- /// </summary>
- /// <param name="bomNumber">Bom编码</param>
- /// <param name="Quantity">需要数量</param>
- /// <returns></returns>
- public async Task CheckMorder(string bomNumber, int Quantity)
- {
- if (string.IsNullOrEmpty(bomNumber) || Quantity < 0)
- {
- //TODO:入参异常;
- //throw new NotImplementedException();
- }
- //var morderList = _mes_morder.(a => a.Id == ObjectId.Parse(id)).ToList().FirstOrDefault();
- //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据
- // 订单状态为 初始或下达工单
- // List =>数量满足Quantity && 生成工单结束日期最早
- }
- public void BomPretreatment(long? orderid, long? BomId, int Quantity)
- {
- if (orderid == null)
- {
- //throw new bu
- }
- if (BomId == null)
- {
- //throw new bu
- }
- //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
- var help = new SnowFlake();
- var bomlist = _ic_bom.GetAll();
- var bomchildlist = _ic_bom_child.GetAll();
- var icitemlist = _ic_item.GetAll();
- List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
- var dto = new BomChildExamineDto();
- dto.bom_id = BomId.Value;
- dto.level = 1;
- dto.id = help.NextId();
- dto.parent_id = help.NextId();
- dto.qty = 1;
- dto.num = "1";
- dto.isbom = 1;
- GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist);
- }
- public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, BomChildExamineDto dto, List<BomChildExamineDto> returnlist)
- {
- int level = dto.level++;//初始化定义level层级
- var help = new SnowFlake();
- var bom = bomlist.WhereIf(true, s => s.Id == dto.bom_id).FirstOrDefault();
- var item = icitemlist.WhereIf(true, a => a.Id == bom.icitem_id).FirstOrDefault();
- if (bom == null || item==null)
- {
- }
- //var dto = new BomChildExamineDto();
- //dto.level = level;
- //dto.bom_id = bomId;
- //dto.id = help.NextId();
- //dto.parent_id = parent_id;
- dto.item_id = bom.icitem_id;
- dto.item_name = bom.item_name;
- dto.item_code = bom.item_number;
- dto.model = item.model;
- dto.unit = bom.unit;
- dto.erp_cls = item.erp_cls;
- dto.erp_cls_name = item.erp_cls_name;
- //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
- returnlist.Add(dto);
- var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.Id).ToList();
- int idx = 1;
- foreach (var c in childlist)
- {
- string childNum = dto.num + "." + idx.ToString();
- var icitem = icitemlist.WhereIf(true, a => a.Id == c.icitem_id).FirstOrDefault();
- //如果此明细查的到BOM信息,则代表此child是一个子BOM。
- if (c.is_bom == 1)
- {
- var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
- if (childBom != null)
- {
- var cdto = new BomChildExamineDto();
- cdto.id = help.NextId();
- cdto.level = level;
- cdto.parent_id = dto.id;
- cdto.qty = c.qty.Value;
- cdto.backflush = c.backflush;
- cdto.num = childNum;
- cdto.isbom = 1;
- GetBomList(bomlist, bomchildlist, icitemlist, cdto, returnlist);
- }
- }
- else
- {
- if (icitem != null)
- {
- var childDto = new BomChildExamineDto();
- childDto.level = level++;
- childDto.bom_id = dto.bom_id;
- childDto.id = help.NextId();
- childDto.parent_id = dto.id;
- childDto.item_id = icitem.Id;
- childDto.item_name = icitem.name;
- childDto.item_code = icitem.number;
- childDto.num = childNum;
- childDto.model = icitem.model;
- childDto.unit = c.unit;
- childDto.erp_cls = item.erp_cls;
- childDto.erp_cls_name = item.erp_cls_name;
- childDto.backflush = c.backflush;
- childDto.qty = c.qty.Value;
- childDto.isbom = 0;
- returnlist.Add(childDto);
- }
- }
- idx++;
- }
- }
- }
- }
|