123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Service;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api.Controllers
- {
- public class TpntStoreController : BaseController
- {
- private readonly ILogger<TpntStoreController> _logger;
- private readonly ITpntStoreService _TpntStoreService;
- private readonly ITpntStoreOrgService _TpntStoreOrgService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TpntStoreService"></param>
- /// <param name="TpntStoreOrgService"></param>
- /// <param name="logger"></param>
- public TpntStoreController(ITpntStoreService TpntStoreService, ITpntStoreOrgService TpntStoreOrgService, ILogger<TpntStoreController> logger)
- {
- _TpntStoreService = TpntStoreService;
- _TpntStoreOrgService = TpntStoreOrgService;
- _logger = logger;
- }
- /// <summary>
- /// 通过ID获取网点信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetStoreAsync/{id}")]
- public async Task<ApiResult> GetStoreAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TpntStoreService.GetByIdAsync(id);
- return new ApiResult<TpntStoreViewModel>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有网点
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetStoresAsync")]
- public async Task<ApiResult> GetStoresAsync()
- {
- try
- {
- var contentList = await _TpntStoreService.GetAllAsync();
- return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过网点名称条件查询
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetStoresByAsync")]
- public async Task<ApiResult> GetStoresByAsync(TpntStoreSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- searchModel.IsPagination = false;
- try
- {
- var contentList = await _TpntStoreService.GetConditionAsync(searchModel);
- return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建网点
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateStoreAsync")]
- public async Task<ApiResult> CreateStoreAsync(TpntStoreViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TpntStoreService.CreateOneAsync(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 创建组织架构下网点
- /// </summary>
- /// <param name="orgCode"></param>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateStoreByOrgAsync/{orgCode}")]
- public async Task<ApiResult> CreateStoreByOrgAsync(Guid orgCode, TpntStoreCreateModel content)
- {
- if (content == null ||Guid.Empty == orgCode)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TpntStoreService.CreateStoreByOrgAsync(orgCode,content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 分配组织架构下网点
- /// </summary>
- /// <param name="orgCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpPost("AllotStoreByOrgAsync/{orgCode}/{storeCode}")]
- public async Task<ApiResult> AllotStoreByOrgAsync(Guid orgCode, Guid storeCode)
- {
- if (Guid.Empty == storeCode || Guid.Empty == orgCode)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TpntStoreService.AllotStoreByOrgAsync(orgCode, storeCode);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除网点
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteStoreAsync/{id}")]
- public async Task<ApiResult> DeleteStoreAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TpntStoreService.DeleteAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新网点
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateStoreAsync/{id}")]
- public async Task<ApiResult> UpdateStoreAsync(Guid id, TpntStoreUpdateModel updateModel)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TpntStoreService.UpdateAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 为组织架构批量分配网点
- /// </summary>
- /// <param name="orgCode"></param>
- /// <param name="storeCodes"></param>
- /// <returns></returns>
- [HttpPost("CreateOrgStoresAsync/{orgCode}")]
- public async Task<ApiResult> CreateOrgStoresAsync(Guid orgCode, IEnumerable<string> storeCodes)
- {
- if (Guid.Empty.Equals(orgCode) || storeCodes == null || !storeCodes.Any())
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TpntStoreOrgService.CreateOrgStoresAsync(orgCode, storeCodes);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 创建组织架构下网点
- /// </summary>
- /// <param name="mode"></param>
- /// <returns></returns>
- [HttpPost("CreateStoreOrgAsync")]
- public async Task<ApiResult> CreateStoreOrgAsync(TpntStoreOrgViewModel mode)
- {
- if (mode == null || Guid.Empty.Equals(mode.C_OrgCode) || string.Empty.Equals(mode.C_StoreCode))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- TpntStoreSearchModel searchModel = new TpntStoreSearchModel();
- searchModel.orgCode = mode.C_OrgCode;
- IEnumerable<TpntStoreViewModel> stores = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
- List<TpntStoreViewModel> listStores = stores.ToList();
- if (listStores[0] != null && listStores.FirstOrDefault(i => i.C_Code == mode.C_StoreCode) != null)
- return new ApiResult(ReturnCode.GeneralError, "此组织架构下已有此网点");
- await _TpntStoreOrgService.CreateOneAsync(mode);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除组织架构下网点
- /// </summary>
- /// <param name="orgCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpDelete("DeleteByOrgStoreCodeAsync/{orgCode}/{storeCode}")]
- public async Task<ApiResult> DeleteByOrgStoreCodeAsync(Guid orgCode,string storeCode)
- {
- if (Guid.Empty.Equals(orgCode)|| string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TpntStoreOrgService.DeleteByOrgStoreCodeAsync(orgCode, storeCode);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 通过网点Code获取关联的组织架构
- /// </summary>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetOrgsByStoreCodeAsync/{storeCode}")]
- public async Task<ApiResult> GetOrgsByStoreCodeAsync(string storeCode)
- {
- if (string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var contentList = await _TpntStoreOrgService.GetOrgsByStoreCodeAsync(storeCode);
- return new ApiResult<IEnumerable<TsysOrganizeViewModel>>(contentList);
-
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过点击组织机构树查看下面的网点
- /// </summary>
- /// <param name="orgCode"></param>
- /// <returns></returns>
- [HttpGet("GetStoresByOrgCodeAsync/{orgCode}")]
- public async Task<ApiResult> GetStoresByOrgCodeAsync(Guid orgCode)
- {
- if (Guid.Empty == orgCode)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- TpntStoreSearchModel searchModel = new TpntStoreSearchModel();
- searchModel.orgCode = orgCode;
- var contentList = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
- return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过点击组织机构树查看下面的网点
- /// </summary>
- /// <returns></returns>
- [HttpPost("GetStoresByOrgCodeNameAsync")]
- public async Task<ApiResult> GetStoresByOrgCodeNameAsync(TpntStoreSearchModel searchModel)
- {
- if (searchModel==null||Guid.Empty == searchModel.orgCode)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var contentList = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
- return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过组织架构Code获取关联的网点,管理公司可以查看所有
- /// </summary>
- /// <param name="orgCode"></param>
- /// <returns></returns>
- [HttpGet("GetStoresOnlyByOrgCodeAsync/{orgCode}")]
- public async Task<ApiResult> GetStoresOnlyByOrgCodeAsync(Guid orgCode)
- {
- if (Guid.Empty == orgCode)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var contentList = await _TpntStoreOrgService.GetStoresOnlyByOrgCodeAsync(orgCode);
- return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
- /// <summary>
- /// 获取所有的PNT类型
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetAllPntType")]
- public async Task<ApiResult> GetAllPntType()
- {
- try
- {
- var contentList = await _TpntStoreService.GetAllPntType();
- return new ApiResult<IList<TpntTypeViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过网点code获取网点信息
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- [HttpGet("GetStoreByCodeAsync/{code}")]
- public async Task<ApiResult> GetStoreByCodeAsync(string code)
- {
- if (string.IsNullOrEmpty(code))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TpntStoreService.GetStoreByCodeAsync(code);
- return new ApiResult<TpntStoreViewModel>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|