457 lines
19 KiB
C#
457 lines
19 KiB
C#
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_VISIT_PLANVMs;
|
|
using wtmProject.Model;
|
|
using BootstrapBlazor.Components;
|
|
using Org.BouncyCastle.Utilities;
|
|
using wtmProject.ViewModel._Admin.FrameworkOutRecordVMs;
|
|
using System.Threading.Tasks;
|
|
using wtmProject.ViewModel._Admin.FrameworkUserVMs;
|
|
using Elsa.Activities.Temporal;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Elsa.Models;
|
|
using Elsa.Server.Api.Endpoints.WorkflowInstances;
|
|
using DotLiquid.Util;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using WalkingTec.Mvvm.Core.Support.FileHandlers;
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
namespace wtmProject.Controllers
|
|
{
|
|
[Area("_Admin")]
|
|
[AuthorizeJwtWithCookie]
|
|
[ActionDescription("拜访计划维护")]
|
|
[ApiController]
|
|
[Route("api/WTM_VISIT_PLAN")]
|
|
[AllRights]
|
|
public partial class WTM_VISIT_PLANController : BaseApiController
|
|
{
|
|
[ActionDescription("Sys.Search")]
|
|
[HttpPost("Search")]
|
|
public IActionResult Search(WTM_VISIT_PLANSearcher searcher)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
var vm = Wtm.CreateVM<WTM_VISIT_PLANListVM>();
|
|
vm.Searcher = searcher;
|
|
return Content(vm.GetJson(enumToString: false));
|
|
}
|
|
else
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.Get")]
|
|
[HttpGet("{id}")]
|
|
public WTM_VISIT_PLANVM Get(string id)
|
|
{
|
|
var vm = Wtm.CreateVM<WTM_VISIT_PLANVM>(id);
|
|
return vm;
|
|
}
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
[HttpPost("Add")]
|
|
public async Task<IActionResult> Add(WTM_VISIT_PLANVM vm)
|
|
{
|
|
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
|
{
|
|
return Content(Localizer["_Admin.HasMainHost"]);
|
|
}
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
await vm.DoAddAsync();
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
return Ok(vm.Entity);
|
|
}
|
|
}
|
|
|
|
}
|
|
[ActionDescription("Sys.Edit")]
|
|
[HttpPut("Edit")]
|
|
public async Task<IActionResult> Edit(WTM_VISIT_PLANVM vm)
|
|
{
|
|
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
|
{
|
|
return Content(Localizer["_Admin.HasMainHost"]);
|
|
}
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
await vm.DoEditAsync(false);
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
return Ok(vm.Entity);
|
|
}
|
|
}
|
|
}
|
|
[HttpPost("BatchDelete")]
|
|
[ActionDescription("Sys.Delete")]
|
|
public async Task<IActionResult> BatchDelete(string[] ids)
|
|
{
|
|
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
|
{
|
|
return Content(Localizer["_Admin.HasMainHost"]);
|
|
}
|
|
var vm = Wtm.CreateVM<WTM_VISIT_PLANBatchVM>();
|
|
List<string> itcode = new List<string>();
|
|
if (ids != null && ids.Count() > 0)
|
|
{
|
|
vm.Ids = ids;
|
|
//itcode = DC.Set<WTM_VISIT_PLAN>().CheckIDs(new List<string>(ids)).Select(x => x.ID.ToString()).ToList();
|
|
//if()
|
|
var ur = DC.Set<WTM_VISIT_PLAN_USER>().Where(x => ids.Contains(x.VisitPlanId.ToString()));
|
|
DC.Set<WTM_VISIT_PLAN_USER>().RemoveRange(ur);
|
|
var ur2 = DC.Set<WTM_VISIT_PLAN_FILE>().Where(x => ids.Contains(x.VisitPlanId.ToString()));
|
|
DC.Set<WTM_VISIT_PLAN_FILE>().RemoveRange(ur2);
|
|
DC.SaveChanges();
|
|
}
|
|
else
|
|
{
|
|
return Ok();
|
|
}
|
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
|
{
|
|
return BadRequest(ModelState.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
//using (var tran = DC.BeginTransaction())
|
|
//{
|
|
// try
|
|
// {
|
|
|
|
// tran.Commit();
|
|
// }
|
|
// catch
|
|
// {
|
|
// tran.Rollback();
|
|
// }
|
|
//}
|
|
|
|
//await Wtm.RemoveUserCache(itcode.ToArray());
|
|
return Ok(ids.Count());
|
|
}
|
|
}
|
|
|
|
|
|
[ActionDescription("Sys.Export")]
|
|
[HttpPost("ExportExcel")]
|
|
public IActionResult ExportExcel(WTM_VISIT_PLANSearcher searcher)
|
|
{
|
|
var vm = Wtm.CreateVM<WTM_VISIT_PLANListVM>();
|
|
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_VISIT_PLANListVM>();
|
|
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_VISIT_PLANImportVM>();
|
|
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_VISIT_PLANImportVM vm)
|
|
{
|
|
if (vm!=null && (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData()))
|
|
{
|
|
return BadRequest(vm.GetErrorJson());
|
|
}
|
|
else
|
|
{
|
|
return Ok(vm?.EntityList?.Count ?? 0);
|
|
}
|
|
}
|
|
|
|
[ActionDescription("Sys.GetWTM_CUSTOMs")]
|
|
[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));
|
|
}
|
|
[ActionDescription("Sys.GetWTM_AREAs")]
|
|
[HttpGet("GetWTM_AREAs")]
|
|
public ActionResult GetWTM_AREAs()
|
|
{
|
|
var userAreas = DC.Set<WTM_USER_AREA>().Where(t => t.UserCode == Wtm.LoginUserInfo.ITCode).Select(m => m.AreaCode).ToList();
|
|
return Ok(DC.Set<WTM_AREA>().Where(x => userAreas.Contains(x.AreaCode)).GetSelectListItems(Wtm, x => x.AreaName ,null, false, false));
|
|
}
|
|
[ActionDescription("Sys.GetWTM_CUSTOM_PERSONs")]
|
|
[HttpGet("GetWTM_CUSTOM_PERSONs")]
|
|
public ActionResult GetWTM_CUSTOM_PERSONs()
|
|
{
|
|
return Ok(DC.Set<WTM_CUSTOM_PERSON>().GetSelectListItems(Wtm, x => x.PersonName));
|
|
}
|
|
[ActionDescription("Sys.GetWTM_CUSTOM_PERSONs_Temp")]
|
|
[HttpGet("GetWTM_CUSTOM_PERSONs_Temp")]
|
|
public ActionResult GetWTM_CUSTOM_PERSONs_Temp(Guid? CustomId)
|
|
{
|
|
if (CustomId != null)
|
|
{
|
|
return Ok(DC.Set<WTM_CUSTOM_PERSON>().Where(o => o.CustomId == CustomId).GetSelectListItems(Wtm, x => x.PersonName));
|
|
}
|
|
else
|
|
{
|
|
return Ok(DC.Set<WTM_CUSTOM_PERSON>().GetSelectListItems(Wtm, x => x.PersonName));
|
|
}
|
|
}
|
|
[ActionDescription("Sys.GetFrameworkUsers")]
|
|
[HttpGet("GetFrameworkUsers")]
|
|
public ActionResult GetFrameworkUsers()
|
|
{
|
|
return Ok(DC.Set<FrameworkUser>().OrderBy(t=>t.DisplayOrder).GetSelectListItems(Wtm, x => x.Name, x => x.ID,false,false));
|
|
}
|
|
[ActionDescription("Sys.GetFrameworkUsersById")]
|
|
[HttpGet("GetFrameworkUsersById")]
|
|
public ActionResult GetFrameworkUsersById(string id)
|
|
{
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
var userIds = DC.Set<WTM_VISIT_PLAN_USER>().Where(o => o.VisitPlanId == new Guid(id)).Select(t=>t.UserId).ToList();
|
|
return Ok(DC.Set<FrameworkUser>().Where(o => userIds.Contains(o.ID)).GetSelectListItems(Wtm, x => x.Name, x => x.ID));
|
|
}
|
|
else
|
|
{
|
|
return Ok(DC.Set<FrameworkUser>().GetSelectListItems(Wtm, x => x.Name, x => x.ID));
|
|
}
|
|
}
|
|
[ActionDescription("Sys.GetFrameworkUsersTemp")]
|
|
[HttpGet("GetFrameworkUsersTemp")]
|
|
public ActionResult GetFrameworkUsersTemp()
|
|
{
|
|
if (Wtm.LoginUserInfo != null)
|
|
{
|
|
return Ok(DC.Set<FrameworkUser>().Where(o => o.ITCode == Wtm.LoginUserInfo.ITCode).GetSelectListItems(Wtm, x => x.Name));
|
|
}
|
|
else
|
|
{
|
|
return Ok(DC.Set<FrameworkUser>().GetSelectListItems(Wtm, x => x.Name));
|
|
}
|
|
}
|
|
[ActionDescription("Sys.GetCustomArea")]
|
|
[HttpGet("GetCustomArea")]
|
|
public ActionResult GetCustomArea(Guid? CustomId)
|
|
{
|
|
WTM_VISIT_PLAN_Temp temp = new WTM_VISIT_PLAN_Temp();
|
|
var vm = DC.Set<WTM_CUSTOM>();
|
|
IQueryable<WTM_CUSTOM> CustomPerson = vm.Select(o => o);
|
|
if (CustomId != null)
|
|
{
|
|
CustomPerson = vm.Where(o => o.ID == CustomId);
|
|
}
|
|
temp = CustomPerson.Select(item => new WTM_VISIT_PLAN_Temp
|
|
{
|
|
AreaId = item.AreaId,
|
|
IndustryType = item.IndustryType
|
|
}).FirstOrDefault();
|
|
return Ok(temp);
|
|
}
|
|
[ActionDescription("Sys.GetVisitPlanViewTemp")]
|
|
[HttpGet("GetVisitPlanViewTemp")]
|
|
public ActionResult GetVisitPlanViewTemp(string name, string deviceType,string CrewInfoValue,string StartDate)
|
|
{
|
|
var temps = new List<WTM_VISIT_PLAN_View>();
|
|
var vm = DC.Set<WTM_VISIT_PLAN>();
|
|
IQueryable<WTM_VISIT_PLAN> visitPlan = vm.Select(o => o);
|
|
//if (!string.IsNullOrEmpty(name))
|
|
//{
|
|
// var id = new Guid(name);
|
|
// frameOutRecord = vm.Where(o => o.MarkManageId == id);
|
|
//}
|
|
if (deviceType == "Desktop" && !string.IsNullOrEmpty(CrewInfoValue))
|
|
{
|
|
var value = DateTime.Parse(CrewInfoValue);
|
|
var startValue = new DateTime(value.Year, value.Month, 1).Date;
|
|
var endValue = startValue.AddMonths(1).Date;//.AddDays(-1)
|
|
visitPlan = vm.Where(o => o.VisitStartTime >= startValue && o.VisitEndTime <= endValue);
|
|
}
|
|
if (deviceType == "Mobile" && !string.IsNullOrEmpty(StartDate))
|
|
{
|
|
var value = DateTime.Parse(StartDate).Date;
|
|
var endValue = value.AddDays(7).Date;
|
|
visitPlan = vm.Where(o => o.VisitStartTime >= value && o.VisitEndTime <= endValue);
|
|
}
|
|
var planIds = visitPlan.Select(o => o.ID).ToList();
|
|
var visitUser = DC.Set<WTM_VISIT_PLAN_USER>().Where(t => planIds.Contains((Guid)t.VisitPlanId)).ToList();
|
|
temps = visitPlan.Select(item => new WTM_VISIT_PLAN_View
|
|
{
|
|
ID = item.ID,
|
|
CustomAllName_view = item.Custom.CustomAllName,
|
|
Name_view = item.MarkManage.Name,
|
|
VisitStartTime = item.VisitStartTime,
|
|
VisitEndTime = item.VisitEndTime,
|
|
UserId = item.MarkManageId,
|
|
City = item.Custom.CustomCity
|
|
}).ToList();
|
|
var users = DC.Set<FrameworkUser>().Select(o => o).ToList();
|
|
var tempUsers = new List<WTM_VISIT_PLAN_View>();
|
|
foreach (var item in visitUser)
|
|
{
|
|
var temp = temps.FirstOrDefault(t => t.ID == item.VisitPlanId);
|
|
var user = users.FirstOrDefault(t => t.ID == item.UserId);
|
|
if (temp != null && user != null)
|
|
{
|
|
WTM_VISIT_PLAN_View view = new WTM_VISIT_PLAN_View();
|
|
view.ID = temp.ID;
|
|
view.CustomAllName_view = temp.CustomAllName_view;
|
|
view.VisitStartTime = temp.VisitStartTime;
|
|
view.VisitEndTime = temp.VisitEndTime;
|
|
view.Name_view = user.Name;
|
|
view.UserId = item.UserId;
|
|
view.City = temp.City;
|
|
tempUsers.Add(view);
|
|
}
|
|
}
|
|
temps.AddRange(tempUsers);
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
var list = name.Split(",").ToList();
|
|
var userList= new List<Guid>();
|
|
foreach (var item in list)
|
|
{
|
|
if (!string.IsNullOrEmpty(item))
|
|
{
|
|
var id = new Guid(item);
|
|
userList.Add(id);
|
|
}
|
|
}
|
|
temps = temps.Where(o => userList.Contains((Guid)o.UserId)).ToList();
|
|
}
|
|
return Ok(temps);
|
|
}
|
|
[ActionDescription("Sys.GetVisitPlans")]
|
|
[HttpGet("GetVisitPlans")]
|
|
public ActionResult GetVisitPlans()
|
|
{
|
|
var temps = new List<WTM_VISIT_PLAN_View>();
|
|
DateTime now = DateTime.Now;
|
|
int daysInMonth = DateTime.DaysInMonth(now.Year, now.Month);
|
|
var StartDate = new DateTime(now.Year, now.Month, 1); // 本月的第一天
|
|
var EndDate = new DateTime(now.Year, now.Month, daysInMonth); // 本月的最后一天
|
|
|
|
// 如果当前日期超过了本月的中间,则取上个月的最后一天到本月的开始日期
|
|
if (now > new DateTime(now.Year, now.Month, daysInMonth / 2))
|
|
{
|
|
StartDate = new DateTime(now.Year, now.Month - 1, 1); // 上个月的第一天
|
|
EndDate = new DateTime(now.Year, now.Month, 1).AddDays(-1); // 本月的第一天往前一天
|
|
}
|
|
var plans = DC.Set<WTM_VISIT_PLAN>().Where(o => o.MarkManageId == new Guid(Wtm.LoginUserInfo.UserId) && o.VisitStartTime >= StartDate && o.VisitStartTime <= EndDate).ToList();
|
|
var planIds = plans.Select(m => m.ID).ToList();
|
|
var planUsers = DC.Set<WTM_VISIT_PLAN_USER>().Where(o => planIds.Contains((Guid)o.VisitPlanId)).ToList();
|
|
var users = DC.Set<FrameworkUser>().ToList();
|
|
planUsers.ForEach(item =>
|
|
{
|
|
item.User = users.FirstOrDefault(o => o.ID == item.UserId);
|
|
});
|
|
var customs = DC.Set<WTM_CUSTOM>();
|
|
var persons = DC.Set<WTM_CUSTOM_PERSON>();
|
|
temps = plans.Select(item => new WTM_VISIT_PLAN_View
|
|
{
|
|
VisitStartTime = item.VisitStartTime,
|
|
VisitEndTime = item.VisitEndTime,
|
|
CustomAllName_view = customs.FirstOrDefault(o=>o.ID == item.CustomId)?.CustomAllName,
|
|
PersonName_view = persons.FirstOrDefault(o=>o.ID == item.VisitObjectId)?.PersonName,
|
|
VisitTarget = item.VisitTarget ==null?null:item.VisitTarget.Replace("\n",""),
|
|
VisitPersons = string.Join(",", planUsers.Where(o => o.VisitPlanId == item.ID).Select(v => v.User?.Name).ToList())
|
|
}).ToList();
|
|
return Ok(temps);
|
|
}
|
|
|
|
//[ActionDescription("Sys.Submit")]
|
|
//[HttpPost("SubmitAll")]
|
|
//public async Task<IActionResult> SubmitAlls(List<WTM_VISIT_PLAN_View> list)
|
|
//{
|
|
// using (var trans = DC.BeginTransaction())
|
|
// {
|
|
// try
|
|
// {
|
|
// if (list != null && list.Any())
|
|
// {
|
|
// foreach (var item in list)
|
|
// {
|
|
// var itemNew = new WTM_VISIT_PLAN();
|
|
// itemNew.ID = Guid.NewGuid();
|
|
// itemNew.AreaId = item.AreaId;
|
|
// itemNew.CustomId = item.CustomId;
|
|
// itemNew.VisitObjectId = item.VisitObjectId;
|
|
// itemNew.MarkManageId = item.MarkManageId;
|
|
// itemNew.VisitStartTime = item.VisitStartTime;
|
|
// itemNew.VisitEndTime = item.VisitEndTime;
|
|
// if (item.SelectedItemsID != null && item.SelectedItemsID.Any())
|
|
// {
|
|
// foreach (var select in item.SelectedItemsID)
|
|
// {
|
|
// WTM_VISIT_PLAN_USER r = new WTM_VISIT_PLAN_USER
|
|
// {
|
|
// VisitPlanId = itemNew.ID,
|
|
// UserId = new Guid(select),
|
|
// CreateBy = Wtm.LoginUserInfo?.ITCode,
|
|
// CreateTime = DateTime.Now,
|
|
// UpdateBy = Wtm.LoginUserInfo?.ITCode,
|
|
// UpdateTime = DateTime.Now,
|
|
// };
|
|
// DC.AddEntity(r);
|
|
// }
|
|
// }
|
|
// DC.AddEntity(itemNew);
|
|
// }
|
|
// }
|
|
// trans.Commit();
|
|
// }
|
|
// catch
|
|
// {
|
|
// trans.Rollback();
|
|
// }
|
|
// }
|
|
// return Ok();
|
|
//}
|
|
}
|
|
}
|
|
|