using DocumentServiceAPI.Application.DocManage.Dtos;
using DocumentServiceAPI.Application.DocManage.Services;
using DocumentServiceAPI.Model.cyDocumentModel;
using DocumentServiceAPI.Utility;
namespace DocumentServiceAPI.Application.DocManage
{
///
/// 资料分类管理
///
public class DocClassificationManageAppService : IDynamicApiController
{
private readonly DocClassificationService _classificationService;
public DocClassificationManageAppService(DocClassificationService classificationService)
{
_classificationService = classificationService;
}
///
/// 根据ID查询对象
///
///
///
public async Task GetInfo(int id)
{
var model =await _classificationService.GetByIdAsync(id);
return new JsonResult(model);
}
///
/// 根据分页条件查询分页数据
///
///
///
public async Task PostListPage(DocClassificationPageSearch page)
{
PageModel pg = new PageModel();
pg.PageSize = page.PageSize;
pg.PageIndex = page.PageIndex;
PageResult result = new PageResult();
if (page.Status.HasValue)
{
result.Items = await _classificationService.GetPageListAsync(c => c.status ==page.Status && c.parent_code == page.Code,pg,c=>c.sort_id,OrderByType.Asc);
}
else
{
result.Items = await _classificationService.GetPageListAsync(c => c.parent_code == page.Code, pg, c => c.sort_id, OrderByType.Asc);
}
result.TotalCount = pg.TotalCount;
result.PageIndex = pg.PageIndex;
result.PageSize = pg.PageSize;
return new JsonResult(result);
}
///
/// 根据类型查询数据
///
///
///
public async Task PostItemList(DocClassificationSearch page)
{
var data = await _classificationService.GetListAsync(c => c.status == 1 && c.parent_code == page.Code);
return new JsonResult(data.OrderBy(c=>c.sort_id).ToList());
}
///
/// 添加数据
///
///
///
public async Task PostAddInfo(Classification_Submit_Dto info)
{
Doc_Classification doc = new Doc_Classification();
doc.add_time = DateTime.Now;
doc.doc_classification = info.name;
doc.doc_classification_code = "";
doc.is_system = false;
doc.parent_code = info.code;
doc.sort_id = info.sort;
doc.status = info.status;
doc.tenant_code = info.tenant_id;
var msg =await _classificationService.InsertAsync(doc);
return new JsonResult(msg);
}
///
/// 修改数据
///
///
///
public async Task PostEdtInfo(Classification_Submit_Dto info)
{
var msg = false;
var model = await _classificationService.GetByIdAsync(info.id);
if (model != null)
{
model.add_time = DateTime.Now;
model.doc_classification = info.name;
model.status = info.status;
model.sort_id = info.sort;
msg = await _classificationService.UpdateAsync(model);
}
return new JsonResult(msg);
}
///
/// 删除数据
///
///
///
public async Task PostDelInfo(int id)
{
var msg = await _classificationService.DeleteByIdAsync(id);
return new JsonResult(msg);
}
}
}