123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472 |
- using Aspose.Cells;
- using FluentValidation;
- using Microsoft.AspNetCore.SignalR;
- using OASystem.API.OAMethodLib;
- using OASystem.API.OAMethodLib.Hub.HubClients;
- using OASystem.API.OAMethodLib.Hub.Hubs;
- using OASystem.API.OAMethodLib.QiYeWeChatAPI;
- using OASystem.API.OAMethodLib.Quartz.Business;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Dtos.PersonnelModule;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.PersonnelModule;
- using OASystem.Domain.ViewModels.PersonnelModule;
- using OASystem.Domain.ViewModels.QiYeWeChat;
- using OASystem.Infrastructure.Repositories.PersonnelModule;
- using System.Collections;
- using System.Data;
- using System.Diagnostics;
- using System.Globalization;
- using static OASystem.API.OAMethodLib.JWTHelper;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 人事模块
- /// </summary>
- [Route("api/[controller]/[action]")]
- public class PersonnelModuleController : ControllerBase
- {
- private Result _result;
- private readonly IMapper _mapper;
- private readonly decimal _chengDuMinimumWage = 2100.00M;
- private readonly IQiYeWeChatApiService _qiYeWeChatApiService;
- private readonly WageSheetRepository _wageSheetRep;
- private readonly UsersRepository _usersRep;
- private readonly TaskAllocationRepository _taskAllocationRep;
- private readonly SqlSugarClient _sqlSugar;
- private readonly IHubContext<ChatHub, IChatClient> _hubContext;
- private readonly GoodsRepository _goodsRep;
- private string url, path;
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="qiYeWeChatApiService"></param>
- /// <param name="wageSheetRep"></param>
- /// <param name="usersRep"></param>
- /// <param name="mapper"></param>
- /// <param name="taskAllocationRep"></param>
- /// <param name="hubContext"></param>
- /// <param name="goodsRep"></param>
- /// <param name="sqlSugar"></param>
- public PersonnelModuleController(
- IHubContext<ChatHub, IChatClient> hubContext,
- IMapper mapper,
- IQiYeWeChatApiService qiYeWeChatApiService,
- WageSheetRepository wageSheetRep,
- UsersRepository usersRep,
- TaskAllocationRepository taskAllocationRep,
- GoodsRepository goodsRep,
- SqlSugarClient sqlSugar
- )
- {
- _mapper = mapper;
- _usersRep = usersRep;
- _qiYeWeChatApiService = qiYeWeChatApiService;
- _wageSheetRep = wageSheetRep;
- _result = new Result();
- _sqlSugar = sqlSugar;
- url = AppSettingsHelper.Get("ExcelBaseUrl");
- path = AppSettingsHelper.Get("ExcelBasePath");
- if (!System.IO.Directory.Exists(path))
- {
- System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
- }
- this._taskAllocationRep = taskAllocationRep;
- _hubContext = hubContext;
- _goodsRep = goodsRep;
- }
- #region 工资表单
- /// <summary>
- /// 工资 月列表
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetMonth()
- {
- string sql = string.Format("Select * From Pm_WageIssueWorkingDay Where IsDel = 0 Order By YearMonth Desc");
- var data = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetMonthView>(sql).ToListAsync();
- return Ok(JsonView(true, "查询成功!", data));
- }
- /// <summary>
- /// 工资 工作日信息
- /// 查询
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetMonthWorkdays(string startDt, string endDt)
- {
- //参数处理
- var dtFormat = "yyyy-MM-dd";
- DateTime startDt1, endDt1;
- var startDtIsValid = DateTime.TryParseExact(startDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt1);
- var endDtIsValid = DateTime.TryParseExact(endDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt1);
- if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
- if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
- var sql = string.Format(@"Select * From Sys_Calendar
- Where Isdel = 0 And Dt between '{0}' And '{1}'", startDt, endDt);
- var data = await _wageSheetRep._sqlSugar.SqlQueryable<CalendarInfoView>(sql).ToListAsync();
- return Ok(JsonView(true, "查询成功!", data));
- }
- /// <summary>
- /// 工资 工作日信息
- /// 编辑
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetMonthWorkdaysAddOrEdit(WageSheetMonthWorkdaysAddOrEditDto dto)
- {
- //参数处理
- string yearFormat = "yyyy-MM";
- string dtFormat = "yyyy-MM-dd";
- DateTime yearDt, startDt1, endDt1;
- bool yearDtIsValid = DateTime.TryParseExact(dto.YearMonth, yearFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDt);
- bool startDtIsValid = DateTime.TryParseExact(dto.StartDate, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt1);
- bool endDtIsValid = DateTime.TryParseExact(dto.EndDate, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt1);
- if (!yearDtIsValid) return Ok(JsonView(false, "年月日期格式错误!正确时间格式:yyyy-MM "));
- if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
- if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
- #region 处理数据
- Pm_WageIssueWorkingDay pm_WageIssueWorkingDay1 = new Pm_WageIssueWorkingDay();
- pm_WageIssueWorkingDay1 = _mapper.Map<Pm_WageIssueWorkingDay>(dto);
- List<Sys_Calendar> sys_Calendars = new List<Sys_Calendar>();
- sys_Calendars = _mapper.Map<List<Sys_Calendar>>(dto.CalendarInfos);
- if (sys_Calendars.Count > 0)
- {
- sys_Calendars = sys_Calendars.OrderBy(it => it.Dt).ToList();
- }
- pm_WageIssueWorkingDay1.Workdays = sys_Calendars.Where(it => it.IsWorkDay == true).ToList().Count;
- foreach (var item in sys_Calendars)
- {
- item.Remark = pm_WageIssueWorkingDay1.Remark;
- item.CreateUserId = pm_WageIssueWorkingDay1.CreateUserId;
- item.CreateTime = pm_WageIssueWorkingDay1.CreateTime;
- }
- #endregion
- var _sqlSugar = _wageSheetRep._sqlSugar;
- _sqlSugar.BeginTran();
- try
- {
- List<Sys_Calendar> sys_Calendars_add = new List<Sys_Calendar>();
- List<Sys_Calendar> sys_Calendars_update = new List<Sys_Calendar>();
- sys_Calendars_add = sys_Calendars.Where(it => it.Id == 0).OrderBy(it => it.Dt).ToList();
- sys_Calendars_update = sys_Calendars.Where(it => it.Id != 0).OrderBy(it => it.Dt).ToList();
- int add1 = 0;
- int upd = 0;
- if (sys_Calendars_add.Count > 0)
- {
- var calendarsAdd = await _sqlSugar.Insertable(sys_Calendars_add).ExecuteReturnIdentityAsync();
- if (calendarsAdd < 0)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "工作日/节假日/休息日添加失败!"));
- }
- }
- if (sys_Calendars_update.Count > 0)
- {
- var calendarsUpdate = await _sqlSugar.Updateable<Sys_Calendar>(sys_Calendars)
- .UpdateColumns(it => new { it.Dt, it.IsWorkDay, it.IsHoliDay, it.HoliName })
- .WhereColumns(it => it.Id)
- .ExecuteCommandAsync();
- if (calendarsUpdate < 0)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "工作日/节假日/休息日编辑失败!"));
- }
- }
- var calendarsDatas = await _sqlSugar.Queryable<Sys_Calendar>()
- .Where(it => Convert.ToDateTime(it.Dt) >= Convert.ToDateTime(dto.StartDate) && Convert.ToDateTime(it.Dt) <= Convert.ToDateTime(dto.EndDate)).ToListAsync();
- if (calendarsDatas.Count < 0)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "日期包暂无工作日/节假日/休息日的信息!"));
- }
- //月份表是否存在
- Pm_WageIssueWorkingDay pm_WageIssueWorkingDay = new Pm_WageIssueWorkingDay()
- {
- YearMonth = dto.YearMonth,
- StartDate = dto.StartDate,
- EndDate = dto.EndDate,
- Workdays = calendarsDatas.Where(it => it.IsWorkDay == true).ToList().Count
- };
- string sql = string.Format("Select * From Pm_WageIssueWorkingDay Where Isdel = 0 And YearMonth='{0}'", dto.YearMonth);
- var workdsys = await _sqlSugar.SqlQueryable<Pm_WageIssueWorkingDay>(sql).FirstAsync();
- pm_WageIssueWorkingDay.CreateUserId = dto.UserId;
- pm_WageIssueWorkingDay.IsDel = 0;
- if (workdsys == null) //添加
- {
- int addId = await _sqlSugar.Insertable(pm_WageIssueWorkingDay).ExecuteReturnIdentityAsync();
- if (addId < 0)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "工作日设置添加失败!"));
- }
- }
- else //更新
- {
- int updCount = await _sqlSugar.Updateable(pm_WageIssueWorkingDay)
- .IgnoreColumns(z => new { z.CreateUserId, z.CreateTime, z.DeleteUserId, z.DeleteTime, z.IsDel })
- .WhereColumns(it => it.YearMonth)
- .ExecuteCommandAsync();
- if (updCount < 0)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "工作日设置编辑失败!"));
- }
- }
- _sqlSugar.CommitTran();
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception ex)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 工资表单 基础数据源
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetBasicsDataSource()
- {
- string companySql = string.Format("Select * From Sys_Company Where IsDel = 0");
- var compnayData = await _wageSheetRep._sqlSugar.SqlQueryable<CompanyNameView>(companySql).ToListAsync();
- string depSql = string.Format("Select * From Sys_Department Where IsDel = 0");
- var depData = await _wageSheetRep._sqlSugar.SqlQueryable<Domain.ViewModels.System.DepartmentView>(depSql).ToListAsync();
- //获取OA系统内所有用户
- var nameData = await _usersRep.GetUserNameList(1);
- if (nameData.Code != 0)
- {
- return Ok(JsonView(false, nameData.Msg));
- }
- var data = new
- {
- compnayData = compnayData,
- depData = depData,
- userNames = nameData.Data
- };
- return Ok(JsonView(true, "查询成功!", data));
- }
- /// <summary>
- /// 获取工资发放月份
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageYaerMonths(WageYearDto dto)
- {
- string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
- Where Isdel = 0 And YearMonth Like '%{0}%'
- Order By YearMonth Asc", dto.Year);
- var data = await _wageSheetRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).ToListAsync();
- return Ok(JsonView(true, "操作成功!", data));
- }
- /// <summary>
- /// 获取工资表单
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetList(WageSheetListDto dto)
- {
- //参数处理
- string ymFormat = "yyyy-MM";
- DateTime yearMonthDt;
- bool yearMonthDttIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- if (!yearMonthDttIsValid)
- {
- _result.Msg = "年月格式错误!正确时间格式:yyyy-MM ";
- return Ok(JsonView(false, _result.Msg));
- }
- //获取月工资数据
- string yearMonth = yearMonthDt.ToString("yyyy-MM");
- if (dto.PortType == 1)
- {
- _result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(yearMonth);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- else if (dto.PortType == 2)
- { }
- else if (dto.PortType == 3)
- { }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口参数"));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 获取工资 详情
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetById(WageSheetInfoDto dto)
- {
- if (dto.PortType == 1)
- {
- _result = await _wageSheetRep.Get_WageSheet_InfoByIdAsync(dto.Id);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- else if (dto.PortType == 2)
- { }
- else if (dto.PortType == 3)
- { }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口参数"));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 人事模块 工资表单 删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostWageSheetDel(WageDelDto dto)
- {
- try
- {
- _result = await _wageSheetRep.Post_WageSheet_DelAsync(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 人事模块 工资表单 添加 Or 修改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostWageSheetAddOrEdit(WageAddOrEditDto dto)
- {
- try
- {
- Pm_WageSheet pm_WageSheet = new Pm_WageSheet();
- pm_WageSheet = _mapper.Map<Pm_WageSheet>(dto);
- pm_WageSheet.LastUpdateUserId = dto.CreateUserId;
- #region 计算工资
- //月工资
- decimal salary = pm_WageSheet.Basic + pm_WageSheet.Floats + pm_WageSheet.PostAllowance + pm_WageSheet.InformationSecurityFee + pm_WageSheet.OtherSubsidies;
- //扣款合计
- decimal totalDeduction = pm_WageSheet.SickLeave + pm_WageSheet.SomethingFalse + pm_WageSheet.LateTo + pm_WageSheet.LeaveEarly + pm_WageSheet.Absenteeism + pm_WageSheet.NotPunch +
- pm_WageSheet.ReservedFunds + pm_WageSheet.WithholdingInsurance + pm_WageSheet.OtherDeductions + pm_WageSheet.OtherDeductions;
- //实发合计 不含个税
- if (pm_WageSheet.RegularDays >= pm_WageSheet.WorkDays)
- {
- pm_WageSheet.RegularDays = pm_WageSheet.WorkDays;
- salary = salary + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle;
- }
- else
- {
- if (dto.UserId == 21) //21==张海麟
- {
- salary = salary + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle;
- }
- else
- {
- salary = PayrollComputation.ConvertToDecimal(salary / pm_WageSheet.WorkDays * pm_WageSheet.RegularDays + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle);
- }
- }
- decimal actualTotal = salary - totalDeduction;
- pm_WageSheet.Should = salary;
- pm_WageSheet.TotalDeductions = totalDeduction;
- pm_WageSheet.TotalRealHair = actualTotal - pm_WageSheet.WithholdingTax;
- pm_WageSheet.AfterTax = actualTotal - pm_WageSheet.WithholdingTax;
- #endregion
- _result = await _wageSheetRep.Post_WageSheet_AddOrEditAsync(dto, pm_WageSheet);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 计算工资
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SalaryCalculatorAsync(SalaryCalculatorDto dto)
- {
- Result result = new Result();
- Stopwatch sw = new Stopwatch();
- sw.Start();
- //参数处理
- string ymFormat = "yyyy-MM";
- string dtFormat = "yyyy-MM-dd";
- DateTime yearMonthDt, startDt, endDt;
- bool yearMonthDtIsValid = DateTime.TryParseExact(dto.yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- bool startDtIsValid = DateTime.TryParseExact(dto.startDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt);
- bool endDtIsValid = DateTime.TryParseExact(dto.endDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt);
- if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
- if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
- if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
- string thisYearMonth = dto.yearMonth;
- string preYearMonth = yearMonthDt.AddMonths(-1).ToString("yyyy-MM");
- //计算本月工资起止时间 比如是2月的1号-28号,那就是2月1号的零点到3月1号的零点
- DateTime thisStartDt = startDt;
- DateTime thisEndDt = endDt; //
- //本月工资是否有数据 有数据则不计算
- result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(thisYearMonth);
- if (result.Code == 0)
- {
- return Ok(JsonView(false, thisYearMonth + " 工资数据已存在,若无人员工资请手动添加!"));
- }
- //获取上个月工资信息
- List<Pm_WageSheet> preWageSheetItems = await _wageSheetRep._sqlSugar.Queryable<Pm_WageSheet>().Where(it => it.IsDel == 0 && it.YearMonth == preYearMonth).ToListAsync();
- preWageSheetItems = preWageSheetItems.OrderBy(it => it.UserId).ToList();
- if (preWageSheetItems.Count <= 0)
- {
- return Ok(JsonView(false, thisYearMonth + " 上月工资数据不存在,请手动添加!"));
- }
- //处理上个月同月同人 多条数据
- List<Pm_WageSheet> preWageSheetItems1 = new List<Pm_WageSheet>();
- preWageSheetItems1 = preWageSheetItems.GroupBy(it => new { it.YearMonth, it.UserId })
- .Select(it => it.FirstOrDefault(item => item.Basic != 0))
- .ToList();
- //获取OA系统内所有用户
- List<UserNameView> userNames = _usersRep._sqlSugar.SqlQueryable<UserNameView>("Select Id,CnName From Sys_Users").ToList();
- List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
- _result = await PayrollComputation.SalaryCalculatorAsync(preWageSheetItems1, userNames, dto.UserId, thisYearMonth, thisStartDt, thisEndDt);
- #region 批量添加
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- wageSheets = _result.Data;
- var add = await _wageSheetRep._sqlSugar.Insertable(wageSheets).ExecuteCommandAsync();
- if (add <= 0)
- {
- return Ok(JsonView(false, "操作失败!"));
- }
- #endregion
- #region 处理返回数据
- //List <WageSheetItemInfoView> wageSheetItems = new List<WageSheetItemInfoView>();
- //wageSheetItems = _mapper.Map<List<WageSheetItemInfoView>>(wageSheets);
- //wageSheetItems = wageSheetItems.Select(it =>
- // {
- // UserNameView? uName1 = new UserNameView();
- // UserNameView? uName2 = new UserNameView();
- // uName1 = userNames.Where(it1 => it.UserId == it1.Id).FirstOrDefault();
- // if (uName1 != null) it.Name = uName1.CnName;
- // uName2 = userNames.Where(it1 => it.LastUpdateUserId == it1.Id).FirstOrDefault();
- // if (uName2 != null) it.LastUpdateUserName = uName2.CnName;
- // return it; }
- // ).ToList();
- #endregion
- sw.Stop();
- return Ok(JsonView(true, "操作成功! 耗时:" + (sw.ElapsedMilliseconds / 1000) + "s"));
- }
- /// <summary>
- /// 计算工资 By YearMonth And UserId
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SalaryCalculatorSingleAsync(SalaryCalculatorSingleDto dto)
- {
- Result result = new Result();
- Stopwatch sw = new Stopwatch();
- sw.Start();
- //参数处理
- string ymFormat = "yyyy-MM";
- string ymdFormat = "yyyy-MM-dd";
- DateTime yearMonthDt, startDt, endDt;
- bool yearMonthDtIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- bool startDtIsValid = DateTime.TryParseExact(dto.StartDate, ymdFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt);
- bool endDtIsValid = DateTime.TryParseExact(dto.EndDate, ymdFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt);
- if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
- if (!startDtIsValid) return Ok(JsonView(false, "开始时间格式错误!正确时间格式:yyyy-MM-dd "));
- if (!yearMonthDtIsValid) return Ok(JsonView(false, "结束时间格式错误!正确时间格式:yyyy-MM-dd "));
- List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
- Pm_WageSheet wageSheet = _mapper.Map<Pm_WageSheet>(dto);
- Pm_WageSheet wageSheet1 = await _wageSheetRep._sqlSugar.Queryable<Pm_WageSheet>().Where(it => it.UserId == dto.UserId && it.YearMonth == dto.YearMonth && it.StartDate == dto.StartDate && it.EndDate == dto.EndDate).FirstAsync();
- if (wageSheet1 != null)
- {
- wageSheet.Id = wageSheet1.Id;
- }
- wageSheets.Add(wageSheet);
- //获取OA系统内所有用户
- List<UserNameView> userNames = _usersRep._sqlSugar.SqlQueryable<UserNameView>("Select Id,CnName From Sys_Users").ToList();
- _result = await PayrollComputation.SalaryCalculatorAsync(wageSheets, userNames, dto.UserId, dto.YearMonth, startDt, endDt);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- List<Pm_WageSheet> wageSheets1 = new List<Pm_WageSheet>();
- wageSheets1 = _result.Data;
- #region 处理返回数据
- List<WageSheetInfoView> wageSheetItems = new List<WageSheetInfoView>();
- wageSheetItems = _mapper.Map<List<WageSheetInfoView>>(wageSheets1);
- wageSheetItems = wageSheetItems.Select(it =>
- {
- UserNameView? uName1 = new UserNameView();
- UserNameView? uName2 = new UserNameView();
- uName1 = userNames.Where(it1 => it.UserId == it1.Id).FirstOrDefault();
- if (uName1 != null) it.Name = uName1.CnName;
- uName2 = userNames.Where(it1 => it.LastUpdateUserId == it1.Id).FirstOrDefault();
- if (uName2 != null) it.LastUpdateUserName = uName2.CnName;
- return it;
- }
- ).ToList();
- #endregion
- sw.Stop();
- return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", wageSheetItems[0]));
- }
- /// <summary>
- /// 导出工资单
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> ExportWageCard(string yearMonth)
- {
- Result result = new Result();
- Stopwatch sw = new Stopwatch();
- sw.Start();
- //参数处理
- string ymFormat = "yyyy-MM";
- DateTime yearMonthDt;
- bool yearMonthDtIsValid = DateTime.TryParseExact(yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
- //公司部门
- string sql = string.Format(@"Select row_number() over(order by pm_ws.Id) as Row_Number,
- sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
- sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
- From Pm_WageSheet pm_ws
- Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
- Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
- Left Join Sys_Company sc On sys_u1.companyId = sc.Id
- Left Join Sys_Department sd On sys_u1.DepId = sd.Id
- Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'", yearMonth);
- var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<ExportWageSheetItemView>(sql).ToListAsync();
- if (wageSheetList.Count <= 0)
- {
- return Ok(JsonView(false, yearMonth + "暂无工资数据!"));
- }
- decimal SumPrice = 0.00M;
- foreach (var item in wageSheetList)
- {
- SumPrice += item.AfterTax;
- }
- WorkbookDesigner designer = new WorkbookDesigner();
- designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/工资详细清单.xlsx");
- designer.Workbook.Worksheets[0].Name = yearMonth + " 工资单";
- designer.SetDataSource("WageSheet", wageSheetList);
- designer.SetDataSource("YearMonth", yearMonth);
- designer.SetDataSource("StartEndDt", wageSheetList[0].StartDate + " - " + wageSheetList[0].EndDate);
- designer.SetDataSource("WorkDays", wageSheetList[0].WorkDays);
- designer.SetDataSource("SumPrice", SumPrice);
- designer.SetDataSource("WageSheetTitle", "工资单");//
- designer.Process();
- string fileName = "WageCard/" + yearMonth + "_工资单_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
- string path = AppSettingsHelper.Get("ExcelBasePath");
- designer.Workbook.Save(path + fileName);
- designer = null;
- string excelPath = AppSettingsHelper.Get("ExcelFtpPath") + fileName;
- string url = AppSettingsHelper.Get("ExcelBaseUrl");
- string fileUrl = url + excelPath;
- sw.Stop();
- return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", new { FileUrl = fileUrl }));
- }
- /// <summary>
- /// 下载个税模板
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> WageSheetTaxTemplate()
- {
- string serverUrl = AppSettingsHelper.Get("WageSheetExcelBaseUrl");
- var userData = await _usersRep.GetUserNameList(1);
- if (userData.Code == 0)
- {
- var userNames = userData.Data;
- List<string> names = new List<string>();
- List<UserNameView> users = new List<UserNameView>();
- names.Add("管理员");
- names.Add("国交共享号");
- names.Add("人事审核号");
- names.Add("国交主管号");
- List<TaxTemlateViuw> taxs = new List<TaxTemlateViuw>();
- users = JsonConvert.DeserializeObject<List<UserNameView>>(JsonConvert.SerializeObject(userNames));
- foreach (UserNameView item in users)
- {
- string uName = item.CnName;
- if (!names.Contains(uName))
- {
- taxs.Add(new TaxTemlateViuw { UserName = item.CnName });
- }
- }
- if (taxs.Count > 0)
- {
- WorkbookDesigner designer = new WorkbookDesigner();
- designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/个税导入模板.xlsx");
- designer.Workbook.Worksheets[0].Name = "个税模板";
- designer.SetDataSource("TaxTemp", taxs);
- designer.Process();
- string fileName = "WageSheetTaxFile/个税模板" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
- string path = AppSettingsHelper.Get("ExcelBasePath");
- designer.Workbook.Save(path + fileName);
- designer = null;
- string excelPath = AppSettingsHelper.Get("ExcelFtpPath") + fileName;
- string url = AppSettingsHelper.Get("ExcelBaseUrl");
- string fileUrl = url + excelPath;
- return Ok(JsonView(true, "操作成功!", new { FileUrl = fileUrl }));
- }
- }
- return Ok(JsonView(false, "操作失败!"));
- }
- /// <summary>
- /// 上传个税
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> UploadTax(IFormFile file)
- {
- try
- {
- var yearMonth = Request.Headers["YearMonth"].ToString();
- //string yearMonth = "2023-10";
- string ymFormat = "yyyy-MM";
- DateTime yearMonthDt;
- bool yearMonthDtIsValid = DateTime.TryParseExact(yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
- if (file != null)
- {
- var fileDir = AppSettingsHelper.Get("WageSheetExcelFptPath");
- //文件名称
- string projectFileName = file.FileName;
- //上传的文件的路径
- string filePath = "";
- if (!Directory.Exists(fileDir))
- {
- Directory.CreateDirectory(fileDir);
- }
- //上传的文件的路径
- filePath = fileDir + $@"\{projectFileName}";
- if (System.IO.File.Exists(filePath))
- {
- //删除文件
- System.IO.File.Delete(filePath);
- }
- using (FileStream fs = System.IO.File.Create(filePath))
- {
- file.CopyTo(fs);
- fs.Flush();
- }
- if (System.IO.File.Exists(filePath))
- {
- Workbook book = new Workbook(filePath);
- DataSet dataSet = new DataSet();
- if (book.Worksheets.Count > 0)
- {
- var sheet = book.Worksheets[0];
- if (sheet != null)
- {
- // sheets 中的数据必须存在
- if (sheet.Cells.MaxDataRow != -1 && sheet.Cells.MaxDataColumn != -1)
- {
- // 方法 ExportDataTable 的参数说明
- // 要导出的第一个单元格的行号。
- // 要导出的第一个单元格的列号。
- // 要导入的行数。
- // 要导入的列数。
- // 指示第一行的数据是否导出到DataTable的列名。
- DataTable dataTable = sheet.Cells.ExportDataTable(0, 0, sheet.Cells.MaxDataRow + 1, sheet.Cells.MaxDataColumn + 1, true);
- dataSet.Tables.Add(dataTable);
- DataTable taxData = dataSet.Tables[0];
- //公司部门
- string sql = string.Format(@"Select row_number() over(order by pm_ws.Id) as Row_Number,
- sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
- sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
- From Pm_WageSheet pm_ws
- Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
- Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
- Left Join Sys_Company sc On sys_u1.companyId = sc.Id
- Left Join Sys_Department sd On sys_u1.DepId = sd.Id
- Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'
- Order By UserId Asc ", yearMonth);
- var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetInfoView>(sql).ToListAsync();
- if (wageSheetList.Count <= 0)
- {
- return Ok(JsonView(false, yearMonth + "工资数据不存在,请先添加工资数据!"));
- }
- for (int i = 0; i < taxData.Rows.Count; i++)
- {
- string name = taxData.Rows[i][0].ToString().Trim();
- List<WageSheetInfoView> wageSheets = new List<WageSheetInfoView>();
- wageSheets = wageSheetList.Where(it => it.Name.Equals(name)).ToList();
- if (wageSheets.Count > 0)
- {
- wageSheetList.Where(it => it.Name.Equals(name))
- .Select(it =>
- {
- //修改 绩效不等于0.00M的数据
- //decimal oldTax = it.WithholdingTax;
- var newTax = Convert.ToDecimal(taxData.Rows[i][1].ToString());
- it.WithholdingTax = newTax;
- it.TotalRealHair = it.Should - it.TotalDeductions - newTax;
- return it;
- })
- .ToList();
- }
- }
- List<Pm_WageSheet> wageSheets1 = new List<Pm_WageSheet>();
- wageSheets1 = _mapper.Map<List<Pm_WageSheet>>(wageSheetList);
- var updateStatus = _wageSheetRep._sqlSugar
- .Updateable(wageSheets1)
- .UpdateColumns(it => new { it.WithholdingTax, it.TotalRealHair })
- .ExecuteCommand();
- if (updateStatus < 0)
- {
- return Ok(JsonView(false, "操作失败!"));
- }
- if (System.IO.File.Exists(filePath))
- {
- //删除文件
- System.IO.File.Delete(filePath);
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- }
- else
- {
- return Ok(JsonView(false, "工作薄没有数据!"));
- }
- }
- }
- return Ok(JsonView(true, "上传成功!", projectFileName));
- }
- else
- {
- return Ok(JsonView(false, "上传失败!"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- /// <summary>
- /// 打卡记录测试
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> Test(string startDt, string endDt, int code)
- {
- UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
- if (userIdListView.errcode != 0)
- {
- _result.Msg = "【企业微信】【打卡】【获取员工ID】【Msg】" + userIdListView.errmsg;
- return Ok(JsonView(false, _result.Msg));
- }
- List<string> qyWhchatIdList = new List<string>();
- qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
- var data = await _qiYeWeChatApiService.GetCheckinDataAsync(qyWhchatIdList, code, Convert.ToDateTime(startDt), Convert.ToDateTime(endDt));
- return Ok(JsonView(true, "操作成功!", data.checkindata));
- }
- /// <summary>
- /// 审批详情
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostApprovalDetailAsync(string spNo)
- {
- if (string.IsNullOrEmpty(spNo))
- {
- return Ok(JsonView(false, "审批单号不能为空!!"));
- }
- var data = await _qiYeWeChatApiService.GetApprovalDetailAsync(spNo);
- return Ok(JsonView(true, "操作成功!", data));
- }
- #endregion
- #region 任务单
- /// <summary>
- /// 任务分配
- /// 基础数据源
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationInit(TaskAllocationInitDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
- #endregion
- #endregion
- var _view = await _taskAllocationRep._Init(dto.PortType, dto.UserId);
- if (_view.Code == 0)
- {
- return Ok(JsonView(true, "查询成功!", _view.Data));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// page
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationPage(TaskAllocationPageDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
- #endregion
- #endregion
- string whereSql = "";
- #region 分页参数处理
- //类型处理
- if (dto.Type == 0) whereSql = "";
- else if (dto.Type == 1) //1 由我指派
- {
- whereSql = string.Format(@" And ta.CreateUserId = {0} Or (Select COUNT(1) As PeopleNumber From Pm_TaskRelevanceUser Where IsDel = 0 And ta.Id = TAId And UserId = {0}) > 0", dto.UserId);
- }
- else if (dto.Type == 2)// 2 指派给我
- {
- whereSql = string.Format(@" And (Select COUNT(1) As PeopleNumber From Pm_TaskRelevanceUser Where IsDel = 0 And ta.Id = TAId And UserId = {0}) > 0", dto.UserId);
- }
- //状态 -1 全部 0 未开始 1 进行中 2 待审核 3 未完成 4 已完成
- if (dto.Status == -1) //全部
- {
- whereSql += "";
- }
- else
- {
- whereSql += string.Format(@" And ta.Status = {0} ", dto.Status);
- }
- //任务名称
- if (!string.IsNullOrEmpty(dto.TaskName))
- {
- whereSql += string.Format(@" And ta.TaskName Like '%{0}%' ", dto.TaskName);
- }
- #endregion
- string pageSql = string.Format(@"Select * From(
- Select ROW_NUMBER() OVER(ORDER BY ta.CreateTime Desc) AS RowNumber,
- ta.Id,ta.TaskName,ta.TaskPriority,d.DepName,di.TeamName,ta.Status,
- ta.PredictBeginTime,ta.PredictEndTime,u.CnName As CreateUserName,ta.CreateTime,
- (SELECT STUFF(
- (Select ',' + u.CnName From Pm_TaskRelevanceUser tra
- Left Join Sys_Users u On tra.UserId = u.Id
- Where tra.Isdel = 0 And tra.TAId = ta.Id
- FOR XML PATH('')),1,1,'')) As Participant,
- (SELECT STUFF(
- (Select ',' + u.CnName From Pm_TaskRelevanceUser tra
- Left Join Sys_Users u On tra.UserId = u.Id
- Where tra.Isdel = 0 And tra.TAId = ta.Id And tra.TaskStatus = 4
- FOR XML PATH('')),1,1,'')) As Consummator
- From Pm_TaskAllocation ta
- Left Join Sys_Department d On ta.DepId = d.Id
- Left Join Grp_DelegationInfo di On ta.DiId = di.Id
- Left Join Sys_Users u On ta.CreateUserId = u.Id
- Where ta.IsDel = 0 {0} ) As temp ", whereSql);
- RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
- var _view = await _taskAllocationRep._sqlSugar.SqlQueryable<TaskListView>(pageSql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
- List<int> taskIds = new List<int>();
- taskIds = _view.Select(it => it.Id).ToList();
- string taskerSql = string.Format(@"Select tau.TAId,tau.Id,tau.UserId,u.CnName As UserName,tau.BeginTime,tau.OverTime,tau.TaskStatus,
- tau.Cause,tau.Score,tau.Remark As ScoreRemark,tau.CreateUserId As TaskCreateUserId
- From Pm_TaskRelevanceUser tau
- Left Join Sys_Users u On tau.UserId = u.Id
- Where tau.IsDel = 0");
- var taskerData = _taskAllocationRep._sqlSugar.SqlQueryable<TaskerDetailsView>(taskerSql).Where(it => taskIds.Contains(it.TAId)).ToList();
- foreach (var item in _view)
- {
- item.TaskerDetails = taskerData.Where(it => it.TAId == item.Id).ToList();
- ////处理任务总状态 And 任务人状态
- //var taskerStatusData = taskerData.Where(it => it.TAId == item.Id && it.TaskCreateUserId != dto.UserId && it.UserId == dto.UserId).FirstOrDefault();
- //if (taskerStatusData != null)
- //{
- // item.Status = taskerStatusData.TaskStatus;
- //}
- }
- return Ok(JsonView(true, "查询成功!", _view, total));
- }
- /// <summary>
- /// 任务分配
- /// 详情
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationDetails(TaskAllocationDetailsDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
- #endregion
- #endregion
- var _view = await _taskAllocationRep._Details(dto.PortType, dto.Id);
- if (_view.Code == 0)
- {
- return Ok(JsonView(true, "查询成功!", _view.Data));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// Add Or Edit
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationAddOrEdit(TaskAllocationAddOrEditDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (dto.Id == 0)
- {
- if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
- }
- else if (dto.Id > 0)
- {
- if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
- }
- #endregion
- #endregion
- var _view = await _taskAllocationRep._AddOrEdit(dto);
- if (_view.Code == 0)
- {
- if (dto.Id == 0) //添加提示任务单创建
- {
- string title = $"[{dto.TaskName}] 任务新建成功!";
- string content = $"[{dto.TaskName}] 任务新建成功,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, dto.UserIds);
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 状态任务归属人详情
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationTaskerDetails(TaskerDetailsDto dto)
- {
- var _view = await _taskAllocationRep._TaskerDetails(dto.Id);
- if (_view.Code == 0)
- {
- return Ok(JsonView(true, "操作成功!", _view.Data));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 状态任务归属人设置开始状态
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationSetStartStatus(TaskerStatusDto dto)
- {
- var _view = await _taskAllocationRep._TaskerSetStartStatus(dto.UserId, dto.Id);
- if (_view.Code == 0)
- {
- //发送消息
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
- if (taskData != null)
- {
- var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == dto.Id).Select(it => it.UserId).ToList();
- if (taskUserIds.Count > 0)
- {
- taskUserIds.Remove(dto.UserId);
- }
- var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.UserId).Select(it => it.CnName).First();
- string title_createUser = $"[{taskData.TaskName}] 进度更新!";
- string conten_createUser = $"[{UserName}] 已开始任务,请注意该工作人员任务进度!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"[{UserName}] 已开始任务.若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
- string content1 = $"任务已开始,请在规定时间完成!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { dto.UserId }); //设置任务人 发送消息
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 状态 任务归属人 设置完成状态
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationSetOverStatus(TaskerStatusDto dto)
- {
- var _view = await _taskAllocationRep._TaskerSetOverStatus(dto.UserId, dto.Id);
- if (_view.Code == 0)
- {
- //发送消息
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
- if (taskData != null)
- {
- var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == dto.Id).Select(it => it.UserId).ToList();
- if (taskUserIds.Count > 0)
- {
- taskUserIds.Remove(dto.UserId);
- }
- var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.UserId).Select(it => it.CnName).First();
- string title_createUser = $"[{taskData.TaskName}] 进度更新!";
- string conten_createUser = $"[{UserName}] 已完成任务,请前往任务页面进行审核操作!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"[{UserName}] 已完成任务,请注意在规定时间内完成任务.若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
- string content1 = $"任务已完成,等待任务发布人审核!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { dto.UserId }); //设置任务人 发送消息
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 状态 任务归属人 设置知晓状态
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationSetHaveStatus(TaskAllocationStatusDto dto)
- {
- var _view = await _taskAllocationRep._TaskSetHaveStatus(dto.SubId);
- if (_view.Code == 0)
- {
- //发送消息
- var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
- if (taskUserData != null)
- {
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
- if (taskData != null)
- {
- var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == taskData.CreateUserId).Select(it => it.CnName).First();
- string title = $"[{taskData.TaskName}] 进度更新!";
- string conten_createUser = $"[{UserName}] 已知晓任务.若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
- string content = $"请注意任务完成时间!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
- }
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 任务发布者 单人设置审批状态
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationSetAuditStatus(TaskAllocationStatusDto dto)
- {
- var _view = await _taskAllocationRep._TaskSetAuditStatus(dto.SubId);
- if (_view.Code == 0)
- {
- //发送消息
- var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
- if (taskUserData != null)
- {
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
- if (taskData != null)
- {
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"任务已完成!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
- }
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 任务发布者 单人设置未完成状态
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationSetUnFinishedStatus(TaskAllocationSetUnFinishedStatusDto dto)
- {
- var _view = await _taskAllocationRep._TaskSetUnFinishedStatus(dto.SubId, dto.Cause);
- if (_view.Code == 0)
- {
- //发送消息
- var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
- if (taskUserData != null)
- {
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
- if (taskData != null)
- {
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"任务未完成!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
- }
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- ///// <summary>
- ///// 任务分配
- ///// 确认任务是否可操作完成
- ///// </summary>
- ///// <returns></returns>
- //[HttpPost]
- //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- //public async Task<IActionResult> PostTaskAllocationIsConfirmCompletion(TaskAllocationScoreDto dto)
- //{
- // try
- // {
- // #region 参数验证
- // if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- // if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- // PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- // #region 页面操作权限验证
- // pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- // if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
- // #endregion
- // #endregion
- // var _view = await _taskAllocationRep._TaskConfirmCompletion(dto.PortType, dto.Id);
- // if (_view.Code == 0)
- // {
- // return Ok(JsonView(true, "操作成功!"));
- // }
- // return Ok(JsonView(false, _view.Msg));
- // }
- // catch (Exception ex)
- // {
- // return Ok(JsonView(false, ex.Message));
- // }
- //}
- ///// <summary>
- ///// 任务分配
- ///// 任务确认完成
- ///// </summary>
- ///// <returns></returns>
- //[HttpPost]
- //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- //public async Task<IActionResult> PostTaskAllocationConfirmCompletion(TaskAllocationConfirmCompletionDto dto)
- //{
- // try
- // {
- // #region 参数验证
- // if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- // if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- // PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- // #region 页面操作权限验证
- // pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- // if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
- // #endregion
- // #endregion
- // var _view = await _taskAllocationRep._TaskConfirmCompletion(dto.PortType,dto.Id);
- // if (_view.Code == 0)
- // {
- // return Ok(JsonView(true, "操作成功!"));
- // }
- // return Ok(JsonView(false, _view.Msg));
- // }
- // catch (Exception ex)
- // {
- // return Ok(JsonView(false, ex.Message));
- // }
- //}
- /// <summary>
- /// 任务分配
- /// 任务发布者 任务评分
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationScore(TaskAllocationScoreDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
- #endregion
- #endregion
- var _view = await _taskAllocationRep._TaskScore(dto);
- if (_view.Code == 0)
- {
- //发送消息
- var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
- if (taskUserData != null)
- {
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
- if (taskData != null)
- {
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"任务评分已完成!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
- }
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 任务发布者 任务终止
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationTermination(TaskAllocationConfirmCompletionDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
- #endregion
- #endregion
- var _view = await _taskAllocationRep._TaskTermination(dto.Id);
- if (_view.Code == 0)
- {
- //发送消息
- var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
- if (taskData != null)
- {
- var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.Id).Select(it => it.UserId).ToList();
- taskUserIds.Add(taskData.CreateUserId);
- string title = $"[{taskData.TaskName}] 进度更新!";
- string content = $"任务已终止!若需查看,请前往任务页面查看详情!";
- await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //设置任务人 发送消息
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- /// <summary>
- /// 任务分配
- /// 任务发布者 任务删除
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostTaskAllocationDel(TaskAllocationConfirmCompletionDto dto)
- {
- #region 参数验证
- if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
- if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
- #endregion
- #endregion
- var _view = await _taskAllocationRep._TaskDel(dto.Id);
- if (_view.Code == 0)
- {
- return Ok(JsonView(true, "操作成功!"));
- }
- return Ok(JsonView(false, _view.Msg));
- }
- #endregion
- #region 团组状态通知
- /// <summary>
- /// 测试
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> Test_QIYEWX(PostTourClientListDownloadFile dto)
- {
- //List<string> templist = new List<string>() { 234.ToString() };
- //await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(14090, templist, QiyeWeChatEnum.TestChat);
- //await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.DiId); ;
- //DeleReminderMessage.PostMessageByWebhook();
- //GroupStatus_UserSimplelistView list = await _qiYeWeChatApiService.GroupStatus_GetUserList();
- //创建群聊
- //List<string> userList1 = new List<string>() { "Feint", "amy.zhu@pan-american-intl.com", "judy.zeng@pan-american-intl.com", "FuHongJin" };
- //List<string> userList2 = new List<string>() { "Feint", "ZhaoYaQi", "LiaoWenYa" };
- //List<string> userList3 = new List<string>() { "Feint", "amy.zhu@pan-american-intl.com", "judy.zeng@pan-american-intl.com", "FuHongJin", "ZhaoYaQi", "LiaoWenYa" };
- //GroupStatus_CreateChatView rst1 = await _qiYeWeChatApiService.GroupStatus_CreateChat("团组通知", "Feint", userList1, "CaiWuChat01");
- //GroupStatus_CreateChatView rst2 = await _qiYeWeChatApiService.GroupStatus_CreateChat("OA通知-国交部", "Feint", userList2, "GuoJiaoLeader01");
- //GroupStatus_CreateChatView rst3 = await _qiYeWeChatApiService.GroupStatus_CreateChat("OA通知-团组(公司客户)", "Feint", userList3, "CompanyCRMChat01");
- //推送消息(模板)
- //List<string> userList = new List<string>() { "Feint", "huaju.liu", "johnny.yang@pan-american-intl.com" };
- //List<string> userList = new List<string>() { "Feint", "johnny.yang@pan-american-intl.com" };
- //GroupStatus_CreateChatView rst1 = await _qiYeWeChatApiService.GroupStatus_CreateChat("团组费用提示", "Feint", userList, "GuoJiaoChat01");
- //团组出发
- //AppNoticeLibrary.SendUserMsg_GroupStatus_Create(2358, userList);
- //费用审核
- //AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(dto.DiId, QiyeWeChatEnum.TestChat);
- //费用审核结果通知(通过情况下发送财务群)
- //List<string> userList = new List<string>() { "234" };
- //AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(dto.DiId, userList, QiyeWeChatEnum.CaiWuChat02);
- //4、财务付款时:(1)对应版块人员【单独发,状态为已付款才发】
- //AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(dto.DiId, userList);
- //团组提醒财务群
- //DateTime dtNow = DateTime.Now;
- //List<Grp_DelegationInfo> listSource = _usersRep.Query<Grp_DelegationInfo>(s => s.IsDel == 0 && s.VisitStartDate >= dtNow).Take(3).ToList();
- //List<Grp_DelegationInfo> listAdd7day = _usersRep.Query<Grp_DelegationInfo>(s => s.IsDel == 0 && s.VisitStartDate >= dtNow).Take(3).ToList();
- //List<Grp_DelegationInfo> listAdd3day = new List<Grp_DelegationInfo>() { };
- //AppNoticeLibrary.SendChatMsg_GroupRemindersToCaiwu(listAdd7day, listAdd3day, QiyeWeChatEnum.TestChat);
- //日付申请提醒财务群
- //AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dto.DiId, QiyeWeChatEnum.CaiWuChat02);
- //日付申请结果推送用户、成功通知财务群
- //AppNoticeLibrary.DailyPayReminder_Audit_ToUser(dto.DiId, userList, QiyeWeChatEnum.TestChat);
- //AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dto.DiId, userList);
- string q = "";
- DeleReminderMessage.PostMessageByWebhook_CRMStatistics();
- return Ok(JsonView(true, "操作成功!"));
- }
- #endregion
- #region 物资进销存
- /// <summary>
- /// 物资进销存
- /// 基础数据类型
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsInitDataSource()
- {
- return Ok(await _goodsRep.InitDataSource());
- }
- /// <summary>
- /// 物资进销存
- /// 基础数据类型 --> 团组名称列表 分页
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsGroupNameInit(QueryGroupListOffsetDto dto)
- {
- var watch = new Stopwatch();
- watch.Start();
- var countyDatas = await _sqlSugar
- .Queryable<Grp_DelegationInfo>()
- .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
- .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
- .Select((di) => new { id = di.Id, name = di.TeamName})
- .ToListAsync();
- countyDatas.Insert(0, new { id = 0, name = "其他物资(公司内部物资)"});
- countyDatas.Insert(0, new { id = -1, name = "拜访客户所使用的物资" });
- var total = countyDatas.Count;
- countyDatas = countyDatas.WhereIF(!string.IsNullOrEmpty(dto.Search), x => x.name.Contains(dto.Search)).ToList();
- countyDatas = countyDatas
- .Skip((dto.PageIndex - 1) * dto.PageSize)
- .Take(dto.PageSize)
- .ToList();
- watch.Stop();
- return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
- }
- /// <summary>
- /// 物资进销存
- /// 物品 列表
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsList(GoodsListDto dto)
- {
- if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
- return Ok(await _goodsRep.GoodsList(dto));
- }
- /// <summary>
- /// 物资进销存
- /// 物品 详情
- /// </summary>
- /// <returns></returns>
- [HttpGet()]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsInfo(int portType, int id)
- {
- if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- return Ok(await _goodsRep.GoodsInfo(portType, id));
- }
- /// <summary>
- /// 物资进销存
- /// 物品 OP(Add OR Edit)
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsOP(GoodsOpDto dto)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- var validator = new GoodsOPDTOValidator();
- var validatorRes = await validator.ValidateAsync(dto);
- if (!validatorRes.IsValid)
- {
- var sb = new StringBuilder();
- foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
- return Ok(JsonView(false, sb.ToString()));
- }
- return Ok(await _goodsRep.GoodsOp(dto, currUserInfo.UserId));
- }
- /// <summary>
- /// 物资进销存
- /// 物品 Del
- /// </summary>
- /// <returns></returns>
- [HttpDelete("{id}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsDel(int id)
- {
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- return Ok(await _goodsRep.GoodsDel(id, currUserInfo.UserId));
- }
- /// <summary>
- /// 物资进销存
- /// 入库 列表
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsStorageList(GoodsStorageListDto dto)
- {
- if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
- return Ok(await _goodsRep.GoodsStorageList(dto));
- }
- /// <summary>
- /// 物资进销存
- /// 入库 详情
- /// </summary>
- /// <returns></returns>
- [HttpGet("{id}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsStorageInfo([FromQuery] int portType, int id)
- {
- if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- return Ok(await _goodsRep.GoodsStorageInfo(portType, id));
- }
- /// <summary>
- /// 物资进销存
- /// 入库 OP(Add OR Edit)
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsStorageOp(GoodsStorageOpDto dto)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- var validator = new GoodsStorageOpDtoValidator();
- var validatorRes = await validator.ValidateAsync(dto);
- if (!validatorRes.IsValid)
- {
- var sb = new StringBuilder();
- foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
- return Ok(JsonView(false, sb.ToString()));
- }
- return Ok(await _goodsRep.GoodsStorageOp(dto, currUserInfo.UserId));
- }
- /// <summary>
- /// 物资进销存
- /// 入库 Del
- /// </summary>
- /// <returns></returns>
- [HttpDelete("{id}")]
- //[Authorize]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsStorageDel(int id)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- return Ok(await _goodsRep.GoodsStorageDel(id, currUserInfo.UserId));
- }
- /// <summary>
- /// 物资进销存
- /// 领用 List
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsReceiveList(GoodsReceiveListDTO dto)
- {
- //var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- //if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
- return Ok(await _goodsRep.GoodsReceiveList(dto));
- }
- /// <summary>
- /// 物资进销存
- /// 领用详情
- /// </summary>
- /// <returns></returns>
- [HttpGet("{id}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsReceiveInfo([FromQuery] int portType, int id)
- {
- if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- return Ok(await _goodsRep.GoodsReceiveInfo(portType, id));
- }
- /// <summary>
- /// 物资进销存
- /// 领用 OP
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsReceiveOP(GoodsReceiveOpDto dto)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- var validator = new GoodsReceiveOpDtoValidator();
- var validatorRes = await validator.ValidateAsync(dto);
- if (!validatorRes.IsValid)
- {
- var sb = new StringBuilder();
- foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
- return Ok(JsonView(false, sb.ToString()));
- }
- return Ok(await _goodsRep.GoodsReceiveOp(dto, currUserInfo.UserId));
- }
- /// <summary>
- /// 物资进销存
- /// 领用 审核
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsReceiveAudit(GoodsReceiveAuditDTO dto)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- var validator = new GoodsReceiveAuditDTOValidator();
- var validatorRes = await validator.ValidateAsync(dto);
- if (!validatorRes.IsValid)
- {
- var sb = new StringBuilder();
- foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
- return Ok(JsonView(false, sb.ToString()));
- }
- int[] idArray = dto.Label
- .Split(',')
- .Select(x =>
- {
- if (int.TryParse(x, out var id)) return id;
- return id;
- })
- .ToArray();
- return Ok(await _goodsRep.GoodsReceiveAudit(idArray, currUserInfo.UserId, dto.AuditEnum));
- }
- /// <summary>
- /// 物资进销存
- /// 领用 Del
- /// </summary>
- /// <returns></returns>
- [HttpDelete("{id}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GoodsReceiveDel(int id)
- {
- var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
- if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
- if (id < 1) return Ok(JsonView(false, MsgTips.Id));
- return Ok(await _goodsRep.GoodsReceiveDel(id, currUserInfo.UserId));
- }
- #endregion
- #region 员工绩效
- /// <summary>
- /// 员工绩效组成结构获取
- /// </summary>
- /// <param name="userid"></param>
- /// <param name="date"></param>
- /// <returns></returns>
- [HttpGet]
- public IActionResult GetPerformanceList(int userid,string date)
- {
- var jw = JsonView(false);
- if (!DateTime.TryParse(date,out DateTime date_Dt))
- {
- jw.Msg = "日期格式有误!";
- return Ok(jw);
- }
- string sql_CTE = $@"-- 定义递归查询的CTE
- WITH PerAssessmentSettingsCTE AS (
- -- 选择指定ID的记录作为起点
- SELECT
- pac.Id,
- pac.Name,
- pac.AssessmentProportion,
- pac.AssessmentStandard,
- pac.ParentId,
- 1 AS Depth
-
- FROM
- Per_AssessmentSetting pac
- INNER JOIN
- Per_AssessmentContentSetting pacs
- ON
- pac.id = pacs.assessmentSettingid AND pacs.isdel = 0
-
- WHERE
- pacs.userid = {userid}
- AND
- pac.isdel = 0
-
- UNION ALL
- -- 递归部分,选择所有子级记录
- SELECT
- ps.Id,
- ps.Name,
- ps.AssessmentProportion,
- ps.AssessmentStandard,
- ps.ParentId,
- CAST(caste.Depth as int) + 1
- FROM
- Per_AssessmentSetting ps
-
- INNER JOIN PerAssessmentSettingsCTE caste ON ps.Id = caste.ParentId)
-
-
- -- 从CTE中选择最终结果
- SELECT * FROM PerAssessmentSettingsCTE
- OPTION (MAXRECURSION 0); -- 允许无限递归 ";
- var result_CTE = _sqlSugar.Ado.SqlQuery<Per_AssessmentSetting>(sql_CTE);
- var ids = result_CTE.Select(x => x.Id);
- var List = _sqlSugar.Queryable<Per_AssessmentSetting>()
- .LeftJoin<Per_AssessmentContentSetting>((a, b) => a.Id == b.AssessmentSettingId && b.IsDel == 0 && b.UserId == userid)
- .LeftJoin<Per_AssessmentScore>((a, b,c) => b.Id == c.AssessmentContentSettingId && c.IsDel == 0 && c.YearMonth.Year == date_Dt.Year && c.YearMonth.Month == date_Dt.Month)
- .Where((a, b) => a.IsDel == 0 && ids.Contains(a.Id))
- .Select((a, b, c) => new TreeNode
- {
- Id = a.Id,
- ContentId = b.Id,
- Name = a.Name,
- ParentId = a.ParentId,
- AssessmentProportion = a.AssessmentProportion, //占比
- AssessmentStandard = a.AssessmentStandard, //描述
- AssessmentProportionChi = b.AssessmentProportionChi, //占比
- UserId = b.UserId,
- JobId = b.JobId,
- AssessmentSettingId = b.AssessmentSettingId,
- Fixed = b.Fixed,
- TargetValue = b.TargetValue,
- AssessmentProportion_Percentage = a.AssessmentProportion * 100,
- HigherUpAssessment = c.HigherUpAssessment,
- HigherUpConfig = c.HigherUpConfig,
- HigherUpUserId = c.HigherUpUserId,
- Score = c.Score,
- ScoreTotal = c.ScoreTotal,
- SelfAssessment = c.SelfAssessment,
- Status = c.Status,
- YearMonth = c.YearMonth,
- })
- .ToList();
- var rootNodeList = List.Where(x => x.ParentId == 0);
- var rootResult = rootNodeList.Select(x => BuildSubTree(x, List));
- jw.Data = rootResult;
- jw.Code = 200;
- jw.Msg = "成功";
- return Ok(jw);
- }
- private TreeNode BuildSubTree(TreeNode parent, List<TreeNode> nodes)
- {
- var children = nodes
- .Where(n => n.ParentId == parent.Id)
- .Select(n => BuildSubTree(n, nodes))
- .ToList();
- parent.Children = children;
- return parent;
- }
- /// <summary>
- /// 绩效项增改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> AssessmentSettingOperationAsync(PerAssessmentSettingOperationDto dto)
- {
- var jw = JsonView(false);
- if (!ModelState.IsValid)
- {
- jw.Msg = "参数错误";
- jw.Data = ModelState;
- return Ok(jw);
- }
- try
- {
- if (dto.ParentId != 0)
- {
- var parent = await _sqlSugar.Queryable<Per_AssessmentSetting>().FirstAsync(x=>x.IsDel == 0 && x.Id == dto.ParentId);
- if (parent == null)
- {
- jw.Msg = "父级节点不存在";
- return Ok(jw);
- }
- }
- var entity = new Per_AssessmentSetting
- {
- Name = dto.Name,
- AssessmentProportion = dto.AssessmentProportion,
- AssessmentStandard = dto.AssessmentStandard,
- ParentId = dto.ParentId,
- Id = dto.Id,
- Remark = dto.Remark,
- };
- jw.Code = 200;
- if (dto.Id == 0)
- {
- entity.CreateUserId = dto.CreateId;
- entity.CreateTime = DateTime.Now;
- await _sqlSugar.Insertable(entity).ExecuteCommandAsync();
- jw.Msg = "添加成功!";
- }
- else
- {
- await _sqlSugar.Updateable(entity).ExecuteCommandAsync();
- jw.Msg = "修改成功!";
- }
- }
- catch (Exception ex)
- {
- jw.Msg = "Api error " + ex.Message;
- jw.Code = 400;
- }
- return Ok(jw);
- }
- /// <summary>
- /// 绩效内容增改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public IActionResult AssessmentSettingOperationContentAsync(AssessmentSettingOperationContenDto dto)
- {
- var jw = JsonView(false, "", "");
- var entity = new Per_AssessmentContentSetting
- {
- AssessmentProportionChi = dto.AssessmentProportionChi,
- AssessmentSettingId = dto.AssessmentSettingId,
- CreateTime = DateTime.Now,
- CreateUserId = dto.CreateUserId,
- Fixed = dto.Fixed,
- Id = dto.Id,
- JobId = dto.JobId,
- TargetValue = dto.TargetValue,
- UserId = dto.UserId,
- Remark = dto.Remark,
- };
- var entity_Fk = _sqlSugar.Queryable<Per_AssessmentSetting>().First(x => x.Id == dto.AssessmentSettingId && x.IsDel == 0);
- if (entity_Fk == null)
- {
- jw.Msg = "考核设置不存在";
- return Ok(jw);
- }
- try
- {
- if (dto.Id == 0)
- {
- //add
- var insertCount = _sqlSugar.Insertable(entity).ExecuteCommand();
- jw.Msg = "添加成功!";
- }
- else
- {
- //update
- var updateCount = _sqlSugar.Updateable(entity).ExecuteCommand();
- jw.Msg = "修改成功!";
- }
- jw.Code = 200;
- }
- catch (Exception ex)
- {
- jw.Msg = "Api error " + ex.Message;
- jw.Code = 400;
- }
- return Ok(jw);
- }
- /// <summary>
- /// 绩效项查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> QueryAssessmentSettingListOffsetAsync(QueryAssessmentSettingListOffsetAsyncDto dto)
- {
- var jw = JsonView(false);
- RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
- var entities = await _sqlSugar.Queryable<Per_AssessmentSetting>()
- .Where(x=>x.IsDel == 0)
- .WhereIF(!string.IsNullOrEmpty(dto.SearchValue), e => e.Name.Contains(dto.SearchValue))
- .ToPageListAsync(dto.pageIndex, dto.pageSize, total);
-
- var DtoResult = entities.Select(e => new
- {
- e.Id,
- Name = e.Name,
- AssessmentProportion = e.AssessmentProportion,
- AssessmentStandard = e.AssessmentStandard,
- ParentId = e.ParentId,
- Remark = e.Remark
- }).ToList();
- jw.Data = new
- {
- total = total.Value,
- dto.pageIndex,
- dto.pageSize,
- List = DtoResult
- };
- jw.Code = 200;
- jw.Msg = "查询成功!";
- return Ok(jw);
- }
- /// <summary>
- /// 绩效分数保存
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public IActionResult SaveUserAssessmen(SaveUserAssessmenDto dto)
- {
- var jw = JsonView(false,"请传入正确的数据!");
- if (dto.Data.Any()) {
- if (!DateTime.TryParse(dto.AssessmenData, out DateTime yearMonth_Dt))
- {
- jw.Data = "月份参数有误!";
- return Ok(jw);
- }
- try
- {
- var ids = dto.Data.Select(x => x.AssessmentContentSettingId).ToList();
- var QueryContent_DB = _sqlSugar.Queryable<Per_AssessmentContentSetting>()
- .InnerJoin<Per_AssessmentSetting>((a, b) => b.IsDel == 0 && a.AssessmentSettingId == b.Id)
- .Where((a, b) => a.IsDel == 0 && ids.Contains(a.Id))
- .Select((a, b) => new
- {
- ContentSettingId = a.Id,
- SettingId = b.Id,
- a.TargetValue,
- b.AssessmentStandard,
- MergeStr = $"【项名称:{b.Name}/目标值:{a.TargetValue}/评估标准:{b.AssessmentStandard}】",
- a.AssessmentProportionChi,
- b.Name
- })
- .ToList()
- .ToDictionary(x => x.ContentSettingId);
- //删除上级未确认数据
- var expressionWhere = Expressionable
- .Create<Per_AssessmentScore>()
- .And(x => x.YearMonth.Year == yearMonth_Dt.Year && x.YearMonth.Month == yearMonth_Dt.Month)
- .And(x => ids.Contains(x.AssessmentContentSettingId))
- .And(x => x.HigherUpConfig == 0)
- .ToExpression();
- _sqlSugar.BeginTran();
- _sqlSugar.Updateable<Per_AssessmentScore>()
- .Where(expressionWhere)
- .SetColumns(x => new Per_AssessmentScore { IsDel = 1, DeleteUserId = dto.CreateUserId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
- .ExecuteCommand();
- var entityList = new List<Per_AssessmentScore>();
- foreach (var x in dto.Data)
- {
- if (x.HigherUpAssessment > 100 || x.SelfAssessment > 100)
- {
- jw.Msg = QueryContent_DB[x.AssessmentContentSettingId].Name + "项分数不能超过100。";
- return Ok(jw);
- }
- Per_AssessmentScore item = new Per_AssessmentScore
- {
- AssessmentContentSettingId = x.AssessmentContentSettingId,
- CreateTime = DateTime.Now,
- CreateUserId = dto.CreateUserId,
- Details = QueryContent_DB[x.AssessmentContentSettingId].MergeStr,
- HigherUpAssessment = x.HigherUpAssessment,
- HigherUpUserId = x.LeadersId,
- HigherUpConfig = x.HigherUpAssessment > 0 ? 1 : 0,
- SelfAssessment = x.SelfAssessment,
- IsDel = 0,
- Status = x.Status,
- YearMonth = yearMonth_Dt,
- Score = x.SelfAssessment * 0.3M + x.HigherUpAssessment * 0.7M,
- ScoreTotal = (x.SelfAssessment * 0.3M + x.HigherUpAssessment * 0.7M) * QueryContent_DB[x.AssessmentContentSettingId].AssessmentProportionChi,
- };
- entityList.Add(item);
- }
- var influenceRow = _sqlSugar.Insertable(entityList).ExecuteCommand();
- _sqlSugar.CommitTran();
- jw.Code = 200;
- jw.Msg = "保存成功!";
- jw.Data = $"{influenceRow}条数据操作成功!";
- }
- catch (Exception ex)
- {
- _sqlSugar.RollbackTran();
- jw.Code = 500;
- jw.Data = $"API ERROR ({ex.Message})";
- }
- }
- return Ok(jw);
- }
- /// <summary>
- /// 绩效项删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public IActionResult DeleteAssessmentSetting(DeleteAssessmentSettingDto dto)
- {
- var jw = JsonView(false, "删除失败!");
- if (!dto.IdArr.Any())
- {
- jw.Msg = "id不能为空!";
- return Ok(jw);
- }
- var rowCount = _sqlSugar.Updateable<Per_AssessmentSetting>()
- .Where(x => dto.IdArr.Contains(x.Id) && x.IsDel == 0)
- .SetColumns(x => new Per_AssessmentSetting
- {
- IsDel = 1,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
- DeleteUserId = dto.UserId,
- })
- .ExecuteCommand();
- jw.Code = 200;
- jw.Msg = $"修改成功!,修改数量{rowCount}";
- return Ok(jw);
- }
- /// <summary>
- /// 绩效内容删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public IActionResult DeleteAssessmentContentSetting(DeleteAssessmentSettingDto dto)
- {
- var jw = JsonView(false, "删除失败!");
- if (!dto.IdArr.Any())
- {
- jw.Msg = "id不能为空!";
- return Ok(jw);
- }
- var rowCount = _sqlSugar.Updateable<Per_AssessmentContentSetting>()
- .Where(x => dto.IdArr.Contains(x.Id) && x.IsDel == 0)
- .SetColumns(x => new Per_AssessmentContentSetting
- {
- IsDel = 1,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
- DeleteUserId = dto.UserId,
- })
- .ExecuteCommand();
- jw.Code = 200;
- jw.Msg = $"修改成功!,修改数量{rowCount}";
- return Ok(jw);
- }
- #endregion
- #region 企微Api测试
- [HttpPost]
- public async Task<IActionResult> GetCheckin_MonthDataAsync(DateTime start, DateTime end)
- {
- var jw = JsonView(false);
- jw.Data = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync1(start,end);
- return Ok(jw);
- }
- [HttpPost]
- public async Task<IActionResult> QueryAssessmentByUser(QueryAssessmentByUser Dto)
- {
- var jw = JsonView(false);
- var user_entity = _sqlSugar.Queryable<Sys_Users>()
- .First(e => e.Id == Dto.UserId && e.IsDel == 0);
- var start_Bool = DateTime.TryParse(Dto.Start, out DateTime start);
- var end_Bool = DateTime.TryParse(Dto.End, out DateTime end);
- if (!start_Bool || !end_Bool)
- {
- jw.Msg = "时间格式不正确!";
- return Ok(jw);
- }
- jw.Msg = "用户企业微信Id未绑定!";
- if (user_entity != null && !string.IsNullOrEmpty(user_entity.QiyeChatUserId))
- {
- var data = await _qiYeWeChatApiService.QueryAssessmentByUser(start, end, new List<string> { user_entity.QiyeChatUserId });
- jw.Data = data;
- jw.Msg = "查询成功!";
- jw.Code = 200;
- }
- return Ok(jw);
- }
- [HttpPost]
- public IActionResult TempTest(QueryAssessmentSettingListOffsetAsyncDto Dto)
- {
- var jw = JsonView(false);
- return Ok(jw);
- }
- #endregion
- }
- }
|