123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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;
- using EInk.Dtos;
- using System.Reflection.Metadata;
- namespace EInk.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class Lot3Controller : ControllerBase
- {
- private readonly ISqlSugarClient _db;
- public Lot3Controller(ISqlSugarClient db)
- {
- _db = db;
- }
- [HttpPost("UploadLot3")]
- 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));
- }
- Lot2Lot3Model lot3model = new()
- {
- lot_id = lot3Dto.id,
- is_send = 0,
- product_no = lot3Dto.slidesNumber,
- content = Lot3Data,
- create_time = DateTime.Now
- };
- //校验是否有id重复的数据
- if (_db.Ado.GetInt(string.Format("select count(*) from lot2lot3_info where lot_id='{0}'", lot3Dto.id)) > 0)
- {
- lot3model.is_send = 3;
- }
- else
- {
- //校验是否有片号重复的数据
- List<Lot2Lot3Model> lot_list = _db.Queryable<Lot2Lot3Model>().Where(x => x.product_no == lot3Dto.slidesNumber).OrderByDescending(x => x.id).ToList();
- if (lot_list.Count > 0)
- {
- Lot2Lot3Dto lot3Dto_db = JsonConvert.DeserializeObject<Lot2Lot3Dto>(lot_list[0].content);
- if (Convert.ToDateTime(lot3Dto.createTime) > Convert.ToDateTime(lot3Dto_db.createTime))
- {
- if (lot3Dto_db.result == "NG") lot3Dto.result = "NG";
- foreach (var item in lot3Dto.itemCheckDatas)
- {
- lot3Dto_db.itemCheckDatas.Add(item);
- }
- lot3Dto.itemCheckDatas = lot3Dto_db.itemCheckDatas;
- lot3model.content = JsonConvert.SerializeObject(lot3Dto);
- }
- else
- {
- lot3model.is_send = 3;
- }
- }
- }
- _db.Insertable(lot3model).ExecuteCommand();
- return Ok(ResultDto.Success());
- }
- catch (Exception ex)
- {
- return Ok(ResultDto.Fail("error:" + ex.Message));
- }
- }
- [HttpPost("UploadColourCast")]
- public IActionResult ColourCastData(string ColourCastData)
- {
- try
- {
- if (String.IsNullOrEmpty(ColourCastData))
- {
- return Ok(ResultDto.Fail("Components is null"));
- }
- ColourCastDto colourcastDto = new ColourCastDto();
- try
- {
- colourcastDto = JsonConvert.DeserializeObject<ColourCastDto>(ColourCastData);
- }
- catch (Exception)
- {
- return Ok(ResultDto.Fail("Incorrect Json format"));
- }
- try
- {
- colourcastDto.Valid();
- }
- catch (Exception ex)
- {
- return Ok(ResultDto.Fail(ex.Message));
- };
- ColourCastModel colourcastmodel = new()
- {
- slidesNumber = colourcastDto.slidesNumber,
- is_send = 0,
- content = ColourCastData,
- create_time = DateTime.Now
- };
- List<ColourCastModel> colourcast_list = _db.Queryable<ColourCastModel>().Where(x => x.slidesNumber == colourcastDto.slidesNumber).OrderByDescending(x => x.id).ToList();
- if (colourcast_list.Count > 0)
- {
- ColourCastDto colourcastDto_db = JsonConvert.DeserializeObject<ColourCastDto>(colourcast_list[0].content);
- if (Convert.ToDateTime(colourcastDto.createTime) > Convert.ToDateTime(colourcastDto_db.createTime))
- {
- colourcastmodel.is_send = 0;
- }
- else
- {
- colourcastmodel.is_send = 3;
- }
- }
- _db.Insertable(colourcastmodel).ExecuteCommand();
- return Ok(ResultDto.Success());
- }
- catch (Exception ex)
- {
- return Ok(ResultDto.Fail("error:" + ex.Message));
- }
- }
- [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());
- }
- }
- }
|