using FHT.Agency.CommonTypes; using FHT.Agency.Queries.ImplementedInterfaces; using FHT.Agency.Services.ImplementedInterfaces; using FHT.Agency.UI.InputModels; using FHT.Agency.Web.Filters; using FHT.Core.Queries.ImplementedInterfaces; using FHT.DDD; using FHT.Management.Interfaces.DependentInterfaces.Services; using Microsoft.AspNet.Identity; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.Cors; using System.Web.Http.Description; namespace FHT.Agency.Web.ApiControllers { /// /// 公海客户数据分配 /// [Authorize] [RoutePrefix("api/openclients")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class OpenClientApiController : ApiController { private readonly ICompanyQuery _companyQuery; private readonly IAgentClientQuery _agentClientQuery; private readonly IAgentClientService _agentClientService; private readonly IExternalMessageService _externalMessageService; public OpenClientApiController(ICompanyQuery companyQuery, IAgentClientQuery agentClientQuery, IAgentClientService agentClientService, IExternalMessageService externalMessageService) { _companyQuery = companyQuery; _agentClientQuery = agentClientQuery; _agentClientService = agentClientService; _externalMessageService = externalMessageService; } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.OpenClients)] [Route("_search")] [ResponseType(typeof(QueryResult))] public async Task SearchAsync(int? companyId = null, int? provinceId = null, int? cityId = null, int currPage = 1, int limit = 20) { int offset = limit * (currPage - 1); QueryResult companys = await _companyQuery.SearchCompanyWithinRegionAsync(companyId, provinceId, cityId, offset, limit); return Ok(companys); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.OpenClients)] [Route("_getExistsOrganizationCompanyIds")] [ResponseType(typeof(List))] public async Task GetExistsOrganizationCompanyIdsAsync(IEnumerable companyIds) { List ids = await _agentClientQuery.GetExistsOrganizationCompanyIdsAsync(companyIds); return Ok(ids); } [HttpPost] [ClaimsAuthorize(FhtUserClaimType.OpenClients)] [ResponseType(typeof(void))] [Route("_allot")] public async Task AllotDataAsync(int agentId, List clients) { int authenticatedUserId = User.Identity.GetUserId(); List successAllotCompanyIds = await _agentClientService.AllotAgentClientAsync(authenticatedUserId, agentId, clients); _externalMessageService.AllotCompanyAgency(agentId, successAllotCompanyIds, DateTime.Now); return Ok(); } } }