zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
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
using HH.WMS.BLL;
using HH.WMS.Common;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Common;
using HH.WMS.WebApi.Areas.Common.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
 
namespace HH.WMS.WebApi.Areas.Basic
{
    public class OwnerController : BaseController
    {
        #region 新增修改
        /// <summary>
        /// 新增修改
        /// </summary>
        /// <param name="postEntity"></param>
        /// <returns></returns>
        [HttpPost]
        public OperateResult Edit(PostEntity postEntity)
        {
            return ValidateToken(postEntity.TokenId, t =>
            {
                var ownerEntity = postEntity.GetPostData<TN_WM_B_OWNEREntity>();
                if (ownerEntity == null)
                    return OperateResult.Error("参数不正确");
                if (string.IsNullOrEmpty(ownerEntity.CN_GUID))
                {
                    ownerEntity.CN_GUID = Guid.NewGuid().ToString();
                    ownerEntity.CN_S_CREATOR = t.CN_S_LOGIN;
                    ownerEntity.CN_S_CREATOR_BY = t.CN_S_NAME;
                    ownerEntity.CN_T_CREATE = DateTime.Now;
                    ownerEntity.CN_S_MODIFY = t.CN_S_LOGIN;
                    ownerEntity.CN_S_MODIFY_BY = t.CN_S_NAME;
                    ownerEntity.CN_T_MODIFY = DateTime.Now;
                    return BLLCreator.CreateDapper<TN_WM_B_OWNEREntity>().Add(ownerEntity);
                }
                else
                {
                    ownerEntity.CN_S_MODIFY = t.CN_S_LOGIN;
                    ownerEntity.CN_S_MODIFY_BY = t.CN_S_NAME;
                    ownerEntity.CN_T_MODIFY = DateTime.Now;
                    return BLLCreator.CreateDapper<TN_WM_B_OWNEREntity>().Update(new
                    {
                        ownerEntity.CN_S_OWNER,
                        ownerEntity.CN_B_DEFAULT,
                        ownerEntity.CN_S_REMARK,
                        ownerEntity.CN_S_MODIFY,
                        ownerEntity.CN_S_MODIFY_BY,
                        ownerEntity.CN_T_MODIFY 
                    }, new
                    {
                        ownerEntity.CN_GUID
                    });
                }
            });
        }
        #endregion
 
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [HttpGet]
        public OperateResult Delete(string guid)
        {
            return ValidateToken(t =>
            {
                return BLLCreator.CreateDapper<TN_WM_B_OWNEREntity>().Delete(new
                {
                    CN_GUID = guid
                });
            });
        }
        #endregion
 
        #region 根据id获取一条
        /// <summary>
        /// 根据id获取一条
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetById(string guid)
        {
            return ValidateToken(t =>
            {
                var entity = BLLCreator.CreateDapper<TN_WM_B_OWNEREntity>().GetSingleEntity(new
                {
                    CN_GUID = guid
                });
                if (entity == null)
                    return OperateResult.Error("未找到该条记录");
                return OperateResult.Succeed(null, entity);
            });
        }
        #endregion
 
        #region 查询
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        [HttpPost]
        public OperateResult OwnerList(SearchModel searchModel)
        {
            return ValidateToken(searchModel.TokenId, t =>
            {
                return BLLCreator.CreateDapper<TN_WM_B_OWNEREntity>().GetPagingResult(searchModel.PageIndex, searchModel.PageSize, new
                  {
                      CN_S_OWNER = Util.ToString(searchModel.SearchCondition.owner)
                  });
            });
        }
        #endregion
    }
}