yanjinhui
2025-03-07 aeb32ca2cc420266734c782df01b27be617e6943
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_ISerialPortRepository;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class Putake : ServiceBase<Dt_Putake, IPutakeRepository>, IPutakeServer
    {
        private IUnitOfWorkManage _uniUnitOfWorkManage;
        private INjTaskRepository _iNjTaskRepository;
 
        public Putake(IPutakeRepository BaseDal, IUnitOfWorkManage uniUnitOfWorkManage, INjTaskRepository iNjTaskRepository) : base(BaseDal)
        {
            _uniUnitOfWorkManage = uniUnitOfWorkManage;//数据库事务
            _iNjTaskRepository= iNjTaskRepository;
        }
 
        private enum cond
        {
            待领筒=1,
            待作业=2,
            待归筒=3,
            待质检=4,
            已完成=5
        }
 
 
        //修改下发任务表的任务状态
        public WebResponseContent ChangeStatus(int id)
        {
            try
            {
                var putake = BaseDal.QueryData(i => i.ID == id).FirstOrDefault();
                if (putake == null)
                {
                    return new WebResponseContent { Status = false, Message = "未找到该任务" };
                }
 
                //putake.Pustatus是字符串,需要先转换成 cond 枚举:
                if (!Enum.TryParse(putake.Pustatus, out cond currentStatus))
                {
                    return new WebResponseContent { Status = false, Message = "当前状态不合法,无法更新" };
                }
 
                switch (currentStatus)
                {
                    case cond.待领筒:
                        putake.Pustatus = cond.待作业.ToString();
                        //_iNjTaskRepository
                        break;
                    case cond.待作业:
                        putake.Pustatus = cond.待归筒.ToString();
                        break;
                    case cond.待归筒:
                        putake.Pustatus = cond.待质检.ToString();
                        break;
                    case cond.待质检:
                        putake.Pustatus=cond.已完成.ToString();
                        putake.Finishedtime = DateTime.Now;
                        break;
                    case cond.已完成:
                        return new WebResponseContent { Status = false, Message = "当前状态已是最终状态,无法再更新" };
                    default:
                        return new WebResponseContent { Status = false, Message = "未知状态,无法更新" };
                }
                //开启事务
                _uniUnitOfWorkManage.BeginTran();
 
                // 更新数据库
                BaseDal.UpdateData(putake);
 
                //提交事务
                _uniUnitOfWorkManage.CommitTran();
                return new WebResponseContent { Status = true,Data= putake };
            }
            catch (Exception ex)
            {
                //回滚事务
                _uniUnitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = "更新失败:" + ex.Message };
            }
        }
 
        //根据条件(组)展示下发任务表
        public WebResponseContent ShowPutake(string group)
        {
            try
            {
                //开启事务
                _uniUnitOfWorkManage.BeginTran();
 
                var dg = BaseDal.QueryData(i=>i.Grouptype== group);
 
                //提交事务
                _uniUnitOfWorkManage.CommitTran();
                return new WebResponseContent { Status = true, Data = dg };
            }
            catch (Exception ex)
            {
                // 回滚事务
                _uniUnitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = $"查看失败:{ex}" };
            }
        }
 
 
        //查看这个下发任务的中任务表中的详情数据
        public WebResponseContent GetNjtake(string njid)
        {
            try
            {
                //开启事务
                _uniUnitOfWorkManage.BeginTran();
 
                var Nj = _iNjTaskRepository.QueryData(i => i.NJtaskID == njid).FirstOrDefault();
 
                if (Nj != null)
                {
                    //提交事务
                    _uniUnitOfWorkManage.CommitTran();
                    return new WebResponseContent { Status = true, Data = Nj };
                }
                else {
                    return new WebResponseContent { Status = false,Message="没有找到" };
                }
 
 
                
            }
            catch (Exception ex)
            {
 
                //回滚事务
                _uniUnitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = "更新失败:" + ex.Message };
            }
        }
    }
}