| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | 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;using System.Linq;using System.Text;using System.Threading.Tasks;namespace OASystem.Infrastructure.Repositories.CRM{    /// <summary>    /// 签证客户公司    /// 仓库    /// </summary>    public class VisaDeleClientCompanyRepository : BaseRepository<Crm_CustomerCompany, CustomerCompanyView>    {        private readonly IMapper _mapper;        public VisaDeleClientCompanyRepository(SqlSugarClient sqlSugar, IMapper mapper) :            base(sqlSugar)        {            _mapper= mapper;        }        /// <summary>        /// 签证客户公司 List        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> GetCrm_ClientCompanyList(DtoBase dto)        {            Result result = new Result() { Code = -2 };            try            {                if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)                {                    string sql = string.Format(@"Select ccc.Id,ccc.CompanyFullName,ccc.CompanyAbbreviation,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 order by CreateTime Desc");                    var _clientCompanyList = await _sqlSugar.SqlQueryable<CustomerCompanyListView>(sql).ToListAsync();                    if (_clientCompanyList.Count > 0)                    {                        result.Code = 0;                        result.Msg = "成功!";                        result.Data = _clientCompanyList;                    }                    else                    {                        result.Msg = "查询失败!";                    }                }            }            catch (Exception ex)            {                 result.Msg = ex.Message;            }            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                    {                        CompanyFullName = 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;        }    }}
 |