ProductOutputConfigController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using Cksoft.Unity.Log4NetConfig;
  5. using DllEapDal;
  6. using DllEapEntity.Dtos;
  7. using DllEapEntity.Mes;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. namespace DllEapBll.Controllers
  14. {
  15. /// <summary>
  16. /// 产品理想产量
  17. /// </summary>
  18. [Authorize]
  19. [ApiController]
  20. [Route("eap/api/[controller]/[action]")]
  21. public class ProductOutputConfigController : ControllerBase
  22. {
  23. /// <summary>
  24. /// 列表
  25. /// </summary>
  26. /// <param name="filter"></param>
  27. /// <param name="pageIndex"></param>
  28. /// <param name="pageSize"></param>
  29. /// <param name="sortField"></param>
  30. /// <param name="sortOrder"></param>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public LayuiModel<ProductIdealOutputConfig> Get(string filter, int pageIndex = 1, int pageSize = 10, string sortField = "ID", string sortOrder = "ascend")
  34. {
  35. if (sortOrder == "descend")
  36. {
  37. sortOrder = "desc";
  38. }
  39. else
  40. {
  41. sortOrder = "asc";
  42. }
  43. if (sortField == "null")
  44. {
  45. sortField = "ID";
  46. }
  47. int start, end;
  48. start = (pageIndex - 1) * pageSize + 1;
  49. end = start + pageSize;
  50. using (IDatabase db = DbFactory.Base("sqlconn"))
  51. {
  52. db.BeginTrans();
  53. var dal = new ProductOutputConfigDal(db);
  54. var total = dal.GetCount(filter);
  55. string errorinfo = string.Empty;
  56. var roles = dal.Get(start, pageSize, sortOrder, sortField, filter, errorinfo);
  57. return new LayuiModel<ProductIdealOutputConfig>
  58. {
  59. code = 1,
  60. count = total,
  61. data = roles,
  62. msg = ""
  63. };
  64. }
  65. }
  66. /// <summary>
  67. /// 详情
  68. /// </summary>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ProductIdealOutputConfig GetSingle(int id)
  73. {
  74. using (IDatabase db = DbFactory.Base("sqlconn"))
  75. {
  76. var dal = new ProductOutputConfigDal(db);
  77. return dal.Get(id);
  78. }
  79. }
  80. /// <summary>
  81. /// 新增/修改
  82. /// </summary>
  83. /// <param name="programMst"></param>
  84. /// <returns></returns>
  85. [HttpPost]
  86. public EapResponse Add([FromBody] ProductIdealOutputConfig programMst)
  87. {
  88. string usercode = Request.Headers["usercode"];
  89. using (IDatabase db = DbFactory.Base("sqlconn"))
  90. {
  91. db.BeginTrans();
  92. var dal = new ProductOutputConfigDal(db);
  93. string errorinfo = string.Empty;
  94. var response = new EapResponse() { Code = 1, Msg = string.Empty };
  95. int id = -1;
  96. if (programMst.ID == 0)
  97. {
  98. id = dal.Add(programMst, usercode, ref errorinfo);
  99. }
  100. else
  101. {
  102. id = dal.Update(programMst, usercode, ref errorinfo);
  103. }
  104. if (id < 0)
  105. {
  106. db.Rollback();
  107. response.Code = -1;
  108. response.Msg = errorinfo;
  109. }
  110. else
  111. {
  112. db.Commit();
  113. LogHelper<ProductIdealOutputConfig>.LogFatal("新增ProductIdealOutputConfig-->" + Json.ToJson(programMst), "用户操作", usercode);
  114. }
  115. response.Id = id;
  116. return response;
  117. }
  118. }
  119. /// <summary>
  120. /// 删除
  121. /// </summary>
  122. /// <param name="id"></param>
  123. /// <returns></returns>
  124. [HttpPost]
  125. public EapResponse Delete([FromBody] int id)
  126. {
  127. IDatabase db = null;
  128. string errormsg = string.Empty;
  129. try
  130. {
  131. db = DbFactory.Base("sqlconn");
  132. var dal = new ProductOutputConfigDal(db);
  133. db.BeginTrans();
  134. var model = dal.getIdealOutputConfig(id);
  135. var res = dal.Delete(id, ref errormsg);
  136. if (res < 0)
  137. {
  138. db.Rollback();
  139. return new EapResponse()
  140. {
  141. Code = -1,
  142. Msg = errormsg
  143. };
  144. }
  145. db.Commit();
  146. LogHelper<IdealOutputConfig>.LogFatal("删除IdealOutputConfig-->:" + Json.ToJson(model), "用户操作", Request.Headers["usercode"]);
  147. return new EapResponse()
  148. {
  149. Code = 1,
  150. Msg = ""
  151. };
  152. }
  153. catch (Exception e)
  154. {
  155. errormsg = e.Message;
  156. return new EapResponse
  157. {
  158. Code = -1,
  159. Msg = errormsg
  160. };
  161. }
  162. finally
  163. {
  164. if (db != null)
  165. db.Close();
  166. }
  167. }
  168. }
  169. }