|
|
|
|
using GDZZ.Core;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using GDZZ.Application.Entity;
|
|
|
|
|
using GDZZ.Core.Entity;
|
|
|
|
|
using GDZZ.Core.OAuth;
|
|
|
|
|
using GDZZ.Application.Help;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 公司属性服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application",Name = "Company", Order = 1)]
|
|
|
|
|
public class CompanyService : ICompanyService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<Company> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<CompanyUserScope> companyUserRep;
|
|
|
|
|
private readonly ICacheService cacheService;
|
|
|
|
|
|
|
|
|
|
public CompanyService(SqlSugarRepository<Company> rep,
|
|
|
|
|
ICacheService cacheService,
|
|
|
|
|
SqlSugarRepository<CompanyUserScope> companyUserRep)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
this.cacheService= cacheService;
|
|
|
|
|
this.companyUserRep= companyUserRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询公司
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Mini/Company/page")]
|
|
|
|
|
public async Task<dynamic> Page([FromQuery] CompanyInput input)
|
|
|
|
|
{
|
|
|
|
|
var entities = await _rep.AsQueryable()
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchValue), u => u.Name.Contains(input.SearchValue.Trim()))
|
|
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
return entities.XnPagedResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新公司属性
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Mini/Company/edit")]
|
|
|
|
|
public async Task Update(UpdateCompanyInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<Company>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取公司详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Mini/Company/Detail")]
|
|
|
|
|
public async Task<Company> Get()
|
|
|
|
|
{
|
|
|
|
|
return await _rep.FirstOrDefaultAsync(u => u.CreatedUserId == UserManager.UserId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建公司
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Mini/Company/UpdateOrInstall")]
|
|
|
|
|
public async Task UpdateOrInstall(AddCompanyInput input)
|
|
|
|
|
{
|
|
|
|
|
var company =await this._rep.AsQueryable().Where(x => x.Code == input.Code && x.Name == input.Name).FirstAsync();
|
|
|
|
|
if(company == null)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<Company>();
|
|
|
|
|
entity.CompanyInfoUrl = entity.CompanyInfoUrl.TrimEnd(',');
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<Company>();
|
|
|
|
|
entity.CompanyInfoUrl = entity.CompanyInfoUrl.TrimEnd(',');
|
|
|
|
|
entity.ApprovalStatus = CompanyEnum.Pending;
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绑定公司
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">公司信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Mini/Comapany/Bing")]
|
|
|
|
|
public async Task BingCompany([FromQuery] AddCompanyInput input)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//验证电话和验证码一致
|
|
|
|
|
var verIfy = await this.cacheService.GetVerifyCode(input.Phone);
|
|
|
|
|
if (verIfy != input.Checking)
|
|
|
|
|
throw new Exception("验证码错误");
|
|
|
|
|
|
|
|
|
|
var companyUser = new CompanyUserScope
|
|
|
|
|
{
|
|
|
|
|
MiniCompanyID = input.Id,
|
|
|
|
|
MiniUserID = UserManager.UserId,
|
|
|
|
|
};
|
|
|
|
|
await this.companyUserRep.InsertAsync(companyUser);
|
|
|
|
|
|
|
|
|
|
//关系表插入信息
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新公司属性
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Mini/Company/CompanyApprove")]
|
|
|
|
|
public async Task CompanyApprove(UpdateCompanyInput input)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var entity = input.Adapt<Company>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|