Нет описания

BusinessController.cs 91KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers.report
  12. {
  13. // [Authority]
  14. public class BusinessController : BaseController
  15. {
  16. public ActionResult ExitUserCode(int deptid)
  17. {
  18. Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(deptid);
  19. string sql = "";
  20. if (deptModel != null)
  21. {
  22. sql += " and F_DeptId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  23. }
  24. DataTable dt = new DataTable();
  25. DataTable depts = new DataTable();
  26. int recordCount = 0;
  27. depts = BLL.PagerBLL.GetListPager(
  28. "T_Sys_UserAccount",
  29. "F_UserId",
  30. "*",
  31. sql,
  32. "",
  33. 1000000,
  34. 1,
  35. true,
  36. out recordCount
  37. );
  38. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(depts);
  39. #region
  40. dt.Columns.Add("姓名");
  41. dt.Columns.Add("账号");
  42. dt.Columns.Add("密码");
  43. dt.Columns.Add("手机");
  44. dt.Columns.Add("角色");
  45. dt.Columns.Add("部门");
  46. dt.Columns.Add("职位");
  47. #endregion
  48. foreach (var it in modelList)
  49. {
  50. DataRow drNew = dt.NewRow();
  51. #region 基本字段
  52. drNew["姓名"] = it.F_UserName;//序号
  53. drNew["账号"] = it.F_UserCode;//姓名
  54. drNew["密码"] = it.F_Password;//地址
  55. drNew["手机"] = it.F_Mobile;
  56. drNew["角色"] = it.F_RoleName;
  57. drNew["部门"] = it.F_DeptName;
  58. drNew["职位"] = it.F_Post;
  59. ;
  60. dt.Rows.Add(drNew);
  61. #endregion
  62. }
  63. NPOIHelper npoi = new NPOIHelper();
  64. if (npoi.ExportToExcel(deptModel.F_DeptName + "大区人员表", dt) == "")
  65. {
  66. return Success("导出成功");
  67. }
  68. else
  69. {
  70. return Error("导出失败");
  71. }
  72. }
  73. public ActionResult AreaComplaint(string stime="", string endtime = "", int isdc=0)
  74. {
  75. List <Complaint> complaintlist = new List<Complaint>();
  76. DateTime strattime,enddatetime ;
  77. string where = "F_IsDelete = 0 and F_Area is not null and (F_Type=2 or (F_Duplicate in(2,0)and F_Type=3))";
  78. if (stime=="")
  79. {
  80. strattime = DateTime.Now.AddDays(-6);
  81. where += " and datediff(day,F_CreateTime,'" + strattime.ToString("yyyy-MM-dd") + "')<=0 ";
  82. }
  83. else
  84. {
  85. strattime = DateTime.Parse(stime);
  86. where += " and datediff(day,F_CreateTime,'" + stime + "')<=0 ";
  87. }
  88. if (endtime=="")
  89. {
  90. enddatetime = DateTime.Now;
  91. where += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  92. }
  93. else
  94. {
  95. enddatetime = DateTime.Parse(endtime);
  96. where += " and datediff(day,F_CreateTime,'" + endtime + "')>=0 ";
  97. }
  98. var workoeder = new BLL.T_Bus_WorkOrder().GetModelList(where);
  99. var Area = new BLL.T_Sys_Department().GetModelList("isnull(F_ParentId, 1) = 1 and F_State = 1 and F_Layer = 1");
  100. float max = 0; float min = 0;
  101. string maxarea = "", minarea="";
  102. Complaint complaints = new Complaint();
  103. complaints.serialnumbe = 20;
  104. complaints.area = "合计";
  105. float Distributionrate = 0;
  106. float documentary = 0;
  107. if (workoeder!=null )
  108. {
  109. for (int i=0;i < Area.Count;i ++ )
  110. {
  111. Complaint complaint = new Complaint();
  112. complaint.serialnumbe = i + 1;//序号
  113. complaint.area = Area[i].F_DeptName;//大区
  114. var group = workoeder.Where(p => p.F_Area == Area[i].F_DeptId.ToString()) ;//投诉总量
  115. complaint.complaintnumber = group.Count();
  116. complaint.assignmentnumber= group.Where(p => p.F_State ==1 || p.F_State == 5).Count ();//待分派
  117. complaints.assignmentnumber += complaint.assignmentnumber;
  118. float a = 0;int c = 0;int assignment=0;
  119. for (DateTime dt = strattime; dt <= enddatetime; dt = dt.AddDays (1))
  120. {
  121. // c++;
  122. assignment += group.Where(p => (p.F_TobeallocatedTime < dt.AddDays(1) && p.F_TobeallocatedTime >= dt
  123. && p.F_TransferTime < dt.AddDays(1) && p.F_TransferTime >= dt
  124. )
  125. ).Count();
  126. // var daycount= group.Where(p => (p.F_TransferTime < dt.AddDays (1)&&( p .F_TransferTime >= dt || p.F_AssignmenttIime==null) )
  127. // ).Count();
  128. //
  129. // var today= group.Where(p => p.F_TransferTime >= dt && p.F_TransferTime < dt.AddDays(1)
  130. // ).Count();
  131. // if (daycount > 0)
  132. // a += (float)today / daycount;//当日分派率
  133. // else
  134. // a += 1;
  135. }
  136. complaint.assignmentrate = string.Format("{0:f2}%",(float ) assignment / complaint.complaintnumber * 100);
  137. Distributionrate += assignment;
  138. complaint.pendingnumber = group.Where(p => p.F_State == 3).Count();//待处理
  139. complaints.pendingnumber += complaint.pendingnumber;
  140. complaint.processingnumber = group.Where(p => p.F_State == 4).Count();//处理中
  141. if (complaint.complaintnumber > 0)
  142. complaint.processingnumberrate = string.Format("{0:f2}%", complaint.processingnumber /(float ) complaint.complaintnumber * 100);//
  143. else
  144. complaint.processingnumberrate = "100%";
  145. complaints.processingnumber += complaint.processingnumber;
  146. complaint.processednumber = group.Where(p => p.F_State == 10).Count();//已处理
  147. complaints.processednumber += complaint.processednumber;
  148. float d = 0;
  149. if (complaint.complaintnumber > 0)
  150. {
  151. d = complaint.processednumber / (float)complaint.complaintnumber;
  152. complaint.processedrate = string.Format("{0:f2}%", complaint.processednumber / (float)complaint.complaintnumber * 100);//处理率
  153. }
  154. else
  155. {
  156. d = 1;
  157. complaint.processedrate = "100%";
  158. }
  159. if (i == 0)
  160. {
  161. min = d;
  162. max = d;
  163. maxarea = Area[i].F_DeptName;
  164. minarea = Area[i].F_DeptName;
  165. }
  166. else
  167. {
  168. if (d > max)
  169. {
  170. max = d;
  171. maxarea = Area[i].F_DeptName ;
  172. }
  173. if (d < min)
  174. {
  175. min = d;
  176. minarea = Area[i].F_DeptName;
  177. }
  178. }
  179. int reminder= group.Where(p => p.F_DealType == 1 ).Count();//催单数量
  180. documentary += reminder;
  181. int perfect= group.Where(p => p.F_DealState == 1).Count();//完善数量
  182. documentary += perfect;
  183. int total = reminder + perfect;
  184. if (group.Count()>0)
  185. complaint.documentaryrate = string.Format("{0:f2}%", total / (float)group.Count() * 100);//跟单率
  186. else
  187. complaint.documentaryrate = "100%";
  188. complaintlist.Add(complaint);
  189. }
  190. complaints.complaintnumber = workoeder.Count();
  191. if (workoeder.Count() > 0)
  192. complaints.assignmentrate = string.Format("{0:f2}%", Distributionrate / workoeder.Count() * 100); //当日分派率
  193. else
  194. complaints.assignmentrate = "100%";
  195. if (complaints.complaintnumber > 0)
  196. complaints.processedrate = string.Format("{0:f2}%", complaints.processednumber/(float )complaints.complaintnumber * 100);//处理率
  197. else
  198. complaints.processedrate = "100%";
  199. if (complaints.complaintnumber > 0)
  200. complaints.documentaryrate = string.Format("{0:f2}%", documentary / complaints.complaintnumber * 100);//跟单率
  201. else
  202. complaints.documentaryrate = "100%";
  203. if (complaints.complaintnumber > 0)
  204. complaints.processingnumberrate = string.Format("{0:f2}%", complaints.processingnumber / (float)complaints.complaintnumber * 100);//
  205. else
  206. complaints.processingnumberrate = "100%";
  207. complaintlist.Add(complaints);
  208. if (isdc>0)
  209. {
  210. NPOIHelper npoi = new NPOIHelper();
  211. if (npoi.Complainthandling(strattime, enddatetime, complaintlist, maxarea,minarea ) == "")
  212. {
  213. return Success("导出成功");
  214. }
  215. else
  216. {
  217. return Error("导出失败");
  218. }
  219. }
  220. else
  221. {
  222. var obj = new
  223. {
  224. complaintlist,
  225. maxarea,
  226. minarea,
  227. };
  228. return Success("获取成功", obj.ToJson ());
  229. }
  230. }
  231. else
  232. {
  233. return Success("暂无数据");
  234. }
  235. }
  236. public ActionResult Afterprogress(string stime = "", string endtime = "", int isdc = 0)
  237. {
  238. List<Aftersale> aftersalelist = new List<Aftersale>();
  239. DateTime strattime, enddatetime;
  240. string where = "F_IsDelete = 0 and F_Area is not null and (F_Type=2 or (F_Duplicate in(2,0)and F_Type=3))";
  241. if (stime == "")
  242. {
  243. strattime =DateTime .Parse ( DateTime.Now.AddMonths (-1).ToString ("yyyy-MM-28"));
  244. where += " and datediff(day,F_CreateTime,'" + strattime.ToString("yyyy-MM-dd") + "')<=0 ";
  245. }
  246. else
  247. {
  248. strattime = DateTime.Parse(stime);
  249. where += " and datediff(day,F_CreateTime,'" + stime + "')<=0 ";
  250. }
  251. if (endtime == "")
  252. {
  253. enddatetime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-27"));
  254. where += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  255. }
  256. else
  257. {
  258. enddatetime = DateTime.Parse(endtime);
  259. where += " and datediff(day,F_CreateTime,'" + endtime + "')>=0 ";
  260. }
  261. var workoeder = new BLL.T_Bus_WorkOrder().GetModelList(where);
  262. var Area = new BLL.T_Sys_Department().GetModelList("isnull(F_ParentId, 1) = 1 and F_State = 1 and F_Layer = 1");
  263. float max = 0; float min = 0;
  264. string maxarea = "", minarea = "";
  265. int Tobeassignment = 0;
  266. Aftersale complaints = new Aftersale();
  267. complaints.serialnumbe = "合计";
  268. complaints.receiving = 0;
  269. complaints.assignmentnumber = 0;
  270. complaints.area = "";
  271. if (workoeder != null)
  272. {
  273. Tobeassignment = workoeder.Where(x => x.F_State == 1 || x.F_State == 5).Count();
  274. for (int i = 0; i < Area.Count; i++)
  275. {
  276. Aftersale aftersale = new Aftersale();
  277. aftersale.serialnumbe = i + 1+"";//序号
  278. aftersale.area = Area[i].F_DeptName;//大区
  279. var group = workoeder.Where(p => p.F_Area == Area[i].F_DeptId.ToString());//投诉总量
  280. aftersale.total = group.Count();
  281. float a = 0; float b = 0; int assignment=0, receivingorders=0;
  282. for (DateTime dt = strattime; dt <= enddatetime; dt = dt.AddDays(1))
  283. {
  284. assignment+= group.Where(p => (p.F_TobeallocatedTime < dt.AddDays(1) && p.F_TobeallocatedTime >= dt
  285. && p.F_TransferTime < dt.AddDays(1) && p.F_TransferTime >= dt
  286. )
  287. ).Count();
  288. receivingorders += group.Where(p => (p.F_TransferTime < dt.AddDays(1) && p.F_TransferTime >= dt
  289. && p.F_Receiving < dt.AddDays(1) && p.F_Receiving >= dt
  290. )
  291. ).Count();
  292. }
  293. complaints.receiving += receivingorders;//接单条数
  294. aftersale.receiving = receivingorders;//接单条数
  295. complaints.assignmentnumber += assignment;
  296. aftersale.assignmentnumber = assignment;//分派投诉
  297. if (aftersale.total > 0)
  298. aftersale.assignmentrate = string.Format("{0:f2}%", (float)assignment / aftersale.total * 100);
  299. else
  300. aftersale.assignmentrate = "100%";
  301. if (aftersale.total > 0)
  302. aftersale.receivingrate = string.Format("{0:f2}%", (float)receivingorders / aftersale.total * 100);//接单率
  303. else
  304. aftersale.receivingrate = "100%";
  305. aftersale.processingnumber = group.Where( p => p.F_State == 4).Count();//处理中投诉
  306. aftersale.processednumber = group.Where( p => p.F_State == 10).Count();//已处理投诉
  307. float d = 0;
  308. if (aftersale.total > 0)
  309. {
  310. d = (float)aftersale.processednumber / aftersale.total;
  311. aftersale.processed = d;
  312. aftersale.processedrate = string.Format("{0:f2}%", (float)aftersale.processednumber / aftersale.total * 100);//完结率
  313. }
  314. else
  315. {
  316. d = 1;
  317. aftersale.processed = 1;
  318. aftersale.processedrate = "100%";
  319. }
  320. if (i == 0)
  321. {
  322. min = d;
  323. max = d;
  324. maxarea = Area[i].F_DeptName;
  325. minarea = Area[i].F_DeptName;
  326. }
  327. else
  328. {
  329. if (d > max)
  330. {
  331. max = d;
  332. maxarea = Area[i].F_DeptName;
  333. }
  334. if (d < min)
  335. {
  336. min = d;
  337. minarea = Area[i].F_DeptName;
  338. }
  339. }
  340. int reminder = group.Where(p => p.F_DealType == 1).Count();//催单数量
  341. if (aftersale.total > 0)
  342. aftersale.reminderrate = string.Format("{0:f2}%", (float)reminder / aftersale.total * 100);//
  343. else
  344. aftersale.reminderrate = "100%";
  345. aftersale.name = User(Area[i].F_DeptName);
  346. aftersalelist.Add(aftersale);
  347. }
  348. complaints.total = workoeder.Count();
  349. if (complaints.total > 0)
  350. complaints.assignmentrate = string.Format("{0:f2}%",(float ) complaints.assignmentnumber / complaints.total * 100); //当日分派率
  351. else
  352. complaints.assignmentrate = "100%";
  353. if (complaints.total > 0)
  354. complaints.receivingrate = string.Format("{0:f2}%", (float)complaints.receiving / complaints.total * 100); //当日分派率
  355. else
  356. complaints.receivingrate = "100%";
  357. complaints.processingnumber = workoeder.Where(p => p.F_State == 4).Count();//处理中投诉
  358. complaints.processednumber = workoeder.Where(p => p.F_State == 10).Count();//已处理投诉
  359. if (complaints.total > 0)
  360. complaints.processedrate = string.Format("{0:f2}%", (float)complaints.processednumber / complaints.total * 100);//完结率
  361. else
  362. complaints.processedrate = "100%";
  363. int remind= workoeder.Where(p => p.F_DealType == 1).Count();//催单数量
  364. if (complaints.total > 0)
  365. complaints.reminderrate = string.Format("{0:f2}%", (float)remind / complaints.total * 100);//
  366. else
  367. complaints.reminderrate = "100%";
  368. complaints.name = "";
  369. int pendingnumber = workoeder.Where(p => p.F_State == 3).Count();//
  370. aftersalelist = aftersalelist.OrderByDescending(x => x.processed).ToList ();
  371. aftersalelist.Add(complaints);
  372. for (int i=0;i < aftersalelist.Count-1;i++)
  373. {
  374. aftersalelist[i].serialnumbe = i+1+"";
  375. }
  376. if (isdc > 0)
  377. {
  378. NPOIHelper npoi = new NPOIHelper();
  379. if (npoi.AftersaleToExcel(strattime, enddatetime, aftersalelist, maxarea, minarea, pendingnumber, Tobeassignment) == "")
  380. {
  381. return Success("导出成功");
  382. }
  383. else
  384. {
  385. return Error("导出失败");
  386. }
  387. }
  388. else
  389. {
  390. var obj = new
  391. {
  392. aftersalelist,
  393. maxarea,
  394. minarea,
  395. pendingnumber
  396. };
  397. return Success("获取成功", obj.ToJson ()
  398. );
  399. }
  400. }
  401. else
  402. {
  403. return Success("暂无数据");
  404. }
  405. }
  406. /// <summary>
  407. ///
  408. /// </summary>
  409. /// <returns></returns>
  410. private string User(string DeptName )
  411. {
  412. string user="";
  413. if (DeptName== "湖南" || DeptName == "豫南" || DeptName == "豫北" || DeptName == "吉林" || DeptName == "闽赣" || DeptName == "综合")
  414. {
  415. var usermodel = new BLL.T_Sys_UserAccount().GetModel("8004");
  416. if (usermodel != null)
  417. user = usermodel.F_UserName;
  418. }
  419. //else if (DeptName == "鲁西" || DeptName == "华东" || DeptName == "鲁东")
  420. //{
  421. // var usermodel = new BLL.T_Sys_UserAccount().GetModel("8010");
  422. // if (usermodel != null)
  423. // user = usermodel.F_UserName;
  424. //}
  425. else if ( DeptName == "京津" || DeptName == "华东" || DeptName == "广东" || DeptName == "川渝" || DeptName == "陕宁" || DeptName == "晋蒙" || DeptName == "餐饮" || DeptName == "禽产品" || DeptName == "广海")
  426. {
  427. var usermodel = new BLL.T_Sys_UserAccount().GetModel("822353");
  428. if (usermodel != null)
  429. user = usermodel.F_UserName;
  430. }
  431. else if (DeptName == "安徽" || DeptName == "湖北" || DeptName == "西北" || DeptName == "云贵" )
  432. {
  433. var usermodel = new BLL.T_Sys_UserAccount().GetModel("8012");
  434. if (usermodel != null)
  435. user = usermodel.F_UserName;
  436. }
  437. else if ( DeptName == "辽宁" || DeptName == "黑龙江" || DeptName == "河北" || DeptName == "江苏" || DeptName == "鲁东" || DeptName == "鲁西" || DeptName == "生鲜品")
  438. {
  439. var usermodel = new BLL.T_Sys_UserAccount().GetModel("822249");
  440. if (usermodel != null)
  441. user = usermodel.F_UserName;
  442. }
  443. return user;
  444. }
  445. /// <summary>
  446. /// 坐席话务量
  447. /// </summary>
  448. /// <param name="date"></param>
  449. /// <returns></returns>
  450. public ActionResult GetAgentTelCount(string stime, string endtime)
  451. {
  452. string where = " ";
  453. if (stime == "")
  454. {
  455. where += " and datediff(day,BeginTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')<=0 ";
  456. }
  457. else
  458. {
  459. where += " and datediff(day,BeginTime,'" + stime + "')<=0 ";
  460. }
  461. if (endtime == "")
  462. {
  463. where += " and datediff(day,BeginTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  464. }
  465. else
  466. {
  467. where += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  468. }
  469. DataTable dtTel = DbHelperSQL.Query(" select * from T_Call_CallRecords where 1=1 " + where).Tables[0];
  470. string sql = "SELECT F_UserCode,F_UserName,F_WorkNumber,F_UserId FROM T_Sys_UserAccount where f_seatFlag=1 and F_DeleteFlag=0";
  471. DataTable dtUser = DbHelperSQL.Query(sql).Tables[0];
  472. string[] users = new string[dtUser.Rows.Count];//坐席工号/姓名
  473. int[] incount = new int[dtUser.Rows.Count];//呼入量
  474. int[] inconnectcount = new int[dtUser.Rows.Count];//呼入接通量
  475. int[] outcount = new int[dtUser.Rows.Count];//呼出量
  476. int[] outconnectcount = new int[dtUser.Rows.Count];//呼出接通量
  477. for (int i = 0; i < dtUser.Rows.Count; i++)
  478. {
  479. //坐席
  480. users[i] = "(" + dtUser.Rows[i]["F_UserCode"].ToString() + ")" + dtUser.Rows[i]["F_UserName"].ToString();
  481. //呼入量
  482. var inlist = dtTel.Select(" CallType=0 and UserCode='" + dtUser.Rows[i]["F_UserCode"].ToString() + "' ");
  483. incount[i] = inlist.Count();
  484. //呼入接通量
  485. var inconnectlist = dtTel.Select(" CallType=0 and CallState=1 and UserCode='" + dtUser.Rows[i]["F_UserCode"].ToString() + "' ");
  486. inconnectcount[i] = inconnectlist.Count();
  487. //呼出量
  488. var outlist = dtTel.Select(" CallType=1 and UserCode='" + dtUser.Rows[i]["F_UserCode"].ToString() + "' ");
  489. outcount[i] = outlist.Count();
  490. //呼出接通量
  491. var outconnectlist = dtTel.Select(" CallType=1 and CallState=1 and UserCode='" + dtUser.Rows[i]["F_UserCode"].ToString() + "' ");
  492. outconnectcount[i] = outconnectlist.Count();
  493. }
  494. var obj = new
  495. {
  496. users,
  497. incount,
  498. inconnectcount,
  499. outcount,
  500. outconnectcount
  501. };
  502. return Success("获取坐席话务量", obj);
  503. }
  504. public class Telephone
  505. {
  506. public List<Proportion> type;//诉求占比占比
  507. public List<Conversation> conversations ;//24小时来电量,接通量统计
  508. public List<TotalDate> dates ;//话务总体数据统计展示
  509. }
  510. public class TotalDate
  511. {
  512. public string average;
  513. public int connection;
  514. public int traffic;
  515. }
  516. public class Conversation
  517. {
  518. public int Incomingcall;//来电量
  519. public int time;
  520. public int Connect;//接通量
  521. }
  522. public class Proportion
  523. {
  524. public string name;
  525. public int total;
  526. public string proportion;
  527. }
  528. public ActionResult GetTelephoneList(string stime, string endtime)
  529. {
  530. string sql = $" F_IsDelete=0";
  531. string where = "";
  532. DataTable dt = new DataTable();
  533. if (stime == "")
  534. {
  535. sql += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')<=0 ";
  536. where += " datediff(day,BeginTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')<=0 ";
  537. }
  538. else
  539. {
  540. sql += " and datediff(day,F_CreateTime,'" + stime + "')<=0 ";
  541. where += " datediff(day,BeginTime,'" + stime + "')<=0 ";
  542. }
  543. if (endtime == "")
  544. {
  545. sql += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  546. where += " and datediff(day,BeginTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  547. }
  548. else
  549. {
  550. sql += " and datediff(day,F_CreateTime,'" + endtime + "')>=0 ";
  551. where += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
  552. }
  553. var workorder = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  554. Telephone telephone = new Telephone();
  555. telephone.type = new List<Proportion>();
  556. for (int i=0;i <2;i++)
  557. {
  558. Proportion proportion = new Proportion();
  559. if (i == 0)
  560. proportion.name = "咨询";
  561. else
  562. proportion.name = "投诉";
  563. proportion.total = 0;
  564. proportion.proportion = "0.00%";
  565. foreach (var it in workorder)
  566. {
  567. if (i == 0 && it.F_Type == 1)
  568. proportion.total++;
  569. else if (i == 1 && it.F_Type == 2)
  570. proportion.total++;
  571. }
  572. telephone.type.Add(proportion);
  573. }
  574. Model.T_Call_CallRecords t_Call_CallRecords = new Model.T_Call_CallRecords();
  575. var CallRecords = new BLL.T_Call_CallRecords().GetModelList(where);
  576. telephone.conversations = new List<Conversation>();
  577. for (int i=0;i<24;i++)
  578. {
  579. Conversation conversation = new Conversation();
  580. conversation.Connect = 0;
  581. conversation.Incomingcall = 0;
  582. conversation. time = i;
  583. foreach (var it in CallRecords)
  584. {
  585. var time = DateTime.Parse(it.BeginTime.ToString()).Hour;
  586. if ( time ==i )
  587. {
  588. conversation.Incomingcall++;
  589. if (it.CallState == 1)
  590. conversation.Connect++;
  591. }
  592. }
  593. telephone.conversations.Add(conversation);
  594. }
  595. int t = 0;
  596. telephone.dates = new List<TotalDate>();
  597. TotalDate totalDate = new TotalDate();
  598. totalDate.connection = 0;
  599. totalDate.traffic = 0;
  600. foreach (var it in CallRecords)
  601. {
  602. if(it.LongTime!=null )
  603. t +=(int ) it.LongTime;
  604. if (it.CallState == 1)
  605. totalDate.connection++;
  606. totalDate.traffic++;
  607. }
  608. if (CallRecords.Count > 0)
  609. totalDate.average = string.Format("{0:f2}",
  610. (double ) t / CallRecords.Count);
  611. telephone.dates.Add(totalDate);
  612. return Success("获取成功", telephone);
  613. }
  614. public class BigDate
  615. {
  616. public List<Realtime> realtime;//当日工单数量实时
  617. public List<Acceptancetime> acceptancetimes ;//24小时时段受理量/处理量分布图
  618. public List<Quantity> states ;//工单各状态数量分布
  619. public List<Quantity> region;//受理区域饼图
  620. }
  621. public class Quantity
  622. {
  623. public string name;
  624. public int total;
  625. }
  626. public class Acceptancetime
  627. {
  628. public int time;
  629. public int accept;
  630. public int handle;
  631. }
  632. public class Realtime
  633. {
  634. public int time;
  635. public int total;
  636. }
  637. /// <summary>
  638. /// 工单分布情况表
  639. /// </summary>
  640. /// <param name="stime"></param>
  641. /// <param name="endtime"></param>
  642. /// <returns></returns>
  643. public ActionResult GetBigdataList(string stime, string endtime)
  644. {
  645. string sql = $" F_IsDelete=0";
  646. DataTable dt = new DataTable();
  647. if (stime=="")
  648. sql += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')<=0 ";
  649. else
  650. sql += " and datediff(day,F_CreateTime,'" + stime + "')<=0 ";
  651. if (endtime == "")
  652. sql += " and datediff(day,F_CreateTime,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')>=0 ";
  653. else
  654. sql += " and datediff(day,F_CreateTime,'" + endtime + "')>=0 ";
  655. var workorder = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  656. BigDate bigDate = new BigDate();
  657. bigDate.realtime = new List<Realtime>();
  658. bigDate.acceptancetimes = new List<Acceptancetime>();
  659. for (int i = 0; i < 24; i++)
  660. {
  661. Realtime realtime = new Realtime();
  662. Acceptancetime acceptancetime = new Acceptancetime();
  663. realtime.time = i;
  664. realtime.total = 0;
  665. acceptancetime.time = i;
  666. acceptancetime.accept = 0;
  667. acceptancetime.handle = 0;
  668. foreach (var it in workorder)
  669. {
  670. var time = DateTime.Parse(it.F_CreateTime.ToString()).Hour;
  671. if (time == i)
  672. {
  673. realtime.total++;
  674. acceptancetime.accept++;
  675. }
  676. if(it .F_State ==4|| it.F_State == 10)
  677. {
  678. try
  679. {
  680. var handletime = DateTime.Parse(it.F_DealTime.ToString()).Hour;
  681. if (handletime == i)
  682. {
  683. acceptancetime.handle++;
  684. }
  685. }
  686. catch
  687. { }
  688. }
  689. }
  690. bigDate.realtime.Add(realtime);
  691. bigDate.acceptancetimes.Add(acceptancetime);
  692. }
  693. bigDate.states = new List<Quantity>();
  694. bigDate.region = new List<Quantity>();
  695. for (int i=0;i<7;i ++)
  696. {
  697. Quantity state = new Quantity();
  698. state.total = 0;
  699. foreach (var it in workorder)
  700. {
  701. switch (i)
  702. {
  703. case 0:
  704. state.name = "待提交";
  705. if (it.F_State == 0)
  706. state.total++;
  707. break;
  708. case 1:
  709. state.name = "待指派";
  710. if (it.F_State == 1)
  711. state.total++;
  712. break;
  713. case 2:
  714. state.name = "待处理";
  715. if (it.F_State == 3)
  716. state.total++;
  717. break;
  718. case 3:
  719. state.name = "处理中";
  720. if (it.F_State == 4)
  721. state.total++;
  722. break;
  723. case 4:
  724. state.name = "退回待提交";
  725. if (it.F_State == 6)
  726. state.total++;
  727. break;
  728. case 5:
  729. state.name = "退回待指派";
  730. if (it.F_State == 5)
  731. state.total++;
  732. break;
  733. case 6:
  734. state.name = "已处理";
  735. if (it.F_State == 10)
  736. state.total++;
  737. break;
  738. }
  739. }
  740. bigDate.states.Add(state);
  741. }
  742. var datement = new BLL.T_Sys_Department().GetModelList("isnull(F_ParentId, 1) = '1' and F_State = 1 and F_Layer = 1 order by F_Sort asc");
  743. if (datement!=null )
  744. {
  745. foreach (var it in datement)
  746. {
  747. Quantity quantity = new Quantity();
  748. quantity.name = it.F_DeptName;
  749. quantity.total = 0;
  750. foreach (var iv in workorder)
  751. {
  752. if (iv .F_State >0 && !string .IsNullOrEmpty (iv.F_Area))
  753. {
  754. try
  755. {
  756. if (int.Parse(iv.F_Area) == it.F_DeptId)
  757. quantity.total++;
  758. }
  759. catch
  760. {
  761. }
  762. }
  763. }
  764. bigDate.region.Add(quantity);
  765. }
  766. }
  767. return Success("获取成功", bigDate);
  768. }
  769. /// <summary>
  770. /// 市场信息简报
  771. /// </summary>
  772. /// <param name="sdate"></param>
  773. /// <param name="edate"></param>
  774. /// <param name="isdc"></param>
  775. /// <returns></returns>
  776. public ActionResult MarketInformation(string sdate, string edate,int isdc = 0)
  777. {
  778. int userId = CurrentUser.UserData.F_UserId;
  779. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  780. string stime = DateTime.Now.ToString("yyyy-MM")+ "-01";
  781. string etime = DateTime.Now.ToString("yyyy-MM-dd"); ;
  782. string sql = $" F_IsDelete=0";
  783. DataTable dt = new DataTable();
  784. if (!string.IsNullOrEmpty(sdate))
  785. {
  786. stime = sdate;
  787. }
  788. if (!string.IsNullOrEmpty(edate))
  789. {
  790. etime = edate;
  791. }
  792. sql += " and datediff(day,F_CreateTime,'" + stime + "')<=0 ";
  793. sql += " and datediff(day,F_CreateTime,'" + etime + "')>=0 ";
  794. var modellist = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  795. var productcpunt = new BLL.T_Bus_WorkOrder().GetModelList(sql+ "and (F_Type=2 or (F_Duplicate in(2,0)and F_Type=3))") ;
  796. var CPDM = new BLL.T_Sys_DictionaryValue().GetModelList (" F_DictionaryFlag='" + "CPDM" + "' and F_State=1 ");
  797. var WTDM = new BLL.T_Sys_DictionaryValue().GetModelList(" F_DictionaryFlag='" + "WTDM" + "' and F_State=1 ");
  798. Market market = new Market();
  799. market.product = new List<Ification>();
  800. market.sediainvolved = new Ification();
  801. Ification product = new Ification();
  802. product.name = "总计";
  803. product.number = productcpunt.Count ;
  804. product.Proportion = "100%";
  805. market.product.Add(product);
  806. if (modellist!=null )
  807. {
  808. if (CPDM != null)
  809. {
  810. foreach (var iv in CPDM)
  811. {
  812. Ification products = new Ification();
  813. products.name = iv.F_Name;
  814. products.number = 0;
  815. foreach (var it in productcpunt)
  816. {
  817. if (iv.F_Name == it.F_ProductType)
  818. products.number++;
  819. }
  820. if (productcpunt.Count > 0)
  821. products.Proportion = string.Format("{0:f2}%", products.number / productcpunt.Count * 100);
  822. else
  823. products.Proportion = "0%";
  824. market.product.Add(products);
  825. }
  826. }
  827. if (WTDM != null)
  828. {
  829. foreach (var iv in WTDM)
  830. {
  831. Ification products = new Ification();
  832. products.name = iv.F_Name;
  833. products.number = 0;
  834. foreach (var it in productcpunt)
  835. {
  836. if (iv.F_Name == it.F_ProblemCode)
  837. products.number++;
  838. }
  839. if (productcpunt.Count > 0)
  840. products.Proportion = string.Format("{0:f2}%", products.number / productcpunt.Count * 100);
  841. else
  842. products.Proportion = "0%";
  843. market.product.Add(products);
  844. }
  845. }
  846. Ification sediainvolved = new Ification();
  847. foreach (var it in productcpunt)
  848. {
  849. if (it.F_Reason == "涉媒")
  850. sediainvolved.number++;
  851. }
  852. sediainvolved.name = "涉媒";
  853. if (productcpunt.Count > 0)
  854. sediainvolved.Proportion = string.Format("{0:f2}%", sediainvolved.number / productcpunt.Count * 100);
  855. else
  856. sediainvolved.Proportion = "0%";
  857. market.sediainvolved = sediainvolved;
  858. }
  859. var obj = new
  860. {
  861. state = "success",
  862. message = "成功",
  863. rows = market,
  864. };
  865. if (isdc>0)
  866. {
  867. NPOIHelper npoi = new NPOIHelper();
  868. if (npoi.MarketExportToExcel(stime, etime, market) == "")
  869. {
  870. return Success("导出成功");
  871. }
  872. else
  873. {
  874. return Error("导出失败");
  875. }
  876. }
  877. else
  878. return Content(obj.ToJson()); ;
  879. }
  880. private class Timeslot
  881. {
  882. public int onetime { get; set; }
  883. public int twotime { get; set; }
  884. public int threetime { get; set; }
  885. public int stime { get; set; }
  886. public int etime { get; set; }
  887. }
  888. private Timeslot GetTimeslot (int mouth)
  889. {
  890. Timeslot timeslot = new Timeslot();
  891. DateTime date = DateTime.Parse(DateTime.Now.ToString("yyyy") + "-" + mouth + "-01");
  892. timeslot.onetime = date.AddMonths (-2).Month ;
  893. timeslot.twotime = date.AddMonths(-1).Month;
  894. timeslot.threetime = date.Month;
  895. timeslot.stime = date.AddMonths(-11).Month;
  896. timeslot.etime = date.AddMonths(-3).Month;
  897. return timeslot;
  898. }
  899. private Date RetuDate(string name, Timeslot timeslot, List <Model .T_Bus_WorkOrder> modelList)
  900. {
  901. Date date = new Date() ;
  902. date.name = DateTime .Parse (name).ToString ("MM月dd日") ;
  903. date.total = 0;
  904. date.MonthCount1 = 0;
  905. date.MonthCount1name = timeslot.stime + "-" + timeslot.etime + "月份日期";
  906. date.MonthCountmix1 = "0.00%";
  907. date.MonthCount2 = 0;
  908. date.MonthCount2name = timeslot.onetime + "月份日期";
  909. date.MonthCountmix2 = "0.00%";
  910. date.MonthCount3 = 0;
  911. date.MonthCount3name = timeslot.twotime + "月份日期";
  912. date.MonthCountmix3 = "0.00%";
  913. date.MonthCount4 = 0;
  914. date.MonthCount4name = timeslot.threetime + "月份日期";
  915. date.MonthCountmix4 = "0.00%";
  916. date.MonthCount5 = 0;
  917. date.MonthCount5name = "不清楚日期";
  918. date.MonthCountmix5 = "0.00%";
  919. for (int j = 0; j < modelList.Count; j++)
  920. {
  921. string datetime = DateTime.Parse(modelList[j].F_CreateTime.ToString()).ToString("yyyy-MM-dd");
  922. if (datetime == name)
  923. {
  924. date.total++;
  925. if (!string.IsNullOrEmpty(modelList[j].F_ProductDate))
  926. {
  927. if (modelList[j].F_ProductDate!="不清")
  928. {
  929. string result = modelList[j].F_ProductDate.Replace(".", "");
  930. var pronos = DateTime.ParseExact(result, "yyyyMMdd", null).Month;
  931. if (timeslot.stime > timeslot.etime)
  932. {
  933. int t = 12 - timeslot.stime;
  934. if (pronos >= timeslot.stime && pronos <= 12)
  935. date.MonthCount1++;
  936. else if (pronos <= timeslot.etime)
  937. date.MonthCount1++;
  938. }
  939. else
  940. {
  941. if (pronos >= timeslot.stime && pronos <= timeslot.etime)
  942. date.MonthCount1++;
  943. }
  944. if (pronos == timeslot.onetime)
  945. date.MonthCount2++;
  946. if (pronos == timeslot.twotime)
  947. date.MonthCount3++;
  948. if (pronos == timeslot.threetime)
  949. date.MonthCount4++;
  950. }
  951. else
  952. {
  953. date.MonthCount5++;
  954. }
  955. }
  956. else
  957. {
  958. date.MonthCount5++;
  959. }
  960. }
  961. }
  962. if (date.total > 0)
  963. {
  964. date.MonthCountmix1 = string.Format("{0:f2}%", (float)date.MonthCount1 / date.total*100);
  965. date.MonthCountmix2 = string.Format("{0:f2}%", (float)date.MonthCount2 / date.total * 100);
  966. date.MonthCountmix3 = string.Format("{0:f2}%", (float)date.MonthCount3 / date.total * 100);
  967. date.MonthCountmix4 = string.Format("{0:f2}%", (float)date.MonthCount4 / date.total * 100);
  968. date.MonthCountmix5 = string.Format("{0:f2}%", (float)date.MonthCount5 / date.total * 100);
  969. }
  970. return date;
  971. }
  972. /// <summary>
  973. /// 产品日期分布情况表
  974. /// </summary>
  975. /// <param name="sdate"></param>
  976. /// <param name="edate"></param>
  977. /// <param name="isdc"></param>
  978. /// <returns></returns>
  979. public ActionResult Distribution(string sttime ,string endtime, int isdc = 0)
  980. {
  981. // int userId = CurrentUser.UserData.F_UserId;
  982. // Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  983. string sql = $" F_IsDelete=0";
  984. DateTime time=DateTime .Now ;
  985. DataTable dt = new DataTable();
  986. if (!string .IsNullOrEmpty (endtime))
  987. {
  988. time =DateTime .Parse (endtime);
  989. }
  990. Timeslot timeslot = GetTimeslot(time.Month );
  991. int days = 30;
  992. int day = 31;
  993. Product product = new Product();
  994. product.dates = new List<Date>();
  995. //时间筛选
  996. if (!string.IsNullOrEmpty(sttime))
  997. {
  998. DateTime stime = DateTime.Parse(sttime);
  999. System.TimeSpan ime = time - stime;
  1000. days = (int )ime.TotalDays+1;
  1001. sql += " and F_CreateTime>='" + stime.ToString("yyyy-MM-dd") + " 00:00:00' ";
  1002. sql += " and F_CreateTime<='" + time.ToString("yyyy-MM-dd") + " 23:59:59' ";
  1003. sql += $" and (F_Type=2 or (F_Duplicate in(2,0)and F_Type=3))";
  1004. var modelLis = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  1005. for (int i = 0; i < days; i++)
  1006. {
  1007. string name = "";
  1008. name = stime.AddDays(i).ToString("yyyy-MM-dd");
  1009. product.dates.Add(RetuDate(name, timeslot, modelLis));
  1010. }
  1011. }
  1012. else
  1013. {
  1014. //系统时间
  1015. if (time.Month == 1)
  1016. {
  1017. days = 31;
  1018. }
  1019. else
  1020. {
  1021. days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(time.Year, time.Month - 1);//获取天数
  1022. }
  1023. DateTime lastmonth = time.AddMonths(-1);
  1024. sql += " and F_CreateTime>='" + lastmonth.ToString("yyyy-MM") + "-28" + " 00:00:00' ";
  1025. if (time.Month != 12)
  1026. {
  1027. sql += " and F_CreateTime<='" + time.ToString("yyyy-MM") + "-27" + " 23:59:59' ";
  1028. day = 27;
  1029. }
  1030. else
  1031. {
  1032. sql += " and F_CreateTime<='" + time.ToString("yyyy-MM") + "-31" + " 23:59:59' ";
  1033. }
  1034. sql += $" and (F_Type=2 or (F_Duplicate in(2,0)and F_Type=3))";
  1035. var modelLis = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  1036. int lastday = days - 27;
  1037. #region 上月28号至最后一天
  1038. if (time.Month != 1)
  1039. {
  1040. for (int i = 0; i < lastday; i++)
  1041. {
  1042. string name = string.Format("{0}-{1}", lastmonth.ToString("yyyy-MM"), 28 + i);
  1043. product.dates.Add(RetuDate(name, timeslot, modelLis));
  1044. }
  1045. }
  1046. for (int i = 0; i < day; i++)
  1047. {
  1048. string name = "";
  1049. if (i < 9)
  1050. {
  1051. name = string.Format("{0}-0{1}", time.ToString("yyyy-MM"), 1 + i);
  1052. }
  1053. else
  1054. {
  1055. name = string.Format("{0}-{1}", time.ToString("yyyy-MM"), 1 + i);
  1056. }
  1057. product.dates.Add(RetuDate(name, timeslot, modelLis));
  1058. }
  1059. }
  1060. #endregion
  1061. #region 本月一号至27号
  1062. var modelList = new BLL.T_Bus_WorkOrder().GetModelList(sql);
  1063. Date date = new Date();
  1064. date.total = modelList.Count;
  1065. date.name = "合计";
  1066. date.MonthCount1 = 0;
  1067. date.MonthCount1name = timeslot.stime + "-" + timeslot.etime + "月份日期";
  1068. date.MonthCountmix1 = "0.00%";
  1069. date.MonthCount2 = 0;
  1070. date.MonthCount2name = timeslot.onetime + "月份日期";
  1071. date.MonthCountmix2 = "0.00%";
  1072. date.MonthCount3 = 0;
  1073. date.MonthCount3name = timeslot.twotime + "月份日期";
  1074. date.MonthCountmix3 = "0.00%";
  1075. date.MonthCount4 = 0;
  1076. date.MonthCount4name = timeslot.threetime + "月份日期";
  1077. date.MonthCountmix4 = "0.00%";
  1078. date.MonthCount5 = 0;
  1079. date.MonthCount5name = "不清楚日期";
  1080. date.MonthCountmix5 = "0.00%";
  1081. for (int j = 0; j < modelList.Count; j++)
  1082. {
  1083. if (!string.IsNullOrEmpty(modelList[j].F_ProductDate))
  1084. {
  1085. if (modelList[j].F_ProductDate!="不清")
  1086. {
  1087. string result = modelList[j].F_ProductDate.Replace(".", "");
  1088. var pronos = DateTime.ParseExact(result, "yyyyMMdd", null).Month;
  1089. if (timeslot.stime > timeslot.etime)
  1090. {
  1091. int t = 12 - timeslot.stime;
  1092. if (pronos >= timeslot.stime && pronos <= 12)
  1093. date.MonthCount1++;
  1094. else if (pronos <= timeslot.etime)
  1095. date.MonthCount1++;
  1096. }
  1097. else
  1098. {
  1099. if (pronos >= timeslot.stime && pronos <= timeslot.etime)
  1100. date.MonthCount1++;
  1101. }
  1102. if (pronos == timeslot.onetime)
  1103. date.MonthCount2++;
  1104. if (pronos == timeslot.twotime)
  1105. date.MonthCount3++;
  1106. if (pronos == timeslot.threetime)
  1107. date.MonthCount4++;
  1108. }
  1109. else
  1110. {
  1111. date.MonthCount5++;
  1112. }
  1113. }
  1114. else
  1115. {
  1116. date.MonthCount5++;
  1117. }
  1118. }
  1119. if (date.total > 0)
  1120. {
  1121. date.MonthCountmix1 = string.Format("{0:f2}%", (float)date.MonthCount1 / date.total*100);
  1122. date.MonthCountmix2 = string.Format("{0:f2}%", (float)date.MonthCount2 / date.total * 100);
  1123. date.MonthCountmix3 = string.Format("{0:f2}%", (float)date.MonthCount3 / date.total * 100);
  1124. date.MonthCountmix4 = string.Format("{0:f2}%", (float)date.MonthCount4 / date.total * 100);
  1125. date.MonthCountmix5 = string.Format("{0:f2}%", (float)date.MonthCount5 / date.total * 100);
  1126. }
  1127. else
  1128. {
  1129. if (date.total > 0)
  1130. {
  1131. date.MonthCountmix1 = "0.00%";
  1132. date.MonthCountmix2 = "0.00%";
  1133. date.MonthCountmix3 = "0.00%";
  1134. date.MonthCountmix4 = "0.00%";
  1135. date.MonthCountmix5 = "0.00%";
  1136. }
  1137. }
  1138. product.dates.Add(date);
  1139. product.factory = new List<Factory>();
  1140. var EquipmentNumber = new BLL.T_Sys_EquipmentNumber().GetModelList("F_IsDelete=0");
  1141. Model.T_Sys_EquipmentNumber t_Sys_EquipmentNumber = new Model.T_Sys_EquipmentNumber();
  1142. t_Sys_EquipmentNumber.F_Production = "不清"; ;
  1143. if (EquipmentNumber!=null )
  1144. {
  1145. EquipmentNumber.Add(t_Sys_EquipmentNumber);
  1146. int total = 0;
  1147. foreach (var it in EquipmentNumber)
  1148. {
  1149. Factory factory = new Factory();
  1150. factory.name = it.F_Production;
  1151. factory.number = 0;
  1152. factory.proportion = "0.00%";
  1153. for (int i=0;i < modelList.Count;i++)
  1154. {
  1155. if (!string .IsNullOrEmpty (modelList[i].F_Manufacturer))
  1156. {
  1157. if (modelList[i].F_Manufacturer .Trim ()== it.F_Production)
  1158. {
  1159. total++;
  1160. factory.number++;
  1161. }
  1162. }
  1163. }
  1164. if (modelList.Count > 0)
  1165. factory.proportion = string.Format("{0:f2}%", (float)factory.number / modelList.Count*100);
  1166. product.factory.Add(factory);
  1167. }
  1168. product.factory.Sort((a, b) => b.number.CompareTo(a.number));
  1169. Factory factor = new Factory();
  1170. factor.name = "合计";
  1171. factor.number = total;
  1172. factor.proportion = "0.00%";
  1173. if (modelList.Count > 0)
  1174. factor.proportion = string.Format("{0:f2}%", (float)total / modelList.Count * 100);
  1175. product.factory.Add(factor);
  1176. }
  1177. var problem = new BLL.T_Sys_DictionaryValue().GetModelList("F_DictionaryFlag='WTDM'");
  1178. product.problem = new List<Factory>();
  1179. if (problem != null)
  1180. {
  1181. int total = 0;
  1182. foreach (var it in problem)
  1183. {
  1184. Factory factory = new Factory();
  1185. if (it.F_Name=="B")
  1186. {
  1187. factory.name = "变质发臭(B)";
  1188. }
  1189. else if (it.F_Name == "SHBS")
  1190. {
  1191. factory.name = "食后不适(SHBS)";
  1192. }
  1193. else if (it.F_Name == "BS")
  1194. {
  1195. factory.name = "生虫(BS)";
  1196. }
  1197. else if (it.F_Name == "P")
  1198. {
  1199. factory.name = "破袋发霉(P)";
  1200. }
  1201. else if (it.F_Name.Contains("Z"))
  1202. {
  1203. factory.name = "杂质(Z**)";
  1204. }
  1205. else if (it.F_Name.Contains("QSZ"))
  1206. {
  1207. factory.name = "少支(QSZ)";
  1208. }
  1209. else if (it.F_Name.Contains("QJL"))
  1210. {
  1211. factory.name = "计量不足(QJL)";
  1212. }
  1213. else
  1214. {
  1215. factory.name = "其他Q";
  1216. }
  1217. factory.number = 0;
  1218. factory.proportion = "0.00%";
  1219. for (int i = 0; i < modelList.Count; i++)
  1220. {
  1221. if (!string .IsNullOrEmpty (modelList[i].F_ProblemCode))
  1222. {
  1223. if (modelList[i].F_ProblemCode.Trim () == it.F_Name)
  1224. {
  1225. total++;
  1226. factory.number++;
  1227. }
  1228. }
  1229. }
  1230. if (modelList.Count>0)
  1231. factory.proportion = string.Format("{0:f2}%", (float)factory.number / modelList.Count * 100);
  1232. product.problem.Add(factory);
  1233. }
  1234. product.problem.ForEach(c => {
  1235. var group = product.problem.Where(a => a.name == c.name);
  1236. c.number = group.Sum(x => x.number);
  1237. c.proportion = string.Format("{0:f2}%", (float)c.number / modelList.Count * 100);
  1238. });
  1239. product.problem = product.problem.Distinct(new ProductNoComparer()).ToList();
  1240. product.problem.Sort((a, b) => b.number.CompareTo(a.number));
  1241. Factory factor = new Factory();
  1242. factor.name = "合计";
  1243. factor.number = total;
  1244. factor.proportion = "0.00%";
  1245. if (modelList.Count > 0)
  1246. factor.proportion = string.Format("{0:f2}%", (float)total / modelList.Count * 100);
  1247. product.problem.Add(factor);
  1248. }
  1249. var productcode = new BLL.T_Sys_DictionaryValue().GetModelList("F_DictionaryFlag='CPDM'");
  1250. product.product = new List<Factory>();
  1251. if (productcode != null )
  1252. {
  1253. int total = 0;
  1254. foreach (var it in productcode)
  1255. {
  1256. Factory factory = new Factory();
  1257. factory.name = it.F_Describe;
  1258. factory.number = 0;
  1259. factory.proportion = "0.00%";
  1260. for (int i = 0; i < modelList.Count; i++)
  1261. {
  1262. if (!string.IsNullOrEmpty(modelList[i].F_ProductType))
  1263. {
  1264. if (modelList[i].F_ProductType.Trim () == it.F_Name)
  1265. {
  1266. total++;
  1267. factory.number++;
  1268. }
  1269. }
  1270. }
  1271. if (modelList.Count > 0)
  1272. factory.proportion = string.Format("{0:f2}%", (float)factory.number / modelList.Count * 100);
  1273. product.product.Add(factory);
  1274. }
  1275. product.product.ForEach(c => {
  1276. var group = product.product.Where(a => a.name == c.name);
  1277. c.number = group.Sum(x => x.number);
  1278. c.proportion = string.Format("{0:f2}%", (float)c.number / modelList.Count * 100);
  1279. });
  1280. product.product = product.product.Distinct(new ProductNoComparer()).ToList();
  1281. product.product.Sort((a, b) => b.number.CompareTo(a.number));
  1282. Factory factor = new Factory();
  1283. factor.name = "合计";
  1284. factor.number = total;
  1285. factor.proportion = "0.00%";
  1286. if (modelList.Count > 0)
  1287. factor.proportion = string.Format("{0:f2}%", (float)total / modelList.Count * 100);
  1288. product.product.Add(factor);
  1289. }
  1290. if (isdc > 0)
  1291. {
  1292. NPOIHelper npoi = new NPOIHelper();
  1293. if (npoi.DistributionToExcel(time, product) == "")
  1294. {
  1295. return Success("导出成功");
  1296. }
  1297. else
  1298. {
  1299. return Error("导出失败");
  1300. }
  1301. }
  1302. var msg = time.Year + "年" + time.Month + "月份投诉产品日期分布情况表";
  1303. var obj = new
  1304. {
  1305. state = "success",
  1306. message = "成功",
  1307. rows = product,
  1308. msg= msg,
  1309. };
  1310. return Success("获取成功", obj);
  1311. #endregion
  1312. }
  1313. class ProductNoComparer : IEqualityComparer<Factory>
  1314. {
  1315. public bool Equals(Factory p1, Factory p2)
  1316. {
  1317. if (p1 == null)
  1318. return p2 == null;
  1319. return p1.name == p2.name;
  1320. }
  1321. public int GetHashCode(Factory p)
  1322. {
  1323. if (p == null)
  1324. return 0;
  1325. return p.name.GetHashCode();
  1326. }
  1327. }
  1328. /// <summary>
  1329. /// 工单来源
  1330. /// </summary>
  1331. /// <returns></returns>
  1332. public ActionResult GetSeatSourceReport(string sdate, string edate, int isdc = 0)
  1333. {
  1334. int userId = CurrentUser.UserData.F_UserId;
  1335. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  1336. DateTime stime = DateTime.Now;
  1337. DateTime etime = DateTime.Now;
  1338. if (!string.IsNullOrEmpty(sdate))
  1339. {
  1340. stime = DateTime.Parse(sdate);
  1341. }
  1342. if (!string.IsNullOrEmpty(edate))
  1343. {
  1344. etime = DateTime.Parse(edate);
  1345. }
  1346. if (string.IsNullOrEmpty(sdate) && string.IsNullOrEmpty(edate))
  1347. {
  1348. stime = new DateTime(stime.Year, stime.Month, 1);
  1349. }
  1350. Dictionary<string, string> paras = new Dictionary<string, string>();
  1351. paras.Add("@sdate", stime.ToString("yyyy-MM-dd"));
  1352. paras.Add("@edate", etime.ToString("yyyy-MM-dd"));
  1353. paras.Add("@groupcode", userModel.groupcode);
  1354. var obj = DbHelperSQL.RunProcedure("P_SeatSourceReport", paras, "SeatSourceReport");
  1355. if (isdc > 0)
  1356. {
  1357. NPOIHelper npoi = new NPOIHelper();
  1358. if (npoi.ExportToExcel("工单来源", obj.Tables[0]) == "")
  1359. {
  1360. return Success("导出成功");
  1361. }
  1362. else
  1363. {
  1364. return Error("导出失败");
  1365. }
  1366. }
  1367. return Success("成功", obj);
  1368. }
  1369. public class Feedback
  1370. {
  1371. public string name;
  1372. public int daynumber;
  1373. public int mounthnumber;
  1374. public int Totalnumber;
  1375. public string Proportion;
  1376. }
  1377. BLL.T_Bus_WorkOrder workOrder = new BLL.T_Bus_WorkOrder();
  1378. /// <summary>
  1379. /// 市场反馈一览表
  1380. /// </summary>
  1381. /// <returns></returns>
  1382. public ActionResult GetFeedbacklList(string stime, string endtime)
  1383. {
  1384. string sql = $" F_IsDelete=0";
  1385. DataTable dt = new DataTable();
  1386. #region 筛选条件
  1387. List<Feedback> modelList = new List<Feedback>(5);
  1388. string smonthtime = "";
  1389. if (!string.IsNullOrEmpty(stime))
  1390. {
  1391. smonthtime = stime.Trim() + " 00:00:01 "; ;
  1392. }
  1393. else
  1394. {
  1395. smonthtime = DateTime.Now.Date.ToString("yyyy-MM-01 00:00:00");
  1396. }
  1397. if (string.IsNullOrEmpty(endtime))
  1398. {
  1399. endtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1400. }
  1401. else
  1402. {
  1403. endtime = endtime + " 23:59:59 "; ;
  1404. }
  1405. string sdaytime = DateTime.Now.Date.ToString("yy" +
  1406. "yy-MM-dd 00:00:00");
  1407. var WTDM = new BLL.T_Sys_DictionaryValue().GetModelList(" F_DictionaryFlag='" + "WTDM" + "' and F_State=1 ");
  1408. int daynumber = 0; int mounthnumber = 0;int Totalnumber = 0;
  1409. if (WTDM!=null )
  1410. {
  1411. foreach (var it in WTDM)
  1412. {
  1413. Feedback model = new Feedback();
  1414. model.name = it.F_Name ;
  1415. float a = workOrder.GetModelList(sql).Count;
  1416. model.daynumber = workOrder.GetModelList(sql + $" and datediff(day,F_CreateTime,'{sdaytime}')<=0 and datediff(day,F_CreateTime,'{endtime}')>=0 " + "and F_ProblemCode='" + it .F_Name +"'").Count;
  1417. daynumber += model.daynumber;
  1418. model.mounthnumber = workOrder.GetModelList(sql + $" and datediff(day,F_CreateTime,'{smonthtime}')<=0 and datediff(day,F_CreateTime,'{endtime}')>=0 " + "and F_ProblemCode='" + it.F_Name + "'").Count;
  1419. mounthnumber += model.mounthnumber;
  1420. model.Totalnumber = workOrder.GetModelList(sql + "and F_ProblemCode='"+it .F_Name + "'").Count;
  1421. Totalnumber += model.Totalnumber;
  1422. model.Proportion = string.Format("{0:f2}%", model.Totalnumber / a * 100);
  1423. modelList.Add(model);
  1424. }
  1425. }
  1426. Feedback modeltotal = new Feedback();
  1427. modeltotal.name = "合计";
  1428. float b = workOrder.GetModelList(sql).Count;
  1429. modeltotal.daynumber = daynumber;
  1430. modeltotal.mounthnumber = mounthnumber;
  1431. modeltotal.Totalnumber = Totalnumber ;
  1432. modeltotal.Proportion = string.Format("{0:f2}%", modeltotal.Totalnumber / b * 100);
  1433. modelList.Add(modeltotal);
  1434. #endregion
  1435. modelList.Sort((a, c) => c.Totalnumber .CompareTo(a.Totalnumber));
  1436. var obj = new
  1437. {
  1438. state = "success",
  1439. message = "成功",
  1440. rows = modelList
  1441. };
  1442. return Content(obj.ToJson()); ;
  1443. }
  1444. /// <summary>
  1445. /// 工单类型报表
  1446. /// </summary>
  1447. /// <returns></returns>
  1448. public ActionResult GetTypeReport(string sdate, string edate, int isdc = 0)
  1449. {
  1450. int userId = CurrentUser.UserData.F_UserId;
  1451. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  1452. DateTime stime = DateTime.Now;
  1453. DateTime etime = DateTime.Now;
  1454. if (!string.IsNullOrEmpty(sdate))
  1455. {
  1456. stime = DateTime.Parse(sdate);
  1457. }
  1458. if (!string.IsNullOrEmpty(edate))
  1459. {
  1460. etime = DateTime.Parse(edate);
  1461. }
  1462. if (string.IsNullOrEmpty(sdate) && string.IsNullOrEmpty(edate))
  1463. {
  1464. stime = new DateTime(stime.Year, stime.Month, 1);
  1465. }
  1466. string where = " F_IsDelete=0 and datediff(day,F_CreateTime,'" + stime + "')<=0 "
  1467. + " and datediff(day,F_CreateTime,'" + etime + "')>=0 and F_Type=F_DictionaryValueId ";
  1468. string dicwhere = "";
  1469. if (!string.IsNullOrEmpty(userModel.groupcode))
  1470. {
  1471. where += " and F_GroupCode = '" + userModel.groupcode + "' ";
  1472. dicwhere += " and F_GroupCode = '" + userModel.groupcode + "' ";
  1473. }
  1474. string sql = " select F_Name TypeName,(select COUNT(1) from T_Bus_WorkOrder where "+ where
  1475. + " ) Count from dbo.T_Sys_DictionaryValue where F_DictionaryFlag='GDLX' and F_State=1 "+ dicwhere;
  1476. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1477. if (isdc > 0)
  1478. {
  1479. NPOIHelper npoi = new NPOIHelper();
  1480. if (npoi.ExportToExcel("工单类型", dt,new string[] { "工单类型", "数量"}) == "")
  1481. {
  1482. return Success("导出成功");
  1483. }
  1484. else
  1485. {
  1486. return Error("导出失败");
  1487. }
  1488. }
  1489. return Success("成功", dt);
  1490. }
  1491. /// <summary>
  1492. /// 投诉类型报表
  1493. /// </summary>
  1494. /// <returns></returns>
  1495. public ActionResult GetSmallTypeReport(string sdate, string edate, int isdc = 0)
  1496. {
  1497. int userId = CurrentUser.UserData.F_UserId;
  1498. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  1499. DateTime stime = DateTime.Now;
  1500. DateTime etime = DateTime.Now;
  1501. if (!string.IsNullOrEmpty(sdate))
  1502. {
  1503. stime = DateTime.Parse(sdate);
  1504. }
  1505. if (!string.IsNullOrEmpty(edate))
  1506. {
  1507. etime = DateTime.Parse(edate);
  1508. }
  1509. if (string.IsNullOrEmpty(sdate) && string.IsNullOrEmpty(edate))
  1510. {
  1511. stime = new DateTime(stime.Year, stime.Month, 1);
  1512. }
  1513. string where = " F_IsDelete=0 and datediff(day,F_CreateTime,'" + stime + "')<=0 "
  1514. + " and datediff(day,F_CreateTime,'" + etime + "')>=0 and F_SmallType=F_DictionaryValueId ";
  1515. string dicwhere = "";
  1516. if (!string.IsNullOrEmpty(userModel.groupcode))
  1517. {
  1518. where += " and F_GroupCode = '" + userModel.groupcode + "' ";
  1519. dicwhere += " and F_GroupCode = '" + userModel.groupcode + "' ";
  1520. }
  1521. string sql = " select F_Name TypeName,(select COUNT(1) from T_Bus_WorkOrder where " + where
  1522. + " ) Count from dbo.T_Sys_DictionaryValue where F_DictionaryFlag='TSLX' and F_State=1 "+ dicwhere;
  1523. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1524. if (isdc > 0)
  1525. {
  1526. NPOIHelper npoi = new NPOIHelper();
  1527. if (npoi.ExportToExcel("投诉类型", dt, new string[] { "投诉类型", "数量" }) == "")
  1528. {
  1529. return Success("导出成功");
  1530. }
  1531. else
  1532. {
  1533. return Error("导出失败");
  1534. }
  1535. }
  1536. return Success("成功", dt);
  1537. }
  1538. /// <summary>
  1539. /// 客诉数量报表
  1540. /// </summary>
  1541. /// <returns></returns>
  1542. public ActionResult GetWorkMonthCountReport(int isdc = 0)
  1543. {
  1544. int userId = CurrentUser.UserData.F_UserId;
  1545. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  1546. //原因
  1547. int type = RequestString.GetInt("type", 0);
  1548. //产品类别
  1549. int producttype = RequestString.GetInt("producttype", 0);
  1550. //大区
  1551. string strarea = RequestString.GetQueryString("area");
  1552. //省份
  1553. string strprov = RequestString.GetQueryString("province");
  1554. //城市
  1555. string strcity = RequestString.GetQueryString("city");
  1556. string where = " F_IsDelete=0 and datediff(month,F_CreateTime,getdate())<=12 ";
  1557. if (!string.IsNullOrEmpty(userModel.groupcode))
  1558. {
  1559. where += " and F_GroupCode = '" + userModel.groupcode + "' ";
  1560. }
  1561. if (type != 0)
  1562. {
  1563. where += " and F_Type = '" + type + "' ";
  1564. }
  1565. if (producttype != 0)
  1566. {
  1567. where += " and F_ProductType = '" + producttype + "' ";
  1568. }
  1569. if (strarea.Trim() != "" && strarea != "undefined")
  1570. {
  1571. where += " and F_Area = '" + strarea.Trim() + "' ";
  1572. }
  1573. if (strprov.Trim() != "" && strprov.Trim() != "undefined")
  1574. {
  1575. where += " and F_Province = '" + strprov.Trim() + "' ";
  1576. }
  1577. if (strcity.Trim() != "" && strcity.Trim() != "undefined")
  1578. {
  1579. where += " and F_City = '" + strcity.Trim() + "' ";
  1580. }
  1581. DataTable dt = new DataTable();
  1582. dt.Columns.Add("年月", typeof(string));
  1583. dt.Columns.Add("数量", typeof(string));
  1584. int[] ints = new int[12];
  1585. string[] months = new string[12];
  1586. for (int i = 12; i > 0; i--)
  1587. {
  1588. var date = DateTime.Now.AddMonths(1 - i);
  1589. string mon = date.ToString("yyyyMM");
  1590. months[12 - i] = mon;
  1591. ints[12 - i] = date.Month;
  1592. DataRow dr = dt.NewRow();
  1593. dr["年月"] = mon;
  1594. dt.Rows.Add(dr);
  1595. }
  1596. var obj = new
  1597. {
  1598. months,
  1599. counts = new int[12]
  1600. };
  1601. int[] count = new int[12];
  1602. for (int i = 0; i < ints.Length; i++)
  1603. {
  1604. string sql = " select count(1) from dbo.T_Bus_WorkOrder where " + where + " and datepart(month, F_CreateTime)=" + ints[i];
  1605. obj.counts[i] = Int32.Parse(DbHelperSQL.Query(sql).Tables[0].Rows[0][0].ToString());
  1606. dt.Rows[i]["数量"] = obj.counts[i];
  1607. }
  1608. if (isdc > 0)
  1609. {
  1610. NPOIHelper npoi = new NPOIHelper();
  1611. if (npoi.ExportToExcel("客诉数量", dt) == "")
  1612. {
  1613. return Success("导出成功");
  1614. }
  1615. else
  1616. {
  1617. return Error("导出失败");
  1618. }
  1619. }
  1620. var result = new
  1621. {
  1622. chartdata = obj,
  1623. list = dt
  1624. };
  1625. return Success("成功", result);
  1626. }
  1627. public ActionResult GetComplaint(int type=0)
  1628. {
  1629. DateTime? thisStart, thisEnd, lastStart, lastEnd;
  1630. DateTime today = DateTime.Today;
  1631. if (type==1)
  1632. {
  1633. thisStart = new DateTime(today.Year, today.Month, 1);
  1634. thisEnd = thisStart.Value.AddMonths(1).AddDays(-1);
  1635. // 上月第一天和最后一天
  1636. lastStart = thisStart.Value.AddMonths(-1);
  1637. lastEnd = thisStart.Value.AddDays(-1);
  1638. }
  1639. else if (type == 2)
  1640. {
  1641. int currentYear = today.Year;
  1642. // 本年第一天和最后一天
  1643. thisStart = new DateTime(currentYear, 1, 1);
  1644. thisEnd = new DateTime(currentYear, 12, 31);
  1645. // 上年第一天和最后一天
  1646. lastStart = new DateTime(currentYear - 1, 1, 1);
  1647. lastEnd = new DateTime(currentYear - 1, 12, 31);
  1648. }
  1649. else
  1650. {
  1651. CultureInfo culture = CultureInfo.CurrentCulture;
  1652. DayOfWeek firstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
  1653. // 计算本周的起始和结束
  1654. int diff = (today.DayOfWeek - firstDayOfWeek + 7) % 7;
  1655. thisStart = today.AddDays(-diff);
  1656. thisEnd = thisStart.Value.AddDays(6);
  1657. lastStart = thisStart.Value.AddDays(-7);
  1658. lastEnd = thisEnd.Value.AddDays(-7);
  1659. }
  1660. string sql = "SELECT " +
  1661. " d.F_Describe AS name," +
  1662. $" COUNT(1) " +
  1663. " AS thisnumber " +
  1664. " FROM T_Sys_DictionaryValue d LEFT JOIN " +
  1665. " T_Bus_WorkOrder o ON d.F_Name = o.F_ProblemCode " +
  1666. " AND o.F_IsDelete = 0 AND o.F_Duplicate != 5 " +
  1667. " AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3))" +
  1668. $" and o.F_CreateTime >= '{thisStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1669. $"AND o.F_CreateTime < '{thisEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1670. " where d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1671. " d.F_Describe ORDER BY d.F_Describe ";
  1672. string sql1 = "SELECT " +
  1673. " d.F_Describe AS name," +
  1674. $" COUNT(1) " +
  1675. " AS lastnumber " +
  1676. " FROM T_Sys_DictionaryValue d LEFT JOIN " +
  1677. " T_Bus_WorkOrder o ON d.F_Name = o.F_ProblemCode " +
  1678. " AND o.F_IsDelete = 0 AND o.F_Duplicate != 5 " +
  1679. " AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3))" +
  1680. $" and o.F_CreateTime >= '{lastStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1681. $"AND o.F_CreateTime < '{lastStart.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1682. " where d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1683. " d.F_Describe ORDER BY d.F_Describe ";
  1684. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1685. DataTable dt1 = DbHelperSQL.Query(sql1).Tables[0];
  1686. int thisnumber = 0, otherthisnumber=0, lastnumber = 0, otherlastnumber = 0;
  1687. int total = 0;
  1688. foreach (DataRow row in dt1.Rows)
  1689. {
  1690. if (row["name"] != null)
  1691. {
  1692. if (row["name"].ToString() == "破袋发霉" || row["name"].ToString() == "杂质异物"
  1693. || row["name"].ToString() == "变质异味")
  1694. {
  1695. lastnumber += int.Parse(row["lastnumber"].ToString());
  1696. }
  1697. else
  1698. {
  1699. otherlastnumber += int.Parse(row["lastnumber"].ToString());
  1700. }
  1701. }
  1702. else
  1703. {
  1704. otherlastnumber += int.Parse(row["lastnumber"].ToString());
  1705. }
  1706. }
  1707. foreach (DataRow row in dt.Rows)
  1708. {
  1709. if (row["name"]!=null )
  1710. {
  1711. if (row["name"].ToString() == "破袋发霉"|| row["name"].ToString() == "杂质异物"
  1712. ||row["name"].ToString() == "变质异味")
  1713. {
  1714. thisnumber += int.Parse(row["thisnumber"].ToString());
  1715. }
  1716. else
  1717. {
  1718. otherthisnumber += int.Parse(row["thisnumber"].ToString());
  1719. }
  1720. }
  1721. else
  1722. {
  1723. otherthisnumber += int.Parse(row["thisnumber"].ToString());
  1724. }
  1725. total += int.Parse(row["thisnumber"].ToString());
  1726. }
  1727. var obj = new
  1728. {
  1729. state = "success",
  1730. message = "成功",
  1731. data = new
  1732. {
  1733. total,
  1734. thisnumber,
  1735. thiscontrast = thisnumber - lastnumber,
  1736. otherthisnumber,
  1737. othercontrast = otherthisnumber - otherlastnumber}
  1738. };
  1739. return Content(obj.ToJson());
  1740. }
  1741. public ActionResult GetComplaintSituation(int type = 0)
  1742. {
  1743. DateTime? thisStart, thisEnd, lastStart, lastEnd;
  1744. DateTime today = DateTime.Today;
  1745. if (type == 1)
  1746. {
  1747. thisStart = new DateTime(today.Year, today.Month, 1);
  1748. thisEnd = thisStart.Value.AddMonths(1).AddDays(-1);
  1749. // 上月第一天和最后一天
  1750. lastStart = thisStart.Value.AddMonths(-1);
  1751. lastEnd = thisStart.Value.AddDays(-1);
  1752. }
  1753. else if (type == 2)
  1754. {
  1755. int currentYear = today.Year;
  1756. // 本年第一天和最后一天
  1757. thisStart = new DateTime(currentYear, 1, 1);
  1758. thisEnd = new DateTime(currentYear, 12, 31);
  1759. // 上年第一天和最后一天
  1760. lastStart = new DateTime(currentYear - 1, 1, 1);
  1761. lastEnd = new DateTime(currentYear - 1, 12, 31);
  1762. }
  1763. else
  1764. {
  1765. CultureInfo culture = CultureInfo.CurrentCulture;
  1766. DayOfWeek firstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
  1767. // 计算本周的起始和结束
  1768. int diff = (today.DayOfWeek - firstDayOfWeek + 7) % 7;
  1769. thisStart = today.AddDays(-diff);
  1770. thisEnd = thisStart.Value.AddDays(6);
  1771. lastStart = thisStart.Value.AddDays(-7);
  1772. lastEnd = thisEnd.Value.AddDays(-7);
  1773. }
  1774. string sql = "SELECT " +
  1775. " d.F_Describe AS name," +
  1776. $" COUNT(1) " +
  1777. " AS thisnumber " +
  1778. " FROM T_Sys_DictionaryValue d LEFT JOIN " +
  1779. " T_Bus_WorkOrder o ON d.F_Name = o.F_ProblemCode " +
  1780. " AND o.F_IsDelete = 0 AND o.F_Duplicate != 5 " +
  1781. " AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3))" +
  1782. $" and o.F_CreateTime >= '{thisStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1783. $"AND o.F_CreateTime < '{thisEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1784. " where d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1785. " d.F_Describe ORDER BY d.F_Describe ";
  1786. string sql1 = "SELECT " +
  1787. " d.F_Describe AS name," +
  1788. $" COUNT(1) " +
  1789. " AS lastnumber " +
  1790. " FROM T_Sys_DictionaryValue d LEFT JOIN " +
  1791. " T_Bus_WorkOrder o ON d.F_Name = o.F_ProblemCode " +
  1792. " AND o.F_IsDelete = 0 AND o.F_Duplicate != 5 " +
  1793. " AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3))" +
  1794. $" and o.F_CreateTime >= '{lastStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1795. $"AND o.F_CreateTime < '{lastEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1796. " where d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1797. " d.F_Describe ORDER BY d.F_Describe ";
  1798. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1799. DataTable dt1 = DbHelperSQL.Query(sql1).Tables[0];
  1800. int mustiness = 0, impurity = 0, gobad = 0, lastgobad = 0, lastmustiness = 0, lastimpurity = 0;
  1801. string mustinessRate = "", impurityRate = "", gobadRate = "";
  1802. int mustinesscontrast=0, impuritycontrast = 0, gobadcontrast = 0;
  1803. foreach (DataRow row in dt1.Rows)
  1804. {
  1805. if (row["name"] != null)
  1806. {
  1807. if (row["name"].ToString() == "破袋发霉")
  1808. {
  1809. lastmustiness += int.Parse(row["lastnumber"].ToString());
  1810. }
  1811. else if (row["name"].ToString() == "杂质异物")
  1812. {
  1813. lastimpurity += int.Parse(row["lastnumber"].ToString());
  1814. }
  1815. else if (row["name"].ToString() == "变质异味")
  1816. {
  1817. lastgobad += int.Parse(row["lastnumber"].ToString());
  1818. }
  1819. }
  1820. }
  1821. foreach (DataRow row in dt.Rows)
  1822. {
  1823. if (row["name"] != null)
  1824. {
  1825. if (row["name"].ToString() == "破袋发霉" )
  1826. {
  1827. mustiness += int.Parse(row["thisnumber"].ToString());
  1828. }
  1829. else if (row["name"].ToString() == "杂质异物")
  1830. {
  1831. impurity += int.Parse(row["thisnumber"].ToString());
  1832. }
  1833. else if (row["name"].ToString() == "变质异味")
  1834. {
  1835. gobad += int.Parse(row["thisnumber"].ToString());
  1836. }
  1837. }
  1838. }
  1839. int total = mustiness + impurity + gobad;
  1840. if (total==0)
  1841. {
  1842. mustinessRate = string.Format("{0:f2}%", mustiness * 100);
  1843. impurityRate = string.Format("{0:f2}%", impurity * 100);
  1844. gobadRate = string.Format("{0:f2}%", gobad * 100);
  1845. }
  1846. else
  1847. {
  1848. mustinessRate = string.Format("{0:f2}%", (float)mustiness / total * 100);
  1849. impurityRate = string.Format("{0:f2}%", (float)impurity / total * 100);
  1850. gobadRate = string.Format("{0:f2}%", (float)gobad / total * 100);
  1851. }
  1852. mustinesscontrast = mustiness - lastmustiness;
  1853. impuritycontrast = impurity - lastimpurity;
  1854. gobadcontrast = gobad - lastgobad;
  1855. var obj = new
  1856. {
  1857. state = "success",
  1858. message = "成功",
  1859. data = new
  1860. {
  1861. mustiness,
  1862. mustinesscontrast,
  1863. mustinessRate,
  1864. impurity,
  1865. impuritycontrast,
  1866. impurityRate,
  1867. gobad,
  1868. gobadcontrast,
  1869. gobadRate
  1870. }
  1871. };
  1872. return Content(obj.ToJson());
  1873. }
  1874. public ActionResult GetComplaintCompleted(int type = 0)
  1875. {
  1876. DateTime? thisStart, thisEnd;
  1877. DateTime today = DateTime.Today;
  1878. if (type == 1)
  1879. {
  1880. thisStart = new DateTime(today.Year, today.Month, 1);
  1881. thisEnd = thisStart.Value.AddMonths(1).AddDays(-1);
  1882. }
  1883. else if (type == 2)
  1884. {
  1885. int currentYear = today.Year;
  1886. // 本年第一天和最后一天
  1887. thisStart = new DateTime(currentYear, 1, 1);
  1888. thisEnd = new DateTime(currentYear, 12, 31);
  1889. }
  1890. else
  1891. {
  1892. CultureInfo culture = CultureInfo.CurrentCulture;
  1893. DayOfWeek firstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
  1894. // 计算本周的起始和结束
  1895. int diff = (today.DayOfWeek - firstDayOfWeek + 7) % 7;
  1896. thisStart = today.AddDays(-diff);
  1897. thisEnd = thisStart.Value.AddDays(6);
  1898. }
  1899. string sql = "SELECT " +
  1900. " d.F_Describe AS name," +
  1901. $" COUNT(1) " +
  1902. " AS number," +
  1903. $" COUNT(CASE WHEN o.F_State in(3,4) THEN 1 END) " +
  1904. " AS receiving," +
  1905. $" COUNT(CASE WHEN o.F_State =10 THEN 1 END) " +
  1906. " AS complete " +
  1907. " FROM T_Sys_DictionaryValue d LEFT JOIN " +
  1908. " T_Bus_WorkOrder o ON d.F_Name = o.F_ProblemCode " +
  1909. " AND o.F_IsDelete = 0 AND o.F_Duplicate != 5 " +
  1910. " AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3))" +
  1911. $" AND o.F_CreateTime >= '{thisStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1912. $" AND o.F_CreateTime < '{thisEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1913. " where d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1914. " d.F_Describe ORDER BY d.F_Describe ";
  1915. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1916. int number = 0, receiving = 0, complete = 0;
  1917. string receivingrate = "100%", completerate = "100%";
  1918. foreach (DataRow row in dt.Rows)
  1919. {
  1920. //if (row["name"] != null)
  1921. //{
  1922. // if (row["name"].ToString() == "破袋发霉" || row["name"].ToString() == "杂质异物"
  1923. // || row["name"].ToString() == "变质异味")
  1924. // {
  1925. // number += int.Parse(row["number"].ToString());
  1926. // receiving += int.Parse(row["receiving"].ToString());
  1927. // complete += int.Parse(row["complete"].ToString());
  1928. // }
  1929. //}
  1930. number += int.Parse(row["number"].ToString());
  1931. receiving += int.Parse(row["receiving"].ToString());
  1932. complete += int.Parse(row["complete"].ToString());
  1933. }
  1934. if (number> 0) { receivingrate = string.Format("{0:f2}%", (float)receiving / number * 100);
  1935. completerate = string.Format("{0:f2}%", (float)complete / number * 100);
  1936. }
  1937. var obj = new
  1938. {
  1939. state = "success",
  1940. message = "成功",
  1941. data = new
  1942. {
  1943. receivingrate,
  1944. completerate
  1945. }
  1946. };
  1947. return Content(obj.ToJson());
  1948. }
  1949. private class ComplaintTrend
  1950. {
  1951. public string time { get; set; }
  1952. public int receiving { get; set; }
  1953. public int complete { get; set; }
  1954. }
  1955. public ActionResult GetComplaintTrend(int type = 0)
  1956. {
  1957. DateTime? thisStart, thisEnd;
  1958. DateTime today = DateTime.Today;string time = "CONVERT(VARCHAR(10)";
  1959. if (type == 1)
  1960. {
  1961. thisStart = new DateTime(today.Year, today.Month, 1);
  1962. thisEnd = thisStart.Value.AddMonths(1).AddDays(-1);
  1963. }
  1964. else if (type == 2)
  1965. {
  1966. int currentYear = today.Year;
  1967. // 本年第一天和最后一天
  1968. thisStart = new DateTime(currentYear, 1, 1);
  1969. thisEnd = new DateTime(currentYear, 12, 31);
  1970. time = "CONVERT(VARCHAR(7)";
  1971. }
  1972. else
  1973. {
  1974. CultureInfo culture = CultureInfo.CurrentCulture;
  1975. DayOfWeek firstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
  1976. // 计算本周的起始和结束
  1977. int diff = (today.DayOfWeek - firstDayOfWeek + 7) % 7;
  1978. thisStart = today.AddDays(-diff);
  1979. thisEnd = thisStart.Value.AddDays(6);
  1980. }
  1981. string sql = " SELECT " +
  1982. " d.F_Describe AS name, " +
  1983. $" {time}, o.F_CreateTime, 120) AS time, " +
  1984. " COUNT(1) AS number," +
  1985. " COUNT(CASE WHEN o.F_State IN(3, 4) THEN 1 END) AS receiving," +
  1986. " COUNT(CASE WHEN o.F_State = 10 THEN 1 END) AS complete FROM " +
  1987. " T_Sys_DictionaryValue d LEFT JOIN T_Bus_WorkOrder o" +
  1988. " ON d.F_Name = o.F_ProblemCode AND o.F_IsDelete = 0" +
  1989. " AND o.F_Duplicate != 5 AND(o.F_Type = 2 OR(o.F_Duplicate NOT IN(1, 4) AND o.F_Type = 3)) " +
  1990. $" and o.F_CreateTime >= '{thisStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"}' " +
  1991. $"AND o.F_CreateTime < '{thisEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"}'" +
  1992. " WHERE d.F_DictionaryFlag = 'WTDM' GROUP BY " +
  1993. $" d.F_Describe, {time}, o.F_CreateTime, 120) ORDER BY d.F_Describe, time ";
  1994. DataTable dt = DbHelperSQL.Query(sql).Tables[0];
  1995. List<ComplaintTrend> complaintTrends = new List<ComplaintTrend>();
  1996. if (type!=2)
  1997. {
  1998. for (DateTime i = thisStart.Value; i <= thisEnd; i = i.AddDays(1))
  1999. {
  2000. ComplaintTrend complaintTrend = new ComplaintTrend();
  2001. complaintTrend.time = i.ToString("MM.dd");
  2002. complaintTrend.receiving =
  2003. dt.Select($" time='{i.ToString("yyyy-MM-dd")}'").Sum(x => x.Field<int>("receiving"));
  2004. complaintTrend.complete =
  2005. dt.Select($" time='{i.ToString("yyyy-MM-dd")}'").Sum(x => x.Field<int>("receiving"));
  2006. complaintTrends.Add(complaintTrend);
  2007. }
  2008. }
  2009. else
  2010. {
  2011. for (DateTime i = thisStart.Value; i <= thisEnd; i = i.AddMonths(1))
  2012. {
  2013. ComplaintTrend complaintTrend = new ComplaintTrend();
  2014. complaintTrend.time = i.ToString("yyyy.MM");
  2015. complaintTrend.receiving =
  2016. dt.Select($" time='{i.ToString("yyyy-MM")}'").Sum(x => x.Field<int>("receiving"));
  2017. complaintTrend.complete =
  2018. dt.Select($" time='{i.ToString("yyyy-MM")}'").Sum(x => x.Field<int>("receiving"));
  2019. complaintTrends.Add(complaintTrend);
  2020. }
  2021. }
  2022. return Success("获取成功", complaintTrends);
  2023. }
  2024. }
  2025. }