229 lines
9.7 KiB
C#
229 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.Res
|
|
{
|
|
public class ResourceController : BaseController
|
|
{
|
|
private readonly IRES_RESOURCETYPE_Q resourceTypeBiz_Q;
|
|
private readonly IRES_ACTIVITY_Q activityBiz_Q;
|
|
private readonly IRES_DISTRIBUTE dISTRIBUTE_Q;
|
|
private readonly IRES_DISTRIBUTE_DETAIL _DISTRIBUTE_DETAIL;
|
|
private readonly IBAS_COMPANY_Q companyBl;
|
|
private readonly IBAS_INNERUSER_Q _IBAS_INNERUSER_Q;
|
|
|
|
ValidationErrors errors = new ValidationErrors();
|
|
|
|
public ResourceController(IRES_RESOURCETYPE_Q _resourceTypeBiz_Q
|
|
, IRES_ACTIVITY_Q _activityBiz_Q
|
|
, IRES_DISTRIBUTE _dISTRIBUTE_Q
|
|
, IBAS_COMPANY_Q _companyBl
|
|
, IBAS_INNERUSER_Q IBAS_INNERUSER_Q
|
|
, IRES_DISTRIBUTE_DETAIL DISTRIBUTE_DETAIL)
|
|
{
|
|
resourceTypeBiz_Q = _resourceTypeBiz_Q;
|
|
activityBiz_Q = _activityBiz_Q;
|
|
dISTRIBUTE_Q = _dISTRIBUTE_Q;
|
|
companyBl = _companyBl;
|
|
_IBAS_INNERUSER_Q = IBAS_INNERUSER_Q;
|
|
_DISTRIBUTE_DETAIL = DISTRIBUTE_DETAIL;
|
|
}
|
|
|
|
//
|
|
// 分配资源上传
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_导入分配资源)]
|
|
public ActionResult Import()
|
|
{
|
|
var list
|
|
= resourceTypeBiz_Q.GetList().OrderByDescending(obj => obj.CTIME);
|
|
|
|
ViewData["ddlResType"] = new SelectList(list, "RESTYPEID", "TYPENAME");
|
|
|
|
#region
|
|
ToolBar tool = new ToolBar();
|
|
tool.AllowButton("Other1", "Other2", "Other3");
|
|
tool.AddOtherButton("Other1", "上传", "icon-upload", "Upload", true);
|
|
tool.AddOtherButton("Other2", "取消导入", "icon-cancel", "UploadCancel", true);
|
|
tool.AddOtherButton("Other3", "确认导入", "icon-save", "SaveDistibute", true);
|
|
ViewBag.ToolBar = tool;
|
|
|
|
//table
|
|
Pager pager = new Pager { page = 1, rows = 10 };
|
|
const string tableId = "tablist";
|
|
Table tab = new Table(tableId);
|
|
tab.AddHeadCol("客户ID", "30%", "客户ID");
|
|
tab.AddHeadCol("工号", "30%", "工号");
|
|
tab.AddHeadCol("工号是否存在", "30%", "");
|
|
tab.AddHeadRow();
|
|
|
|
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15");
|
|
#endregion
|
|
|
|
return View();
|
|
}
|
|
|
|
public ActionResult GetActivity(decimal resid)
|
|
{
|
|
var list = activityBiz_Q.GetList_RESID(resid).OrderByDescending(obj => obj.CTIME);
|
|
return Json(list, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public JsonResult Upload(HttpPostedFileBase fileData)
|
|
{
|
|
if (fileData != null)
|
|
{
|
|
try
|
|
{
|
|
//文件上传后的保存路径
|
|
string filePath = Server.MapPath("~/Uploads/");
|
|
if (!Directory.Exists(filePath))
|
|
{
|
|
Directory.CreateDirectory(filePath);
|
|
}
|
|
string fileName = Path.GetFileName(fileData.FileName);//原始文件名称
|
|
string fileExtension = Path.GetExtension(fileName); //文件扩展名
|
|
string saveName = Guid.NewGuid() + fileExtension; //保存文件名称
|
|
|
|
fileData.SaveAs(filePath + saveName);
|
|
return Json(new
|
|
{
|
|
Success = true,
|
|
FileName = fileName,
|
|
SaveName = saveName
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Json(new { Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
return Json(new { Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
public ActionResult SaveDistibute()
|
|
{
|
|
try
|
|
{
|
|
decimal _RESTYPEID;
|
|
if (!decimal.TryParse(Request["resType"], out _RESTYPEID))
|
|
{
|
|
return Json(new { Success = false, Message = "请选择资源类型!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
var _COMPANYID = resourceTypeBiz_Q.GetModel(_RESTYPEID).COMPANYID;
|
|
if (_COMPANYID == null)
|
|
return Json(new { Success = false, Message = "所属公司不存在!" }, JsonRequestBehavior.AllowGet);
|
|
var companyModel = companyBl.GetModel_Company(_COMPANYID.Value);
|
|
if (companyModel == null)
|
|
return Json(new { Success = false, Message = "所属公司不存在!" }, JsonRequestBehavior.AllowGet);
|
|
decimal _ACTIVITYID;
|
|
if (!decimal.TryParse(Request["actity"], out _ACTIVITYID))
|
|
{
|
|
return Json(new { Success = false, Message = "请选择资源活动!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
DataTable _uploadtable = TempData["uploadtable"] as DataTable;
|
|
if (_uploadtable == null || _uploadtable.Rows.Count == 0)
|
|
{
|
|
return Json(new { Success = false, Message = "请导入资源!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
_uploadtable.Columns["客户ID0"].ColumnName = "RESID";
|
|
_uploadtable.Columns["工号1"].ColumnName = "SALESID";
|
|
List<RES_DISTRIBUTE_DETAIL> list_DISTRIBUTE_DETAIL = new List<RES_DISTRIBUTE_DETAIL>();//_uploadtable.ToList<RES_DISTRIBUTE_DETAIL>();
|
|
RES_DISTRIBUTE model = new RES_DISTRIBUTE
|
|
{
|
|
PICI = companyModel.SYSTEMCODE + "IM" + DateTime.Now.ToString("yyMMddHHmmss"),
|
|
RESTYPEID = _RESTYPEID,
|
|
ACTIVITYID = _ACTIVITYID,
|
|
CREATEUSER = UserId,
|
|
CTIME = DateTime.Now,
|
|
DISLEADER = Request["disLeader"],
|
|
SALESREMARK = Request["salesRemark"],
|
|
REMARK = Request["remark"]
|
|
};
|
|
bool rst = true;
|
|
rst &= dISTRIBUTE_Q.Create(ref errors, model);
|
|
foreach (DataRow dr in _uploadtable.Rows)
|
|
{
|
|
if (dr[2].ToString() == "False")
|
|
continue;
|
|
var detail = new RES_DISTRIBUTE_DETAIL();
|
|
detail.RESID = dr["RESID"].ToString();
|
|
detail.SALESID = InnerUserHelper.Instance.GetUserIdByEid(decimal.Parse(dr["SALESID"].ToString()));
|
|
detail.DISTRIBUTEID = model.PKID;
|
|
detail.CTIME = DateTime.Now;
|
|
list_DISTRIBUTE_DETAIL.Add(detail);
|
|
}
|
|
rst &= _DISTRIBUTE_DETAIL.BatchAdd(ref errors, list_DISTRIBUTE_DETAIL);
|
|
|
|
if (rst)
|
|
return Json(new { Success = false, Message = "保存成功" }, JsonRequestBehavior.AllowGet);
|
|
if (errors.Count > 0)
|
|
return Json(new { Success = false, Message = errors[0].ErrorMessage }, JsonRequestBehavior.AllowGet);
|
|
return Json(new { Success = false, Message = "导入出错!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("资源分配:" + ex.ToString());
|
|
return Json(new { Success = false, Message = "导入出错!" }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
|
|
public ActionResult BindResUploadRes(Pager pager, string columns, string file)
|
|
{
|
|
DataTable dt = null;
|
|
try
|
|
{
|
|
NPOIHelper.InitializeWorkbook_xls(AppDomain.CurrentDomain.BaseDirectory + "Uploads\\" + file);
|
|
dt = NPOIHelper.ConvertToDataTable();
|
|
dt.Columns.Add("客服ID是否存在");
|
|
TempData["uploadtable"] = dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Json(new { Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
Table table = new Table(columns, true) { gridPager = pager };
|
|
|
|
if (dt.Rows.Count > 0 || dt.Columns.Count == 2)
|
|
{
|
|
List<BAS_INNERUSER> list_BAS_INNERUSER = _IBAS_INNERUSER_Q.GetList();
|
|
foreach (DataRow dataRow in dt.Rows)
|
|
{
|
|
dataRow["客服ID是否存在"] = list_BAS_INNERUSER.Any(obj => obj.EID.ToString() == dataRow["工号1"].ToString());
|
|
}
|
|
|
|
pager.totalRows = dt.Rows.Count;
|
|
int start = (pager.page - 1) * pager.rows;
|
|
int end = start + pager.rows;
|
|
while (start < end && start < pager.totalRows)
|
|
{
|
|
DataRow model = dt.Rows[start++];
|
|
table.AddCol(model[0]);
|
|
table.AddCol(model[1]);
|
|
table.AddCol(model[2].ToString() == "True" ? "" : "工号不存在");
|
|
table.AddRow();
|
|
}
|
|
}
|
|
|
|
var json = new
|
|
{
|
|
totalPages = pager.totalPages,
|
|
totalRows = pager.totalRows,
|
|
rowsList = table.GetRows()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
}
|