Commit 6a44de0c by xin.yang

some update

parent d46d88c5
...@@ -31,6 +31,137 @@ namespace Siger.ApiACC.Controllers ...@@ -31,6 +31,137 @@ namespace Siger.ApiACC.Controllers
_toolsAssemblyRepository = toolsAssemblyRepository; _toolsAssemblyRepository = toolsAssemblyRepository;
} }
[HttpGet]
public IActionResult GetPageList(int id, int page, int pagesize)
{
var data = _toolsCategoryRepository.GetPagedList(id, ProjectId, page, pagesize);
return new PagedObjectResult(data.Data, data.Total, page, pagesize);
}
[HttpPost]
public IActionResult Add([FromBody]RequestAddFixtureToolsCategory req)
{
var data = _toolsCategoryRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.name == req.name);
if (data != null)
{
throw new BadRequestException(RequestEnum.DataExist);
}
var parent = "";
if(req.parentid.ToInt() > 0)
{
var exsit = _toolsCategoryRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.id == req.parentid.ToInt());
if(exsit == null)
{
throw new BadRequestException(CommonEnum.RecordNotFound);
}
else
{
parent = exsit.guid;
}
}
var entity = new siger_automation_fixture_tools_category
{
name = req.name,
parent = parent,
guid = Guid.NewGuid().ToString(),
projectId = ProjectId,
createtime = DateTime.Now,
updatetime = DateTime.Now,
};
_toolsCategoryRepository.Insert(entity);
if (_unitOfWork.Commit() > 0)
{
return new ObjectResult(CommonEnum.Succefull);
}
else
{
throw new BadRequestException(CommonEnum.Fail);
}
}
[HttpPost]
public IActionResult Update([FromBody]RequestUpdateFixtureToolsCategory req)
{
var entity = _toolsCategoryRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.id == req.id);
var data = _toolsCategoryRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.name == req.name &&
q.id != req.id);
if (data != null)
{
throw new BadRequestException(RequestEnum.DataExist);
}
var parent = "";
if (req.parentid.ToInt() > 0)
{
var exsit = _toolsCategoryRepository.Get(q => q.projectId == ProjectId && q.status == (int)RowState.Valid && q.id == req.parentid.ToInt());
if (exsit == null)
{
throw new BadRequestException(CommonEnum.RecordNotFound);
}
else
{
parent = exsit.guid;
}
}
entity.name = req.name;
entity.parent = parent;
entity.guid = Guid.NewGuid().ToString();
entity.updatetime = DateTime.Now;
_toolsCategoryRepository.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 = _toolsCategoryRepository.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;
_toolsCategoryRepository.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 = _toolsCategoryRepository.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;
_toolsCategoryRepository.Update(entity);
}
if (_unitOfWork.Commit() > 0)
return new ObjectResult(CommonEnum.Succefull);
throw new BadRequestException(CommonEnum.Fail);
}
} }
} }
...@@ -12,9 +12,9 @@ namespace Siger.Middlelayer.AccRepository.Entities ...@@ -12,9 +12,9 @@ namespace Siger.Middlelayer.AccRepository.Entities
public string parent { get; set; } public string parent { get; set; }
public DateTime createTime { get; set; } public DateTime createtime { get; set; }
public DateTime? updateTime { get; set; } public DateTime? updatetime { get; set; }
public string extend1 { get; set; } public string extend1 { get; set; }
} }
......
...@@ -4,6 +4,8 @@ using System.Linq.Expressions; ...@@ -4,6 +4,8 @@ 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.Paged; using Siger.Middlelayer.Repository.Paged;
...@@ -16,5 +18,31 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -16,5 +18,31 @@ namespace Siger.Middlelayer.AccRepository.Repositories
{ {
_context = context; _context = context;
} }
public IPagedCollectionResult<ResponseFixtureToolsCategory> GetPagedList(int id, int projectid, int page, int pagesize)
{
Expression<Func<ResponseFixtureToolsCategory, bool>> FunNum = f => true;
var query = from q in _context.siger_automation_fixture_tools_category
join p in _context.siger_automation_fixture_tools_category on q.parent equals p.guid
where q.projectId == projectid && q.status == (int)RowState.Valid
select new ResponseFixtureToolsCategory
{
id = q.id,
name = q.name,
parentid = p == null ? 0 : p.id,
parentname = p.name ?? "",
parent = q.parent,
guid = q.guid,
createtime = q.createtime.ToString(ParameterConstant.DateTimeFormat),
time = q.createtime
};
if (id > 0)
{
FunNum = q => q.id == id;
}
var entities = query.Where(FunNum).OrderBy(q => q.parentid).OrderBy(q => q.createtime).Skip((page - 1) * pagesize).Take(pagesize).AsNoTracking().ToList();
var totalCount = query.Where(FunNum).Count();
return new PagedCollectionResult<ResponseFixtureToolsCategory>(entities, totalCount);
}
} }
} }
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,5 +7,6 @@ namespace Siger.Middlelayer.AccRepository.Repositories.Interface ...@@ -6,5 +7,6 @@ namespace Siger.Middlelayer.AccRepository.Repositories.Interface
{ {
public interface IAutomationFixtureToolsCategoryRepository : IAccRepositoryBase<siger_automation_fixture_tools_category> public interface IAutomationFixtureToolsCategoryRepository : IAccRepositoryBase<siger_automation_fixture_tools_category>
{ {
IPagedCollectionResult<ResponseFixtureToolsCategory> GetPagedList(int id, int projectid, int page, int pagesize);
} }
} }
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Siger.Middlelayer.Common.ModuleEnum;
using Siger.Middlelayer.Repository.Request;
namespace Siger.Middlelayer.AccRepository.Request
{
public class RequestAddFixtureToolsCategory
{
public string parentid { get; set; }
public string name { get; set; }
}
public class RequestUpdateFixtureToolsCategory : RequestAddFixtureToolsCategory
{
public int id { get; set; }
}
public class RequestDeleteRange
{
public List<int> ids { get; set; } = new List<int>();
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Siger.Middlelayer.AccRepository.Response
{
public class ResponseFixtureToolsCategory
{
public int id { get; set; }
public string name { get; set; }
public int parentid { get; set; }
public string parentname { get; set; }
public string guid { get; set; }
public string parent { get; set; }
public DateTime time { get; set; }s
public string createtime { get; set; }
public string updatetime { get; set; }
public string extend1 { get; set; }
}
}
...@@ -184,8 +184,8 @@ CREATE TABLE IF NOT EXSIT `siger_automation_fixture_tools_category` ( ...@@ -184,8 +184,8 @@ CREATE TABLE IF NOT EXSIT `siger_automation_fixture_tools_category` (
`parent` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'siger_automation_fixture_tools_category.guid', `parent` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'siger_automation_fixture_tools_category.guid',
`projectid` int(11) NOT NULL, `projectid` int(11) NOT NULL,
`status` int(11) NOT NULL, `status` int(11) NOT NULL,
`createTime` datetime(0) NOT NULL, `createtime` datetime(0) NOT NULL,
`updateTime` datetime(0) NULL DEFAULT NULL, `updatetime` datetime(0) NULL DEFAULT NULL,
`extend1` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `extend1` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
......
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