2024-05-28 14:49:22 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using WalkingTec.Mvvm.Core;
|
|
|
|
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
|
|
|
|
using WalkingTec.Mvvm.Mvc;
|
|
|
|
|
|
using wtmProject.ViewModel._Admin.WTM_CONTRACTVMs;
|
|
|
|
|
|
using wtmProject.Model;
|
|
|
|
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
|
|
using NodaTime;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace wtmProject.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
[Area("_Admin")]
|
|
|
|
|
|
[AuthorizeJwtWithCookie]
|
|
|
|
|
|
[ActionDescription("合同管理")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("api/WTM_CONTRACT")]
|
|
|
|
|
|
public partial class WTM_CONTRACTController : BaseApiController
|
|
|
|
|
|
{
|
|
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
|
|
|
|
[HttpPost("Search")]
|
|
|
|
|
|
public IActionResult Search(WTM_CONTRACTSearcher searcher)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTListVM>();
|
|
|
|
|
|
vm.Searcher = searcher;
|
|
|
|
|
|
return Content(vm.GetJson(enumToString: false));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Get")]
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
public WTM_CONTRACTVM Get(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTVM>(id);
|
|
|
|
|
|
return vm;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
|
|
|
|
[HttpPost("Add")]
|
|
|
|
|
|
public IActionResult Add(WTM_CONTRACTVM vm)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.DoAdd();
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(vm.Entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
|
|
|
|
[HttpPut("Edit")]
|
|
|
|
|
|
public IActionResult Edit(WTM_CONTRACTVM vm)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.DoEdit(false);
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(vm.Entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("BatchDelete")]
|
|
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
|
|
|
|
public IActionResult BatchDelete(string[] ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTBatchVM>();
|
|
|
|
|
|
if (ids != null && ids.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.Ids = ids;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(ids.Count());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Export")]
|
|
|
|
|
|
[HttpPost("ExportExcel")]
|
|
|
|
|
|
public IActionResult ExportExcel(WTM_CONTRACTSearcher searcher)
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTListVM>();
|
|
|
|
|
|
vm.Searcher = searcher;
|
|
|
|
|
|
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
|
|
|
|
|
return vm.GetExportData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.CheckExport")]
|
|
|
|
|
|
[HttpPost("ExportExcelByIds")]
|
|
|
|
|
|
public IActionResult ExportExcelByIds(string[] ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTListVM>();
|
|
|
|
|
|
if (ids != null && ids.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.Ids = new List<string>(ids);
|
|
|
|
|
|
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
|
|
|
|
|
}
|
|
|
|
|
|
return vm.GetExportData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.DownloadTemplate")]
|
|
|
|
|
|
[HttpGet("GetExcelTemplate")]
|
|
|
|
|
|
public IActionResult GetExcelTemplate()
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = Wtm.CreateVM<WTM_CONTRACTImportVM>();
|
|
|
|
|
|
var qs = new Dictionary<string, string>();
|
|
|
|
|
|
foreach (var item in Request.Query.Keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
qs.Add(item, Request.Query[item]);
|
|
|
|
|
|
}
|
|
|
|
|
|
vm.SetParms(qs);
|
|
|
|
|
|
var data = vm.GenerateTemplate(out string fileName);
|
|
|
|
|
|
return File(data, "application/vnd.ms-excel", fileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Import")]
|
|
|
|
|
|
[HttpPost("Import")]
|
|
|
|
|
|
public ActionResult Import(WTM_CONTRACTImportVM vm)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (vm!=null && (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return BadRequest(vm.GetErrorJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(vm?.EntityList?.Count ?? 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("GetWTM_CUSTOMs")]
|
|
|
|
|
|
public ActionResult GetWTM_CUSTOMs()
|
|
|
|
|
|
{
|
|
|
|
|
|
var userAreas = DC.Set<WTM_USER_AREA>().Where(t => t.UserCode == Wtm.LoginUserInfo.ITCode).Select(m => m.AreaCode).ToList();
|
|
|
|
|
|
return Ok(DC.Set<WTM_CUSTOM>().Where(t => t.Area != null && userAreas.Contains(t.Area.AreaCode)).GetSelectListItems(Wtm, x => x.CustomAllName));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("GetWTM_CUSTOM_PERSONs")]
|
|
|
|
|
|
public ActionResult GetWTM_CUSTOM_PERSONs()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(DC.Set<WTM_CUSTOM_PERSON>().GetSelectListItems(Wtm, x => x.PersonName));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("GetFrameworkUsers")]
|
|
|
|
|
|
public ActionResult GetFrameworkUsers()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok(DC.Set<FrameworkUser>().OrderBy(m => m.DisplayOrder).GetSelectListItems(Wtm, x => x.Name, null, false, false));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("GetWTM_PROJECTs")]
|
|
|
|
|
|
public ActionResult GetWTM_PROJECTs()
|
|
|
|
|
|
{
|
|
|
|
|
|
var userProjects = DC.Set<WTM_USER_PROJECT>().Where(t => t.UserCode == Wtm.LoginUserInfo.ITCode).Select(m => m.ProjectCode).ToList();
|
|
|
|
|
|
return Ok(DC.Set<WTM_PROJECT>().Where(x => userProjects.Contains(x.ProjectCode)).GetSelectListItems(Wtm, x => x.ProjectName));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|