using System;
using Learun.Util;
using System.Data;
using Learun.Application.TwoDevelopment.PersonnelManagement;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using Learun.Application.Organization;
using Learun.Application.TwoDevelopment.LR_Desktop;
using Learun.Util.Operat;
using Newtonsoft.Json;
namespace Learun.Application.Web.Areas.PersonnelManagement.Controllers
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 力软敏捷开发框架
/// Copyright (c) 2013-2018 上海力软信息技术有限公司
/// 创 建:超级管理员
/// 日 期:2019-09-24 15:32
/// 描 述:内控管理
///
public class MP_ManagementPlanController : MvcControllerBase
{
private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
private UserIBLL userIBLL=new UserBLL();
private MP_ManagementPlanIBLL mP_ManagementPlanIBLL = new MP_ManagementPlanBLL();
#region 视图功能
///
/// 主页面
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
///
/// 管理员页面
///
///
[HttpGet]
public ActionResult IndexManagement()
{
return View();
}
///
/// 提交材料页面
///
///
[HttpGet]
public ActionResult IndexChildren()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult Form()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult UploadForm()
{
return View();
}
#endregion
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
[HttpGet]
[AjaxOnly]
public ActionResult GetPageList(string pagination, string queryJson)
{
Pagination paginationobj = pagination.ToObject();
var data = mP_ManagementPlanIBLL.GetPageList(paginationobj, queryJson);
var jsonData = new
{
rows = data,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records
};
return Success(jsonData);
}
///
/// 获取表单数据
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetFormData(string keyValue)
{
var MP_ManageMentPlanData = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
var jsonData = new
{
MP_ManageMentPlan = MP_ManageMentPlanData,
};
return Success(jsonData);
}
[HttpGet]
[AjaxOnly]
public ActionResult GetAcademicYear()
{
var data = WebHelper.GenerateNearByAcademicTwo();
return Success(data);
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult DeleteForm(string keyValue)
{
mP_ManagementPlanIBLL.DeleteEntity(keyValue);
return Success("删除成功!");
}
///
/// 合格/不合格
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult Qqualified(string keyValue, bool status)
{
var entity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
entity.MPConclusion = status?1:0;
mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
return Success("修改成功!");
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveForm(string keyValue, string strEntity)
{
MP_ManageMentPlanEntity entity = strEntity.ToObject();
entity.MPType = 0;
mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
return Success("保存成功!");
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult UploadForm(string keyValue, string strEntity)
{
MP_ManageMentPlanEntity entity = strEntity.ToObject();
if (!string.IsNullOrEmpty(keyValue))
{
var entity2 = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
if (!string.IsNullOrEmpty(entity.MPFileTwo))
{
entity.MPStatus = 0;//已提交
entity.MPUploadTimes = $"{DateTime.Now.ToString()}, {entity2.MPUploadTimes}";
entity.SUpdateTime = entity2.SUpdateTime + 1;
}
}
else
{
entity.Create();
if (!string.IsNullOrEmpty(entity.MPFileTwo))
{
entity.MPStatus = 0;//已提交
entity.MPUploadTimes = DateTime.Now.ToString();
entity.SUpdateTime = 1;
entity.MPType = 0;
}
}
entity.MPUploaderTwo = LoginUserInfo.Get().userId;
mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
return Success("保存成功!");
}
public void PushWeixin(string MPId)
{
var title = "";
//获取内控模板信息
var mpEntity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(MPId);
//根据部门获取所有需要推送的人员
var UserList = new List();
if (mpEntity != null)
{
var departmentList = mpEntity.MPDepartment.Split(',').ToList();
foreach (var departmentId in departmentList)
{
var entityList=userIBLL.GetListByDepartmentId(departmentId);
if (entityList.Count>0)
{
UserList.Union(entityList);
}
}
switch (mpEntity.MPType)
{
case 0:
title = "您有内控检查材料需要上传,请查看";
break;
case 1:
title = "您有绩效测试材料需要上传,请查看";
break;
case 2:
title = "您有质量测试材料需要上传,请查看";
break;
}
}
var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
string appid = WeChatConfigentity.APPId;
string secret = WeChatConfigentity.secret;
var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
string weixintaskurl = wechatemplete.TUrl;
string weixintasktempid = wechatemplete.TempId;
var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
OperateLogModel operateLogModel = new OperateLogModel();
operateLogModel.title = title;
operateLogModel.type = OperationType.Other;
operateLogModel.url = "NoticeController";
operateLogModel.sourceObjectId = "002";
operateLogModel.sourceContentJson = responsejson;
OperatorHelper.Instance.WriteOperateLog(operateLogModel);
foreach (UserEntity userinfo in UserList)
{
if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
{
//执行推送任务
if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
{
if (!string.IsNullOrEmpty(responsejson))
{
var weixintokenobj = JsonConvert.DeserializeObject(responsejson);
if (string.IsNullOrEmpty(weixintokenobj.errcode))
{
string access_token = weixintokenobj.access_token;
string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
"\"template_id\":\"" + weixintasktempid + "\"," +
"\"url\":\"" + weixintaskurl + "\"," +
"\"data\":{" +
"\"first\": {\"value\":\"您有新的未读通知公告\",\"color\":\"#173177\"}," +
"\"keyword1\":{\"value\":\"未读通知公告\",\"color\":\"#173177\"}," +
"\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
"\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
"\"keyword4\": {\"value\":\"您有新的未读通知公告【" + title + "】\",\"color\":\"#173177\"}" +
"}" +
"}";
string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
operateLogModel.title = title;
operateLogModel.type = OperationType.Other;
operateLogModel.url = "NoticeController";
operateLogModel.sourceObjectId = "002";
operateLogModel.sourceContentJson = pushresult;
OperatorHelper.Instance.WriteOperateLog(operateLogModel);
}
}
}
}
}
}
#endregion
}
}