using Microsoft.AspNetCore.Mvc;
using DOAN.Model.MES.group;
using DOAN.Model.MES.group.Dto;
using DOAN.Service.group.IService;
using DOAN.Admin.WebApi.Filters;
using SqlSugar.Extensions;
using System.Collections.Generic;
using System;
using static System.Runtime.InteropServices.JavaScript.JSType;
//创建时间:2024-08-08
namespace DOAN.Admin.WebApi.Controllers
{
///
/// 排班
///
[Verify]
[Route("mes/groupManagement/GroupSchedule")]
public class GroupScheduleController : BaseController
{
///
/// 排班接口
///
private readonly IGroupScheduleService _GroupScheduleService;
public GroupScheduleController(IGroupScheduleService GroupScheduleService)
{
_GroupScheduleService = GroupScheduleService;
}
///
/// 查询排班列表
///
///
///
[HttpGet("list")]
//[ActionPermissionFilter(Permission = "business:groupschedule:list")]
public IActionResult QueryGroupSchedule([FromQuery] GroupScheduleQueryDto parm)
{
var response = _GroupScheduleService.GetList(parm);
return SUCCESS(response);
}
///
/// 查询排班详情
///
///
///
[HttpGet("{Id}")]
// [ActionPermissionFilter(Permission = "business:groupschedule:query")]
public IActionResult GetGroupSchedule(string Id)
{
var response = _GroupScheduleService.GetInfo(Id);
var info = response.Adapt();
return SUCCESS(info);
}
///
/// 添加排班
///
///
[HttpPost]
// [ActionPermissionFilter(Permission = "business:groupschedule:add")]
[Log(Title = "排班", BusinessType = BusinessType.INSERT)]
public IActionResult AddGroupSchedule([FromBody] GroupScheduleDto parm)
{
var modal = parm.Adapt().ToCreate(HttpContext);
var response = _GroupScheduleService.AddGroupSchedule(modal);
return SUCCESS(response);
}
///
/// 更新排班
///
///
[HttpPut]
// [ActionPermissionFilter(Permission = "business:groupschedule:edit")]
[Log(Title = "排班", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateGroupSchedule([FromBody] GroupScheduleDto parm)
{
var modal = parm.Adapt().ToUpdate(HttpContext);
var response = _GroupScheduleService.UpdateGroupSchedule(modal);
return ToResponse(response);
}
//TODO 获取班组
[HttpGet("get_group")]
public IActionResult GetGroup(string group_name="", string group_code = "")
{
var response = _GroupScheduleService.GetALLGroup(group_code, group_name);
return SUCCESS(response);
}
///
/// 1 根据日期获取班组
///
///
///
[HttpGet("list_by_date")]
public IActionResult ListGroupByDate(GroupScheduleQueryDto2 query)
{
if (query.ScheduleDate == DateTime.MinValue)
{
return SUCCESS(null);
}
var response = _GroupScheduleService.ListGroupByDate(query);
return SUCCESS(response);
}
// TODO 2 根据日期添加班组
///
/// 添加排班
///
///
[HttpPost("bydate_add")]
[Log(Title = "排班", BusinessType = BusinessType.INSERT)]
public IActionResult AddGroupSchedule2([FromBody] GroupScheduleDto parm)
{
if (parm.ScheduleDate == DateTime.MinValue)
{
return SUCCESS(null);
};
parm.ScheduleDate = parm.ScheduleDate.Value.Date;
var modal = parm.Adapt().ToCreate(HttpContext);
var response = _GroupScheduleService.AddGroupSchedule(modal);
return SUCCESS(response);
}
// TODO
///
/// 3 删除班组
///
///
[HttpDelete("{ids}")]
// [ActionPermissionFilter(Permission = "business:groupschedule:delete")]
[Log(Title = "排班", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteGroupSchedule(string ids)
{
string[] idsArr = Tools.SpitStrArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _GroupScheduleService.Delete(idsArr);
return ToResponse(response);
}
///
/// //TODO 查询班组绑定的人员
///
/// 班组id
///
[HttpGet("list_person_bind")]
public IActionResult SearchPerson_group_bind(DateTime schedule_date, string group_code)
{
if (string.IsNullOrEmpty(group_code))
{
return SUCCESS(null);
}
var response = _GroupScheduleService.SearchPerson_group_bind(schedule_date.Date,group_code);
return SUCCESS(response);
}
///
/// TODO 查询排班未绑定的人员
///
/// 班id
///
[HttpPost("list_person_bind_no")]
public IActionResult SearchPerson_group_bind_No([FromBody] GroupScheduleQueryDto3 parm)
{
if (string.IsNullOrEmpty(parm.group_code))
{
return SUCCESS(null);
}
var response = _GroupScheduleService.SearchPerson_group_bind_No(parm);
return SUCCESS(response);
}
//TODO 班组添加人员
[HttpGet("add_person")]
public IActionResult GroupAddPerson(string group_code, string person_id,DateTime schedule_date)
{
if (string.IsNullOrEmpty(group_code)) { return SUCCESS(null); }
if (string.IsNullOrEmpty(person_id)) { return SUCCESS(null); }
var response = _GroupScheduleService
.GroupAddPerson(group_code, person_id, schedule_date, HttpContext.GetName());
return SUCCESS(response);
}
//TODO 班组删除人员
[HttpGet("delete_person")]
public IActionResult GroupRemovePerson(string group_code, string person_id)
{
if (string.IsNullOrEmpty(group_code)) { return SUCCESS(null); }
if (string.IsNullOrEmpty(person_id)) { return SUCCESS(null); }
var response = _GroupScheduleService
.GroupRemovePerson(group_code, person_id);
return SUCCESS(response);
}
//TODO 获取月份的排班情况
///
/// 获取月份的排班情况
///
///
/// <日期,排组的数量>
[HttpGet("month_schedule_result")]
public IActionResult GetMonthScheduleResult(string yearmonth)
{
if (string.IsNullOrEmpty(yearmonth)) { return SUCCESS(null); }
(int Year, int Month) ExtractYearAndMonth(string dateString)
{
if (DateTime.TryParseExact(dateString, "yyyy-MM", null, 0, out DateTime date)) // 使用 0 代替 None
{
return (date.Year, date.Month);
}
else
{
throw new ArgumentException("Invalid date format.", nameof(dateString));
}
}
(int Year, int Month) result = ExtractYearAndMonth(yearmonth);
var response = _GroupScheduleService.GetMonthScheduleResult(result.Year, result.Month);
return SUCCESS(response);
}
//TODO 复制班组
///
/// 复制班组
///
/// 要排的日期
/// -2 已有数据不可复制 -1 前一天无数据无法复制 >=1 复制的数量
[HttpGet("CopyGroup")]
public IActionResult CopyGroup(DateTime date)
{
var response= _GroupScheduleService.CopyPreDaySchedule(date,HttpContext.GetName());
return SUCCESS(response);
}
//TODO 获取工艺路线
public IActionResult GetAllRoutes()
{
var response = _GroupScheduleService.GetAllRoutes();
return SUCCESS(response);
}
//TODO 获取人员拥有的技能
public IActionResult GetSkillsOFperson(string person_id,int route_id)
{
var response = _GroupScheduleService.GetSkillsOFperson(person_id, route_id);
return SUCCESS(response);
}
}
}