Lot3Controller.cs 4.5 KB

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