123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using OASystem.Domain.Entities.Resource;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using AutoMapper;
- using OASystem.Domain.Dtos.Resource;
- using EyeSoft.Extensions;
- using OASystem.Domain;
- using OASystem.Domain.ViewModels.Resource;
- using OASystem.Domain.AesEncryption;
- namespace OASystem.Infrastructure.Repositories.Resource
- {
- /// <summary>
- /// 策划部供应商资料
- /// 仓储
- /// </summary>
- public class MediaSuppliersRepository : BaseRepository<Res_MediaSuppliers, Res_MediaSuppliers>
- {
- private readonly IMapper _mapper;
- private readonly List<int> _portIds;
- public MediaSuppliersRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- _portIds = new List<int> { 1, 2, 3 };
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> Init()
- {
- var result = new JsonView() { Code = 400, Msg = "操作失败" };
- var typeData = await _sqlSugar.Queryable<Sys_SetData>()
- .Where(x => x.IsDel == 0 && x.STid == 21)
- .Select(x => new { x.Id, Text = x.Name })
- .ToListAsync();
- result.Code = 200;
- result.Data = typeData;
- return result;
- }
- /// <summary>
- /// 详情
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> Info(MediaSupplierInfoDto dto)
- {
- var result = new JsonView() { Code = 400, Msg = "操作失败" };
- if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
- if (dto.Id < 1) { result.Msg = MsgTips.Id; return result; }
- var info = await _sqlSugar.Queryable<Res_MediaSuppliers>()
- .Where(x => x.IsDel == 0 && x.Id == dto.Id)
- .Select(x => new MediaSupplierInfoView()
- {
- Id = x.Id,
- TypeId = x.TypeId,
- Privince = x.Privince,
- City = x.City,
- UnitName = x.UnitName,
- UnitAbbreviation = x.UnitAbbreviation,
- UnitAddress = x.UnitAddress,
- Contact = x.Contact,
- Sex = x.Sex,
- Post = x.Post,
- Fax = x.Fax,
- Tel = x.Tel,
- Email = x.Email,
- WeChat = x.WeChat,
- Remark = x.Remark
- })
- .FirstAsync();
- EncryptionProcessor.DecryptProperties(info);
- result.Code = 200;
- result.Data = info;
- result.Msg = MsgTips.Succeed;
- return result;
- }
- /// <summary>
- /// 分页查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> PageItem(MediaSupplierPageItemDto dto)
- {
- var result = new JsonView() { Code = 400, Msg = "操作失败" };
- if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
- var typeLabel = new List<int>();
- if (!string.IsNullOrEmpty(dto.TypeLabel))
- {
- typeLabel = dto.TypeLabel.Split(',')
- .Select(s =>
- {
- int value = 0;
- if (int.TryParse(s, out value)) return value;
- return value;
- })
- .Where(i => i != 0)
- .ToList();
- }
- var search = AesEncryptionHelper.Encrypt(dto.Search);
- RefAsync<int> total = 0;
- var infos = await _sqlSugar.Queryable<Res_MediaSuppliers>()
- .LeftJoin<Sys_Users>((ms, u) => ms.CreateUserId == u.Id)
- .Where((ms, u) => ms.IsDel == 0)
- .WhereIF(typeLabel.Count > 0 , (ms, u) => typeLabel.Contains(ms.TypeId))
- .WhereIF(!string.IsNullOrEmpty(search), (ms, u) => ms.UnitName.Contains(search) || ms.Contact.Contains(search) || ms.Tel.Contains(search))
- .OrderByDescending((ms, u) => ms.CreateTime)
- .Select((ms, u) => new PageItemView()
- {
- Id = ms.Id,
- Privince = ms.Privince,
- City = ms.City,
- UnitName = ms.UnitName,
- Contact = ms.Contact,
- Sex = ms.Sex,
- Post = ms.Post,
- Tel = ms.Tel,
- CreateUserName = u.CnName,
- CreateTime = ms.CreateTime
- })
- .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
- foreach (var info in infos) EncryptionProcessor.DecryptProperties(info);
- result.Msg = MsgTips.Succeed;
- result.Code = 200;
- result.Data = infos;
- result.Count = total;
- return result;
- }
- /// <summary>
- /// 操作(添加 Or 编辑)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> AddOrEdit(MediaSupplierAddOrEditDto dto)
- {
- var result = new JsonView() { Code = 400, Msg = "操作失败" };
- if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
- var userId = dto.CurrUserId;
- if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
- var info = _mapper.Map<Res_MediaSuppliers>(dto);
- info.CreateUserId = userId;
- EncryptionProcessor.DecryptProperties(info);
- if (info.Id < 1) //添加
- {
- var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
- if (add < 1) return result;
- }
- else //编辑
- {
- var upd = await _sqlSugar.Updateable(info).IgnoreColumns(x => new { x.CreateUserId, x.CreateTime }).ExecuteCommandAsync();
- if (upd < 1) return result;
- }
- result.Code = 200;
- result.Msg = $"操作成功!";
- return result;
- }
- /// <summary>
- /// 软删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> SoftDel(MediaSupplierSoftDelDto dto)
- {
- var result = new JsonView() { Code = 400, Msg = "操作失败" };
- int userId = dto.CurrUserId, id = dto.Id;
- if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
- if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
- if (id < 1) { result.Msg = MsgTips.Id; return result; }
- var status = await _sqlSugar.Updateable<Res_MediaSuppliers>()
- .SetColumns(x => new Res_MediaSuppliers() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
- .Where(x => x.Id == id)
- .ExecuteCommandAsync();
- if (status > 0)
- {
- result.Code = 200;
- result.Msg = $"操作成功!";
- }
- return result;
- }
- }
- }
|