1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120 |
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Common.Wechat;
- using Common;
- using System.Data;
- using ZcPeng.PublicLibrary;
- using CoreEntity.Entity;
- using Common.Model;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using System.Data.SqlClient;
- using CoreEntity.TimedTask;
- using ZcPeng.weixin.PublicAccount;
- using CoreEntity.DAL;
- using CoreEntity.TimeJob;
- using PublicLibrary.Model;
- using Microsoft.Extensions.Caching.Memory;
- using PublicLibrary.Common;
- using CoreEntity.BAL;
- using SupplierWeb.Codes.mvc;
- using SupplierWeb.Codes.Push;
- using Npoi.Mapper;
- using System.IO;
- using Microsoft.AspNetCore.Hosting;
- using LigerRM.Common;
- namespace SupplierWeb.Controllers
- {
- [Route("web/push")]
- public class PushRecordController : BaseController
- {
- public PushRecordController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
-
- [AuthPermission]
- [HttpPost, Route("pushrecord/{staffId}")]
- public ActionResult PushRecord(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields,
- string staffId,
- [FromBody]dynamic data,
- bool timeout = false,
- bool belowlimit = false,
- bool all = false)
- {
- string userids = getStaff("userid");
- string RoleId = getStaff("roleid");
-
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- items = new string[] { },
- sum = new { },
- totalCount = -1,
- timeout = 1,
- });
- }
- if (data != null)
- {
-
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取推送记录
- DataTable dt = new DataTable();
- string result;
-
- string filterstr = "";
- List<SqlParameter> parameters = new List<SqlParameter>();
- filterstr += QueryFilter.getFilterSqlParam(filters, out parameters, new PushRecordExt(), "B.");
- filterstr = filterstr.Replace("B.AccountRealName", "isnull(C.AccountRealName,D.Contact)");
- if (timeout)
- filterstr += " and datediff( hour, B.CreationTime, getdate() ) >= 6";
- if (belowlimit)
- filterstr += " and exists (select A1.PushRecordId from " + Config.TablePrefix + "PushFeedback A1 where A1.PushRecordId = B.Id and A1.State=2)";
- if (all)
- filterstr += "";
-
- string StaffDocId = StaffDocDAL.GetStaffId(userids);
-
-
-
- string direct = " desc ";
- if (sortDirection != 1)
- direct = " asc";
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- string filterPurrole = FilterTranslator.ruleSql(ref parameters);
- string commandText0 = "select * from ";
- string commandText1 = "(" +
- "select B.*,isnull(C.AccountRealName,D.Contact) as AccountRealName," +
- "row_number() over" +
- "( order by " + sortField + " " + direct + " ) as rownum from " +
- Config.TablePrefix + "PushRecord as B " +
- " left join sup_Account C on B.PushAccountId = C.Id " +
- " left join ContactDoc D on D.EntId = B.EntId and D.ContactId = B.ContactId" +
- " where 1=1 " +
-
-
- filterstr +
-
- filterPurrole +
- ")AAA ";
- string commandText = commandText0 + commandText1 + " where AAA.rownum>" + start + " and AAA.rownum<" + end;
- bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
-
- IList<PushRecordExt> users = new List<PushRecordExt>();
- if (dt != null && dt.Rows.Count > 0)
- {
-
- users = ModelConvertHelper<PushRecordExt>.ConvertToModel(dt);
- }
- #endregion
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- var jsonData = JsonConvert.SerializeObject(users, timejson);
- string result1;
- string commandTextCount = "select count(Id) from " + commandText1;
- long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters.ToArray(), out result1);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
-
- [AuthPermission]
- [HttpPost, Route("pushfeedback/{state}/{staffId}")]
- public ActionResult PushFeedback(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields,
- String state,
- string staffId,
- [FromBody]dynamic data)
- {
- string userids = getStaff("userid");
- string RoleId = getStaff("roleid");
-
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- items = new string[] { },
- sum = new { },
- totalCount = -1,
- timeout = 1,
- });
- }
- if (data != null)
- {
-
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取推送记录明细
- DataTable dt = new DataTable();
- string result = string.Empty;
- string direct = " desc ";
- if (sortDirection != 1)
- direct = " asc";
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- string filter = string.Empty;
- if (state == null || state == "")
- filter = " and " + " A.State IS NULL OR A.State in (0,5) ";
- else if (state == "0,5")
- filter = " and " + " A.State IS NULL OR A.State in (0,5)";
- else if (state == "5,6")
- filter = " R A.State in (5,6)";
- else if (state == "0,5,6")
- filter = " and " + " A.State IS NULL OR A.State in (0,5,6)";
- else if (state == "999")
- filter = " and " + " A.State in (0,5,6) and datediff( hour, A.CreationTime, getdate() ) >= 6";
- else if (state == "1")
- filter = " and " + " A.State = 1";
- else if (state == "1,2")
- filter = " and " + " A.State in (1,2)";
- else if (state == "3")
- filter = " and " + " A.State = 3";
- else if (state == "4")
- filter = " and " + " A.State = 4";
- else if (state == "all")
- filter = "";
- else
- filter = " and " + " A.State = " + state;
-
- string StaffDocId = StaffDocDAL.GetStaffId(userids);
-
-
-
-
- List<SqlParameter> parameters1 = new List<SqlParameter>();
- string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new PushFeedbackExt(), "A.");
- if (filterstr.IndexOf("AccountRealName") > 0)
- {
- filterstr = filterstr.Replace("and A.AccountRealName", "and isnull(C.AccountRealName,D0.Contact)");
- }
- else if (filterstr.IndexOf("DiffHour") > 0)
- {
- filterstr = filterstr.Replace("and A.DiffHour", "and CAST(datediff( hour, A.CreationTime, getdate() ) as decimal)");
- }
- filterstr = filterstr.Replace("and A.CentPayMd", "and D.CentPayMd ");
- filterstr = filterstr.Replace("and A.ReceiptMd", "and D.ReceiptMd ");
- filterstr = filterstr.Replace("and A.RequestDate", "and CONVERT(datetime,D.EndDate,101) ");
- filter += filterstr;
- filter = filter.Replace("A.IsPrepayI", " Case D.IsPrepay When 'Y' Then 1 Else 0 End ");
- filter = filter.Replace("A.PrepayAmt", "D.PrepayAmt");
- string filterPurrole = FilterTranslator.ruleSql(ref parameters1);
- string commandText0 = "select * from (";
- string commandText1 = "select A.*,'' as OrgId,'' as DepId," +
- "isnull(C.AccountRealName,D0.Contact) as AccountRealName," +
- " CAST(datediff( hour, A.CreationTime, getdate() ) as decimal) as DiffHour, " +
- (state != "3" && state != "4" ? "" : "D.CentPayMd,D.ReceiptMd," +
- "CASE D.EndDate WHEN '0001-01-01' THEN null ELSE CONVERT(datetime,D.EndDate,101) END as RequestDate," +
- "Case D.IsPrepay When 'Y' Then 1 Else 0 End IsPrepayI,D.PrepayAmt,"
- ) +
- "'盒' as Unit,F.WmsMeas," +
- "row_number() over" +
- "( order by A." + sortField + direct + " ) as rownum";
- string commandText2 = " from " + Config.TablePrefix + "PushFeedback A left join " + Config.TablePrefix + "PushRecord B on A.PushRecordId = B.Id " +
- " left join " + Config.TablePrefix + "Account C on C.Id = A.PushAccountId " +
- " left join ContactDoc D0 on D0.EntId = A.EntId and D0.ContactId = A.ContactId " +
- (state != "3" && state != "4" ? "" : " left join PurPlanMT D on D.EntId = B.EntId and D.PushRecordId = B.Id and D.K_ContactId = A.ContactId and D.BillState=0 ") +
-
- " left join GoodsAttr F on F.EntId = A.EntId and F.GoodsId = A.GoodsId " +
- " where 1 = 1 " +
- (state != "3" && state != "4" ? "" : " and D.BillState=0 ") +
- filter +
- filterPurrole +
- "";
- string commandText = commandText0 + commandText1 + commandText2 + ")AAA where AAA.rownum>" + start + " and AAA.rownum<" + end
- ;
-
- bool success = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
- #endregion
-
- IList<PushFeedbackExt> users = new List<PushFeedbackExt>();
- if (dt != null && dt.Rows.Count > 0)
- {
-
- users = ModelConvertHelper<PushFeedbackExt>.ConvertToModel(dt);
- foreach (PushFeedbackExt pfbe in users)
- {
- pfbe.ContactId = pfbe.ContactId + "_" + pfbe.SuppliersId + "_" + pfbe.PushAccountId;
- }
- }
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- var jsonData = JsonConvert.SerializeObject(users, timejson);
- string result1;
- string commandTextCount = "select count(*) " + commandText2;
- long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out result1);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
- [AuthPermission]
- [HttpPost, Route("exportexcel")]
- public ActionResult exportExcel([FromServices]IHostingEnvironment env, string filter, string staffId,string size, string index)
- {
- string userids;
- string RoleId = getStaff("roleid");
- userids = getStaffUserid(staffId);
-
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = false,
- msg = "没有登录"
- });
- }
- #region 获取推送记录明细
- DataTable dt = new DataTable();
- string result;
- string direct = " desc ";
- if (0 != 1) {
- direct = " asc";
- }
- string StaffDocId = StaffDocDAL.GetStaffId(userids);
- string filterPurrole = FilterRuleByPur.getRolePermFilter(RoleId, " and B.PushAccountId in (select userid from K_contactsp K1 left join ContactDoc A1 on K1.ContactId = A1.ContactId " +
- " and K1.SaleManId = '" + StaffDocId + "')");
- List<SqlParameter> parameters2;
-
- QueryFilter[] filters = JsonConvert.DeserializeObject<QueryFilter[]>(filter);
- String filterstr1 = QueryFilter.getFilterSqlParam(filters, out parameters2, new Temp());
-
-
-
- List<List<Object>> parameters = new List<List<Object>>();
-
-
- if (!string.IsNullOrEmpty(filter)&&filter!= "[]")
- {
- parameters.Add(new List<Object>() { filters[0].field+"_0", "%"+filters[0].value+"%" });
- }
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- string commandText0 = "select * from (";
- string commandText1 = "select A.*,'' as OrgId,'' as DepId, C.AccountRealName, E.Unit," +
- "row_number() over (order by A.Id " + direct + ") as rownum" +
- " from " +
- Config.TablePrefix + "PushFeedback A " +
- " left join " + Config.TablePrefix + "PushRecord B on A.PushRecordId = B.Id" +
- " left join " + Config.TablePrefix + "Account C on A.PushAccountId = C.Id" +
- " left join PGPrice E on E.EntId = A.EntId and E.GoodsId = A.GoodsId" +
- " where 1 = 1 and A.state = '2'" + filterstr1 + ")AAA ";
-
- string commandText2= "";
- if (!string.IsNullOrEmpty(size)&& !string.IsNullOrEmpty(index))
- {
- if (index == "1")
- {
- commandText2 = " WHERE rownum>=1 and rownum<="+size;
- }
- else
- {
- commandText2 = " WHERE rownum>="+ Convert.ToInt32(index) * Convert.ToInt32(size) +"and rownum<"+Convert.ToInt32(size) * (Convert.ToInt32(index)+1);
- }
- }
- string commandText = commandText0 + commandText1+ commandText2;
- bool success = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
-
-
- IList<PushRecordExcel> users = new List<PushRecordExcel>();
- if (dt != null && dt.Rows.Count > 0)
- {
-
- users = ModelConvertHelper<PushRecordExcel>.ConvertToModel(dt);
- }
- #endregion
- var mapper = new Mapper();
-
- var fileName = Path.Combine("excel", "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
- mapper
- .Map<PushRecordExcel>("推送时间", o => o.CreationTime)
- .Map<PushRecordExcel>("业务员", o => o.AccountRealName)
- .Map<PushRecordExcel>("商品编码", o => o.GoodsCode)
- .Map<PushRecordExcel>("商品名称", o => o.GoodsName)
- .Map<PushRecordExcel>("业务员备注", o => o.Feedback)
- .Map<PushRecordExcel>("订货数量", o => o.StoreGapNum)
- .Map<PushRecordExcel>("库存缺口总数", o => o.PurchaseTotalNum)
- .Map<PushRecordExcel>("标准进价", o => o.ActPrice)
- .Map<PushRecordExcel>("实际进价", o => o.PurPrice)
- .Map<PushRecordExcel>("供应商编码", o => o.BusinessCode)
- .Map<PushRecordExcel>("品牌名称", o => o.BrandName)
- .Map<PushRecordExcel>("商品规格", o => o.GoodsSpec)
- .Map<PushRecordExcel>("生产厂家", o => o.Manufacturer)
- .Map<PushRecordExcel>("备注", o => o.Remark)
-
- .Save(Path.Combine(env.WebRootPath, fileName), users, "newSheet", overwrite: true, xlsx: false);
- byte[] fileBytes = System.IO.File.ReadAllBytes(Path.Combine(env.WebRootPath, fileName));
- System.IO.File.Delete(env.WebRootPath + Path.DirectorySeparatorChar + fileName);
- return File(fileBytes, "application/ms-excel", DateTime.Now.ToString("MMddHHmmss") + ".xls");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [AuthPermission]
- [HttpPost, Route("storlimit")]
- public ActionResult StorLimit(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
- {
- if (data != null)
- {
-
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取库存低于下限记录
- DataTable dt = new DataTable();
- string result;
- string connectstr = "Data Source =192.168.50.30; Initial Catalog = LJHYBZK; Persist Security Info = True; User ID = sa; Password = xq!@#2014;Pooling=true;MAX Pool Size=512;Min Pool Size=50;Connection Lifetime=30";
- string direct = " desc ";
- if (sortDirection != 1)
- direct = " asc";
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- List<SqlParameter> parameters1 = new List<SqlParameter>();
- string filter = QueryFilter.getFilterSqlParam(filters, out parameters1,new PushStorLimit());
- string commandText0 = "select * from ";
- string commandText1 = "(select *, row_number() over" +
- "( order by "+ sortField + direct + " ) as rownum" +
- " from " + Config.TablePrefix + "PushStorLimit " +
- " where 1=1 "+ filter +
- ")AAA";
- string commandText = commandText0 + commandText1 + " where AAA.rownum>" + start + " and AAA.rownum<" + end +
- " ";
-
- bool success = DataAccess.GetValues(connectstr,commandText, ref dt, parameters1.ToArray(), out result);
- #endregion
-
- IList<PushStorLimit> users = new List<PushStorLimit>();
- if (dt!=null && dt.Rows.Count > 0)
- {
-
- users = ModelConvertHelper<PushStorLimit>.ConvertToModel(dt);
- }
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- var jsonData = JsonConvert.SerializeObject(users, timejson);
- string result1;
- string commandTextCount = "select count(*) from "+ commandText1;
- int totalcount = DataAccess.GetRowCountDefine(connectstr, commandTextCount, parameters1.ToArray(), out result1);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [HttpGet, Route("PrepayAmt")]
- public JsonResult PrepayAmt(string PushRecordId,string BusinessId)
- {
- string sql = "select sum(ActPrice*StoreGapNum) as PrepayAmt from " + Config.TablePrefix+ "PushFeedback" +
- " where PushRecordId = @PushRecordId " +
- " and BusinessId = @BusinessId " +
- " group by PushRecordId,BusinessId";
- string result = string.Empty;
- List<SqlParameter> param = new List<SqlParameter>(2);
- param.Add(new SqlParameter("PushRecordId", PushRecordId));
- param.Add(new SqlParameter("BusinessId", BusinessId));
- DataAccess.GetOneValue(sql, param,out var PrepayAmt, out result);
- return Json(new
- {
- success = 1,
- sum = PrepayAmt,
- msg = result
- });
- }
- }
- }
|