刘磊
2025-08-25 4c308eab6106324bd40e6ad7fd9e769a5cedcedf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_IBusinessesRepository;
using WIDESEA_IBusinessServices;
using WIDESEA_Model.Models;
using WIDESEA_Repository;
 
namespace WIDESEA_BusinessServices
{
    public class Dt_PalletInfoService : ServiceBase<Dt_PalletInfo, IDt_PalletInfoRepository>, IDt_PalletInfoService
    {
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IDt_AreaInfoRepository _areaInfoRepository;
        public Dt_PalletInfoService(IDt_PalletInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDt_AreaInfoRepository areaInfoRepository) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _areaInfoRepository = areaInfoRepository;
        }
 
        public override WebResponseContent AddData(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //string palletCode = saveModel.MainData["palletCode"].ToString();
                string areaCode = saveModel.MainData["areaCode"].ToString();
 
                var areaInfo = _areaInfoRepository.QueryFirst(x => x.AreaCode == areaCode);
                if (areaInfo == null) throw new Exception("未知区域");
 
                var barcodeInfo = BaseDal.QueryData(x => x.AreaCode == areaCode).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                int serial = 1;
                if (barcodeInfo != null)
                {
                    serial = barcodeInfo.SerialNo + 1;
                }
 
                Dt_PalletInfo palletInfo = new Dt_PalletInfo
                {
                    AreaCode = areaCode,
                    CreateDate = DateTime.Now,
                    Creater = App.User.UserName,
                    PalletCode = areaInfo.AreaType + serial.ToString().PadLeft(6, '0'),
                    PalletType = 1,
                    PrintStatus = 0,
                    SerialNo = serial
                };
 
                if (BaseDal.AddData(palletInfo) > 0)
                {
                    return content.OK($"添加条码信息成功");
                }
                else
                {
                    throw new Exception("添加条码信息异常");
                }
            }
            catch (Exception ex)
            {
                return content.Error($"添加托盘信息异常{ex.Message}");
            }
        }
 
 
 
        public WebResponseContent PrintStatusUp(string printCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var palletInfo = BaseDal.QueryFirst(x => x.PalletCode == printCode);
                if (palletInfo == null) throw new Exception("打印条码信息不存在");
 
                palletInfo.PrintStatus = 1;
                BaseDal.UpdateData(palletInfo);
                return content.OK("打印条码成功");
            }
            catch (Exception ex)
            {
                return content.Error($"打印条码异常{ex.Message}");
            }
        }
    }
}