SystemController.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. 
  2. namespace OASystem.API.Controllers
  3. {
  4. /// <summary>
  5. /// 系统设置
  6. /// </summary>
  7. //[Authorize]
  8. [Route("api/[controller]/[action]")]
  9. public class SystemController : ControllerBase
  10. {
  11. private readonly CompanyRepository _syscomRep;
  12. private readonly DepartmentRepository _sysDepRep;
  13. private readonly UsersRepository _userRep;
  14. private readonly IMapper _mapper;
  15. public SystemController( CompanyRepository syscom,DepartmentRepository sysDepRep, UsersRepository userRep,
  16. IMapper mapper)
  17. {
  18. _syscomRep = syscom;
  19. _sysDepRep = sysDepRep;
  20. _userRep = userRep;
  21. _mapper = mapper;
  22. }
  23. #region user 操作
  24. /// <summary>
  25. /// 查询所有员工(web)
  26. /// </summary>
  27. /// <param name="dto"></param>
  28. /// <returns></returns>
  29. [HttpPost]
  30. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31. public async Task<IActionResult> GetUserList(DtoBase dto)
  32. {
  33. try
  34. {
  35. var result = _userRep.GetUserList(dto.PortType,string.Empty);
  36. if (result.Result.Code != 0)
  37. {
  38. return Ok(JsonView(false, "暂无数据!"));
  39. }
  40. return Ok(JsonView(result.Result.Data));
  41. }
  42. catch (Exception)
  43. {
  44. return Ok(JsonView(false, "程序错误!"));
  45. throw;
  46. }
  47. }
  48. #endregion
  49. #region 企业操作
  50. /// <summary>
  51. /// 查询企业数据
  52. /// </summary>
  53. /// <param name="dto"></param>
  54. /// <returns></returns>
  55. [HttpPost]
  56. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  57. public async Task<IActionResult> getCompanyList(DtoBase dto)
  58. {
  59. try
  60. {
  61. if (dto.PortType == 1)
  62. {
  63. return Ok(JsonView(false, "暂无数据!"));
  64. }
  65. else if (dto.PortType == 2)
  66. {
  67. var companyList = _sysDepRep.QueryDto<Sys_Company, CompanyView>(a=>a.ToBool(true)).ToList();
  68. if (companyList.Count == 0)
  69. {
  70. return Ok(JsonView(false, "暂无数据!"));
  71. }
  72. return Ok(JsonView(companyList));
  73. }
  74. else if (dto.PortType == 3)
  75. {
  76. return Ok(JsonView(false, "暂无数据!"));
  77. }
  78. else
  79. {
  80. return Ok(JsonView(false, "暂无数据!"));
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. return Ok(JsonView(false, "程序错误!"));
  86. throw;
  87. }
  88. }
  89. /// <summary>
  90. /// 添加企业数据
  91. /// </summary>
  92. /// <param name="dto"></param>
  93. /// <returns></returns>
  94. [HttpPost]
  95. [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)]
  96. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  97. {
  98. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId==0 || !string.IsNullOrWhiteSpace(dto.CompanyCode))
  99. {
  100. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  101. }
  102. else if (string.IsNullOrWhiteSpace(dto.Tel))
  103. {
  104. return Ok(JsonView(-1, "请检查联系方式是否输入正确!", null));
  105. }
  106. else
  107. {
  108. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  109. int id = await _syscomRep.AddAsyncReturnId(_Company);
  110. if (id == 0)
  111. {
  112. return Ok(JsonView(-1, "添加失败!", null));
  113. }
  114. return Ok(JsonView(0, "成功", id));
  115. }
  116. }
  117. /// <summary>
  118. /// 企业修改
  119. /// </summary>
  120. /// <param name="dto"></param>
  121. /// <returns></returns>
  122. [HttpPost]
  123. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  124. public async Task<IActionResult>EditCompany(EditCompanyDto dto)
  125. {
  126. try
  127. {
  128. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ParentCompanyId == 0 || dto.ContactUserId == 0)
  129. {
  130. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  131. }
  132. else if (string.IsNullOrWhiteSpace(dto.Tel))
  133. {
  134. return Ok(JsonView(-1, "请检查联系方式是否输入正确!", null));
  135. }
  136. else
  137. {
  138. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  139. {
  140. CompanyName = dto.CompanyName,
  141. CompanyCode = dto.CompanyCode,
  142. Address = dto.Address,
  143. ParentCompanyId = dto.ParentCompanyId,
  144. Tel = dto.Tel,
  145. ContactUserId = dto.ContactUserId,
  146. });
  147. if (!res) { return Ok(JsonView(-1, "失败", null)); }
  148. return Ok(JsonView(0, "成功", null));
  149. }
  150. }
  151. catch (Exception)
  152. {
  153. return Ok(JsonView(false, "程序错误!"));
  154. throw;
  155. }
  156. }
  157. /// <summary>
  158. /// 企业删除
  159. /// </summary>
  160. /// <param name="dto"></param>
  161. /// <returns></returns>
  162. [HttpPost]
  163. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  164. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  165. {
  166. try
  167. {
  168. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  169. if (!res) { return Ok(JsonView(-1, "失败", null)); }
  170. return Ok(JsonView(0, "成功", null));
  171. }
  172. catch (Exception)
  173. {
  174. return Ok(JsonView(false, "程序错误!"));
  175. throw;
  176. }
  177. }
  178. #endregion
  179. #region 部门操作
  180. /// <summary>
  181. /// 查询部门数据
  182. /// </summary>
  183. /// <param name="dto"></param>
  184. /// <returns></returns>
  185. //[Authorize]
  186. [HttpPost]
  187. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  188. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  189. {
  190. try
  191. {
  192. if (dto.PortType==1)
  193. {
  194. return Ok(JsonView(false, "暂无数据!"));
  195. }
  196. else if (dto.PortType==2)
  197. {
  198. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  199. if (result.Count == 0)
  200. {
  201. return Ok(JsonView(false, "暂无数据!"));
  202. }
  203. return Ok(JsonView(result));
  204. }
  205. else if (dto.PortType == 3)
  206. {
  207. return Ok(JsonView(false, "暂无数据!"));
  208. }
  209. else
  210. {
  211. return Ok(JsonView(false, "暂无数据!"));
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. return Ok(JsonView(false, "程序错误!"));
  217. throw;
  218. }
  219. }
  220. #endregion
  221. #region 用户操作
  222. /// <summary>
  223. /// 查询用户数据
  224. /// </summary>
  225. /// <param name="dto"></param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  229. public async Task<IActionResult> QueryUserList(UserDto dto)
  230. {
  231. try
  232. {
  233. string sqlWhere = string.Empty;
  234. if (dto.CompanyId!=0)
  235. {
  236. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  237. }
  238. if (dto.DepId != 0)
  239. {
  240. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  241. }
  242. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  243. {
  244. Regex r = new Regex("And");
  245. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  246. }
  247. var result=_userRep.GetUserList(dto.PortType,sqlWhere);
  248. if (result.Result.Code!=0)
  249. {
  250. return Ok(JsonView(false, "暂无数据!"));
  251. }
  252. return Ok(JsonView(result.Result.Data));
  253. }
  254. catch (Exception)
  255. {
  256. return Ok(JsonView(false, "程序错误!"));
  257. throw;
  258. }
  259. }
  260. #endregion
  261. }
  262. }