Commit 43c745cb by xin.yang

some update

parent 361f2e73
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.AspNetCore.Mvc;
using Siger.ApiCommon.Result;
using Siger.Middlelayer.AccRepository.Entities;
using Siger.Middlelayer.AccRepository.Repositories.Interface;
using Siger.Middlelayer.AccRepository.Response;
using Siger.Middlelayer.AccRepository.Request;
using Siger.Middlelayer.Common;
using Siger.Middlelayer.Common.Extensions;
using Siger.Middlelayer.Repository.Repositories.Interface;
using Siger.Middlelayer.Repository;
using Siger.Middlelayer.Repository.Extensions;
using System.Linq;
using Siger.Middlelayer.Repository.Entities;
namespace Siger.ApiACC.Controllers
{
public class AutomationLocationController : BaseController
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAutomationFixtureToolsCategoryRepository _toolsCategoryRepository;
private readonly IAutomationFixtureToolsRepository _toolsRepository;
private readonly IAutomationLocationRepository _autoLocationRepository;
private readonly ISigerTrMaterialsRepository _materialsRepository;
public AutomationLocationController(IUnitOfWork unitOfWork, IAutomationFixtureToolsCategoryRepository toolsCategoryRepository,
IAutomationFixtureToolsRepository toolsRepository, IAutomationLocationRepository autoLocationRepository,
ISigerTrMaterialsRepository materialsRepository)
{
_unitOfWork = unitOfWork;
_toolsCategoryRepository = toolsCategoryRepository;
_toolsRepository = toolsRepository;
_autoLocationRepository = autoLocationRepository;
_materialsRepository = materialsRepository;
}
public IActionResult GetPageList(string category, string code, string name, string state, int page, int pagesize)
{
var data = _toolsRepository.GetPagedList(category.ToInt(), code, name, string.IsNullOrEmpty(state) ? -1 : state.ToInt(), ProjectId, page, pagesize);
return new PagedObjectResult(data.Data, data.Total, page, pagesize);
}
[HttpPost]
public IActionResult Add([FromBody]RequestAddAutomationLocation req)
{
if (string.IsNullOrEmpty(req.locationid) || string.IsNullOrEmpty(req.fixturetoolid) || string.IsNullOrEmpty(req.materialid))
{
throw new BadRequestException(RequestEnum.ParameterMiss);
}
var fixturetool = _toolsRepository.Get(q => q.id == req.fixturetoolid.ToInt() && q.projectId == ProjectId && q.status == (int)RowState.Valid);
if (fixturetool == null)
{
throw new BadRequestException(RequestEnum.FixtureToolNotFound);
}
var location = _autoLocationRepository.GetLocation(req.locationid.ToInt(), ProjectId);
if (location == null)
{
throw new BadRequestException(RequestEnum.LocationNull);
}
var material = _materialsRepository.Get(q => q.id == req.materialid.ToInt() && q.projectId == ProjectId && q.status == (int)RowState.Valid);
var data = _autoLocationRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.fixturetools == fixturetool.guid &&
q.locationid == req.locationid.ToInt());
if (data != null)
{
throw new BadRequestException(RequestEnum.DataExist);
}
var state = 1;
if (fixturetool != null && material == null)
{
state = 1;//有工装 无工件
}
else if(fixturetool != null && material != null)
{
state = 2;//有工装 有工件
}
var entity = new siger_automation_location
{
guid = Guid.NewGuid().ToString(),
locationid = req.locationid.ToInt(),
fixturetools = fixturetool.guid,
materialid = req.materialid.ToInt(),
processid = req.processid.ToInt(),
materialstate = state,
attachment = req.attachment,
remark = req.remark,
projectId = ProjectId,
updatetime = DateTime.Now,
updator = UserId,
};
_autoLocationRepository.Insert(entity);
if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
[HttpPost]
public IActionResult Update([FromBody]RequestUpdateAutomationLocation req)
{
if (string.IsNullOrEmpty(req.locationid) || string.IsNullOrEmpty(req.fixturetoolid) || string.IsNullOrEmpty(req.materialid))
{
throw new BadRequestException(RequestEnum.ParameterMiss);
}
var entity = _autoLocationRepository.Get(q => q.id == req.id && q.projectId == ProjectId && q.status == (int)RowState.Valid);
var fixturetool = _toolsRepository.Get(q => q.id == req.fixturetoolid.ToInt() && q.projectId == ProjectId && q.status == (int)RowState.Valid);
if (fixturetool == null)
{
throw new BadRequestException(RequestEnum.FixtureToolNotFound);
}
var location = _autoLocationRepository.GetLocation(req.locationid.ToInt(), ProjectId);
if (location == null)
{
throw new BadRequestException(RequestEnum.LocationNull);
}
var material = _materialsRepository.Get(q => q.id == req.materialid.ToInt() && q.projectId == ProjectId && q.status == (int)RowState.Valid);
var data = _autoLocationRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.fixturetools == fixturetool.guid &&
q.locationid == req.locationid.ToInt() && q.id != req.id);
if (data != null)
{
throw new BadRequestException(RequestEnum.DataExist);
}
var state = 1;
if (fixturetool != null && material == null)
{
state = 1;//有工装 无工件
}
else if (fixturetool != null && material != null)
{
state = 2;//有工装 有工件
}
entity.locationid = req.locationid.ToInt();
entity.fixturetools = fixturetool.guid;
entity.materialid = req.materialid.ToInt();
entity.processid = req.processid.ToInt();
entity.materialstate = state;
entity.attachment = req.attachment;
entity.remark = req.remark;
entity.updatetime = DateTime.Now;
entity.updator = UserId;
_autoLocationRepository.Update(entity);
if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
[HttpGet]
public IActionResult Delete(int id)
{
var entity = _autoLocationRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.id == id);
if (entity == null)
{
throw new BadRequestException(CommonEnum.RecordNotFound);
}
entity.status = (int)RowState.Invalid;
_autoLocationRepository.Update(entity);
if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
[HttpPost]
public IActionResult Deletes([FromBody]RequestDeleteRange req)
{
if (req.ids == null || !req.ids.Any())
{
throw new BadRequestException(RequestEnum.ParameterMiss);
}
var entities = _autoLocationRepository.GetList(t =>
req.ids.Contains(t.id) && t.projectId == ProjectId && t.status == (int)RowState.Valid).ToList();
if (!entities.Any())
{
throw new BadRequestException(CommonEnum.RecordNotFound);
}
foreach (var entity in entities)
{
entity.status = (int)RowState.Invalid;
_autoLocationRepository.Update(entity);
}
if (_unitOfWork.Commit() > 0)
return new ObjectResult(CommonEnum.Succefull);
throw new BadRequestException(CommonEnum.Fail);
}
}
}
...@@ -65,7 +65,7 @@ namespace Siger.ApiACC.Controllers ...@@ -65,7 +65,7 @@ namespace Siger.ApiACC.Controllers
managetype = req.managetype.ToInt(), managetype = req.managetype.ToInt(),
partnumber = req.partnumber, partnumber = req.partnumber,
name = req.name, name = req.name,
specifition = req.specifition, specification = req.specifition,
number = req.number.ToInt(), number = req.number.ToInt(),
remark = req.remark, remark = req.remark,
attachment = req.attachment, attachment = req.attachment,
...@@ -113,7 +113,7 @@ namespace Siger.ApiACC.Controllers ...@@ -113,7 +113,7 @@ namespace Siger.ApiACC.Controllers
entity.managetype = req.managetype.ToInt(); entity.managetype = req.managetype.ToInt();
entity.partnumber = req.partnumber; entity.partnumber = req.partnumber;
entity.name = req.name; entity.name = req.name;
entity.specifition = req.specifition; entity.specification = req.specifition;
entity.number = req.number.ToInt(); entity.number = req.number.ToInt();
entity.remark = req.remark; entity.remark = req.remark;
entity.attachment = req.attachment; entity.attachment = req.attachment;
...@@ -153,7 +153,7 @@ namespace Siger.ApiACC.Controllers ...@@ -153,7 +153,7 @@ namespace Siger.ApiACC.Controllers
} }
[HttpPost] [HttpPost]
public IActionResult Delete([FromBody]RequestDeleteRange req) public IActionResult Deletes([FromBody]RequestDeleteRange req)
{ {
if (req.ids == null || !req.ids.Any()) if (req.ids == null || !req.ids.Any())
{ {
......
...@@ -156,7 +156,7 @@ namespace Siger.ApiACC.Controllers ...@@ -156,7 +156,7 @@ namespace Siger.ApiACC.Controllers
} }
[HttpPost] [HttpPost]
public IActionResult Delete([FromBody]RequestDeleteRange req) public IActionResult Deletes([FromBody]RequestDeleteRange req)
{ {
if (req.ids == null || !req.ids.Any()) if (req.ids == null || !req.ids.Any())
{ {
......
...@@ -156,5 +156,9 @@ namespace Siger.Middlelayer.AccRepository ...@@ -156,5 +156,9 @@ namespace Siger.Middlelayer.AccRepository
public DbSet<siger_automation_section_property> siger_automation_section_property { get; set; } public DbSet<siger_automation_section_property> siger_automation_section_property { get; set; }
public DbSet<siger_automation_section_route> siger_automation_section_route { get; set; } public DbSet<siger_automation_section_route> siger_automation_section_route { get; set; }
public DbSet<siger_automation_task_list> siger_automation_task_list { get; set; } public DbSet<siger_automation_task_list> siger_automation_task_list { get; set; }
public DbSet<siger_wms_storage> siger_wms_storage { get; set; }
public DbSet<siger_wms_storage_location> siger_wms_storage_location { get; set; }
} }
} }
...@@ -29,7 +29,7 @@ namespace Siger.Middlelayer.AccRepository.Entities ...@@ -29,7 +29,7 @@ namespace Siger.Middlelayer.AccRepository.Entities
/// <summary> /// <summary>
/// 规格型号 /// 规格型号
/// </summary> /// </summary>
public string specifition { get; set; } public string specification { get; set; }
/// <summary> /// <summary>
/// 数量 /// 数量
/// </summary> /// </summary>
......
...@@ -33,7 +33,7 @@ namespace Siger.Middlelayer.AccRepository.Entities ...@@ -33,7 +33,7 @@ namespace Siger.Middlelayer.AccRepository.Entities
/// <summary> /// <summary>
/// 附件 /// 附件
/// </summary> /// </summary>
public int attachment { get; set; } public string attachment { get; set; }
/// <summary> /// <summary>
/// 备注 /// 备注
/// </summary> /// </summary>
......
//-----------------------------------------------------------------------
// <copyright file=" siger_wms_storage.cs" company="xxxx Enterprises">
// * Copyright (C) 2019 xxxx Enterprises All Rights Reserved
// * version : 4.0.30319.42000
// * author : auto generated by T4
// * FileName: siger_wms_storage.cs
// * history : Created by T4 04/01/2019 09:14:26
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Siger.Middlelayer.AccRepository.Entities
{
/// <summary>
/// siger_wms_storage Entity Model
/// </summary>
public class siger_wms_storage : AccEntityBase
{
/// <summary>
/// 分类
/// </summary>
public int typeid { get; set; }
/// <summary>
/// 仓库名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 编号
/// </summary>
public string serial_number { get; set; }
/// <summary>
/// 仓库详细地址
/// </summary>
public string address { get; set; }
/// <summary>
/// 联系人
/// </summary>
public string manager { get; set; }
/// <summary>
///
/// </summary>
public int creator { get; set; }
/// <summary>
///
/// </summary>
public DateTime create_time { get; set; }
/// <summary>
///
/// </summary>
public int updator { get; set; }
/// <summary>
///
/// </summary>
public DateTime update_time { get; set; }
public string description { get; set; }
public string phone { get; set; }
public string mobile { get; set; }
public string option { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" siger_wms_storage_location.cs" company="xxxx Enterprises">
// * Copyright (C) 2019 xxxx Enterprises All Rights Reserved
// * version : 4.0.30319.42000
// * author : auto generated by T4
// * FileName: siger_wms_storage_location.cs
// * history : Created by T4 04/01/2019 09:14:26
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Siger.Middlelayer.AccRepository.Entities
{
/// <summary>
/// siger_wms_storage_location Entity Model
/// </summary>
public class siger_wms_storage_location : AccEntityBase
{
/// <summary>
/// 仓库id
/// </summary>
public int storageid { get; set; }
/// <summary>
/// 父类
/// </summary>
public int parentid { get; set; }
/// <summary>
///
/// </summary>
public string name { get; set; }
/// <summary>
/// 区分层级 区域1,货架2,层号3,位置4
/// </summary>
public int level { get; set; }
/// <summary>
/// 分类
/// </summary>
public int typeid { get; set; }
/// <summary>
/// 储位编号-只有level=4才有
/// </summary>
public string serial_number { get; set; }
/// <summary>
///
/// </summary>
public int creator { get; set; }
/// <summary>
///
/// </summary>
public DateTime create_time { get; set; }
/// <summary>
///
/// </summary>
public int updator { get; set; }
/// <summary>
///
/// </summary>
public DateTime update_time { get; set; }
public string option { get; set; }
public string realname { get; set; }
public int locationid { get; set; }
}
}
...@@ -37,7 +37,7 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -37,7 +37,7 @@ namespace Siger.Middlelayer.AccRepository.Repositories
category = p.name, category = p.name,
managetype = q.managetype, managetype = q.managetype,
partnumber = q.partnumber, partnumber = q.partnumber,
specifition = q.specifition, specification = q.specification,
number = q.number, number = q.number,
remark = q.remark, remark = q.remark,
attachment = q.attachment, attachment = q.attachment,
......
...@@ -4,7 +4,10 @@ using System.Linq.Expressions; ...@@ -4,7 +4,10 @@ using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Siger.Middlelayer.AccRepository.Entities; using Siger.Middlelayer.AccRepository.Entities;
using Siger.Middlelayer.AccRepository.Repositories.Interface; using Siger.Middlelayer.AccRepository.Repositories.Interface;
using Siger.Middlelayer.AccRepository.Response;
using Siger.Middlelayer.Common;
using Siger.Middlelayer.Repository.Data.Acc; using Siger.Middlelayer.Repository.Data.Acc;
using Siger.Middlelayer.Repository.Extensions;
using Siger.Middlelayer.Repository.Paged; using Siger.Middlelayer.Repository.Paged;
namespace Siger.Middlelayer.AccRepository.Repositories namespace Siger.Middlelayer.AccRepository.Repositories
...@@ -16,5 +19,63 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -16,5 +19,63 @@ namespace Siger.Middlelayer.AccRepository.Repositories
{ {
_context = context; _context = context;
} }
public IPagedCollectionResult<ResponseAutomationLocation> GetPagedList(int wavehouseid, int locationid, int projectid, int page, int pagesize)
{
var query = from q in _context.siger_automation_location
join t in _context.siger_automation_fixture_tools on q.fixturetools equals t.guid
join c in _context.siger_automation_fixture_tools_category on t.category equals c.guid
join l in _context.siger_wms_storage_location on q.locationid equals l.locationid
join w in _context.siger_wms_storage on l.storageid equals w.id
join m in _context.siger_tr_assist_materials on q.materialid equals m.id
join p in _context.siger_project_process on q.processid equals p.id into pp
from p in pp.DefaultIfEmpty()
join u in _context.siger_project_user on q.updator equals u.mid into uu
from u in uu.DefaultIfEmpty()
where q.projectId == projectid && q.status == (int)RowState.Valid
select new ResponseAutomationLocation
{
id = q.id,
locationid=l.id,
location=l.name,
wavehouseid=w.id,
wavehouse=w.name,
fixturetoolid=t.id,
fixturetool=t.name,
category=c.name,
code=t.code,
specfication=t.specification,
materialid=q.materialid,
materialcode=m.pn,
processid = q.processid,
processnumber = p == null ? 0 : p.Process_Seq,
processname = p.Process_name??"",
materialstate = q.materialstate,
attachment=q.attachment,
remark=q.remark,
updator = u.name ?? "",
status = q.status,
updatetime = q.updatetime.HasValue && q.updatetime > DateTime.MinValue ? q.updatetime.Value.ToString(ParameterConstant.DateTimeFormat) : ""
};
Expression<Func<ResponseAutomationLocation, bool>> wavehouseidExpression = f => true;
if (wavehouseid > 0)
{
wavehouseidExpression = q => q.wavehouseid == wavehouseid;
}
Expression<Func<ResponseAutomationLocation, bool>> locationidExpression = f => true;
if (locationid > 0)
{
locationidExpression = q => q.locationid == locationid;
}
var expression = wavehouseidExpression.And(locationidExpression);
var entities = query.Where(expression).OrderByDescending(q => q.id).Skip((page - 1) * pagesize).Take(pagesize).AsNoTracking().ToList();
var totalCount = query.Where(expression).Count();
return new PagedCollectionResult<ResponseAutomationLocation>(entities, totalCount);
}
public siger_wms_storage_location GetLocation(int id, int projectid)
{
return _context.siger_wms_storage_location.FirstOrDefault(q => q.locationid == id && q.projectId == projectid && q.status == (int)RowState.Valid);
}
} }
} }
using Siger.Middlelayer.AccRepository.Entities; using Siger.Middlelayer.AccRepository.Entities;
using Siger.Middlelayer.AccRepository.Response;
using Siger.Middlelayer.Repository.Data.Acc; using Siger.Middlelayer.Repository.Data.Acc;
using Siger.Middlelayer.Repository.Paged; using Siger.Middlelayer.Repository.Paged;
...@@ -6,6 +7,9 @@ namespace Siger.Middlelayer.AccRepository.Repositories.Interface ...@@ -6,6 +7,9 @@ namespace Siger.Middlelayer.AccRepository.Repositories.Interface
{ {
public interface IAutomationLocationRepository : IAccRepositoryBase<siger_automation_location> public interface IAutomationLocationRepository : IAccRepositoryBase<siger_automation_location>
{ {
IPagedCollectionResult<ResponseAutomationLocation> GetPagedList(int wavehouseid, int locationid, int projectid, int page, int pagesize);
siger_wms_storage_location GetLocation(int id, int projectid);
} }
} }
...@@ -90,4 +90,39 @@ namespace Siger.Middlelayer.AccRepository.Request ...@@ -90,4 +90,39 @@ namespace Siger.Middlelayer.AccRepository.Request
{ {
public int id { get; set; } public int id { get; set; }
} }
public class RequestAddAutomationLocation
{
/// <summary>
/// 储位位置
/// </summary>
public string locationid { get; set; }
/// <summary>
/// 工装ID
/// </summary>
public string fixturetoolid { get; set; }
/// <summary>
/// 物料ID
/// </summary>
public string materialid { get; set; }
/// <summary>
/// 工序ID
/// </summary>
public string processid { get; set; }
/// <summary>
/// 附件
/// </summary>
public string attachment { get; set; }
/// <summary>
/// 备注
/// </summary>
public string remark { get; set; }
}
public class RequestUpdateAutomationLocation : RequestAddAutomationLocation
{
public int id { get; set; }
}
} }
...@@ -53,7 +53,7 @@ namespace Siger.Middlelayer.AccRepository.Response ...@@ -53,7 +53,7 @@ namespace Siger.Middlelayer.AccRepository.Response
/// <summary> /// <summary>
/// 规格型号 /// 规格型号
/// </summary> /// </summary>
public string specifition { get; set; } public string specification { get; set; }
/// <summary> /// <summary>
/// 数量 /// 数量
/// </summary> /// </summary>
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Siger.Middlelayer.AccRepository.Response
{
public class ResponseAutomationLocation
{
public int id { get; set; }
/// <summary>
/// 储位位置
/// </summary>
public int locationid { get; set; }
public string location { get; set; }
public int wavehouseid { get; set; }
public string wavehouse { get; set; }
/// <summary>
/// 工装ID
/// </summary>
public int fixturetoolid { get; set; }
public string fixturetool { get; set; }
public string category { get; set; }
public string code { get; set; }
public string specfication { get; set; }
/// <summary>
/// 物料ID
/// </summary>
public int materialid { get; set; }
public string materialcode { get; set; }
/// <summary>
/// 工序ID
/// </summary>
public int processid { get; set; }
public int processnumber { get; set; }
public string processname { get; set; }
/// <summary>
/// 物料状态
/// </summary>
public int materialstate { get; set; }
/// <summary>
/// 附件
/// </summary>
public string attachment { get; set; }
/// <summary>
/// 备注
/// </summary>
public string remark { get; set; }
public string updator { get; set; }
public string updatetime { get; set; }
public int status { get; set; }
}
}
...@@ -201,7 +201,7 @@ CREATE TABLE IF NOT EXISTS `siger_automation_fixture_tools` ( ...@@ -201,7 +201,7 @@ CREATE TABLE IF NOT EXISTS `siger_automation_fixture_tools` (
`managetype` int(11) NOT NULL DEFAULT 0 COMMENT '管理类型', `managetype` int(11) NOT NULL DEFAULT 0 COMMENT '管理类型',
`partnumber` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '工装料号', `partnumber` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '工装料号',
`name` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '工装名称', `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '工装名称',
`specifition` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '规格型号', `specification` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '规格型号',
`number` int(11) NOT NULL DEFAULT 0 COMMENT '数量', `number` int(11) NOT NULL DEFAULT 0 COMMENT '数量',
`remark` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', `remark` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
`attachment` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '附件', `attachment` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '附件',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment