wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
using Model.ModelDto.SysDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IDAL.ISysInterface;
using Dm;
 
namespace WMS.DAL.SysInfrastructure
{
    /// <summary>
    /// 部门仓储实践
    /// </summary>
    public class DepartmentRepository : BaseRepository<SysDepartment>, IDepartmentRepository
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public DepartmentRepository() : base(Db)
        {
        }
 
 
        /// <summary>
        /// 获取部门信息列表
        /// </summary>
        /// <param name="DepartmentName">部门名称</param>
        /// <param name="DepartmentNo">部门号</param>
        /// <returns></returns>
        public List<DepartmentDto> GetDepartmentList(string DepartmentName, string DepartmentNo)
        {
            string str = "select dep.*,user1.RealName CreateUserName from SysDepartment dep left join SysUserInfor user1 on dep.CreateUser = user1.id where dep.IsDel = @isdel";
            //判断部门名称是否为空
            if (!string.IsNullOrEmpty(DepartmentName))
            {
                str += " and dep.DepartmentName like @departmentname";
            }
            //判断部门号是否为空
            if (!string.IsNullOrEmpty(DepartmentNo))
            {
                str += " and dep.DepartmentNo like @departmentno";
            }
            List<DepartmentDto> departmentlist = Db.Ado.SqlQuery<DepartmentDto>(str, new
            {
                isdel = "0", //是否删除
                departmentname = "%" + DepartmentName + "%", //部门名称
                departmentno = "%" + DepartmentNo + "%" //部门号
            });
            return departmentlist;
        }
 
        /// <summary>
        /// 根据id获取部门信息
        /// </summary>
        /// <param name="id">部门id</param>
        /// <returns></returns>
        public SysDepartment GetDepartmentById(int id)
        {
            string str = "select * from SysDepartment where IsDel = '0' and Id = @id";
            var departmentlist = Db.Ado.SqlQuerySingle<SysDepartment>(str, new
            {
                id //id
            });
            return departmentlist;
        }
 
        /// <summary>
        /// 根据部门号获取部门信息
        /// </summary>
        /// <param name="DepartmentNo">部门号</param>
        /// <returns></returns>
        public List<SysDepartment> GetDepartmentByNo(string DepartmentNo)
        {
            string str = "select * from SysDepartment where DepartmentNo = @departmentno";
            List<SysDepartment> departmentlist = Db.Ado.SqlQuery<SysDepartment>(str, new
            {
                departmentno = DepartmentNo //部门号
            });
            return departmentlist;
        }
 
        /// <summary>
        /// 新增部门信息
        /// </summary>
        /// <param name="department">部门实体模型</param>
        /// <returns></returns>
        public async Task<int> AddDepartment(SysDepartment department)
        {
            string str = "insert into SysDepartment values(@departmentno, @departmentname, @demo, @isdel, @createtime, @createuser, null, null)";
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                departmentno = department.DepartmentNo, //部门号
                departmentname = department.DepartmentName, //部门名称
                demo = department.Demo, //备注
                isdel = "0", //是否删除
                createtime = Db.GetDate(), //创建时间
                createuser = department.CreateUser //创建人
            });
            return i;
        }
 
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="department">部门实体模型</param>
        /// <returns></returns>
        public async Task<int> DelDepartment(SysDepartment department)
        {
            string str = "update SysDepartment set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where id = @id";
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                isdel = "1", //是否删除
                updatetime = Db.GetDate(), //更改时间
                updateuser = department.UpdateUser, //更改人
                id = department.Id //id
            });
            return i;
        }
 
        /// <summary>
        /// 编辑部门信息
        /// </summary>
        /// <param name="department">部门实体模型</param>
        /// <returns></returns>
        public async Task<int> ExitDepartment(SysDepartment department)
        {
 
            string str = "update SysDepartment set DepartmentNo = @departmentno, DepartmentName = @departmentname,Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser where id = @id";
            int i = await Db.Ado.ExecuteCommandAsync(str, new
            {
                departmentno = department.DepartmentNo, //部门号
                departmentname = department.DepartmentName, //部门名称
                demo = department.Demo, //备注
                updatetime = Db.GetDate(), //更改时间
                updateuser = department.UpdateUser, //更改人
                id = department.Id //id
            });
            return i;
        }
    }
}