| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345 |
- using RMYY_CallCenter_Api.DB;
- using RMYY_CallCenter_Api.Model;
- using RMYY_CallCenter_Api.Utility;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web;
- using System.Web.Mvc;
- namespace RMYY_CallCenter_Api.Controllers.System
- {
- public class DeviceController : BaseController
- {
- BLL.T_Adjust_Device deviceservice = new BLL.T_Adjust_Device();
- BLL.T_Adjust_DeviceType typeservice = new BLL.T_Adjust_DeviceType();
- BLL.T_Adjust_Log logBll = new BLL.T_Adjust_Log();
- private static InternalMessagesController msg = new InternalMessagesController();
- BLL.T_Adjust_TpInfo tpinfoBll = new BLL.T_Adjust_TpInfo();
- Bll.T_Sys_Department deptbll = new Bll.T_Sys_Department();
- /// <summary>
- /// 设备信息list Device/GetList
- /// </summary>
- /// <param name="typeName">设备名称</param>
- /// <param name="dicId">设备类型对应的字典的id</param>
- /// <param name="assetCode">资产编码</param>
- /// <param name="deviceShortCode">设备短码</param>
- /// <param name="deptId">所属科室</param>
- /// <param name="deviceStatus">int 设备状态 设备调配(1待上架,2闲置,3使用中) </param>
- /// <param name="orderBy"> 排序 F_DicId或 F_UpdateTime</param>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <param name="orderByRule">倒序还是正序,desc或者 asc</param>
- /// <returns></returns>
- public ActionResult GetList(string typeName, string assetCode, string code, string deviceTypeId, string deviceShortCode, string orderBy, string deviceStatus, int orderByRule = 0, int page = 1, int pagesize = 10, int isdc = 0, int deptId = 0, int dicId = 0)
- {
- string sql = " and F_IsDelete=0 and F_Classify=1";
- if (!string.IsNullOrEmpty(deviceTypeId))
- {
- sql += " and F_DeviceTypeId in ( " + deviceTypeId + ")";
- }
- if (!string.IsNullOrEmpty(code))
- {
- sql += " and (F_AssetCode='" + code + "' or F_DeviceShortCode='" + code + "')";
- }
- DataTable dt = new DataTable();
- string strorderby = " order by ";
- if (string.IsNullOrEmpty(orderBy))
- {
- strorderby += " F_UpdateTime";
- }
- else
- {
- strorderby += orderBy;
- }
- if (orderByRule == 0)
- {
- strorderby += " desc";
- }
- else
- {
- strorderby += " asc";
- }
- if (!string.IsNullOrEmpty(typeName))
- {
- sql += " and F_TypeName like '%" + typeName + "%' ";
- }
- if (dicId > 0)
- {
- sql += " and F_DicId='" + dicId + "' ";
- }
- if (!string.IsNullOrEmpty(assetCode))
- {
- sql += " and F_AssetCode='" + assetCode + "' ";
- }
- if (!string.IsNullOrEmpty(deviceShortCode))
- {
- sql += " and F_DeviceShortCode='" + deviceShortCode + "' ";
- }
- if (deptId > 0)
- {
- sql += " and F_BelongDept='" + deptId + "' ";
- }
- if (!string.IsNullOrEmpty(deviceStatus))
- {
- //string[] strlist= deviceStatus.Split(',');
- //List<int> lis = new List<int>();
- //foreach (var item in strlist)
- //{
- // lis.Add(Convert.ToInt32(item));
- //}
- sql += " and F_DeviceStatus in (" + deviceStatus + ") ";
- }
- if (isdc > 0)
- {
- string dcsql = " and a.F_IsDelete=0 and and a.F_Classify=1";
- string dcstrorderby = " order by ";
- if (string.IsNullOrEmpty(orderBy))
- {
- dcstrorderby += " a.F_UpdateTime";
- }
- else
- {
- dcstrorderby += orderBy;
- }
- if (orderByRule == 0)
- {
- strorderby += " desc";
- }
- else
- {
- strorderby += " asc";
- }
- //if (!string.IsNullOrEmpty(code))
- //{
- // sql += " and (a.F_AssetCode='" + code + "' or a. F_DeviceShortCode='" + code + "')";
- //}
- if (!string.IsNullOrEmpty(typeName))
- {
- dcsql += " and a.F_TypeName like '%" + typeName + "%' ";
- }
- if (dicId > 0)
- {
- dcsql += " and a.F_DicId='" + dicId + "' ";
- }
- if (!string.IsNullOrEmpty(assetCode))
- {
- dcsql += " and a.F_AssetCode='" + assetCode + "' ";
- }
- if (!string.IsNullOrEmpty(deviceShortCode))
- {
- dcsql += " and a.F_DeviceShortCode='" + deviceShortCode + "' ";
- }
- if (deptId > 0)
- {
- dcsql += " and a.F_BelongDept='" + deptId + "' ";
- }
- if (!string.IsNullOrEmpty(deviceStatus))
- {
- sql += " and a.F_DeviceStatus in (" + deviceStatus + ") ";
- }
- //if (deviceTypeId > 0)
- //{
- // dcsql += " and a.F_DeviceTypeId=" + deviceTypeId + "";
- //}
- if (!string.IsNullOrEmpty(deviceTypeId))
- {
- dcsql += " and F_DeviceTypeId in ( " + deviceTypeId + " )";
- }
- var dtdc = DB.DbHelperSQL.Query("SELECT a.F_BigTypeName 设备类型,a.F_TypeName 设备名称,F_AssetCode 资产编码 , F_DeviceShortCode 设备短码,F_Specification 规格型号, F_Code 出厂编码,F_BelongDeptName 归属科室, F_BelongPhone 归属科室电话, (CASE F_DeviceStatus WHEN 1 THEN '待上架' WHEN 2 THEN '闲置' WHEN 3 THEN '使用中' ELSE '' END) 设备状态,CAST(b.F_price AS VARCHAR) + '/' + b.F_ChargingStandard 计费标准 from T_Adjust_Device a LEFT join T_Adjust_DeviceType b on b.F_TypeId = a.F_DeviceTypeId where 1=1 " + dcsql + dcstrorderby).Tables[0];
- var msg = new NPOIHelper().ExportToExcel("设备管理", dtdc);
- if (msg == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "(SELECT T_Adjust_Device.*,b.F_Price,F_ChargingStandard from T_Adjust_Device LEFT join T_Adjust_DeviceType b on b.F_TypeId=T_Adjust_Device.F_DeviceTypeId ) T_Adjust_Device",
- "F_DeviceId",
- "*",
- sql,
- strorderby,
- pagesize,
- page,
- true,
- out recordCount);
- dt.Columns.Add("FileUrl", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(fileurlpath) && !string.IsNullOrEmpty(dr["F_File"].ToString()))
- {
- dr["FileUrl"] = GetFileData(dr["F_File"].ToString(), fileurlpath);
- }
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 添加或编辑设备信息 Device/AddOrEditDevice
- /// </summary>
- /// <param name="address">部门地址</param>
- /// <param name="deptId">部门id</param>
- /// <param name="deptName">部门名</param>
- /// <param name="phone">部门电话</param>
- /// <param name="assetCode">资产编码</param>
- /// <param name="deviceShortCode">设备断码</param>
- /// <param name="code">出厂编号</param>
- /// <param name="specification">规格型号</param>
- /// <param name="deviceTypeId">设备类型表的id</param>
- /// <param name="deviceId">设备id</param>
- /// <returns></returns>
- public ActionResult AddOrEditDevice(string address, int deptId, string deptName
- , string phone, string assetCode, string deviceShortCode, string file,
- string code, string specification, string bigTypeName, string typeName, int dicId = 0,
- int deviceTypeId = 0, int deviceId = 0)
- {
- int chuancan = deviceTypeId;
- if (deviceTypeId == 0)
- {
- if (string.IsNullOrEmpty(bigTypeName) && string.IsNullOrEmpty(typeName))
- {
- return Error("请选择或者输入设备类型和设备名称");
- }
- }
- Model.T_Adjust_DeviceType typemodel = new T_Adjust_DeviceType();
- if (deviceTypeId > 0)
- {
- typemodel = typeservice.GetModel(deviceTypeId);
- if (typemodel == null)
- {
- return Error(" 设备类型不存在");
- }
- }
- else
- {
- //找不到字典 判断字典表是否存在,不存在加一个字典值
- int dicaddid = 0;
- if (dicId > 0)
- {
- Model.T_Sys_DictionaryValue dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(dicId);
- if (dicmodel != null)
- {
- dicaddid = dicmodel.F_DictionaryValueId;
- }
- }
- else
- {
- Model.T_Sys_DictionaryValue dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(bigTypeName);
- if (dicmodel != null)
- {
- dicaddid = dicmodel.F_DictionaryValueId;
- }
- else
- {
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(bigTypeName);
- }
- }
- //先添加字典的记录
- //添加设备类型记录
- // int dicaddid = new Bll.T_Sys_DictionaryValue().Add(bigTypeName);
- Model.T_Adjust_DeviceType modeltype = typeservice.GetModel(bigTypeName, typeName, 1);
- if (modeltype == null)
- {
- Model.T_Adjust_DeviceType model = new T_Adjust_DeviceType();
- model.F_DeviceNum = 0;
- model.F_IsDelete = 0;
- model.F_Classification = 1;
- model.F_CreateBy = User.F_UserCode;
- model.F_BigTypeName = bigTypeName;
- model.F_TypeName = typeName;
- model.F_DicId = dicaddid;
- model.F_CreateTime = DateTime.Now;
- int res = typeservice.Add(model);
- deviceTypeId = res;
- }
- else { deviceTypeId = modeltype.F_TypeId; }
- }
- if (string.IsNullOrEmpty(assetCode))
- {
- return Error("资产编码不能为空");
- }
- var existslist = deviceservice.GetModelList(" F_AssetCode ='" + assetCode + "'");
- if (deviceId > 0)
- {
- if (existslist.Count == 0)
- { }
- else if (existslist.Count == 1 && existslist.First().F_DeviceId == deviceId)
- { }
- else
- {
- return Error("资产编码不能重复!");
- }
- ////设备类型的数量加1
- //var mm = typeservice.GetModel(deviceTypeId);
- //mm.F_DeviceNum = mm.F_DeviceNum == null ? 1 : mm.F_DeviceNum + 1;
- //mm.F_UpdateTime = DateTime.Now;
- //typeservice.Update(mm);
- if (deviceTypeId != existslist.First().F_DeviceId)
- {
- //修改了类型说明
- var mm = typeservice.GetModel(deviceTypeId);
- mm.F_DeviceNum = mm.F_DeviceNum == null ? 1 : mm.F_DeviceNum + 1;
- mm.F_UpdateTime = DateTime.Now;
- typeservice.Update(mm);
- var olddevice = deviceservice.GetModel(existslist.First().F_DeviceId);
- var oldtype = typeservice.GetModel(olddevice.F_DeviceTypeId);
- oldtype.F_DeviceNum = oldtype.F_DeviceNum - 1;
- oldtype.F_UpdateTime = DateTime.Now;
- typeservice.Update(oldtype);
- }
- Model.T_Adjust_Device model = deviceservice.GetModel(deviceId);
- //编辑
- model.F_BigTypeName = typemodel.F_BigTypeName;
- model.F_TypeName = typemodel.F_TypeName;
- model.F_DicId = typemodel.F_DicId;
- model.F_BelongPhone = phone;
- model.F_BelongAddress = address;
- model.F_BelongDept = deptId;
- model.F_BelongDeptName = deptName;
- model.F_DeviceTypeId = deviceTypeId;
- model.F_AssetCode = assetCode;
- model.F_DeviceShortCode = deviceShortCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_File = file;
- model.F_UpdateTime = DateTime.Now;
- if (deviceservice.Update(model))
- {
- return Success("修改成功");
- }
- else
- {
- return Error("修改失败");
- }
- }
- else
- {
- if (existslist.Count > 0)
- {
- return Error("资产编码不能重复!");
- }
- Model.T_Adjust_Device model = new T_Adjust_Device();
- model.F_BigTypeName = typemodel.F_BigTypeName;
- model.F_TypeName = typemodel.F_TypeName;
- model.F_DicId = typemodel.F_DicId;
- model.F_BelongPhone = phone;
- model.F_BelongAddress = address;
- model.F_BelongDept = deptId;
- model.F_BelongDeptName = deptName;
- model.F_DeviceTypeId = deviceTypeId;
- model.F_AssetCode = assetCode;
- model.F_DeviceShortCode = deviceShortCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_Source = 1;
- model.F_CreateBy = User.F_UserCode;
- model.F_CreateTime = DateTime.Now;
- model.F_UpdateTime = DateTime.Now;
- model.F_DeviceStatus = 1;//待上架
- model.F_Classify = 1;
- model.F_IsDelete = 0;
- model.F_File = file;
- int res = deviceservice.Add(model);
- if (res > 0)
- {
- //设备类型的数量加1
- var mm = typeservice.GetModel(deviceTypeId);
- mm.F_DeviceNum = mm.F_DeviceNum == null ? 1 : mm.F_DeviceNum + 1;
- mm.F_UpdateTime = DateTime.Now;
- typeservice.Update(mm);
- return Success("添加成功");
- }
- else
- {
- return Error("添加失败");
- }
- }
- }
- /// <summary>
- /// 删除设备 DelDeviceType
- /// </summary>
- /// <param name="deviceId"></param>
- /// <returns></returns>
- public ActionResult DelDevice(int deviceId)
- {
- if (deviceId <= 0)
- {
- return Error("请选中要删除的列");
- }
- string sql = " update T_Adjust_Device set F_IsDelete=1 where F_DeviceId=" + deviceId;
- if (DbHelperSQL.ExecuteSql(sql) > 0)
- {
- //把设备类型表的数量-1
- string updatenum = " update T_Adjust_DeviceType set F_DeviceNum=(SELECT Count(1) from T_Adjust_Device WHERE F_IsDelete=0 and F_DeviceTypeId in (SELECT F_DeviceTypeId from T_Adjust_Device WHERE F_IsDelete=0 and F_DeviceId=" + deviceId + ")) WHERE F_TypeId in (SELECT F_DeviceTypeId from T_Adjust_Device WHERE F_DeviceId=" + deviceId + ")";
- DbHelperSQL.ExecuteSql(updatenum);
- return Success("删除成功");
- }
- else
- {
- return Error("删除失败");
- }
- }
- /// <summary>
- /// GetTypeName 添加编辑时根据dicid获取设备名称下拉框
- /// </summary>
- /// <param name="dicId"></param>
- /// <returns></returns>
- public ActionResult GetTypeName(string bigTypeName, string typeName, int dicId = 0, int classification = 0)
- {
- string sql = " F_IsDelete=0 ";
- if (dicId >= 0)
- {
- sql += " and F_DicId=" + dicId + " ";
- }
- if (classification > 0)
- {
- sql += " and F_Classification=" + classification + " ";
- }
- if (!string.IsNullOrEmpty(bigTypeName))
- {
- sql += " and F_BigTypeName='" + bigTypeName + "' ";
- }
- if (!string.IsNullOrEmpty(typeName))
- {
- sql += " and F_TypeName='" + typeName + "' ";
- }
- List<T_Adjust_DeviceType> devices = typeservice.GetModelList(sql);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = devices
- };
- return Content(obj.ToJson());
- //return deviceservice.GetModelList(" F_DicId='" + dicId + "' and F_IsDelete=0");
- }
- /// <summary>
- /// BatchUpdate
- /// </summary>
- /// <param name="ids"></param>
- /// <param name="operateType">下架1 上架2 </param>
- /// <returns></returns>
- public ActionResult BatchUpdate(int[] ids, int operateType)
- {
- int total = 0;
- if (ids != null && ids.Length > 0)
- {
- foreach (int item in ids)
- {
- Model.T_Adjust_Device model = deviceservice.GetModel(item);
- if (model.F_DeviceStatus == 3)
- {
- continue;
- }
- model.F_DeviceStatus = operateType;
- if (operateType == 2)
- {
- model.F_ListingTime = DateTime.Now;
- }
- else
- {
- model.F_ListingTime = null;
- }
- model.F_UpdateTime = DateTime.Now;
- bool insertlog = false;
- if (model.F_Classify == 2)
- {
- insertlog = true;
- }
- if (deviceservice.Update(model))
- {
- if (insertlog)
- {
- string desc = "";
- if (operateType == 1)
- {
- desc = "下架";
- }
- else
- {
- desc = "上架";
- }
- InsertLog(model.F_DeviceId, desc);
- }
- total++;
- }
- }
- if (total > 0)
- {
- return Success("批量修改成功");
- }
- else
- {
- return Error("批量修改失败");
- }
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- /// <summary>
- /// 我的设备列表 Device/GetMyDeviceList
- /// </summary>
- /// <param name="typeName">设备名称</param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="dicId">设备类型</param>
- /// <param name="deviceStatus">设备状态传int 1 待上架 2 闲置 3 使用中</param>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- public ActionResult GetMyDeviceList(
- string typeName, string startTime, string endTime, int dicId = 0, int deviceStatus = 0, int page = 1, int pagesize = 10, int isdc = 0)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 and F_Classify=2";
- int mydeptid = User.F_DeptId;
- sql += " and (F_BelongDept= " + mydeptid + " or F_UseDept=" + mydeptid + " )";
- if (dicId > 0)
- {
- sql += " and F_DicId='" + dicId + "' ";
- }
- if (!string.IsNullOrEmpty(startTime))
- {
- sql += " and F_ListingTime>='" + startTime + "'";
- }
- if (!string.IsNullOrEmpty(endTime))
- {
- sql += " and F_ListingTime<='" + endTime + "'";
- }
- if (!string.IsNullOrEmpty(typeName))
- {
- sql += " and F_TypeName like '%" + typeName + "%' ";
- }
- if (deviceStatus > 0)
- {
- sql += " and F_DeviceStatus='" + deviceStatus + "' ";
- }
- if (isdc > 0)
- {
- var dtdc = DB.DbHelperSQL.Query(" SELECT F_TypeName 设备名称, F_Desc 设备描述,F_AssetCode 资产编码 , F_DeviceShortCode 设备短码,F_Specification 规格型号, F_BelongDeptName 归属科室, F_BelongPhone 归属科室电话,(CASE F_DeviceStatus WHEN 1 THEN '待上架' WHEN 2 THEN '可调拨' WHEN 3 THEN '调拨中' ELSE ''END) 设备状态,F_ListingTime 上架时间 from T_Adjust_Device a WITH(NOLOCK) where 1=1 " + sql + "order by F_DeviceId desc").Tables[0];
- var msg = new NPOIHelper().ExportToExcel("我的设备", dtdc);
- if (msg == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "T_Adjust_Device",
- "F_DeviceId",
- "*",
- sql,
- " order by F_DeviceId desc",
- pagesize,
- page,
- true,
- out recordCount);
- dt.Columns.Add("FileUrl", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(fileurlpath) && !string.IsNullOrEmpty(dr["F_File"].ToString()))
- {
- dr["FileUrl"] = GetFileData(dr["F_File"].ToString(), fileurlpath);
- }
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 我的设备列表中添加编辑设备 Device/AddOrEditMyDevice
- /// </summary>
- /// <param name="address">部门地址</param>
- /// <param name="phone">部门电话</param>
- /// <param name="assetCode">资产编码</param>
- /// <param name="file">文件 string</param>
- /// <param name="desc">描述</param>
- /// <param name="deviceTypeId">设备类型表的主键id,不是dicId</param>
- /// <param name="deviceId">设备id,编辑用</param>
- /// <returns></returns>
- public ActionResult AddOrEditMyDevice(string address
- , string phone, string assetCode, string file, string desc, string deviceShortCode, string bigTypeName, string typeName,
- string code, string specification, int dicId = 0,
- int deviceTypeId = 0, int deviceId = 0)
- {
- if (deviceTypeId == 0)
- {
- if (string.IsNullOrEmpty(bigTypeName) && string.IsNullOrEmpty(typeName))
- {
- return Error("请选择或者输入设备类型和设备名称");
- }
- if (dicId == 0 && string.IsNullOrEmpty(typeName))
- {
- return Error("请选择或者输入设备类型和设备名称");
- }
- }
- Model.T_Adjust_DeviceType typemodel = new T_Adjust_DeviceType();
- if (deviceTypeId > 0)
- {
- typemodel = typeservice.GetModel(deviceTypeId);
- if (typemodel == null)
- {
- return Error(" 设备类型不存在");
- }
- }
- else
- {
- //先添加字典的记录
- //添加设备类型记录
- //T_Sys_DictionaryValue orderModel = new T_Sys_DictionaryValue();
- //orderModel.F_Name = bigTypeName;
- //orderModel.F_State = true;
- //orderModel.F_DictionaryFlag = "DBSBLX";
- //int dicaddid = new Bll.T_Sys_DictionaryValue().Add(bigTypeName);
- int dicaddid = 0;
- if (dicId > 0)
- {
- Model.T_Sys_DictionaryValue dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(dicId);
- if (dicmodel != null)
- {
- dicaddid = dicmodel.F_DictionaryValueId;
- bigTypeName = dicmodel.F_Name;
- }
- }
- else
- {
- Model.T_Sys_DictionaryValue dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(bigTypeName);
- if (dicmodel != null)
- {
- dicaddid = dicmodel.F_DictionaryValueId;
- }
- else
- {
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(bigTypeName);
- }
- }
- Model.T_Adjust_DeviceType modeltype = typeservice.GetModel(bigTypeName, typeName, 2);
- if (modeltype == null)
- {
- // Model.T_Adjust_DeviceType model = new T_Adjust_DeviceType();
- typemodel.F_DeviceNum = 0;
- typemodel.F_IsDelete = 0;
- typemodel.F_CreateBy = User.F_UserCode;
- typemodel.F_BigTypeName = bigTypeName;
- typemodel.F_TypeName = typeName;
- typemodel.F_Classification = 2;
- typemodel.F_DicId = dicaddid;
- typemodel.F_CreateTime = DateTime.Now;
- typemodel.F_UpdateTime = DateTime.Now;
- int res = typeservice.Add(typemodel);
- deviceTypeId = res;
- }
- else
- {
- typemodel = modeltype;
- deviceTypeId = modeltype.F_TypeId;
- }
- }
- var existslist = deviceservice.GetModelList(" F_AssetCode ='" + assetCode + "' and F_AssetCode is not null and F_AssetCode!='' ");
- if (deviceId > 0)
- {
- if (existslist.Count == 0)
- { }
- else if (existslist.Count == 1 && existslist.First().F_DeviceId == deviceId)
- {
- }
- else
- {
- return Error("资产编码不能重复!");
- }
- Model.T_Adjust_Device model = deviceservice.GetModel(deviceId);
- int old = model.F_DeviceTypeId;
- bool needupdatecount = false;
- if (old != deviceTypeId)
- {
- needupdatecount = true;
- }
- //编辑
- model.F_BigTypeName = typemodel.F_BigTypeName;
- model.F_TypeName = typemodel.F_TypeName;
- model.F_DicId = typemodel.F_DicId;
- model.F_DeviceTypeId = deviceTypeId;
- model.F_BelongPhone = phone;
- model.F_BelongAddress = address;
- model.F_AssetCode = assetCode;
- model.F_DeviceShortCode = deviceShortCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_File = file;
- model.F_UpdateTime = DateTime.Now;
- model.F_DeviceShortCode = deviceShortCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_Desc = desc;
- if (deviceservice.Update(model))
- {
- if (needupdatecount)
- {
- string uda = " update T_Adjust_DeviceType set F_DeviceNum= isnull(F_DeviceNum,0)+1 where F_TypeId=" + deviceId + "";
- string uda2 = " update T_Adjust_DeviceType set F_DeviceNum= isnull(F_DeviceNum,0)-1 where F_TypeId=" + old + "";
- DbHelperSQL.ExecuteSql(uda);
- DbHelperSQL.ExecuteSql(uda2);
- }
- return Success("修改成功");
- }
- else
- {
- return Error("修改失败");
- }
- }
- else
- {
- if (!string.IsNullOrEmpty(assetCode) && existslist.Count > 0)
- {
- return Error("资产编码不能重复!");
- }
- // Model.T_Sys_Department dept = new Bll.T_Sys_Department().GetModel(User.F_DeptId);
- var dept = DbHelperSQL.Query(" SELECT * from T_AllDept WHERE F_deptid = " + User.F_DeptId + "").Tables[0];
- Model.T_Adjust_Device model = new T_Adjust_Device();
- model.F_BelongDept = User.F_DeptId;
- model.F_BelongDeptName = dept.Rows[0]["keyname"].ToString();
- model.F_Source = 1;
- model.F_DeviceStatus = 1;//待上架
- model.F_Classify = 2;
- model.F_IsDelete = 0;
- model.F_CreateBy = User.F_UserCode;
- model.F_CreateTime = DateTime.Now;
- model.F_UpdateTime = DateTime.Now;
- model.F_DeviceShortCode = deviceShortCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_DeviceTypeId = deviceTypeId;
- model.F_BigTypeName = typemodel.F_BigTypeName;
- model.F_TypeName = typemodel.F_TypeName;
- model.F_DicId = typemodel.F_DicId;
- model.F_BelongPhone = phone;
- model.F_BelongAddress = address;
- model.F_AssetCode = assetCode;
- model.F_Desc = desc;
- model.F_File = file;
- int res = deviceservice.Add(model);
- if (res > 0)
- {
- string uda = " update T_Adjust_DeviceType set F_DeviceNum= isnull(F_DeviceNum,0)+1 where F_TypeId=" + deviceTypeId + "";
- DbHelperSQL.ExecuteSql(uda);
- InsertLog(res, "添加设备");
- return Success("添加成功");
- }
- else
- {
- return Error("添加失败");
- }
- }
- }
- /// <summary>
- /// GetUnusedList 调拨管理中的闲置列表,状态都是闲置
- /// </summary>
- /// <param name="typeName">设备名称</param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="dicId">设备类型</param>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- public ActionResult GetUnusedList(
- string typeName, string startTime, string endTime, int dicId = 0, int page = 1, int pagesize = 10, int listType = 1, int isdc = 0)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 and F_Classify=2 ";
- if (listType == 1)
- {
- sql += " and F_DeviceStatus in (2,3)";
- sql += " and F_BelongDept !=" + User.F_DeptId + "";
- }
- else
- {
- sql += " and F_DeviceStatus=3";
- }
- if (dicId > 0)
- {
- sql += " and F_DicId='" + dicId + "' ";
- }
- if (!string.IsNullOrEmpty(startTime))
- {
- sql += " and F_ListingTime>='" + startTime + "'";
- }
- if (!string.IsNullOrEmpty(endTime))
- {
- sql += " and F_ListingTime<='" + endTime + "'";
- }
- if (!string.IsNullOrEmpty(typeName))
- {
- sql += " and F_TypeName like '%" + typeName + "%' ";
- }
- //if (deviceStatus > 0)
- //{
- // sql += " and F_DeviceStatus='" + deviceStatus + "' ";
- //}
- if (isdc > 0)
- {
- var dtdc = DB.DbHelperSQL.Query(" SELECT F_TypeName 设备名称, F_Desc 设备描述,F_AssetCode 资产编码 , F_DeviceShortCode 设备短码,F_Specification 规格型号, F_BelongDeptName 归属科室, F_BelongPhone 归属科室电话,(CASE F_DeviceStatus WHEN 1 THEN '待上架' WHEN 2 THEN '可调拨' WHEN 3 THEN '调拨中' ELSE ''END) 设备状态,F_ListingTime 上架时间 from T_Adjust_Device a WITH(NOLOCK) where 1=1 " + sql + "order by F_DeviceId desc").Tables[0];
- var msg = new NPOIHelper().ExportToExcel("空闲设备", dtdc);
- if (msg == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "T_Adjust_Device",
- "F_DeviceId",
- "*",
- sql,
- " order by F_ListingTime desc",
- pagesize,
- page,
- true,
- out recordCount);
- dt.Columns.Add("FileUrl", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(fileurlpath) && !string.IsNullOrEmpty(dr["F_File"].ToString()))
- {
- dr["FileUrl"] = GetFileData(dr["F_File"].ToString(), fileurlpath);
- }
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- private string fileurlpath = ConfigHelper.GetValue("fileurlpath");
- public DataTable GetFileData(string ids, string prefix)
- {
- DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + ids + ")").Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- if (FileHelper.Exists(FileHelper.GetPath() + dr["F_FileUrl"].ToString()))
- {
- dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
- }
- else
- {
- string url = HomeController.Upload(dr["F_FileUrl"].ToString(), dr["F_FileName"].ToString(), "/" + dr["F_FileUrl"].ToString().Replace(dr["F_FileName"].ToString(), ""));
- if (url == "1")
- dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
- else
- dr["F_FileUrl"] = url;
- }
- }
- return dt;
- }
- /// <summary>
- /// AuditDB
- /// </summary>
- /// <param name="reason">拒绝的时候原因</param>
- /// <param name="operate">0 拒绝 1 同意</param>
- /// <param name="deviceId"></param>
- /// <returns></returns>
- public ActionResult AuditDB(string reason, int operate, int deviceId = 0)
- {
- if (deviceId <= 0)
- {
- return Error("请选择设备");
- }
- Model.T_Adjust_Device model = deviceservice.GetModel(deviceId);
- string reusercode = model.F_UseCode;
- Model.T_Adjust_Device oldmodel = deviceservice.GetModel(deviceId);
- // 参考附件图片,同意、拒绝操作需要给对应人发消息(钉钉)
- //1.同意:设备状态变更为待上架,归属科室变更为申请科室
- //2.拒绝:设备状态变更为可调配,需要输入拒绝原因
- if (operate == 1)
- {
- model.F_DeviceStatus = 1;
- model.F_BelongAddress = model.F_UseAddress;
- model.F_BelongDept = model.F_UseDept;
- model.F_BelongDeptName = model.F_UseDeptName;
- model.F_BelongPhone = model.F_UsePhone;
- model.F_UseDept = null;
- model.F_UseAddress = "";
- model.F_UseDeptName = "";
- model.F_UsePhone = "";
- model.F_UseCode = "";
- model.F_ListingTime = null;
- model.F_UpdateTime = DateTime.Now;
- if (deviceservice.Update(model))
- {
- //添加操作日志
- InsertLog(deviceId, "同意申请," + oldmodel.F_TypeName + "归属科室更改为" + oldmodel.F_UseDeptName);
- msg.AddInternalMessagesInfo("调拨审核同意", model.F_TypeName + "同意调拨", reusercode, User.F_UserCode, EnumSmsType.comprehensive
- , 0);
- return Success("审核成功");
- }
- else
- {
- return Error("审核失败");
- }
- }
- if (operate == 0)
- {
- model.F_DeviceStatus = 2;
- model.F_UseDept = null;
- model.F_UseAddress = "";
- model.F_UseDeptName = "";
- model.F_UsePhone = "";
- model.F_UseCode = "";
- model.F_UpdateTime = DateTime.Now;
- if (deviceservice.Update(model))
- {
- if (!string.IsNullOrEmpty(reason))
- {
- reason = ",原因:" + reason;
- }
- InsertLog(deviceId, "拒绝申请" + reason);
- msg.AddInternalMessagesInfo("调拨审核拒绝", model.F_TypeName + "拒绝申请", reusercode, User.F_UserCode, EnumSmsType.comprehensive
- , 0);
- return Success("审核成功");
- }
- else
- {
- return Error("审核失败");
- }
- }
- return Error("审核失败");
- }
- /// <summary>
- /// 申请调拨 Adjust
- /// </summary>
- /// <param name="deviceId"></param>
- /// <returns></returns>
- public ActionResult Adjust(int deviceId)
- {
- if (deviceId <= 0)
- {
- return Error("请选择设备");
- }
- Model.T_Adjust_Device model = deviceservice.GetModel(deviceId);
- if (model.F_DeviceStatus == 3)
- {
- return Error("调拨中不允许申请");
- }
- if (model.F_BelongDept == User.F_DeptId)
- {
- return Error("此设备所属部门是登录人的部门");
- }
- Model.T_Sys_Department deptmodel = new Bll.T_Sys_Department().GetModel(User.F_DeptId);
- var dept = DbHelperSQL.Query(" SELECT * from T_AllDept WHERE F_deptid = " + User.F_DeptId + "").Tables[0];
- model.F_UseDept = User.F_DeptId;
- model.F_UseAddress = dept.Rows[0]["F_location"].ToString();// dept.F_Location;
- model.F_UseDeptName = dept.Rows[0]["keyname"].ToString();
- model.F_UsePhone = deptmodel.F_OfficeTelephone;
- model.F_UseCode = User.F_UserCode;
- model.F_DeviceStatus = 3;
- model.F_UpdateTime = DateTime.Now;
- if (deviceservice.Update(model))
- {
- InsertLog(deviceId, "申请设备调拨");
- return Success("申请成功");
- }
- else
- {
- return Error("申请失败");
- }
- }
- /// <summary>
- /// GetDetail
- /// </summary>
- /// <param name="deviceId"></param>
- /// <param name="classify">1 调配 2调拨</param>
- /// <returns></returns>
- public ActionResult GetDetail(int deviceId, int classify = 1)
- {
- var dt = deviceservice.GetList(" F_DeviceId=" + deviceId + "").Tables[0];
- dt.Columns.Add("FileUrl", typeof(object));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(fileurlpath) && !string.IsNullOrEmpty(dr["F_File"].ToString()))
- {
- dr["FileUrl"] = GetFileData(dr["F_File"].ToString(), fileurlpath);
- }
- }
- var tpinfo = tpinfoBll.GetModelList(" F_DeviceId=" + deviceId + " order by F_CreateTime desc");
- var obj = new
- {
- state = "success",
- message = "成功",
- data = dt,
- logs = tpinfo
- };
- return Content(obj.ToJson());
- }
- public ActionResult GetDBInfo(int deviceId = 0, int page = 1, int pagesize = 10)
- {
- if (deviceId == 0)
- {
- return Error("deviceId 不能为空");
- }
- DataTable dt = new DataTable();
- string sql = " and 1 = 1";
- if (deviceId > 0)
- {
- sql += " and F_DeviceId='" + deviceId + "' ";
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "T_Adjust_Log",
- "F_LogId",
- "*",
- sql,
- " order by F_CreateTime desc",
- pagesize,
- page,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- data = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- public void InsertLog(int deviceId, string log)
- {
- Model.T_Adjust_Log logmodel = new T_Adjust_Log();
- logmodel.F_CreateBy = User.F_UserName + "(" + User.F_UserCode + ")";
- logmodel.F_CreateTime = DateTime.Now;
- logmodel.F_Log = log;
- logmodel.F_DeviceId = deviceId;
- logBll.Add(logmodel);
- }
- //工单相关的接口
- /// <summary>
- /// GetAllDPDevice创建工单时,获取所有的调配设备
- /// </summary>
- /// <returns></returns>
- public ActionResult GetAllDPDevice()
- {
- string sql = "select F_DeviceId,F_TypeName from T_Adjust_Device where F_Classify=1 and F_IsDelete=0 ";
- var list = DbHelperSQL.Query(sql).Tables[0];
- var obj = new
- {
- state = "success",
- message = "成功",
- data = list
- };
- return Content(obj.ToJson());
- }
- //列表默认显示对应借用类型名称下的闲置设备,可使用资产编码或短码搜索;可选择对应设备点击出库进行出库;
- /// <summary>
- /// GetUnuseDevice根据工单编号查找 该工单借用的类型名称.下的闲置设备,可使用资产编码或短码搜索;可选择对应设备点击出库进行出库;
- /// </summary>
- /// <param name="workOrderCode"></param>
- /// <param name="assetCode"></param>
- /// <param name="deviceShortCode"></param>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- public ActionResult GetUnuseDevice(string assetCode, string deviceShortCode, int deviceTypeId = 0, int page = 1, int pagesize = 10)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 and F_Classify=1 and F_DeviceStatus=2 ";
- sql += " and F_DeviceTypeId=" + deviceTypeId + "";
- if (!string.IsNullOrEmpty(assetCode))
- {
- sql += " and F_AssetCode='" + assetCode + "' ";
- }
- if (!string.IsNullOrEmpty(deviceShortCode))
- {
- sql += " and F_DeviceShortCode='" + deviceShortCode + "' ";
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "T_Adjust_Device",
- "F_DeviceId",
- "*",
- sql,
- " order by F_DeviceId desc",
- pagesize,
- page,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- //列表默认显示当前用户所在的科室下所有使用中的设备,可使用资产编码或短码搜索其他设备;可选择对应设备点击入库进行入库;
- /// <summary>
- /// GetUseDevice
- /// </summary>
- /// <param name="assetCode">资产编码</param>
- /// <param name="deviceShortCode">短码</param>
- /// <param name="page"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- public ActionResult GetUseDevice(string assetCode, string deviceShortCode, int deviceTypeId = 0, int page = 1, int pagesize = 10)
- {
- DataTable dt = new DataTable();
- string sql = " and F_IsDelete=0 and F_Classify=1 and F_DeviceStatus=3 and F_UseDept='" + User.F_DeptId + "'";
- sql += " and F_DeviceTypeId=" + deviceTypeId + "";
- if (!string.IsNullOrEmpty(assetCode))
- {
- sql += " and F_AssetCode='" + assetCode + "' ";
- }
- if (!string.IsNullOrEmpty(deviceShortCode))
- {
- sql += " and F_DeviceShortCode='" + deviceShortCode + "' ";
- }
- int recordCount = 0;
- dt = Bll.PagerBll.GetListPager(
- "T_Adjust_Device",
- "F_DeviceId",
- "*",
- sql,
- " order by F_DeviceId desc",
- pagesize,
- page,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- //string address
- // , string phone, string assetCode, string file,string desc, string deviceShortCode,
- // string code, string specification,
- // string bigname,string name ,
- //1 调配 2调拨
- public ActionResult ImportDevice()
- {
- HttpPostedFileBase _upfile = Request.Files["upFile"];
- int headrow = 0;
- string savepath = Server.MapPath("..") + "/Upload/import/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd");
- // 如果不存在就创建file文件夹
- if (!Directory.Exists(savepath))
- {
- if (savepath != null) Directory.CreateDirectory(savepath);
- }
- string realurl = Path.Combine(savepath, _upfile.FileName);
- // 指定保存文件的路径
- // 保存文件到服务器
- _upfile.SaveAs(realurl);
- NPOIHelper npoi = new NPOIHelper();
- DataTable dt = npoi.ExcelToTable(_upfile, headrow);
- try
- {
- bool isValid = true;
- if (dt != null && dt.Columns.Count >= 2)
- {
- string firstColumnName = dt.Columns[7].ColumnName;
- string secondColumnName = dt.Columns[2].ColumnName;
- isValid = (firstColumnName == "出厂编号" && secondColumnName == "科室电话");
- }
- if (isValid == false)
- {
- return Error("导入模版错误");
- }
- }
- catch (Exception)
- {
- return Error("导入模版错误");
- }
- int res = 0;
- string returnerror = "";
- foreach (DataRow dr in dt.Rows)
- {
- int deviceTypeId = 0;
- int dicaddid = 0;
- headrow = headrow + 1;
- if (dr[0].ToString() != "" && dr[1].ToString() != "" && dr[4].ToString() != "")
- {
- var existslist = deviceservice.GetModelList(" F_AssetCode ='" + dr[4].ToString() + "'");
- if (existslist.Count > 0)
- {
- Model.T_Adjust_Device model = existslist.First();
- if (model.F_Classify != 1)
- {
- returnerror += "第" + headrow + "行资产编码已存在,属于调拨类型";
- continue;
- }
- model.F_BigTypeName = dr[0].ToString();// typemodel.F_BigTypeName;
- model.F_TypeName = dr[1].ToString();
- //根据bigtypename去找dic
- Model.T_Sys_DictionaryValue dic = new Bll.T_Sys_DictionaryValue().GetModel(dr[0].ToString());
- if (dic == null)
- {
- //先添加字典的记录
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(dr[0].ToString());
- }
- model.F_DicId = dicaddid == 0 ? dic.F_DictionaryValueId : dicaddid;//.F_DicId;
- Model.T_Adjust_DeviceType modeltype = typeservice.GetModel(dr[0].ToString(), dr[1].ToString(), 1);
- if (modeltype == null)
- {//添加设备类型记录
- Model.T_Adjust_DeviceType addmodel = new T_Adjust_DeviceType();
- addmodel.F_DeviceNum = 0;
- addmodel.F_IsDelete = 0;
- addmodel.F_Classification = 1;
- addmodel.F_CreateBy = User.F_UserCode;
- addmodel.F_BigTypeName = dr[0].ToString();
- addmodel.F_TypeName = dr[1].ToString();
- addmodel.F_DicId = dicaddid;
- addmodel.F_CreateTime = DateTime.Now;
- addmodel.F_UpdateTime = DateTime.Now;
- int rees = typeservice.Add(addmodel);
- deviceTypeId = rees;
- }
- var dept = DbHelperSQL.Query(" SELECT * from T_AllDept WHERE F_deptid = " + User.F_DeptId + "").Tables[0];
- model.F_BelongPhone = dr[2].ToString();
- model.F_BelongAddress = dr[3].ToString();
- model.F_BelongDept = User.F_DeptId;
- // model.F_BelongDeptName = dept.F_DeptName;// eptName;
- model.F_BelongDeptName = dept.Rows[0]["keyname"].ToString();
- model.F_DeviceTypeId = deviceTypeId == 0 ? modeltype.F_TypeId : deviceTypeId;
- model.F_AssetCode = dr[4].ToString();
- model.F_DeviceShortCode = dr[5].ToString();
- model.F_Specification = dr[6].ToString();
- model.F_Code = dr[7].ToString();
- model.F_UpdateTime = DateTime.Now;
- deviceservice.Update(model);
- }
- else
- {
- Model.T_Adjust_Device model = new T_Adjust_Device();
- model.F_BigTypeName = dr[0].ToString();// typemodel.F_BigTypeName;
- model.F_TypeName = dr[1].ToString();
- //根据bigtypename去找dic
- Model.T_Sys_DictionaryValue dic = new Bll.T_Sys_DictionaryValue().GetModel(dr[0].ToString());
- if (dic == null)
- {
- //先添加字典的记录
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(dr[0].ToString());
- }
- model.F_DicId = dicaddid == 0 ? dic.F_DictionaryValueId : dicaddid;//.F_DicId;
- Model.T_Adjust_DeviceType modeltype = typeservice.GetModel(dr[0].ToString(), dr[1].ToString(), 1);
- if (modeltype == null)
- {//添加设备类型记录
- Model.T_Adjust_DeviceType addmodel = new T_Adjust_DeviceType();
- addmodel.F_DeviceNum = 0;
- addmodel.F_IsDelete = 0;
- addmodel.F_Classification = 1;
- addmodel.F_CreateBy = User.F_UserCode;
- addmodel.F_BigTypeName = dr[0].ToString();
- addmodel.F_TypeName = dr[1].ToString();
- addmodel.F_DicId = dicaddid;
- addmodel.F_CreateTime = DateTime.Now;
- addmodel.F_UpdateTime = DateTime.Now;
- int rees = typeservice.Add(addmodel);
- deviceTypeId = rees;
- }
- var dept = DbHelperSQL.Query(" SELECT * from T_AllDept WHERE F_deptid = " + User.F_DeptId + "").Tables[0];
- // Model.T_Sys_Department dept = new Bll.T_Sys_Department().GetModel(User.F_DeptId);
- model.F_BelongPhone = dr[2].ToString();
- model.F_BelongAddress = dr[3].ToString();
- model.F_BelongDept = User.F_DeptId;
- model.F_BelongDeptName = dept.Rows[0]["keyname"].ToString();
- model.F_DeviceTypeId = modeltype.F_TypeId;
- model.F_AssetCode = dr[4].ToString();
- model.F_DeviceShortCode = dr[5].ToString();
- model.F_Specification = dr[6].ToString();
- model.F_Code = dr[7].ToString();
- model.F_Source = 1;
- model.F_CreateBy = User.F_UserCode;
- model.F_CreateTime = DateTime.Now;
- model.F_UpdateTime = DateTime.Now;
- model.F_DeviceStatus = 1;//待上架
- model.F_Classify = 1;
- model.F_IsDelete = 0;
- deviceservice.Add(model);
- // 设备的数量重新算一遍
- string updatesql = "update T_Adjust_DeviceType set F_DeviceNum = (SELECT Count(1) from T_Adjust_Device WHERE F_IsDelete = 0 and F_DeviceTypeId =" + modeltype.F_TypeId + " ) WHERE F_TypeId =" + modeltype.F_TypeId;
- DbHelperSQL.ExecuteSql(updatesql);
- }
- }
- else
- {
- return Error("第" + headrow + "行,第1,2,5 列信息不能为空,未导入");
- }
- }
- return Success("导入成功!" + returnerror);
- }
- public ActionResult ImportMyDevice()
- {
- HttpPostedFileBase _upfile = Request.Files["upFile"];
- int headrow = 0;
- NPOIHelper npoi = new NPOIHelper();
- DataTable dt = npoi.ExcelToTable(_upfile, headrow);
- try
- {
- bool isValid = true;
- if (dt != null && dt.Columns.Count >= 2)
- {
- string firstColumnName = dt.Columns[8].ColumnName;
- string secondColumnName = dt.Columns[2].ColumnName;
- isValid = (firstColumnName == "描述" && secondColumnName == "科室电话");
- }
- if (isValid == false)
- {
- return Error("导入模版错误");
- }
- }
- catch (Exception)
- {
- return Error("导入模版错误");
- }
- int exportnum = 0;
- string returnerror = "";
- var bll = new Bll.T_Cus_Customer();
- int res = 0;
- // Model.T_Sys_Department dept = new Bll.T_Sys_Department().GetModel(User.F_DeptId);
- var dept = DbHelperSQL.Query(" SELECT * from T_AllDept WHERE F_deptid = " + User.F_DeptId + "").Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- int dicaddid = 0;
- int deviceTypeId = 0;
- headrow = headrow + 1;
- if (dr[0].ToString() != "" && dr[1].ToString() != "")
- {
- // Model.T_Adjust_DeviceType typemodel = typeservice.GetModel(dr[0].ToString(), dr[1].ToString(),2);
- //根据bigtypename去找dic
- Model.T_Sys_DictionaryValue dic = new Bll.T_Sys_DictionaryValue().GetModel(dr[0].ToString());
- if (dic == null)
- {
- //先添加字典的记录
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(dr[0].ToString());
- }
- Model.T_Adjust_DeviceType modeltype = typeservice.GetModel(dr[0].ToString(), dr[1].ToString(), 1);
- if (modeltype == null)
- {
- continue;
- //添加设备类型记录
- //Model.T_Adjust_DeviceType addmodel = new T_Adjust_DeviceType();
- //addmodel.F_DeviceNum = 0;
- //addmodel.F_IsDelete = 0;
- //addmodel.F_Classification = 2;
- //addmodel.F_CreateBy = User.F_UserCode;
- //addmodel.F_BigTypeName = dr[0].ToString();
- //addmodel.F_TypeName = dr[1].ToString();
- //addmodel.F_DicId = dicaddid;
- //addmodel.F_CreateTime = DateTime.Now;
- //addmodel.F_UpdateTime = DateTime.Now;
- //int rees = typeservice.Add(addmodel);
- //deviceTypeId = rees;
- }
- var existslist = deviceservice.GetModelList(" F_AssetCode ='" + dr[4].ToString() + "' ");
- if (existslist.Count > 0)
- {
- Model.T_Adjust_Device model
- = existslist.First();
- if (model.F_Classify != 2)
- {
- returnerror += "第" + headrow + "行资产编码已存在,属于调配类型";
- continue;
- }
- model.F_DeviceTypeId = deviceTypeId == 0 ? modeltype.F_TypeId : deviceTypeId;
- model.F_BigTypeName = dr[0].ToString();
- model.F_TypeName = dr[1].ToString();
- model.F_DicId = dicaddid == 0 ? dic.F_DictionaryValueId : dicaddid;
- model.F_BelongPhone = dr[2].ToString();
- model.F_BelongAddress = dr[3].ToString();
- model.F_AssetCode = dr[4].ToString();
- model.F_DeviceShortCode = dr[5].ToString();
- model.F_Specification = dr[6].ToString();
- model.F_Code = dr[7].ToString();
- model.F_Desc = dr[8].ToString();
- model.F_UpdateTime = DateTime.Now;
- deviceservice.Update(model);
- }
- else
- {
- Model.T_Adjust_Device model
- = new T_Adjust_Device();
- model.F_BelongDept = User.F_DeptId;
- // model.F_BelongDeptName = dept.F_DeptName;
- model.F_BelongDeptName = dept.Rows[0]["keyname"].ToString();
- model.F_Source = 1;
- model.F_DeviceStatus = 1;//待上架
- model.F_Classify = 2;
- model.F_IsDelete = 0;
- model.F_CreateBy = User.F_UserCode;
- model.F_CreateTime = DateTime.Now;
- model.F_UpdateTime = DateTime.Now;
- model.F_DeviceTypeId = deviceTypeId == 0 ? modeltype.F_TypeId : deviceTypeId;
- model.F_BigTypeName = dr[0].ToString();
- model.F_TypeName = dr[1].ToString();
- model.F_DicId = dicaddid == 0 ? dic.F_DictionaryValueId : dicaddid;
- model.F_BelongPhone = dr[2].ToString();
- model.F_BelongAddress = dr[3].ToString();
- model.F_AssetCode = dr[4].ToString();
- model.F_DeviceShortCode = dr[5].ToString();
- model.F_Specification = dr[6].ToString();
- model.F_Code = dr[7].ToString();
- model.F_Desc = dr[8].ToString();
- int addre = deviceservice.Add(model);
- if (addre > 0)
- {
- exportnum++;
- // 设备的数量重新算一遍
- string updatesql = "update T_Adjust_DeviceType set F_DeviceNum = (SELECT Count(1) from T_Adjust_Device WHERE F_IsDelete = 0 and F_DeviceTypeId =" + model.F_DeviceTypeId + " ) WHERE F_TypeId =" + model.F_DeviceTypeId;
- DbHelperSQL.ExecuteSql(updatesql);
- }
- }
- }
- else
- {
- return Error("第" + headrow + "行,第1,2列信息不能为空,未导入");
- }
- }
- //if (exportnum == 0)
- //{
- // return Success("0条数据被导入");
- //}
- //else {
- return Success("导入成功,导入" + exportnum + "数据");
- //}
- }
- /// <summary>
- /// ordertype 1 是调配 2 是调拨
- /// </summary>
- /// <param name="month">格式是yyyy-mm</param>
- /// <returns></returns>
- [AllowAnonymous]
- public ActionResult GetTotalReport(string month,int ordertype=1)
- {
- if (string.IsNullOrEmpty(month))
- {
- month = DateTime.Now.ToString("yyyy-MM");
- }
- DataTable jiechu = new DataTable();
- DataTable jieru = new DataTable();
- if (ordertype == 1)
- {
- jiechu = DbHelperSQL.Query("SELECT F_BelongDept,F_BelongDeptName,SUM(F_Cost) jiechu FROM [T_Adjust_TpOrder] where F_IsDelete=0 and F_BelongDept is not null and F_OrderStatus=2 and F_ordertype=" + ordertype + " and CONVERT(VARCHAR(7), F_OutTime, 120)='" + month + "' GROUP BY F_BelongDept, F_BelongDeptName").Tables[0];
- jieru = DbHelperSQL.Query("SELECT F_UseDept,F_UseDeptName,SUM(F_Cost) jieru FROM [T_Adjust_TpOrder] where F_IsDelete=0 and F_UseDept is not null and F_OrderStatus=2 and F_ordertype=" + ordertype + " and CONVERT(VARCHAR(7), F_OutTime, 120)='" + month + "' GROUP BY F_UseDept, F_UseDeptName ").Tables[0];
- }
- else {
- jiechu = DbHelperSQL.Query("SELECT F_BelongDept,F_BelongDeptName,SUM(F_total) jiechu FROM [T_Adjust_TpOrder] where F_IsDelete=0 and F_BelongDept is not null and F_OrderStatus=2 and F_ordertype=" + ordertype + " and CONVERT(VARCHAR(7), F_OutTime, 120)='" + month + "' GROUP BY F_BelongDept, F_BelongDeptName").Tables[0];
- jieru = DbHelperSQL.Query("SELECT F_UseDept,F_UseDeptName,SUM(F_total) jieru FROM [T_Adjust_TpOrder] where F_IsDelete=0 and F_UseDept is not null and F_OrderStatus=2 and F_ordertype=" + ordertype + " and CONVERT(VARCHAR(7), F_OutTime, 120)='" + month + "' GROUP BY F_UseDept, F_UseDeptName ").Tables[0];
- }
- var idList = new List<int>(jiechu.AsEnumerable().Select(x => x.Field<int>("F_BelongDept")));
- var idList2 = new List<int>(jieru.AsEnumerable().Select(x => x.Field<int>("F_UseDept")));
- var union = idList.Union(idList2);
- List<ReturnReport> lists = new List<ReturnReport>();
- foreach (int item in union)
- {
- ReturnReport re = new ReturnReport();
- DataRow[] rows = jiechu.Select("F_BelongDept=" + item + " ");
- if (rows != null && rows.Count() > 0)
- {
- re.DeptName = rows[0]["F_BelongDeptName"].ToString();
- // re.jiechu = Convert.ToDecimal(rows[0]["jiechu"].ToString());
- re.jiechu = !string.IsNullOrEmpty(rows[0]["jiechu"].ToString()) ? Convert.ToDecimal(rows[0]["jiechu"].ToString()) : 0;
- }
- re.DeptId = item;
- DataRow[] rows2 = jieru.Select("F_UseDept=" + item + " ");
- if (rows2 != null && rows2.Count() > 0)
- {
- re.DeptName = rows2[0]["F_UseDeptName"].ToString();
- re.jieru = !string.IsNullOrEmpty(rows2[0]["jieru"].ToString())?Convert.ToDecimal(rows2[0]["jieru"].ToString()) :0;
- }
-
- lists.Add(re);
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- data = lists
- };
- return Content(obj.ToJson());
- }
- public class ReturnReport
- {
- public string DeptName { get; set; }
- public int DeptId { get; set; }
- public decimal jiechu { get; set; }
- public decimal jieru { get; set; }
- }
- /// <summary>
- /// 同步数据,过来是调配类型的
- /// </summary>
- [AllowAnonymous]
- public void tpdata()
- {
- string depsql = "select F_DeptId, keyname from DeptNameName ";
- DataTable deptdt = DbHelperSQL.Query(depsql).Tables[0];
- List<Model.T_Sys_Department> deptlist = deptbll.GetModelList("F_State=1");
- // 转换为字典以加速查找
- var deptDict = deptdt.AsEnumerable()
- .ToDictionary(row => row.Field<int>("F_DeptId"), row => row.Field<string>("keyname"));
- //var departmentDict = deptlist.ToDictionary(d => d.F_DeptName, d => d);
- // 过滤掉重复的部门名称,保留第一个出现的
- var departmentDict = deptlist
- .GroupBy(d => d.F_DeptName)
- .Select(g => g.First())
- .ToDictionary(d => d.F_DeptName, d => d);
-
- int pageSize = 100; // 每页1000条
- // int currentPage = 0; // 当前页码(从0开始)
- //一次同步1000条,避免卡死
- int rescount = (int)DbHelperSQL.GetSingle("SELECT count(1) FROM T_SyncEquip where tb_bz=1");
- // 预先计算总页数(避免在循环中计算)
- int totalPages = (rescount + pageSize - 1) / pageSize;
- int lastId = 0; // 起始值(根据sb_Id类型调整)
- int processed = 0;
- List<Model.T_Adjust_Device> devicesToAdd = new List<Model.T_Adjust_Device>();
- List<Model.T_Adjust_Device> devicesToUpdate = new List<Model.T_Adjust_Device>();
- Dictionary<int,int> deviceTypeUpdates = new Dictionary<int, int>();
- while (processed < rescount)
- {
- // 使用参数化查询防止注入
- string sql = @"
- SELECT TOP (@take) *
- FROM T_SyncEquip
- WHERE tb_bz=1 and sb_Id > @lastId
- ORDER BY sb_Id";
- SqlParameter[] parameters = {
- new SqlParameter("@take", pageSize),
- new SqlParameter("@lastId", lastId)
- };
- DataTable dt = DbHelperSQL.Query(sql, parameters).Tables[0];
- if (dt.Rows.Count == 0) break;
- // 并行处理当前页数据(行级并行)
- Parallel.For(0, dt.Rows.Count, new ParallelOptions
- {
- MaxDegreeOfParallelism = Environment.ProcessorCount
- }, i =>
- {
- DataRow item = dt.Rows[i];
- int deviceTypeId = 0;
- int dicaddid = 0;
- string bigTypeName = item["category_name"].ToString();//设备类别名称
- string typeName = item["equip_name"].ToString();
- string assetCode = item["equip_code"].ToString();//设备编码唯一
- string specification = item["spec_model"].ToString();//规格型号
- string code = item["precoding"].ToString();//出厂编码/SN
- string mandept_name = item["mandept_name"].ToString();//管理部门
- string usedept_name = item["usedept_name"].ToString();//使用部门
- if (string.IsNullOrEmpty(bigTypeName) && string.IsNullOrEmpty(typeName))
- {
- return;
- //continue;
- // return Error("请选择或者输入设备类型和设备名称");
- }
- if (string.IsNullOrEmpty(assetCode))
- {
- return;
- //continue;
- //return Error("资产编码不能为空");
- }
- Model.T_Adjust_DeviceType typemodel = new T_Adjust_DeviceType();
- //找不到这个设备类型,给它自动添加一个设备类型
- // return Error(" 设备类型不存在");
- //先看字典id
- typemodel = typeservice.GetModel(bigTypeName, typeName, 1);
- Model.T_Sys_DictionaryValue dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(bigTypeName);
- if (dicmodel != null)
- {
- dicaddid = dicmodel.F_DictionaryValueId;
- }
- else
- {
- //// 实时添加新字典值
- //lock (this) // 防止并发添加相同记录
- //{
- // 再次检查,避免并发添加
- // dicmodel = new Bll.T_Sys_DictionaryValue().GetModel(bigTypeName);
- //if (dicmodel == null)
- //{
- dicaddid = new Bll.T_Sys_DictionaryValue().Add(bigTypeName);
- //}
- //else
- //{
- // dicaddid = dicmodel.F_DictionaryValueId;
- //}
- // }
- }
- if (typemodel == null)
- { // 实时添加新设备类型
- //lock (this) // 防止并发添加相同记录
- //{
- // // 再次检查,避免并发添加
- // typemodel = typeservice.GetModel(bigTypeName, typeName, 1);
- // if (typemodel == null)
- // {
- // Model.T_Adjust_DeviceType addtypemodel = new T_Adjust_DeviceType
- // {
- // F_DeviceNum = 0,
- // F_IsDelete = 0,
- // F_Classification = 1,
- // F_CreateBy = "8000",
- // F_BigTypeName = bigTypeName,
- // F_TypeName = typeName,
- // F_DicId = dicaddid,
- // F_CreateTime = DateTime.Now,
- // F_UpdateTime = DateTime.Now
- // };
- // int addres = typeservice.Add(addtypemodel);
- // deviceTypeId = addres;
- // }
- // else
- // {
- // deviceTypeId = typemodel.F_TypeId;
- // }
- //}
- Model.T_Adjust_DeviceType addtypemodel = new T_Adjust_DeviceType
- {
- F_DeviceNum = 0,
- F_IsDelete = 0,
- F_Classification = 1,
- F_CreateBy = "8000",
- F_BigTypeName = bigTypeName,
- F_TypeName = typeName,
- F_DicId = dicaddid,
- F_CreateTime = DateTime.Now,
- F_UpdateTime = DateTime.Now
- };
- int addres = typeservice.Add(addtypemodel);
- deviceTypeId = addres;
- }
- else
- {
- deviceTypeId = typemodel.F_TypeId;
- }
- var existslist = deviceservice.GetModelList(" F_AssetCode ='" + assetCode + "'");
- Model.T_Adjust_Device model = new T_Adjust_Device();
- //检查设备是否已存在(实时查询)
- if (existslist.Count > 0)
- {
- //存在这个资产编码,更新原来的值
- Model.T_Adjust_Device devicemodel = existslist.First();
- if (devicemodel.F_BigTypeName == bigTypeName && devicemodel.F_TypeName == typeName && devicemodel.F_DicId == dicaddid
- && devicemodel.F_Specification == specification && devicemodel.F_Code == code
- )
- {
- return;
- //continue;
- }
- //devicemodel.F_BigTypeName = bigTypeName;
- // devicemodel.F_TypeName = typeName;
- // devicemodel.F_DicId = dicaddid;
- // devicemodel.F_Specification = specification;
- // devicemodel.F_Code = code;
- // devicemodel.F_UpdateTime = DateTime.Now;
- // deviceservice.Update(devicemodel);
- //return;
- devicemodel.F_BigTypeName = bigTypeName;
- devicemodel.F_TypeName = typeName;
- devicemodel.F_DicId = dicaddid;
- devicemodel.F_Specification = specification;
- devicemodel.F_Code = code;
- devicemodel.F_UpdateTime = DateTime.Now;
- lock (devicesToUpdate)
- {
- devicesToUpdate.Add(devicemodel);
- }
- return;
- //continue;
- // return Error("资产编码不能重复!");
- }
- // 10. 设置设备部门和状态信息(使用预加载的部门数据)
- if (departmentDict.TryGetValue(mandept_name, out Model.T_Sys_Department targetDepartment))
- {
- model.F_BelongPhone = targetDepartment.F_OfficeTelephone;
- model.F_BelongAddress = targetDepartment.F_Location;
- model.F_BelongDept = targetDepartment.F_DeptId;
- if (deptDict.TryGetValue(targetDepartment.F_DeptId, out string keyname))
- {
- model.F_BelongDeptName = keyname;
- }
- if (departmentDict.TryGetValue(usedept_name, out Model.T_Sys_Department useDepartment))
- {
- model.F_UseAddress = useDepartment.F_Location;
- model.F_UseDept = useDepartment.F_DeptId;
- if (deptDict.TryGetValue(useDepartment.F_DeptId, out string usekeyname))
- {
- model.F_UseDeptName = usekeyname;
- }
- model.F_UsePhone = useDepartment.F_OfficeTelephone;
- model.F_DeviceStatus = 3; // 使用中
- }
- else
- {
- model.F_DeviceStatus = 1; // 待上架
- }
- }
- else
- {
- model.F_DeviceStatus = 1; // 待上架
- }
- // 11. 设置设备基本信息
- model.F_BigTypeName = bigTypeName;
- model.F_TypeName = typeName;
- model.F_DicId = dicaddid;
- model.F_DeviceTypeId = deviceTypeId;
- model.F_AssetCode = assetCode;
- model.F_Specification = specification;
- model.F_Code = code;
- model.F_Source = 3;
- model.F_CreateBy = "8000";
- model.F_CreateTime = DateTime.Now;
- model.F_UpdateTime = DateTime.Now;
- model.F_Classify = 1;
- model.F_IsDelete = 0;
- // 12. 添加到待处理列表
- lock (devicesToAdd)
- {
- // 关键字段判断:根据业务需求定义重复逻辑
- bool exists = devicesToAdd.Any(x =>x.F_AssetCode == model.F_AssetCode);
- // 仅当不存在重复时添加
- if (!exists)
- {
- devicesToAdd.Add(model);
- }
-
- }
- // 13. 记录需要更新的设备类型计数
- lock (deviceTypeUpdates)
- {
- if (deviceTypeUpdates.ContainsKey(deviceTypeId))
- {
- deviceTypeUpdates[deviceTypeId]++;
- }
- else
- {
- deviceTypeUpdates[deviceTypeId] = 1;
- }
- }
- // });
-
- #region
- //有使用科室,并且能查到使用科室id ,就给状态是使用中,不然就待上架
- //Model.T_Sys_Department targetDepartment = deptlist.FirstOrDefault(d => d.F_DeptName == mandept_name);
- // Model.T_Sys_Department useDepartment = deptlist.FirstOrDefault(d => d.F_DeptName == usedept_name);
- // if (targetDepartment != null)
- // {
- // // 找到后的操作
- // model.F_BelongPhone = targetDepartment.F_OfficeTelephone;
- // model.F_BelongAddress = targetDepartment.F_Location;
- // model.F_BelongDept = targetDepartment.F_DeptId;
- // var keyname = deptdt.AsEnumerable()
- // .Where(row => row.Field<int>("F_DeptId") == targetDepartment.F_DeptId)
- // .Select(row => row.Field<string>("keyname"))
- // .FirstOrDefault();
- // if (keyname != null)
- // {
- // model.F_BelongDeptName = keyname;
- // }
- // if (useDepartment != null)
- // {
- // model.F_UseAddress = useDepartment.F_Location;
- // model.F_UseDept = useDepartment.F_DeptId;
- // var usekeyname = deptdt.AsEnumerable()
- // .Where(row => row.Field<int>("F_DeptId") == useDepartment.F_DeptId)
- // .Select(row => row.Field<string>("keyname"))
- // .FirstOrDefault();
- // if (keyname != null)
- // {
- // model.F_UseDeptName = usekeyname;
- // }
- // model.F_UsePhone = useDepartment.F_OfficeTelephone;
- // model.F_DeviceStatus = 3;//使用中
- // }
- // else
- // {
- // model.F_DeviceStatus = 1;//待上架
- // }
- // }
- // else
- // {
- // model.F_DeviceStatus = 1;//待上架
- // }
- // model.F_BigTypeName = bigTypeName;
- // model.F_TypeName = typeName;
- // model.F_DicId = dicaddid;
- // model.F_DeviceTypeId = deviceTypeId;
- // model.F_AssetCode = assetCode;
- // // model.F_DeviceShortCode = deviceShortCode;
- // model.F_Specification = specification;
- // model.F_Code = code;
- // model.F_Source = 3;
- // model.F_CreateBy = "8000";
- // model.F_CreateTime = DateTime.Now;
- // model.F_UpdateTime = DateTime.Now;
- // model.F_DeviceStatus = 1;//待上架
- // model.F_Classify = 1;
- // model.F_IsDelete = 0;
- //// model.F_File = file;
- //try
- //{
- // int res = deviceservice.Add(model);
- // if (res > 0)
- // {
- // //设备类型的数量加1
- // var mm = typeservice.GetModel(deviceTypeId);
- // mm.F_DeviceNum = mm.F_DeviceNum == null ? 1 : mm.F_DeviceNum + 1;
- // mm.F_UpdateTime = DateTime.Now;
- // typeservice.Update(mm);
- // // return Success("添加成功");
- // }
- // else
- // {
- // // return Error("添加失败");
- // }
- //}
- //catch (Exception)
- //{
- //}
- ////}
- // }
- #endregion
- });
- // 14. 批量处理当前页数据
- if (devicesToAdd.Count > 0)
- {
- BatchAddDevices(devicesToAdd);
- DbHelperSQL.ExecuteSql(" insert into T_Log(F_Type,F_Content) values('同步设备,添加','" + devicesToAdd.Count + "')");
- devicesToAdd.Clear();
- }
- if (devicesToUpdate.Count > 0)
- {
- BatchUpdateDevices(devicesToUpdate);
- DbHelperSQL.ExecuteSql(" insert into T_Log(F_Type,F_Content) values('同步设备,修改','" + devicesToUpdate.Count + "')");
- devicesToUpdate.Clear();
- }
- // 15. 更新设备类型计数
- if (deviceTypeUpdates.Count > 0)
- {
- BatchUpdateDeviceTypeCounts(deviceTypeUpdates);
- deviceTypeUpdates.Clear();
- }
- // 更新分页键
- lastId = Convert.ToInt32(dt.Rows[dt.Rows.Count - 1]["sb_Id"]);
- processed += dt.Rows.Count;
- }
- //把所有的tb_bz=1的更新成0
- DbHelperSQL.ExecuteSql("update T_SyncEquip set tb_bz=0 ");
- }
- // 批量添加设备的方法
- private void BatchAddDevices(List<Model.T_Adjust_Device> devices)
- {
- int batchSize = 70; // 根据实际情况调整
- for (int i = 0; i < devices.Count; i += batchSize)
- {
- int count = Math.Min(batchSize, devices.Count - i);
- List<Model.T_Adjust_Device> batch = devices.GetRange(i, count);
- deviceservice.BatchAddDevices(batch);
- }
- }
- // 批量更新设备的方法
- private void BatchUpdateDevices(List<Model.T_Adjust_Device> devices)
- {
-
- deviceservice.BatchUpdateDevices(devices);
-
-
- }
- // 批量更新设备类型计数的方法
- private void BatchUpdateDeviceTypeCounts(Dictionary<int, int> typeCounts)
- {
- deviceservice.BatchUpdateDeviceTypeCounts(typeCounts);
-
- }
- }
- }
-
-
-
-
-
|