| | |
| | | using WIDESEA_IBasicService; |
| | | using SqlSugar; |
| | | using WIDESEA_Core.Attributes; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.CodeConfigEnum; |
| | | using WIDESEA_Core.DB; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.Seed; |
| | | using WIDESEA_DTO.Base; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | |
| | | namespace WIDESEA_BasicService |
| | | { |
| | | public class BasicService : IBasicService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public IPalletCodeInfoService PalletCodeInfoService { get; } |
| | | |
| | | public ILocationInfoService LocationInfoService { get; } |
| | |
| | | |
| | | public IMaterielCodeInfoService MaterielCodeInfoService { get; } |
| | | |
| | | public BasicService(ILocationInfoService locationInfoService, IMaterielInfoService materielInfoService, IWarehouseService warehouseService, IPalletCodeInfoService palletCodeInfoService, IMaterielCodeInfoService materielCodeInfoService) |
| | | public IMaterialUnitService MaterialUnitService { get; } |
| | | |
| | | public BasicService(IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService, IMaterielInfoService materielInfoService, IWarehouseService warehouseService, IPalletCodeInfoService palletCodeInfoService, IMaterielCodeInfoService materielCodeInfoService, IMaterialUnitService materialUnitService) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | LocationInfoService = locationInfoService; |
| | | MaterielInfoService = materielInfoService; |
| | | WarehouseService = warehouseService; |
| | | PalletCodeInfoService = palletCodeInfoService; |
| | | MaterielCodeInfoService = materielCodeInfoService; |
| | | MaterialUnitService = materialUnitService; |
| | | } |
| | | |
| | | #region |
| | | |
| | | static object lockObj = new object(); |
| | | public string CreateCodeByRule(string ruleCode) |
| | | { |
| | | lock (lockObj) |
| | | { |
| | | string code = string.Empty; |
| | | DateTime dataTime = DateTime.Now; |
| | | DateTime now = DateTime.Now; |
| | | |
| | | try |
| | | { |
| | | Dt_CodeRuleConfig ruleConfig = _unitOfWorkManage.Db.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First(); |
| | | if (ruleConfig.ModifyDate != null) |
| | | { |
| | | dataTime = ruleConfig.ModifyDate.Value; |
| | | } |
| | | else |
| | | { |
| | | dataTime = ruleConfig.CreateDate; |
| | | } |
| | | |
| | | if (now.Year == dataTime.Year && now.Month == dataTime.Month && now.Day == dataTime.Day) |
| | | { |
| | | now = dataTime; |
| | | ruleConfig.CurrentVal = Convert.ToInt32(ruleConfig.CurrentVal) + 1; |
| | | } |
| | | else |
| | | { |
| | | ruleConfig.CurrentVal = 1; |
| | | } |
| | | |
| | | ruleConfig.ModifyDate = DateTime.Now; |
| | | |
| | | code = ruleConfig.Format; |
| | | code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0')); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.ST}]", ruleConfig.StartStr.ToString()); |
| | | code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", ruleConfig.CurrentVal.ToString().PadLeft(ruleConfig.Length, '0')); |
| | | |
| | | _unitOfWorkManage.Db.Updateable(ruleConfig).ExecuteCommand(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | return code; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region åä½è½¬æ¢ |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="fromUnit"></param> |
| | | /// <param name="toUnit"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitQuantityConvert(string materialCode, string fromUnit, string toUnit, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(fromUnit)) |
| | | { |
| | | throw new Exception($"转æ¢ååä½ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(toUnit)) |
| | | { |
| | | throw new Exception($"转æ¢ååä½ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | decimal ratio = 1; |
| | | |
| | | if (fromUnit.Trim().ToLower() == toUnit.Trim().ToLower()) |
| | | { |
| | | return new UnitConvertResultDTO(materialCode, fromUnit, toUnit, quantity, ratio); |
| | | } |
| | | |
| | | Dt_MaterialUnit materialUnit = MaterialUnitService.Repository.QueryFirst(x => x.ItemNo == materialCode && x.FromUom == fromUnit && x.ToUom == toUnit); |
| | | if (materialUnit != null) |
| | | { |
| | | ratio = materialUnit.Ratio; |
| | | return new UnitConvertResultDTO(materialCode, fromUnit, toUnit, quantity, ratio); |
| | | } |
| | | else |
| | | { |
| | | materialUnit = MaterialUnitService.Repository.QueryFirst(x => x.ItemNo == materialCode && x.FromUom == toUnit && x.ToUom == fromUnit); |
| | | if (materialUnit == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°åä½è½¬æ¢å
³ç³»ï¼ç©æç¼å·ï¼{materialCode}ï¼è½¬æ¢ååä½ï¼{fromUnit}ï¼è½¬æ¢ååä½ï¼{toUnit}"); |
| | | } |
| | | ratio = materialUnit.Ratio; |
| | | return new UnitConvertResultDTO(materialCode, fromUnit, toUnit, quantity, ratio); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼é¢æè½¬éè´ |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitUsageToPurchase(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.usageUOM, materielInfo.purchaseUOM, quantity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼é¢æè½¬åºå |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitUsageToInventory(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.usageUOM, materielInfo.inventoryUOM, quantity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼éè´è½¬åºå |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitPurchaseToInventory(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.purchaseUOM, materielInfo.inventoryUOM, quantity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼éè´è½¬é¢æ |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitPurchaseToUsage(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.purchaseUOM, materielInfo.usageUOM, quantity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼åºåè½¬é¢æ |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitInventoryToUsage(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.inventoryUOM, materielInfo.usageUOM, quantity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åä½è½¬æ¢ï¼åºå转éè´ |
| | | /// </summary> |
| | | /// <param name="materialCode"></param> |
| | | /// <param name="quantity"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public UnitConvertResultDTO UnitInventoryToPurchase(string materialCode, decimal quantity) |
| | | { |
| | | if (string.IsNullOrEmpty(materialCode)) |
| | | { |
| | | throw new Exception($"ç©æç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_MaterielInfo materielInfo = MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == materialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æä¿¡æ¯{materialCode}"); |
| | | } |
| | | |
| | | return UnitQuantityConvert(materialCode, materielInfo.inventoryUOM, materielInfo.purchaseUOM, quantity); |
| | | } |
| | | #endregion |
| | | } |
| | | } |