Bläddra i källkod

新增客户资料列表与客户公司增删改查

wangh 1 år sedan
förälder
incheckning
d5ffe79c13

+ 63 - 0
OASystem/OASystem.Api/Controllers/CRMController.cs

@@ -1,5 +1,7 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using OASystem.Domain.Dtos.CRM;
+using OASystem.Domain.Entities.Customer;
 using OASystem.Infrastructure.Repositories.CRM;
 
 namespace OASystem.API.Controllers
@@ -44,6 +46,67 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(clientCompanyData.Data, clientCompanyData.Data.Count));
         }
 
+        /// <summary>
+        /// 签证客户公司列表操作(Status:1.新增,2.修改)
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> OperationClientCompany(OperationClientCompanyDto dto)
+        {
+            try
+            {
+                if (dto.CompanyName == "")
+                {
+                    return Ok(JsonView(false, "请检查客户单位名称是否填写!"));
+                }
+                if (dto.Address == "")
+                {
+                    return Ok(JsonView(false, "请检查客户单位地址是否填写!"));
+                }
+                if (dto.PostCodes == "")
+                {
+                    return Ok(JsonView(false, "请检查客户单位邮编是否填写!"));
+                }
+                Result clientCompanyData = await _clientCompanyRepository.OperationClientCompany(dto);
+              
+                if (clientCompanyData.Code != 0)
+                {
+                    return Ok(JsonView(false, clientCompanyData.Msg));
+                }
+                return Ok(JsonView(true, clientCompanyData.Msg));
+            }
+            catch (Exception)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+            
+        }
+        /// <summary>
+        /// 签证客户公司列表操作(删除)
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> DelClientCompany(ClientCompanyDto dto)
+        {
+            try
+            {
+                var res = await _clientCompanyRepository.SoftDeleteByIdAsync<Crm_CustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
+                if (!res)
+                {
+                    return Ok(JsonView(false, "删除失败"));
+                }
+                return Ok(JsonView(true, "删除成功!"));
+            }
+            catch (Exception ex)
+            {
+                return Ok(JsonView(false, "程序错误!"));
+                throw;
+            }
+        }
         /// <summary>
         /// 获取签证客户列表
         /// </summary>

+ 11 - 1
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -1,8 +1,10 @@
-using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.Dtos.CRM;
+using OASystem.Domain.Dtos.Groups;
 using OASystem.Domain.Dtos.Resource;
 using OASystem.Domain.Dtos.System;
 using OASystem.Domain.Dtos.UserDto;
 using OASystem.Domain.Entities;
+using OASystem.Domain.Entities.Customer;
 using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.Resource;
 using OASystem.Domain.Entities.System;
@@ -108,6 +110,14 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<Edit_ResItemInfoDto, Res_ItemDetailInfo>();
             #endregion
             #endregion
+
+            #region Crm
+
+            #region 客户公司资料板块
+            CreateMap<OperationClientCompanyDto, Crm_CustomerCompany>();
+            #endregion
+
+            #endregion
         }
     }
 }

+ 59 - 0
OASystem/OASystem.Domain/Dtos/CRM/ClientCompanyDto.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.CRM
+{
+    public class OperationClientCompanyDto
+    {
+
+        /// <summary>
+        /// 操作状态
+        /// 1 添加 
+        /// 2 修改 
+        /// </summary>
+        public int Status { get; set; }
+        /// <summary>
+        /// 编号
+        /// </summary>
+
+        public int Id { get; set; }
+        /// <summary>
+        /// 客户公司名称
+        /// </summary>
+        public string CompanyName { get; set; }
+        /// <summary>
+        /// 公司地址
+        /// </summary>
+        public string Address { get; set; }
+        /// <summary>
+        /// 邮政编码
+        /// </summary>
+        public string PostCodes { get; set; }
+        /// <summary>
+        /// 最后操作人
+        /// </summary>
+        public int LastedOpUserId { get; set; }
+        /// <summary>
+        /// 最后操作时间
+        /// </summary>
+        public DateTime LastedOpDt { get; set; }= DateTime.Now;
+        
+        /// <summary>
+        /// 创建者Id
+        /// </summary>
+        public int CreateUserId { get; set; }
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string Remark { get; set; }
+     
+    }
+    public class ClientCompanyDto
+    {
+        public int Id { get; set; }
+        public int DeleteUserId { get; set; }
+    }
+}

+ 6 - 2
OASystem/OASystem.Domain/ViewModels/CRM/VisaCustomerCompanyView.cs

@@ -11,7 +11,7 @@ namespace OASystem.Domain.ViewModels.CRM
     /// <summary>
     /// 
     /// </summary>
-    public class VisaCustomerCompanyView : Crm_VisaCustomerCompany
+    public class CustomerCompanyView : Crm_VisaCustomerCompany
     { }
 
 
@@ -19,7 +19,7 @@ namespace OASystem.Domain.ViewModels.CRM
     /// 签证客户公司
     /// 返回视图
     /// </summary>
-    public class VisaCustomerCompanyListView
+    public class CustomerCompanyListView
     {
         /// <summary>
         /// ID
@@ -50,5 +50,9 @@ namespace OASystem.Domain.ViewModels.CRM
         /// 创建时间
         /// </summary>
         public DateTime CreateTime { get; set; }
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string Remark { get; set; }
     }
 }

+ 70 - 7
OASystem/OASystem.Infrastructure/Repositories/CRM/VisaDeleClientCompanyRepository.cs

@@ -1,7 +1,10 @@
-using OASystem.Domain;
+using AutoMapper;
+using OASystem.Domain;
 using OASystem.Domain.Dtos;
+using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Dtos.UserDto;
 using OASystem.Domain.Entities.Customer;
+using OASystem.Domain.Entities.Resource;
 using OASystem.Domain.ViewModels.CRM;
 using System;
 using System.Collections.Generic;
@@ -15,10 +18,14 @@ namespace OASystem.Infrastructure.Repositories.CRM
     /// 签证客户公司
     /// 仓库
     /// </summary>
-    public class VisaDeleClientCompanyRepository : BaseRepository<Crm_VisaCustomerCompany, VisaCustomerCompanyView>
+    public class VisaDeleClientCompanyRepository : BaseRepository<Crm_CustomerCompany, CustomerCompanyView>
     {
-        public VisaDeleClientCompanyRepository(SqlSugarClient sqlSugar) :
-            base(sqlSugar){ }
+        private readonly IMapper _mapper;
+        public VisaDeleClientCompanyRepository(SqlSugarClient sqlSugar, IMapper mapper) :
+            base(sqlSugar)
+        {
+            _mapper= mapper;
+        }
 
         /// <summary>
         /// 签证客户公司 List
@@ -31,10 +38,10 @@ namespace OASystem.Infrastructure.Repositories.CRM
 
             if (dto.PortType == 1 || dto.PortType == 2)
             {
-                string sql = string.Format(@"Select ccc.Id,ccc.CompanyName,ccc.Address,ccc.PostCodes,su.CnName UserName,ccc.CreateTime 
-                                             From Crm_CustomerCompany ccc Inner Join Sys_Users su On ccc.CreateUserId = su.Id");
+                string sql = string.Format(@"Select ccc.Id,ccc.CompanyName,ccc.Address,ccc.PostCodes,su.CnName UserName,ccc.CreateTime,ccc.Remark
+                                             From Crm_CustomerCompany ccc Inner Join Sys_Users su On ccc.CreateUserId = su.Id where ccc.IsDel=0");
 
-                var _clientCompanyList = await _sqlSugar.SqlQueryable<VisaCustomerCompanyListView>(sql).ToListAsync();
+                var _clientCompanyList = await _sqlSugar.SqlQueryable<CustomerCompanyListView>(sql).ToListAsync();
                 if (_clientCompanyList.Count > 0)
                 {
                     result.Code = 0;
@@ -50,5 +57,61 @@ namespace OASystem.Infrastructure.Repositories.CRM
             return result;
         }
 
+        public async  Task<Result> OperationClientCompany(OperationClientCompanyDto dto)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                if (dto.Status == 1)//添加
+                {
+                    string selectSql = string.Format(@"select * from Crm_CustomerCompany WHERE CompanyName='{0}' and IsDel='{1}'"
+                                                       , dto.CompanyName, 0);
+                    var CustomerCompany = await _sqlSugar.SqlQueryable<Crm_CustomerCompany>(selectSql).FirstAsync();//查询是否存在
+                    if (CustomerCompany != null)
+                    {
+                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+
+                    }
+                    else//不存在,可添加
+                    {
+                        Crm_CustomerCompany _CustomerCompany = _mapper.Map<Crm_CustomerCompany>(dto);
+                        int id = await AddAsyncReturnId(_CustomerCompany);
+                        if (id == 0)
+                        {
+                            return result = new Result() { Code = -1, Msg = "添加失败!" };
+
+                        }
+                        result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
+                    }
+                }
+                else if (dto.Status == 2)//修改
+                {
+                    bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_CustomerCompany
+                    {
+                        CompanyName=dto.CompanyName,
+                        Address = dto.Address,
+                        PostCodes = dto.PostCodes,
+                        LastedOpUserId = dto.LastedOpUserId,
+                        LastedOpDt = dto.LastedOpDt,
+                        Remark = dto.Remark,
+                     
+                    });
+                    if (!res)
+                    {
+                        return result = new Result() { Code = -1, Msg = "修改失败!" };
+                    }
+                    result = new Result() { Code = 0, Msg = "修改成功!" };
+                }
+                else
+                {
+                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
+                }
+            }
+            catch (Exception ex)
+            {
+                return result = new Result() { Code = -2, Msg = "程序错误!" };
+            }
+            return result;
+        }
     }
 }