123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using EInk.Dtos;
- using EInk.Models;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using SqlSugar;
- using System;
- using System.ComponentModel;
- using System.Xml.Linq;
- using System;
- using System.Threading;
- using System.Text;
- namespace EInk.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class Lot3Controller : ControllerBase
- {
- private readonly ISqlSugarClient _db;
- public Lot3Controller(ISqlSugarClient db)
- {
- _db = db;
- }
- // POST api/<Lot3Controller>
- [HttpPost("AccessLot3")]
- public IActionResult Lot3Data(string Lot3Data)
- {
- try
- {
- if (String.IsNullOrEmpty(Lot3Data))
- {
- return Ok(ResultDto.Fail("Components is null"));
- }
- Lot2Lot3Dto lot3Dto = new Lot2Lot3Dto();
- try
- {
- lot3Dto = JsonConvert.DeserializeObject<Lot2Lot3Dto>(Lot3Data);
- }
- catch (Exception)
- {
- return Ok(ResultDto.Fail("Incorrect Json format"));
- }
- try
- {
- lot3Dto.Valid();
- }
- catch (Exception ex)
- {
- return Ok(ResultDto.Fail(ex.Message));
- }
- //int id = _db.Ado.GetInt("select max(count) from lot2lot3_info");
- Lot2Lot3Model lot3model = new()
- {
- //id = id + 1,
- lot_id = lot3Dto.id,
- //判断数据是否重复插入,重复插入is_send标记为3
- is_send = _db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Dto.id)) == 0 ? 0 : 3,
- content = Lot3Data,
- create_time = DateTime.Now
- };
- _db.Insertable(lot3model).ExecuteCommand();
- return Ok(ResultDto.Success());
- }
- catch (Exception ex)
- {
- return Ok(ResultDto.Fail("error:" + ex.Message));
- }
- }
- // POST api/<Lot3Controller>
- [HttpPost("UpdateDefectInfo")]
- public IActionResult UpdateDefectInfo(IFormFile file)
- {
- if (file == null || file.Length == 0)
- {
- return Ok(ResultDto.Fail("No file selected"));
- }
- string line;
- try
- {
- _db.Ado.BeginTran();
- _db.Deleteable<DefectModel>().ExecuteCommand();
- using (var reader = new StreamReader(file.OpenReadStream(), Encoding.GetEncoding("gb2312")))
- {
- var header = reader.ReadLine();
- var headers = header.Split(',');
- while ((line = reader.ReadLine()) != null)
- {
- string[] linelist = line.Split(",");
- _db.Insertable(new DefectModel
- {
- id = Convert.ToInt32(linelist[0]),
- defect_code = linelist[1],
- defect_name = linelist[2],
- classification = linelist[3].Replace(';', ',')
- }).ExecuteCommand();
- }
- }
- _db.Ado.CommitTran();
- }
- catch(Exception ex)
- {
- _db.Ado.RollbackTran();
- return Ok(ResultDto.Fail(ex.Message));
- }
- return Ok(ResultDto.Success());
- }
- }
- }
|