You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.2 KiB
169 lines
6.2 KiB
using Senparc.Weixin.Entities.TemplateMessage;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Wx;
|
|
using Znyc.Admin.Commons.Cache;
|
|
using Znyc.Admin.Commons.Const;
|
|
using Znyc.Admin.Commons.Entitys;
|
|
using Znyc.Admin.Commons.Enums;
|
|
using Znyc.Admin.Commons.Mapping;
|
|
using Znyc.Admin.Commons.Pages;
|
|
using Znyc.Admin.Commons.Services;
|
|
using Znyc.Admin.Security.Dtos;
|
|
using Znyc.Admin.Security.Entitys;
|
|
using Znyc.Admin.Security.IRepositories;
|
|
using Znyc.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class CompanyService : BaseService<Company, CompanyOutputDto, long>, ICompanyService
|
|
{
|
|
private readonly ICompanyRepository _companyRepository;
|
|
private readonly IVehicleRepository _vehicleRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly ICacheService _cacheService;
|
|
public CompanyService(ICompanyRepository companyRepository,
|
|
IVehicleRepository vehicleRepository,
|
|
IUserRepository userRepository,
|
|
ICacheService cacheService
|
|
|
|
) : base(companyRepository)
|
|
{
|
|
_companyRepository = companyRepository;
|
|
_vehicleRepository = vehicleRepository;
|
|
_userRepository = userRepository;
|
|
_cacheService = cacheService;
|
|
|
|
}
|
|
|
|
public async Task<PageResult<CompanyOutputDto>> FindWithPagerSearchAsync(SearchUserModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (!string.IsNullOrEmpty(search.Keywords))
|
|
{
|
|
@where += string.Format(" and (CompanyName like '%{0}%')", search.Keywords);
|
|
}
|
|
|
|
if (search.Status > (int)CommonStatus.DELETED)
|
|
{
|
|
@where += string.Format(" and Status={0}", search.Status);
|
|
}
|
|
if (!string.IsNullOrEmpty(search.StartTime))
|
|
{
|
|
@where += " and CreatedTime >='" + search.StartTime + " 00:00:00'";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(search.EndTime))
|
|
{
|
|
@where += " and CreatedTime <='" + search.EndTime + " 23:59:59'";
|
|
}
|
|
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
List<Company> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
|
List<CompanyOutputDto> companyOutput = list.MapTo<CompanyOutputDto>();
|
|
foreach (var item in companyOutput)
|
|
{
|
|
//string condition = string.Format(@" CompanyId=" + item.Id + " Status=1");
|
|
item.VehicleCount = await _vehicleRepository.GetCountByWhereAsync(" CompanyId=" + item.Id + " and Status=1");
|
|
item.CompanyLogo = CommonConst.Default_Image_Prefix + item.CompanyLogo;
|
|
}
|
|
PageResult<CompanyOutputDto> pageResult = new PageResult<CompanyOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = companyOutput,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ���˹�˾״̬
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="status"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> AuditAsync(long id, int status)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
string where = $@" Id={id}";
|
|
Company company = await _companyRepository.GetWhereAsync(where);
|
|
User user = await _userRepository.GetWhereAsync($@"Phone={company.ContactPhone}");
|
|
var isExistCount = await _companyRepository.GetCountByWhereAsync($@"ContactPhone={company.ContactPhone} and Status=1");
|
|
if (isExistCount > 0)
|
|
{
|
|
result.ResData = ReturnConst.Audit_Repeat;
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Audit_Repeat;
|
|
return result;
|
|
}
|
|
if (company.Status != (int)CommonStatus.ENABLE)
|
|
{
|
|
result.Success = await _companyRepository.AuditAsync(id, status);
|
|
string phrase2 = ReturnConst.Audit_Failed;
|
|
string thing3 = ReturnConst.Audit_Failed_Note;
|
|
if (status == (int)CommonStatus.ENABLE)
|
|
{
|
|
phrase2 = ReturnConst.Audit_Success;
|
|
thing3 = ReturnConst.Audit_Success_Note;
|
|
}
|
|
await CommonHelper.SendCompanyAuditAsync(company.CompanyName, phrase2, thing3, user.OpenId).ConfigureAwait(false);
|
|
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
result.ResData = ReturnConst.Audit_Error;
|
|
result.Success = false;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// �Ĺ�˾״̬
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="status"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> UpdateAsync(long id, int status)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
string where = string.Format(@" Id={0}", id);
|
|
Company company = await _companyRepository.GetWhereAsync(where);
|
|
if (company.Status == (int)CommonStatus.ENABLE)
|
|
{
|
|
result.Success = await _companyRepository.UpdateStatusAsync(id, status);
|
|
await ClearCompanyCacheAsync(company.Id);
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
result.ResData = "�ù�˾��ͣ��";
|
|
result.Success = false;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="companyId"></param>
|
|
/// <returns></returns>
|
|
public async Task ClearCompanyCacheAsync(long companyId)
|
|
{
|
|
//��������
|
|
await _cacheService.RemoveAsync(CacheKey.CACHE_KEY_COMPANY + $"{companyId}");
|
|
}
|
|
|
|
|
|
}
|
|
}
|