FactoryRegionController.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using Cksoft.Unity.Log4NetConfig;
  5. using DllEapDal;
  6. using DllEapEntity;
  7. using DllEapEntity.Dtos;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. namespace DllEapBll.OFILM
  15. {
  16. [Route("eap/api/[controller]/[action]")]
  17. [Authorize]
  18. public class FactoryRegionController : ControllerBase
  19. {
  20. [HttpGet]
  21. public IEnumerable<FactoryRegionTreeDto> Get(string filter)
  22. {
  23. using (IDatabase db = DbFactory.Base("eapslave"))
  24. {
  25. db.BeginTrans();
  26. var dal = new FactoryRegionDal(db);
  27. string errorinfo = string.Empty;
  28. var roles = dal.GetRegionTree(filter, ref errorinfo);
  29. return roles;
  30. }
  31. }
  32. [HttpGet]
  33. public FactoryRegion GetSingle(int id)
  34. {
  35. using (IDatabase db = DbFactory.Base("eapslave"))
  36. {
  37. var dal = new FactoryRegionDal(db);
  38. return dal.Get(id);
  39. }
  40. }
  41. [HttpPost]
  42. public EapResponse Add([FromBody] FactoryRegion programMst)
  43. {
  44. string usercode = Request.Headers["usercode"];
  45. using (IDatabase db = DbFactory.Base("eap"))
  46. {
  47. db.BeginTrans();
  48. var dal = new FactoryRegionDal(db);
  49. string errorinfo = string.Empty;
  50. var response = new EapResponse() { Code = 1, Msg = string.Empty };
  51. int id = -1;
  52. if (programMst.Id == 0)
  53. {
  54. id = dal.Add(programMst, usercode, ref errorinfo);
  55. }
  56. else
  57. {
  58. id = dal.Update(programMst, usercode, ref errorinfo);
  59. }
  60. if (id < 0)
  61. {
  62. db.Rollback();
  63. response.Code = -1;
  64. response.Msg = errorinfo;
  65. }
  66. else
  67. {
  68. db.Commit();
  69. if (programMst.Id == 0)
  70. {
  71. LogHelper<FactoryRegion>.LogFatal("新增FactoryRegion-->" + Json.ToJson(programMst), "用户操作", usercode);
  72. }
  73. else
  74. LogHelper<FactoryRegion>.LogFatal("修改FactoryRegion-->" + Json.ToJson(programMst), "用户操作", usercode);
  75. }
  76. response.Id = id;
  77. return response;
  78. }
  79. }
  80. [HttpPost]
  81. public EapResponse Delete([FromBody] int id)
  82. {
  83. IDatabase db = null;
  84. string errormsg = string.Empty;
  85. try
  86. {
  87. db = DbFactory.Base("eap");
  88. var dal = new FactoryRegionDal(db);
  89. db.BeginTrans();
  90. var model = dal.getFactoryRegion(id);
  91. var modelsec = dal.Get(id);
  92. var res = dal.Delete(id, ref errormsg);
  93. if (res < 0)
  94. {
  95. db.Rollback();
  96. return new EapResponse()
  97. {
  98. Code = -1,
  99. Msg = errormsg
  100. };
  101. }
  102. db.Commit();
  103. LogHelper<FactoryRegion>.LogFatal("删除FactoryRegion-->:" + Json.ToJson(model) + ";" + Json.ToJson(modelsec), "用户操作", Request.Headers["usercode"]);
  104. return new EapResponse()
  105. {
  106. Code = 1,
  107. Msg = ""
  108. };
  109. }
  110. catch (Exception e)
  111. {
  112. errormsg = e.Message;
  113. return new EapResponse
  114. {
  115. Code = -1,
  116. Msg = errormsg
  117. };
  118. }
  119. finally
  120. {
  121. if (db != null)
  122. db.Close();
  123. }
  124. }
  125. [HttpGet]
  126. public IEnumerable<TreeSelectDto> GetRegionTreeSelect(int id)
  127. {
  128. using (IDatabase db = DbFactory.Base("eapslave"))
  129. {
  130. db.BeginTrans();
  131. var dal = new FactoryRegionDal(db);
  132. string errorinfo = string.Empty;
  133. var roles = dal.GetRegionTreeSelect(id, ref errorinfo);
  134. return roles;
  135. }
  136. }
  137. [HttpGet]
  138. [AllowAnonymous]
  139. public IEnumerable<SelectDto<int?>> GetSelect()
  140. {
  141. using (IDatabase db = DbFactory.Base("eapslave"))
  142. {
  143. db.BeginTrans();
  144. var dal = new FactoryRegionDal(db);
  145. string errorinfo = string.Empty;
  146. var roles = dal.GetFactorySelect(ref errorinfo);
  147. return roles;
  148. }
  149. }
  150. [HttpGet]
  151. [AllowAnonymous]
  152. public IEnumerable<SelectDto<int?>> GetSelectMulti()
  153. {
  154. using (IDatabase db = DbFactory.Base("eapslave"))
  155. {
  156. db.BeginTrans();
  157. var dal = new FactoryRegionDal(db);
  158. string errorinfo = string.Empty;
  159. var roles = dal.GetFactorySelectMulti(ref errorinfo);
  160. return roles;
  161. }
  162. }
  163. [HttpGet]
  164. [AllowAnonymous]
  165. public IEnumerable<SelectDto<int?>> GetPlantsSelect(int? factoryId)
  166. {
  167. if (factoryId == null)
  168. return null;
  169. string errorinfo = string.Empty;
  170. using (IDatabase db = DbFactory.Base("eapslave"))
  171. {
  172. var dal = new FactoryRegionDal(db);
  173. return dal.GetChildrenSelect(factoryId.Value, ref errorinfo);
  174. }
  175. }
  176. [HttpGet]
  177. [AllowAnonymous]
  178. public IEnumerable<SelectDto<int?>> GetFloorsSelect(int? plantId)
  179. {
  180. if (plantId == null)
  181. return null;
  182. string errorinfo = string.Empty;
  183. using (IDatabase db = DbFactory.Base("eapslave"))
  184. {
  185. var dal = new FactoryRegionDal(db);
  186. return dal.GetChildrenSelect(plantId.Value, ref errorinfo);
  187. }
  188. }
  189. [HttpGet]
  190. [AllowAnonymous]
  191. public IEnumerable<SelectDto<int?>> GetLinesSelect(string ids)
  192. {
  193. if (string.IsNullOrEmpty(ids))
  194. return null;
  195. var floorIds = ids.Split(new char[] { ',' });
  196. if (floorIds == null || floorIds.Count() <= 0)
  197. return null;
  198. string errorinfo = string.Empty;
  199. using (IDatabase db = DbFactory.Base("eapslave"))
  200. {
  201. var dal = new FactoryRegionDal(db);
  202. return dal.GetLinesSelect(floorIds.Select(c => Convert.ToInt32(c)).ToArray());
  203. }
  204. }
  205. [HttpGet]
  206. public IEnumerable<object> GetFactoryRegions(int id)
  207. {
  208. using (IDatabase db = DbFactory.Base("eapslave"))
  209. {
  210. var dal = new FactoryRegionDal(db);
  211. var entities = dal.Get(1, 1000, "a.id", "asc", $" and a.ParentId={id}", "").OrderBy(c => c.Id).Select(c => new { Label = c.FName, Value = c.Id });
  212. return entities;
  213. }
  214. }
  215. [HttpGet]
  216. public IEnumerable<object> GetFactoryRegionsMulti(string filter)
  217. {
  218. using (IDatabase db = DbFactory.Base("eapslave"))
  219. {
  220. var dal = new FactoryRegionDal(db);
  221. var entities = dal.Get(1, 1000, "a.id", "asc", $" {filter}", "").OrderBy(c => c.Id).Select(c => new { Label = c.FName, Value = c.Id });
  222. return entities;
  223. }
  224. }
  225. public IEnumerable<object> GetRegionSelects(string filter, int type = 1)
  226. {
  227. using (IDatabase db = DbFactory.Base("eapslave"))
  228. {
  229. var dal = new FactoryRegionDal(db);
  230. return dal.GetRegionSelects(filter, type);
  231. }
  232. }
  233. [HttpGet]
  234. public IEnumerable<object> GetFactoryRegionsAll()
  235. {
  236. //string client = AppConfigurtaionServices.Configuration["DbType"];
  237. using (IDatabase db = DbFactory.Base("eapslave"))
  238. {
  239. var dal = new FactoryRegionDal(db);
  240. var entities = dal.Get(1, 1000, "a.id", "asc", $" and a.ParentId=0 and a.ParentId!=154", "").OrderBy(c => c.Id).Select(c => new { Label = c.FName, Value = c.Id });
  241. return entities;
  242. }
  243. }
  244. }
  245. }