Lot3Controller.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using EInk.Dtos;
  2. using EInk.Models;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Newtonsoft.Json;
  5. using SqlSugar;
  6. using System;
  7. using System.ComponentModel;
  8. using System.Xml.Linq;
  9. using System;
  10. using System.Threading;
  11. using System.Text;
  12. using EInk.Dtos;
  13. using System.Reflection.Metadata;
  14. namespace EInk.Controllers
  15. {
  16. [Route("api/[controller]")]
  17. [ApiController]
  18. public class Lot3Controller : ControllerBase
  19. {
  20. private readonly ISqlSugarClient _db;
  21. public Lot3Controller(ISqlSugarClient db)
  22. {
  23. _db = db;
  24. }
  25. [HttpPost("UploadLot3")]
  26. public IActionResult Lot3Data(string Lot3Data)
  27. {
  28. try
  29. {
  30. if (String.IsNullOrEmpty(Lot3Data))
  31. {
  32. return Ok(ResultDto.Fail("Components is null"));
  33. }
  34. Lot2Lot3Dto lot3Dto = new Lot2Lot3Dto();
  35. try
  36. {
  37. lot3Dto = JsonConvert.DeserializeObject<Lot2Lot3Dto>(Lot3Data);
  38. }
  39. catch (Exception)
  40. {
  41. return Ok(ResultDto.Fail("Incorrect Json format"));
  42. }
  43. try
  44. {
  45. lot3Dto.Valid();
  46. }
  47. catch (Exception ex)
  48. {
  49. return Ok(ResultDto.Fail(ex.Message));
  50. }
  51. Lot2Lot3Model lot3model = new()
  52. {
  53. lot_id = lot3Dto.id,
  54. is_send = 0,
  55. product_no = lot3Dto.slidesNumber,
  56. content = Lot3Data,
  57. create_time = DateTime.Now
  58. };
  59. //根据guid查看是否为重复插入
  60. if (_db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Dto.id)) > 0)
  61. {
  62. lot3model.is_send = 3;
  63. }
  64. //else
  65. //{
  66. // //校验是否有片号重复的数据
  67. // List<Lot2Lot3Model> lot_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.product_no == lot3Dto.slidesNumber).OrderByDescending(x => x.id).ToList();
  68. // if (lot_list.Count > 0)
  69. // {
  70. // Lot2Lot3Dto lot3Dto_db = JsonConvert.DeserializeObject<Lot2Lot3Dto>(lot_list[0].content);
  71. // if (Convert.ToDateTime(lot3Dto.createTime) > Convert.ToDateTime(lot3Dto_db.createTime))
  72. // {
  73. // if (lot3Dto_db.result == "NG") lot3Dto.result = "NG";
  74. // foreach (var item in lot3Dto.itemCheckDatas)
  75. // {
  76. // lot3Dto_db.itemCheckDatas.Add(item);
  77. // }
  78. // lot3Dto.itemCheckDatas = lot3Dto_db.itemCheckDatas;
  79. // lot3model.content = JsonConvert.SerializeObject(lot3Dto);
  80. // }
  81. // else
  82. // {
  83. // lot3model.is_send = 3;
  84. // }
  85. // }
  86. //}
  87. _db.Insertable(lot3model).ExecuteCommand();
  88. return Ok(ResultDto.Success());
  89. }
  90. catch (Exception ex)
  91. {
  92. return Ok(ResultDto.Fail("error:" + ex.Message));
  93. }
  94. }
  95. [HttpPost("UploadColourCast")]
  96. public IActionResult ColourCastData(string ColourCastData)
  97. {
  98. try
  99. {
  100. if (String.IsNullOrEmpty(ColourCastData))
  101. {
  102. return Ok(ResultDto.Fail("Components is null"));
  103. }
  104. ColourCastDto colourcastDto = new ColourCastDto();
  105. try
  106. {
  107. colourcastDto = JsonConvert.DeserializeObject<ColourCastDto>(ColourCastData);
  108. }
  109. catch (Exception)
  110. {
  111. return Ok(ResultDto.Fail("Incorrect Json format"));
  112. }
  113. try
  114. {
  115. colourcastDto.Valid();
  116. }
  117. catch (Exception ex)
  118. {
  119. return Ok(ResultDto.Fail(ex.Message));
  120. };
  121. ColourCastModel colourcastmodel = new()
  122. {
  123. gid = colourcastDto.id,
  124. slidesNumber = colourcastDto.slidesNumber,
  125. is_send = 0,
  126. content = ColourCastData,
  127. create_time = DateTime.Now
  128. };
  129. //根据guid查看是否为重复插入
  130. if (_db.Ado.GetInt(string.Format("select count(*) from colourcast_info where gid='{0}'", colourcastDto.id)) > 0)
  131. {
  132. colourcastmodel.is_send = 3;
  133. }
  134. //List<ColourCastModel> colourcast_list = _db.Queryable<ColourCastModel>().Where(x => x.slidesNumber == colourcastDto.slidesNumber).OrderByDescending(x => x.id).ToList();
  135. //if (colourcast_list.Count > 0)
  136. //{
  137. // ColourCastDto colourcastDto_db = JsonConvert.DeserializeObject<ColourCastDto>(colourcast_list[0].content);
  138. // if (Convert.ToDateTime(colourcastDto.createTime) > Convert.ToDateTime(colourcastDto_db.createTime))
  139. // {
  140. // colourcastmodel.is_send = 0;
  141. // }
  142. // else
  143. // {
  144. // colourcastmodel.is_send = 3;
  145. // }
  146. //}
  147. _db.Insertable(colourcastmodel).ExecuteCommand();
  148. return Ok(ResultDto.Success());
  149. }
  150. catch (Exception ex)
  151. {
  152. return Ok(ResultDto.Fail("error:" + ex.Message));
  153. }
  154. }
  155. [HttpPost("UpdateDefectInfo")]
  156. public IActionResult UpdateDefectInfo(IFormFile file)
  157. {
  158. if (file == null || file.Length == 0)
  159. {
  160. return Ok(ResultDto.Fail("No file selected"));
  161. }
  162. string line;
  163. try
  164. {
  165. _db.Ado.BeginTran();
  166. _db.Deleteable<DefectModel>().ExecuteCommand();
  167. using (var reader = new StreamReader(file.OpenReadStream(), Encoding.GetEncoding("gb2312")))
  168. {
  169. var header = reader.ReadLine();
  170. var headers = header.Split(',');
  171. while ((line = reader.ReadLine()) != null)
  172. {
  173. string[] linelist = line.Split(",");
  174. _db.Insertable(new DefectModel
  175. {
  176. id = Convert.ToInt32(linelist[0]),
  177. defect_code = linelist[1],
  178. defect_name = linelist[2],
  179. classification = linelist[3].Replace(';', ',')
  180. }).ExecuteCommand();
  181. }
  182. }
  183. _db.Ado.CommitTran();
  184. }
  185. catch (Exception ex)
  186. {
  187. _db.Ado.RollbackTran();
  188. return Ok(ResultDto.Fail(ex.Message));
  189. }
  190. return Ok(ResultDto.Success());
  191. }
  192. }
  193. }