| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- using CallCenter.Utility;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers.Wiki
- {
- [Authority]
- public class FunctionsController : BaseController
- {
- // GET: Policy
- /// <summary>
- /// 上传附件
- /// </summary>
- /// <returns></returns>
- public ActionResult UploadFile()
- {
- HttpFileCollection files = RequestString.GetFiles();
- if (files.Count > 0)
- {
- List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
- string path = "/Upload/Wiki/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
- for (int i = 0; i < files.Count; i++)
- {
- HttpPostedFile file = files[i];
- FileUp fu = new FileUp();
- string name = fu.Upload(file, path);
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_FileName = name;//附件名称
- model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
- model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
- model_T_Sys_Accessories.F_Size = file.ContentLength;
- model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人
- int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- model_T_Sys_Accessories.F_FileId = id;
- acs.Add(model_T_Sys_Accessories);
- }
- return Success("成功", acs);
- }
- else
- {
- return Error("请选择要上传的文件");
- }
- }
- /// <summary>
- /// 列表
- /// </summary>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <param name="isdc"></param>
- /// <returns></returns>
- public ActionResult GetList(string keyvalue, string stime, string etime, int key = 0, int page = 1, int pagesize = 10, int isdc = 0)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 ";
- string sqldt = "";
- if (stime.Trim() != "" && stime != "undefined")
- {
- sql += " and F_FaBuShiJian >= '" + stime + " 00:00:00" + "' ";
- }
- if (etime.Trim() != "" && etime != "undefined")
- {
- sql += " and F_FaBuShiJian <= '" + etime + " 23:59:59" + "' ";
- }
- if (key > 0)
- {
- //sql += " and F_Key = " + key;
- sqldt = " INNER JOIN [GetValueId]('" + key + "') Value on a.F_Key = Value.F_ValueId";
- }
- if (!string.IsNullOrEmpty(keyvalue))
- {
- sql += " and (F_FaWenWenHao like '%" + keyvalue + "%' or F_FaWenDanWei like '%" + keyvalue + "%' orF_BiaoShiBianMa like '%" + keyvalue + "%' or F_ZhiNengBuMen like '%" + keyvalue + "%' or F_WenJianMingCheng like '%" + keyvalue + "%' or F_WenJianNeiRong like '%" + keyvalue + "%')";
- }
-
- if (isdc > 0)
- {
- string cols = "(case when a.F_Id <100 then RIGHT ('00'+CONVERT (varchar(10),a.F_Id),3) else CONVERT(varchar(10), a.F_Id) end) as 序号,F_HangYe as 所属行业 ,F_ZhiNengBuMen as 职能部门,F_WenJianNeiRong as 文件内容,F_WenJianMingCheng as 文件名称,F_FaWenWenHao as 发文文号,F_FaWenDanWei as 发文单位,dbo.GetKeyNames(F_Key) as 四级关键词,F_FaBuShiJian as 发布时间,F_FaBuRen as 发布人,F_FaBuDanWei as 发布单位,F_BiaoShiBianMa as 标识编码,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as 附件,地区 as F_DiQu";
- var dtdc = DB.DbHelperSQL.Query(" select " + cols + " from T_Wiki_Functions a with(nolock) " + sqldt + " where 1=1 " + sql).Tables[0];
- var msg = new NPOIHelper().ExportToExcel("部门职能", dtdc);
- if (msg == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_Wiki_Functions a with(nolock) " + sqldt,
- "F_Id",
- "a.*,dbo.GetDictionaryName(F_Key) as KeyName",
- sql,
- "ORDER BY F_DianJiLiang,F_CreateTime DESC",
- pagesize,
- page,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
-
- /// <summary>
- /// 获取
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult GetModel(int id = 0)
- {
- if (id != 0)
- {
- var model = new BLL.T_Wiki_Functions().GetModel(id);
- if (model != null)
- {
- DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions set F_DianJiLiang=F_DianJiLiang+1 where F_Id=" + id);
- DataTable dtkey = new DataTable();
- if (model.F_Key > 0)
- {
- dtkey = DB.DbHelperSQL.Query(" select * from View_KeysSplit where id=" + model.F_Key).Tables[0];
- }
- DataTable dtfile = new DataTable();
- var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
- if (!string.IsNullOrEmpty(model.F_File) && configfj != null)
- {
- dtfile = DB.DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + model.F_File + ")").Tables[0];
- foreach (DataRow dr in dtfile.Rows)
- {
- dr["F_FileUrl"] = configfj.F_ParamValue + dr["F_FileUrl"].ToString();
- }
- }
- var obj = new { model, dtkey, dtfile };
- return Success("成功", obj);
- }
- return Error("参数错误");
- }
- else
- {
- return Error("参数错误");
- }
- }
-
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AddModel(int id = 0, int key = 0)
- {
- string fabudanwei = RequestString.GetFormString("fabudanwei");
- string faburen = RequestString.GetFormString("faburen");
- string hangye = RequestString.GetFormString("hangye");
- string diqu = RequestString.GetFormString("diqu");
- string shengxiaoshijian = RequestString.GetFormString("shengxiaoshijian");
- string shixiaoshijian = RequestString.GetFormString("shixiaoshijian");
- string fabushijian = RequestString.GetFormString("fabushijian");
- string fawenwenhao = RequestString.GetFormString("fawenwenhao");
- string fawendanwei = RequestString.GetFormString("fawendanwei");
- string biaoshibianma = RequestString.GetFormString("biaoshibianma");
- string zhinengbumen = RequestString.GetFormString("zhinengbumen");
- string file = RequestString.GetFormString("file");
- string wenjianmingcheng = RequestString.GetFormString("wenjianmingcheng");
- string wenjianneirong = RequestString.GetFormString("wenjianneirong");
- Model.T_Wiki_Functions dModel = new Model.T_Wiki_Functions();
- if (id == 0)
- {
- //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 ").Tables[0];
- //if (list.Rows.Count > 0)
- //{
- // return Error("已经存在");
- //}
- //else
- //{
-
- dModel.F_FaBuRen = User.F_UserName;
- dModel.F_FaBuDanWei = fabudanwei;
- dModel.F_HangYe = hangye;
- dModel.F_DiQu = diqu;
- try
- {
- dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
- }
- catch { };
- try
- {
- dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
- }
- catch { };
- dModel.F_FaBuShiJian = DateTime.Now;
- dModel.F_Key = key;
- dModel.F_FaWenWenHao = DateTime.Now.ToString("yyyyMMddHHmmssff");
- dModel.F_FaWenDanWei = fawendanwei;
- // dModel.F_BiaoShiBianMa = biaoshibianma;
- dModel.F_ZhiNengBuMen = zhinengbumen;
- dModel.F_File = file;
- dModel.F_WenJianMingCheng = wenjianmingcheng;
- dModel.F_WenJianNeiRong = wenjianneirong;
- dModel.F_DianJiLiang = 0;
- dModel.F_IsDelete = 0;
- dModel.F_CreateUser = User.F_UserCode;
- dModel.F_CreateTime = DateTime.Now;
- int n = new BLL.T_Wiki_Functions().Add(dModel);
- if (n > 0)
- {
- DB.DbHelperSQL.ExecuteSql("update T_Wiki_Functions set F_BiaoShiBianMa =right('00000'+'" + User.F_DeptId + "' ,5)+right('0000000'+'" + n + "' ,8) where F_Id=" + n);
- return Success("添加成功", n);
- }
-
- else
- return Error("添加失败");
- //}
- }
- else
- {
- dModel = new BLL.T_Wiki_Functions().GetModel(id);
- if (dModel != null)
- {
- //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 and F_Id!='" + id + "' ").Tables[0];
- //if (list.Rows.Count > 0)
- //{
- // return Error("已经存在");
- //}
- //else
- //{
- dModel.F_FaBuRen = faburen;
- dModel.F_FaBuDanWei = fabudanwei;
- dModel.F_HangYe = hangye;
- dModel.F_DiQu = diqu;
- try
- {
- dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian);
- }
- catch { };
- try
- {
- dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian);
- }
- catch { };
- try
- {
- dModel.F_FaBuShiJian = DateTime.Parse(fabushijian);
- }
- catch { };
- dModel.F_Key = key;
- dModel.F_FaWenWenHao = fawenwenhao;
- dModel.F_FaWenDanWei = fawendanwei;
- dModel.F_BiaoShiBianMa = biaoshibianma;
- dModel.F_ZhiNengBuMen = zhinengbumen;
- dModel.F_File = file;
- dModel.F_WenJianMingCheng = wenjianmingcheng;
- dModel.F_WenJianNeiRong = wenjianneirong;
- if (new BLL.T_Wiki_Functions().Update(dModel))
- return Success("修改成功");
- else
- return Error("修改失败");
- //}
- }
- else
- {
- return Error("修改失败");
- }
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelModel(string[] ids)
- {
- if (ids == null || ids.Length <= 0)
- {
- return Error("请选择要删除的选项");
- }
- var idStr = string.Join(",", ids);
- if (string.IsNullOrEmpty(idStr.Trim()))
- {
- return Error("请选择要删除的选项");
- }
- int n = DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
- if (n > 0)
- {
- return Success("删除成功");
- }
- return Error("删除失败");
- }
- /// <summary>
- /// 导出word
- /// </summary>
- /// <returns></returns>
- public ActionResult ExportWord(int id)
- {
- var aw = new AsposeWord();
- aw.OpenWithTemplate(Server.MapPath("/Upload/Word/政策法规模板.doc"));
- var dt = DB.DbHelperSQL.Query("select a.*,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as fileurl from T_Wiki_Policy a with(nolock) where a.F_Id=" + id).Tables[0];
- string F_key = dt.Rows[0]["F_key"].ToString();
- var dt2 = DB.DbHelperSQL.Query("SELECT * FROM View_KeysSplit WHERE id=" + F_key).Tables[0];
- aw.Builder();
- aw.CreateDepartmentFunctionsWord(dt, dt2);
- var bt = aw.ExportAs();
- Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
- return File(bt, "application/msword", DateTime.Now.Ticks.ToString() + ".doc");
- }
- }
- }
|