using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using SlnMesnac.Model.domain; using SlnMesnac.Plc; using SlnMesnac.Repository.service; namespace SlnMesnac.Controllers { /// /// 人员基础信息 /// [Route("api/[controller]")] [ApiController] public class BaseUserController : ControllerBase { private readonly ILogger _logger; private readonly IBaseUserService _service; private readonly PlcPool _plcPool; /// /// /// /// /// public BaseUserController(ILogger logger, IBaseUserService service, PlcPool plcPool) { _logger = logger; _service = service; _plcPool = plcPool; } /// /// 获取人员基础信息 /// /// [HttpGet] public IEnumerable Get() { _plcPool.InitPlc("SiemensPlc", "127.0.0.1", 102, "SiemensPlc"); IEnumerable users = null; try { users = _service.GetUsers(); } catch (Exception ex) { _logger.LogError($"获取用户信息接口调用异常:{ex.Message}"); } return users; } /// /// 通过用户名称获取指定用户信息 /// /// 用户名称 /// [HttpGet("Gets/{userName}")] public IEnumerable GetUserByUserName(string userName) { IEnumerable users = null; try { users = _service.GetUsers(); } catch (Exception ex) { _logger.LogError($"获取用户信息接口调用异常:{ex.Message}"); } return users; } /// /// 添加用户信息 /// /// 用户列表 /// [HttpPut] public bool InsertUserInfo(List users) { return _service.InsertUsers(users); } } }