|
- using BPA.SAAS.Manage.Application.Device.Dtos.DeviceTechnology;
- using BPA.SAAS.Manage.Application.Device.Interface;
- using BPA.SAAS.Manage.Comm.Const;
- using BPA.SAAS.Manage.Comm.Enum;
- using BPA.SAAS.Manage.Core.Base;
- using BPA.SAAS.Manage.Core.Device;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
-
- namespace BPA.SAAS.Manage.Application.Device.Services
- {
- public class DeviceTechnologyService: IDeviceTechnologyService, ITransient
- {
- ISqlSugarClient _db;
- public DeviceTechnologyService(ISqlSugarClient db)
- {
- _db = db;
- }
- #region 工艺基础信息
- /// <summary>
- /// 获取工艺基础信息列表
- /// </summary>
- /// <param name="inputDto"></param>
- /// <returns></returns>
- public async Task<PageUtil> GetDeviceTechnologyPage(DeviceTechnologyPageBase inputDto)
- {
- RefAsync<int> total = 0;
- var res = await _db.Queryable<BPA_DeviceTechnology, BPA_DeviceVesion>((x, b) => new JoinQueryInfos(JoinType.Left, b.Id == x.DeviceVersionKey))
-
- .OrderBy((x, b) => x.CreateAt, OrderByType.Desc)
- .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Name), (x, b) => x.Name.Contains(inputDto.Name))
- .WhereIF(inputDto.Status != null, (x, b) => x.Status == inputDto.Status)
- .Select((x, b) => new
- {
- Name = x.Name,
- Status = x.Status,
- x.Id,
- x.GroupId,
- x.ForeignKeyRe,
- x.DeviceVersionKey,
- DeviceTypeKey = b.DeviceTypeKey,
- Vesion = b.Vesion
-
- })
- .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
- return new PageUtil()
- {
- Data = res,
- Total = total
- };
- }
- /// <summary>
- /// 查询所有工艺信息
- /// </summary>
- /// <returns></returns>
- public async Task<List<DeviceTechnologyDto>> GetDeviceTechnology()
- {
- var res =await _db.Queryable<BPA_DeviceTechnology>().Where(x => x.Status == 0)
- .OrderBy(i => i.CreateAt, OrderByType.Desc)
- .Select(x => new DeviceTechnologyDto()
- {
- Id = x.Id,
- Name = x.Name,
- IsBatch = SqlFunc.Subqueryable<BPA_DeviceTechnologyAction>().Where(p => p.DevicetechnologyId == x.Id).Any()
- })
- .ToListAsync();
- return res;
- }
- /// <summary>
- /// 添加工艺
- /// </summary>
- /// <param name="inputDto"></param>
- /// <returns></returns>
- public async Task<bool> AddDeviceTechnology(DeviceTechnologyBaseDto inputDto)
- {
-
- var data = _db.Queryable<BPA_DeviceTechnology>()
- .Where(a => a.Name == inputDto.Name).ToList();
- if (data.Count > 0)
- {
- throw Oops.Oh("工艺名称已存在");
- }
- else
- {
- var res =await _db.Insertable(new BPA_DeviceTechnology()
- {
- Id = Guid.NewGuid().ToString(),
- Name = inputDto.Name,
- Status = CommonStatus.ENABLE,
- CreateAt = DateTime.Now,
- IsDeleted = 0,
- ForeignKeyRe = inputDto.ForeignKeyRe,
- DeviceVersionKey = inputDto.DeviceVersionKey
- }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
- return res > 0;
- }
- }
- /// <summary>
- /// 修改工艺
- /// </summary>
- /// <param name="inputDto"></param>
- /// <returns></returns>
- public async Task<bool> UpdateDeviceTechnology(DeviceTechnologyBaseDto inputDto)
- {
- var check = _db.Queryable<BPA_DeviceTechnology>().Any(a => a.Id != inputDto.Id && a.Name == inputDto.Name);
- if (check) throw Oops.Oh("工艺名称已存在");
- var data = _db.Queryable<BPA_DeviceTechnology>().Where(a => a.Id == inputDto.Id).First();
- data.Name = inputDto.Name;
- data.DeviceVersionKey = inputDto.DeviceVersionKey;
- data.ForeignKeyRe = inputDto.ForeignKeyRe;
- var res =await _db.Updateable(data).ExecuteCommandAsync();
- return res > 0;
- }
- /// <summary>
- /// 删除配方工艺
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public async Task<bool> DeleteDeviceTechnology(List<string> ids)
- {
- var resEntity = _db.Queryable<BPA_DeviceTechnology>().Where(x => ids.Contains(x.Id)).ToList();
- foreach (var item in resEntity)
- {
- item.IsDeleted = 1;
- }
- var res =await _db.Updateable(resEntity).ExecuteCommandAsync();
- return res > 0;
- }
- #endregion
- #region 工艺模型
- /// <summary>
- /// 根据工艺id查询工艺模型
- /// </summary>
- /// <returns></returns>
- public async Task<List<BPA_DeviceTechnologyAction>> GetTechnologyActionList(string devicetechnologyId)
- {
-
- var res = await _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => x.IsDeleted == 0 && x.DevicetechnologyId == devicetechnologyId )
- .OrderBy(i => i.Sort, OrderByType.Asc)
- .ToListAsync();
- return res;
- }
- /// <summary>
- /// 查询所有工艺模型
- /// </summary>
- /// <returns></returns>
- public async Task<List<BPA_DeviceTechnologyAction>> GetTechnologyActionList()
- {
-
- var res = await _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => x.IsDeleted == 0)
- .OrderBy(i => i.Sort, OrderByType.Asc)
- .ToListAsync();
- return res;
- }
- /// <summary>
- /// 添加工艺模型
- /// </summary>
- /// <param name="inputDto"></param>
- /// <returns></returns>
- public async Task<bool> AddDeviceTechnologyAction(DeviceTechnologyActionBaseDto inputDto)
- {
- var check = _db.Queryable<BPA_DeviceTechnologyAction>()
- .Any(a => a.DevicetechnologyId == inputDto.DevicetechnologyId && a.IsDeleted == 0 && a.ActionName == inputDto.ActionName && a.ActionType == inputDto.ActionType);
- if (check)
- {
- throw Oops.Oh("工艺流程动作已存在");
- }
- else
- {
- var res = await _db.Insertable(new BPA_DeviceTechnologyAction()
- {
- DevicetechnologyId = inputDto.DevicetechnologyId,
- ActionName = inputDto.ActionName,
- ActionType = inputDto.ActionType,
- ActionValue = inputDto.ActionValue,
- Unit = inputDto.Unit,
- IsBatch = true,//inputDto.IsBatch,
- IsDeleted = 0,
- Sort = inputDto.Sort,
- }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); ;
- return res > 0;
- }
- }
- /// <summary>
- /// 修改工艺模型
- /// </summary>
- /// <param name="inputDto"></param>
- /// <returns></returns>
- public async Task<bool> UpdateBomTechnology(DeviceTechnologyActionBaseDto inputDto)
- {
- var check = _db.Queryable<BPA_DeviceTechnologyAction>().Any(a => a.DevicetechnologyId == inputDto.DevicetechnologyId && a.ActionName == inputDto.ActionName && a.ActionType == inputDto.ActionType && a.Id != inputDto.Id);
- if (check) throw Oops.Oh("工艺流程动作已存在");
- var data = _db.Queryable<BPA_DeviceTechnologyAction>().Where(a => a.Id == inputDto.Id).First();
- if (data == null) throw Oops.Oh("工艺流程动作不存在");
- data.ActionName = inputDto.ActionName;
- data.ActionType = inputDto.ActionType;
- data.ActionValue = inputDto.ActionValue;
- data.Unit = inputDto.Unit;
- data.IsBatch = inputDto.IsBatch;
- data.Sort = inputDto.Sort;
- var res = await _db.Updateable(data).ExecuteCommandAsync();
- return res > 0;
- }
- /// <summary>
- /// 删除工艺模型
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public async Task<bool> DeleteTechnologyAction(List<string> ids)
- {
- var resEntity = _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => ids.Contains(x.Id)).ToList();
- foreach (var item in resEntity)
- {
- item.IsDeleted = 1;
- }
- var res = await _db.Updateable(resEntity).ExecuteCommandAsync();
- return res > 0;
- }
- #endregion
- }
- }
|