Lot3Controller.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. using Microsoft.AspNetCore.Mvc.Rendering;
  15. using EInk.Tools;
  16. namespace EInk.Controllers
  17. {
  18. [Route("api/[controller]")]
  19. [ApiController]
  20. public class Lot3Controller : ControllerBase
  21. {
  22. private readonly ISqlSugarClient _db;
  23. public Lot3Controller(ISqlSugarClient db)
  24. {
  25. _db = db;
  26. }
  27. [HttpPost("UploadLot3")]
  28. public IActionResult Lot3Data([FromBody] Lot2Lot3Dto lot3Data)
  29. {
  30. string jsonStr = JsonConvert.SerializeObject(lot3Data);
  31. try
  32. {
  33. try
  34. {
  35. lot3Data.Valid();
  36. }
  37. catch (Exception ex)
  38. {
  39. LogerHelper.RecordLogTxt($"UploadLot3, Valid Fail, Data:{jsonStr}, Message:{ex.Message}");
  40. return Ok(ResultDto.Fail(ex.Message));
  41. }
  42. Lot2Lot3Model lot3model = new()
  43. {
  44. lot_id = lot3Data.id,
  45. is_send = 0,
  46. product_no = lot3Data.slidesNumber,
  47. content = jsonStr,
  48. create_time = DateTime.Now
  49. };
  50. //根据guid查看是否为重复插入
  51. if (_db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Data.id)) > 0)
  52. {
  53. lot3model.is_send = 3;
  54. }
  55. _db.Insertable(lot3model).ExecuteCommand();
  56. return Ok(ResultDto.Success());
  57. }
  58. catch (Exception ex)
  59. {
  60. LogerHelper.RecordLogTxt($"UploadLot3, Data:{jsonStr}, StackTrace:{ex.StackTrace}, Message:{ex.Message}");
  61. return Ok(ResultDto.Fail("error:" + ex.Message));
  62. }
  63. }
  64. [HttpPost("UploadColourCast")]
  65. public IActionResult ColourCastData([FromBody] ColourCastDto ColourCastData)
  66. {
  67. string jsonStr = JsonConvert.SerializeObject(ColourCastData);
  68. try
  69. {
  70. try
  71. {
  72. ColourCastData.Valid();
  73. }
  74. catch (Exception ex)
  75. {
  76. LogerHelper.RecordLogTxt($"UploadColourCast, Valid Fail, Data:{jsonStr}, Message:{ex.Message}");
  77. return Ok(ResultDto.Fail(ex.Message));
  78. };
  79. ColourCastModel colourcastmodel = new()
  80. {
  81. gid = ColourCastData.id,
  82. slidesNumber = ColourCastData.slidesNumber,
  83. is_send = 0,
  84. content = jsonStr,
  85. create_time = DateTime.Now
  86. };
  87. //根据guid查看是否为重复插入
  88. if (_db.Ado.GetInt(string.Format("select count(*) from colourcast_info where gid='{0}'", ColourCastData.id)) > 0)
  89. {
  90. colourcastmodel.is_send = 3;
  91. }
  92. _db.Insertable(colourcastmodel).ExecuteCommand();
  93. return Ok(ResultDto.Success());
  94. }
  95. catch (Exception ex)
  96. {
  97. LogerHelper.RecordLogTxt($"UploadColourCast, Data:{jsonStr}, StackTrace:{ex.StackTrace}, Message:{ex.Message}");
  98. return Ok(ResultDto.Fail("error:" + ex.Message));
  99. }
  100. }
  101. [HttpPost("UpdateDefectInfo")]
  102. public IActionResult UpdateDefectInfo(IFormFile file)
  103. {
  104. if (file == null || file.Length == 0)
  105. {
  106. return Ok(ResultDto.Fail("No file selected"));
  107. }
  108. string line;
  109. try
  110. {
  111. _db.Ado.BeginTran();
  112. _db.Deleteable<DefectModel>().ExecuteCommand();
  113. using (var reader = new StreamReader(file.OpenReadStream(), Encoding.GetEncoding("gb2312")))
  114. {
  115. var header = reader.ReadLine();
  116. var headers = header.Split(',');
  117. while ((line = reader.ReadLine()) != null)
  118. {
  119. string[] linelist = line.Split(",");
  120. _db.Insertable(new DefectModel
  121. {
  122. id = Convert.ToInt32(linelist[0]),
  123. defect_code = linelist[1],
  124. defect_name = linelist[2],
  125. classification = linelist[3].Replace(';', ',')
  126. }).ExecuteCommand();
  127. }
  128. }
  129. _db.Ado.CommitTran();
  130. }
  131. catch (Exception ex)
  132. {
  133. _db.Ado.RollbackTran();
  134. return Ok(ResultDto.Fail(ex.Message));
  135. }
  136. return Ok(ResultDto.Success());
  137. }
  138. }
  139. }