ComplianceServer/oldcode/WEB/Controllers/Csvr/ToDoItemController.cs

374 lines
15 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.IBLL.Csvr;
using WX.CRM.IBLL.Res;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
using WX.CRM.WebHelper.DoItems;
namespace WX.CRM.WEB.Controllers.Csvr
{
public class ToDoItemController : BaseController
{
//
// GET: /ToDoItem/
private ICSVR_TODOITEM _todoItem;
private ICSVR_TODOITEM_Q _todoItemq;
private IRES_CUSTOMER_Q _customer;
private IBAS_INNERUSER_Q _inneruserq;
private IRES_CUSTOMERDETAIL_Q _customerDetail;
ValidationErrors errors = new ValidationErrors();
public ToDoItemController(
ICSVR_TODOITEM todoItem,
ICSVR_TODOITEM_Q todoItemq,
IRES_CUSTOMER_Q customer,
IBAS_INNERUSER_Q inneruserq,
IRES_CUSTOMERDETAIL_Q customerDetail
)
{
this._todoItem = todoItem;
this._todoItemq = todoItemq;
this._customer = customer;
this._inneruserq = inneruserq;
_customerDetail = customerDetail;
}
public ActionResult Index()
{
var tool = new ToolBar();
tool.AllowButton("Create", "Edit", "Other1");
tool.AddOtherButton("Other1", "完成", "icon-flag", "Complete_Click", true);
ViewBag.ToolBar = tool;
var pager = new Pager() { page = 1, rows = 10 };
var tableId = "tablist";
var tab = new Table(tableId);
tab.isCheckbox = true;
tab.AddHiddenHeadCol("pkid", "ID");//隐藏列
tab.AddHeadCol("map_SENDEDUSERID", "10%", "发起待办事项人 ");
tab.AddHeadCol("map_RECEIVEDUSERID", "10%", "接收待办事项人 ");
tab.AddHeadCol("map_RESID", "10%", "客户ID号");
tab.AddHeadCol("CNAME", "", "姓名");
tab.AddHeadCol("map_MEMO", "10%", "待办事项");
tab.AddHeadCol("REMARK", "", "备注");
tab.AddHeadCol("map_STARTTIME", "10%", "提醒时间");
tab.AddHeadCol("map_DOSTATUS", "", "状态");
//tab.AddHeadCol("map_DOREMARK", "", "处理结果");
tab.AddHeadCol("map_DOUSERID", "", "完成人");
tab.AddHeadCol("map_DOTIME", "", "完成时间");
tab.AddHeadCol("URL", "", "");
tab.AddHeadRow();
ViewBag.List = tab.GetTable() + Pagination.GetPage(pager, tableId, "10,20,50,100,200");
ViewBag.inneruserid = UserId;
ViewBag.userGroupId = userGroupId;
ViewBag.saleDeptId = saleDeptId;
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
return View();
}
[HttpPost]
public JsonResult GetHtmlList(Pager pager, string resid, string columns, string memo, QueryUserComboDto usercomboDto, string resourcetag)
{
try
{
DateTime? ctime = Request.Form["ctime"].GetDateTime();
DateTime? etime = Request.Form["etime"].GetDateTime();
decimal status = Request.Form["status"].GetDecimal(-1);
//string groupId = Request.Form["groupId"];
//string userId = Request.Form["userId"];
var list = _todoItemq.GetToDoItemsByParam(ref pager, resid, memo, ctime, etime, status, usercomboDto, resourcetag);
var resids = list.Select(p => p.RESID);
var customers = _customerDetail.GetList(p => resids.Contains(p.RESID));
var table = new Table(columns, true)
{
gridPager = pager
};
table.isCheckbox = true;
foreach (var model in list)
{
var customer = customers.FirstOrDefault(p => p.RESID == model.RESID);
var linkUrl = string.Format("<a href=\"javascript:parent.ChildAddTab('{0}', '{1}', '')\">{2}</a>"
, "客户详细"
, "/Csvr/CustomerInfo/CustomerDetail?resid=" + model.map_RESID
, model.map_RESID);
table.AddHiddenCol(model.map_PKID);//影藏列
table.AddCol(InnerUserHelper.Instance.EidAndName(model.map_SENDEDUSERID));
table.AddCol(InnerUserHelper.Instance.EidAndName(model.map_RECEIVEDUSERID));
if (string.IsNullOrEmpty(model.URL))
{
table.AddCol(model.RESID);
}
else
{
table.AddCol(linkUrl);
}
table.AddCol(customer == null ? "" : customer.CNAME);
table.AddCol(model.map_MEMO);
table.AddCol(model.REMARK);
table.AddCol(model.map_STARTTIME);
table.AddCol(model.map_DOSTATUS == 0 ? "未完成" : "已完成");
//table.AddCol(model.map_DOREMARK);
table.AddCol(InnerUserHelper.Instance.EidAndName(model.map_DOUSERID));
table.AddCol(model.map_DOTIME);
if (model.map_DOSTATUS == 0)
{
if (string.IsNullOrEmpty(model.URL))
{
table.AddCol("");
}
else
{
table.AddCol(string.Format("<a href=\"javascript:gotoComplete('{0}', '{1}', '{3}')\">{2}</a>", model.URLTITLE, model.URL, "去完成", model.PKID));
}
}
else
table.AddCol("");
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("ToDoItemController_GetHtmlList:" + ex.StackTrace + ";" + ex.Message);
var json = new
{
errorMessag = "系统错误:" + ex.Message
};
return Json(json, JsonRequestBehavior.AllowGet);
}
}
[HttpGet]
public ActionResult Add(string id)
{
CSVR_TODOITEM model = null;
if (id != null)
{
model = _todoItemq.GetToDoItemById(Convert.ToDecimal(id));
// var inneruser = _inneruserq.GetModel(model.map_RECEIVEDUSERID);
decimal? RECEIVEDUSERID = InnerUserHelper.Instance.GetEidByUserId(model.map_RECEIVEDUSERID);
model.map_RECEIVEDUSERID = RECEIVEDUSERID.HasValue ? RECEIVEDUSERID.Value : 0;
}
ViewBag.mySelf = UserId;
return View(model);
}
[HttpPost]
public ActionResult Add(CSVR_TODOITEM model)
{
try
{
model.map_SENDEDUSERID = UserId;
model.map_DOSTATUS = 0;
//model.RESID = model.RESID.Trim();
if (model.map_SENDEDUSERID == model.map_RECEIVEDUSERID)
{
model.map_ISPRIVATE = 1;
}
else { model.map_ISPRIVATE = 0; }
model.map_RECEIVEDUSERID = InnerUserHelper.Instance.GetUserIdByEid(model.map_RECEIVEDUSERID);
if (ModelState.IsValid)
{
if (model.PKID == 0)
{
bool result = this._todoItem.Create(ref errors, model);
return JsonHandler.InsertMessage(errors, result);
}
else
{
if (model.map_DOSTATUS == 0)
{
bool result = this._todoItem.Update(ref errors, model);
return JsonHandler.UpdateMessage(errors, result);
}
else { return JsonHandler.ManageMessage("该事项已完成", false); }
}
}
else
{
return JsonHandler.JsonResultSerialize(ModelState);
}
}
catch (Exception ex)
{
LogHelper.Error(ex.Message);
return JsonHandler.ManageMessage(ex.Message, false);
}
}
[HttpPost]
public ActionResult DoItems()
{
string msg = "";
string msginfo = "";
string url = "";
string urk = "";
try
{
foreach (var tool in WebHelper.DoItems.PopupMessageFactory.PopupMessageArray)
{
msg = tool.GetMessage(UserId);
if (msg != string.Empty)
{
url = tool.GetUrl().IndexOf("?") > -1 ? (tool.GetUrl() + "&userid=" + UserId) : (tool.GetUrl() + "?userid=" + UserId);
msginfo += msg + ",";
urk += url + ",";
}
}
if (!string.IsNullOrEmpty(msginfo))
{
string[] msglist = msginfo.Substring(0, msginfo.Length - 1).Split(',');
string[] urllist = urk.Substring(0, urk.Length - 1).Split(',');
var json = new { result = true, messages = msglist, url = urllist };//数组初始化
return Json(json, JsonRequestBehavior.AllowGet);
}
else
{
var json = new
{
result = false,
messages = "",
url = ""
};
return Json(json, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
LogHelper.Error("DoItems" + ex.ToString());
var json = new
{
result = false,
messages = ex.Message,
url = ""
};
return Json(json, JsonRequestBehavior.AllowGet);
}
}
//public ActionResult SetNeedRefresh()
//{
// WebHelper.DoItems.PopupMessageFactory.toDoItemMessage.SetNeedRefresh();
// var json = new
// {
// result = true,
// messages = "",
// url = ""
// };
// return Json(json, JsonRequestBehavior.AllowGet);
//}
[HttpPost]
public ActionResult Complete(string allid)
{
if (string.IsNullOrEmpty(allid))
{
return JsonHandler.ManageMessage("参数有误!", false);
}
var ids = allid.Replace("][", ";").Replace("]", "").Replace("[", "");
string nojieshouren = "";
foreach (var item in ids.Split(';'))
{
var id = Convert.ToDecimal(item);
var model = _todoItemq.GetToDoItemById(id);
if (model != null)
{
if (model.DOSTATUS < 1)
{
if (model.RECEIVEDUSERID == UserId)
{
model.DOSTATUS = 1;
model.DOTIME = DateTime.Now;
model.DOUSERID = UserId;
model.DOREMARK = "完成";
bool result = this._todoItem.Update(ref errors, model);
if (!result)
{
return JsonHandler.UpdateMessage(errors, result);
}
else
{
PopupMessageFactory.toDoItemMessage.SetView(model.map_RECEIVEDUSERID, model.map_PKID.ToString());
}
}
else
{
nojieshouren += string.IsNullOrEmpty(nojieshouren) ? $"{id}" : $",{id}";
//return JsonHandler.ManageMessage("非接收人不能完成该待办事项", false);
}
}
//else
//{
// return JsonHandler.ManageMessage("该事项已完成", false);
//}
//return JsonHandler.ManageMessage("修改成功", true);
}
else
{
//return JsonHandler.ManageMessage("找不到该数据", false);
}
}
if (string.IsNullOrEmpty(nojieshouren))
return JsonHandler.ManageMessage("修改成功", true);
else
{
return JsonHandler.ManageMessage($"ID:{nojieshouren}非接收人不能完成该待办事项", false);
}
}
public FileResult ExportAll(string resid, string columns, QueryUserComboDto usercomboDto, string resourcetag)
{
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
string checkedFilds = PageRequest.GetQueryString("checkedFilds");
string checkedTitles = PageRequest.GetQueryString("checkedTitles");
DateTime? ctime = Request.QueryString["ctime"].GetDateTime();
DateTime? etime = Request.QueryString["etime"].GetDateTime();
decimal status = Request.QueryString["status"].GetDecimal(-1);
var list = _todoItemq.GetToDoItemsByParamExport(ref pager, resid, ctime, etime, status, usercomboDto, resourcetag);
//List<WX.CRM.Model.Entity.BAS_INNERUSER_Extend> list = inneruserBiz_Q.GetList(ref pager, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
return File(ExcelHelper.ExportListModelToExcel<WX.CRM.Model.Entity.CSVR_TODOITEM_MAP>(list, "代办事项", 10000, checkedFilds, checkedTitles, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("代办事项.xls"));
}
//用作委托传递
public string DataFormart(string key, object value)
{
string formartValue = string.Empty;
switch (key)
{
case "map_DOSTATUS":
switch (Convert.ToString(value))
{
case "0": formartValue = "未完成"; break;
default: formartValue = "已完成"; break;
}; break;
case "map_SENDEDUSERID":
formartValue = InnerUserHelper.Instance.EidAndName(Convert.ToDecimal(value)); break;
case "map_RECEIVEDUSERID":
formartValue = InnerUserHelper.Instance.EidAndName(Convert.ToDecimal(value)); break;
case "URL":
formartValue = ""; break;
default: formartValue = string.Format("{0}", value); break;
}
return formartValue;
}
}
}