Lot3Controller.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. //校验是否有id重复的数据
  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. slidesNumber = colourcastDto.slidesNumber,
  124. is_send = 0,
  125. content = ColourCastData,
  126. create_time = DateTime.Now
  127. };
  128. List<ColourCastModel> colourcast_list = _db.Queryable<ColourCastModel>().Where(x => x.slidesNumber == colourcastDto.slidesNumber).OrderByDescending(x => x.id).ToList();
  129. if (colourcast_list.Count > 0)
  130. {
  131. ColourCastDto colourcastDto_db = JsonConvert.DeserializeObject<ColourCastDto>(colourcast_list[0].content);
  132. if (Convert.ToDateTime(colourcastDto.createTime) > Convert.ToDateTime(colourcastDto_db.createTime))
  133. {
  134. colourcastmodel.is_send = 0;
  135. }
  136. else
  137. {
  138. colourcastmodel.is_send = 3;
  139. }
  140. }
  141. _db.Insertable(colourcastmodel).ExecuteCommand();
  142. return Ok(ResultDto.Success());
  143. }
  144. catch (Exception ex)
  145. {
  146. return Ok(ResultDto.Fail("error:" + ex.Message));
  147. }
  148. }
  149. [HttpPost("UpdateDefectInfo")]
  150. public IActionResult UpdateDefectInfo(IFormFile file)
  151. {
  152. if (file == null || file.Length == 0)
  153. {
  154. return Ok(ResultDto.Fail("No file selected"));
  155. }
  156. string line;
  157. try
  158. {
  159. _db.Ado.BeginTran();
  160. _db.Deleteable<DefectModel>().ExecuteCommand();
  161. using (var reader = new StreamReader(file.OpenReadStream(), Encoding.GetEncoding("gb2312")))
  162. {
  163. var header = reader.ReadLine();
  164. var headers = header.Split(',');
  165. while ((line = reader.ReadLine()) != null)
  166. {
  167. string[] linelist = line.Split(",");
  168. _db.Insertable(new DefectModel
  169. {
  170. id = Convert.ToInt32(linelist[0]),
  171. defect_code = linelist[1],
  172. defect_name = linelist[2],
  173. classification = linelist[3].Replace(';', ',')
  174. }).ExecuteCommand();
  175. }
  176. }
  177. _db.Ado.CommitTran();
  178. }
  179. catch (Exception ex)
  180. {
  181. _db.Ado.RollbackTran();
  182. return Ok(ResultDto.Fail(ex.Message));
  183. }
  184. return Ok(ResultDto.Success());
  185. }
  186. }
  187. }