using Learun.Application.Base.AuthorizeModule; using Learun.Application.Base.SystemModule; using Learun.Application.Organization; using Learun.Application.TwoDevelopment.LogisticsManagement; using Learun.Application.TwoDevelopment.LR_Desktop; using Learun.Util; using Nancy; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Learun.Application.WebApi { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创 建:超级管理员 /// 日 期:2020-06-03 14:29 /// 描 述:系部数据 /// public class RepairReportStudentApi : BaseApi { private RepairReportStudentIBLL repairreportStudentIBLL = new RepairReportStudentBLL(); private MessageRindIBLL messageRindIBLL = new MessageRindBLL(); private UserRelationIBLL userRelationIBLL = new UserRelationBLL(); private DataItemIBLL dataItemIBLL = new DataItemBLL(); private UserIBLL userIbll = new UserBLL(); private RoleIBLL roleIBLL = new RoleBLL(); /// /// 注册接口 /// public RepairReportStudentApi() : base("/learun/adms/repairreportStudent") { Get["/pagelist"] = GetPageList; Get["/form"] = GetForm; Post["/delete"] = DeleteForm; Post["/save"] = SaveForm; Post["/submit"] = Submit; } #region 获取数据 /// /// 获取页面显示列表分页数据 /// /// /// public Response GetPageList(dynamic _) { ReqPageParam parameter = this.GetReqData(); var data = repairreportStudentIBLL.GetPageList(parameter.pagination, parameter.queryJson); var jsonData = new { rows = data, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records }; return Success(jsonData); } /// /// 获取表单数据 /// /// /// public Response GetForm(dynamic _) { string keyValue = this.GetReqData(); var RepairReport_StudentData = repairreportStudentIBLL.GetRepairReport_StudentEntity(keyValue); var jsonData = new { RepairReport_Student = RepairReport_StudentData, }; return Success(jsonData); } #endregion #region 提交数据 /// /// 删除实体数据 /// /// /// public Response DeleteForm(dynamic _) { string keyValue = this.GetReqData(); repairreportStudentIBLL.DeleteEntity(keyValue); return Success("删除成功!"); } /// /// 保存实体数据(新增、修改) /// /// /// public Response SaveForm(dynamic _) { ReqFormEntity parameter = this.GetReqData(); RepairReport_StudentEntity entity = parameter.strEntity.ToObject(); if (string.IsNullOrWhiteSpace(entity.Contact)) return Fail("联系电话不能为空!"); if(entity.Status==2 && string.IsNullOrWhiteSpace(entity.Repairname)) return Fail("维修人不能为空!"); repairreportStudentIBLL.SaveEntity(parameter.keyValue, entity); //entity.Status = 2; if (entity.Status == 2) { var model = repairreportStudentIBLL.GetRepairReport_StudentEntity(parameter.keyValue); //获取所有的维修员账号并添加 var userList = userIbll.GetListByUserIds(model.Creator); List datalist = dataItemIBLL.GetDetailList("repairtype", ""); string servicevalue = datalist.Where(c => c.F_ItemValue == model.ServiceType).FirstOrDefault().F_ItemName; string content = "您发起" + model.Address + "-" + servicevalue + "维修请求已处理,请评价。"; addmessagerind(userList, model, content, "评价通知"); } return Success("保存成功!"); } /// /// 提交 /// /// /// public Response Submit(dynamic _) { string keyValue = this.GetReqData(); //repairreportStudentIBLL.ModifyStatus(keyValue, 1,""); int existcount = repairreportStudentIBLL.Waitevaluatecount(); if (existcount > 0) { return Fail("您有待评价的保修单,请评价后在提交!"); } //修改状态 repairreportStudentIBLL.ModifyStatus(keyValue, 1, ""); var model = repairreportStudentIBLL.GetRepairReport_StudentEntity(keyValue); //向所有维修员发消息 var MaintainRoleId = Config.GetValue("MaintainRoleId"); var data = userRelationIBLL.GetUserIdList(MaintainRoleId); string userIds = ""; foreach (var item in data) { if (userIds != "") { userIds += ","; } userIds += item.F_UserId; } //获取所有的维修员账号并添加 var userList = userIbll.GetListByUserIds(userIds); List datalist = dataItemIBLL.GetDetailList("repairtype", ""); string servicevalue = datalist.Where(c => c.F_ItemValue == model.ServiceType).FirstOrDefault().F_ItemName; string content = model.DeptName + model.CreatorName + "发起" + model.Address + "-" + servicevalue + "维修请求。"; addmessagerind(userList, model, content); return Success("提交成功!"); } #endregion #region 私有类 /// /// 表单实体类 /// private class ReqFormEntity { public string keyValue { get; set; } public string strEntity { get; set; } public string DetailList { get; set; } } #endregion #region 插入提醒公告 private void addmessagerind(List userList, RepairReport_StudentEntity model, string content, string title = "维修通知") { foreach (var userinfo in userList) { //站内通知逻辑 MessageRemindEntity entity = new MessageRemindEntity(); entity.ReceiptId = userinfo.F_UserId; entity.ReceiptName = userinfo.F_RealName; entity.SenderId = model.Creator; entity.SenderName = model.CreatorName; entity.TheTitle = title; entity.TheContent = content; entity.InstanceId = model.ID; entity.ConnectionUrl = "/LogisticsManagement/RepairReportStudent/FormView?keyValue="; entity.SendTime = DateTime.Now; entity.ReadSigns = false; messageRindIBLL.SaveEntity("", entity); } } #endregion } }