123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.SuperSocket.Common;
- using ChangFa.Machinery.Common;
- using ChangFa.Machinery.Common.Enums;
- using ChangFa.Machinery.Entity;
- using ChangFa.Machinery.Entity.Enum;
- using ChangFa.Machinery.Service.IService;
- using ChangFa.Machinery.Service.ServiceImp;
- using ChangFa.Machinery.Utility;
- using ChangFa.Machinery.WebPage.Controllers;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Transactions;
- using System.Web;
- using System.Web.Mvc;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class AlarmController : BaseController
- {
- /// <summary>
- /// 字典编码
- /// </summary>
- ICodeManage CodeManage = new CodeManage();
- /// <summary>
- /// 经销商
- /// </summary>
- IDepartmentManage DepartmentManage = new DepartmentManage();
- // GET: SysManage/Alarm
- // [UserAuthorizeAttribute(ModuleAlias = "CarAlarmList", OperaAction = "View")]
- public ActionResult Index()
- {
- string carid = string.Empty; PageInfo alrmreslut; DateTime fromdate, todate;
- if (!Request.QueryString["carid"].IsEmpty())
- {
- carid = Request.QueryString["carid"].ToString();
- }
- var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"];
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var q = orm.Queryable<YW_AlarmInformation>();
- if (!carid.IsEmpty())
- {
- q = q.Where(p => p.CarId == carid);
- }
- if (!startdate.IsEmpty() && enddate.IsEmpty())
- {
- fromdate = startdate.ToDateTime();
- q = q.Where(p => p.Add_Time == fromdate);
- }
- if (!enddate.IsEmpty() && startdate.IsEmpty())
- {
- todate = enddate.ToDateTime();
- q = q.Where(p => p.Add_Time == todate);
- }
- if (!startdate.IsEmpty() && !enddate.IsEmpty())
- {
- fromdate = startdate.ToDateTime();
- todate = enddate.ToDateTime();
- q = q.Where(p => p.Add_Time >= fromdate && p.Add_Time <= todate);
- }
- int pageno = (page - 1) * pagesize;
- var reslut = q.OrderByDesc(a => a.Add_Time).Skip(pageno).Top(pagesize).ToList(request);
- List<YW_AlarmInformation> modlist = new List<YW_AlarmInformation>();
- if (reslut.IsSuccess)
- {
- int count = q.Count();
- alrmreslut = new PageInfo(base.page, base.pagesize, count, JsonConverter.JsonClass(reslut.ResultModel));
- }
- else
- {
- alrmreslut = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
- }
- }
- ViewData["startdate"] = startdate;
- ViewData["enddate"] = enddate;
- return View(alrmreslut);
- }
- /// <summary>
- /// 页面标记显示
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult MarkFence(string id)
- {
- ResponseAlarmCheckInfo markmod = new ResponseAlarmCheckInfo();
- try
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
- var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
- .InnerJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID);
- //.InnerJoin<Entity.YW_CarPurchaser>((user, city, province) => city.CarID == province.carId);
- Guid guid = new Guid(id.Split(';')[0]);
- //var views = usercarlist.Select((strip, sbicycle, purchser) => new { Users = sbicycle, trip = strip, userpurch = purchser }).Where(p => p.trip.id == guid).FirstOrDefault(res);
- var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }).Where(p => p.trip.id == guid).FirstOrDefault(res);
- //.Where(p => p.Users.UserId == usermod.userInfo.uid)
- if (views.IsSuccess)
- {
- YW_MarkAlarmFence mod = views.ResultModel.trip; EntYW_Bicycle carmod = views.ResultModel.Users; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch;
- markmod.imei = carmod.CarID;
- markmod.productBarCode = carmod.carBar;
- markmod.productModel = carmod.CarModel;
- markmod.productName = carmod.CarName;
- markmod.FactoryNumber = carmod.FactoryNumber;
- markmod.MarkFenceType = mod.MarkFenceType.ToString();
- markmod.state = mod.state.ToString();
- markmod.carType = carmod.carType.ToInt32();
- markmod.backPayTime = mod.backPayTime.ToDateTime();
- markmod.startDate = mod.MarkStartDate.ToDateTime();
- markmod.endDate = mod.MarkEndDate.ToDateTime();
- var purrchreslut = orm.Queryable<Entity.YW_CarPurchaser>().Where(p => p.carId == carmod.CarID).FirstOrDefault(res);
- if (purrchreslut.IsSuccess)
- {
- Entity.YW_CarPurchaser purchser = purrchreslut.ResultModel;
- markmod.name = purchser.userName;
- markmod.tel = purchser.userTel;
- markmod.saleDate = purchser.SaleDate.ToDateTime();
- }
- markmod.note = mod.notes;
- markmod.applyName = mod.add_name;
- markmod.apply_id = mod.id.ToString();
- markmod.carState = ChangFa.Machinery.Entity.GetCarState.getCarStateStr(carmod.CarSate.ToInt32());
- markmod.isOnLine = carmod.LeaseStatus.ToInt32();
- //if (mod.MarkFenceType == 30)
- //{
- // var distributorsreslut = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.ID == carmod.DistributorsID).FirstOrDefault(res);
- // if (distributorsreslut.IsSuccess)
- // {
- // EntSYS_DISTRIBUTORS dismod = distributorsreslut.ResultModel;
- // markmod.distributorsAddress = dismod.Address;
- // markmod.distributorsName = dismod.NAME;
- // markmod.distributorsContact = "";
- // markmod.distributorsTel = "";
- // }
- //}
- markmod.productionDate = DateTimeUtility.ConvertDateTimeInt(carmod.productionDate.ToDateTime());
- }
- }
- return View(markmod);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- public ActionResult MarkFenceList(string id)
- {
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
- };
- var q = orm.Queryable<Entity.YW_MarkAlarmFence>();
- if (id.IsEmpty())
- {
- return View(pageInfo);
- }
- q = q.Where(p => p.imei == id);
- int pageno = (page - 1) * pagesize;
- var tripreslut = q.OrderByDesc(p => p.add_time).Skip(pageno).Top(pagesize).ToList(res);
- if (tripreslut.IsSuccess)
- {
- tripreslut.RecordNum = q.Count();
- pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, Common.JsonConverter.JsonClass(tripreslut.ResultModel));
- }
- }
- return View(pageInfo);
- }
- /// <summary>
- /// 所有农机设置围栏内成功
- /// </summary>
- /// <returns></returns>
- public ActionResult updateAlarmFence()
- {
- ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "所有农机设置围栏内成功!", Status = "n", ReUrl = "/Car/CarAlarmList" };
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var reslut = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { FenceState = 1 }, f => f.FenceState == 2, res);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- }
- return Json(json);
- }
- /// <summary>
- /// 标记电子围栏
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult markAlarmFence(string id)
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
- string gid = id.Split(';')[0]; string carid = id.Split(';')[1];
- var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == carid).FirstOrDefault();
- if (reslut.IsSuccess)
- {
- EntYW_Bicycle mod = reslut.ResultModel;
- ViewData["carname"] = mod.CarName;
- ViewData["FactoryNumber"] = mod.FactoryNumber;
- ViewData["CarBar"] = mod.carBar;
- ViewData["CarID"] = mod.CarID;
- }
- }
- return View();
- }
- /// <summary>
- /// 保存报警标记
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult SaveMarkAlarm()
- {
- ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "报警标记保存成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
- DateTime markstartdate = new DateTime(); DateTime markenddate = new DateTime();
- var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"]; var carid = Request["CarID"];
- if (!startdate.IsEmpty())
- {
- markstartdate = startdate.ToDateTime();
- }
- if (!enddate.IsEmpty())
- {
- markenddate = enddate.ToDateTime();
- }
- var marktype = Request["CarSate"];
- if (marktype.IsEmpty() || marktype == "0")
- {
- json.Status = "n";
- json.Msg = "标记类型不能为空!";
- return Json(json);
- }
- var buyTime = DateTime.Now;//购买时间
- string backPayTime = Request.Params["backPayTime"]; //回款时间
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存围栏信息" };
- YW_MarkAlarmFence mod = new YW_MarkAlarmFence();
- var q = orm.Queryable<YW_AlarmInformation>().Where(p => p.CarId == carid).OrderByDesc(p => p.Add_Time).FirstOrDefault(request);
- if (q.IsSuccess)
- {
- YW_AlarmInformation yW_Alarm = q.ResultModel;
- buyTime = yW_Alarm.Add_Time.ToDateTime();
- }
- var username = Request.Params["username"]; //购买人
- var userTel = Request.Params["userTel"]; //购买电话
- var userAddress = Request.Params["userAddress"]; //购买地址
- if (marktype == "10")//外出参展
- {
- mod.MarkStartDate = markstartdate;
- mod.MarkEndDate = markenddate;
- }
- if (marktype == "20") //销售未回款
- {
- if (username.IsEmpty())
- {
- json.Status = "n";
- json.Msg = "购买人不能为空!";
- return Json(json);
- }
- if (userTel.IsEmpty())
- {
- json.Status = "n";
- json.Msg = "购买人手机不能为空!";
- return Json(json);
- }
- var count = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid && p.state == 0).Count(); //查看是否有回款记录
- if (count > 0)
- {
- json.Status = "n";
- json.Msg = "这台农机已申请解除围栏,等待审核!";
- return Json(json);
- }
- mod.backPayTime = buyTime.ToDateTime().AddDays(10);
- YW_CarPurchaser enty = new YW_CarPurchaser();
- enty.ID = Guid.NewGuid();
- enty.imei = Request["CarID"];
- enty.userName = username;
- enty.userTel = userTel;
- enty.userAddress = userAddress;
- enty.carId = Request["CarID"];
- enty.carBar = Request["CarBar"];
- enty.addName = CurrentUser.Name;
- enty.SaleDate = buyTime;
- enty.addDate = DateTime.Now;
- var reslutPurchaser = orm.Save(enty, request);
- }
- if (marktype == "30")//销售已回款
- {
- if (username.IsEmpty())
- {
- json.Status = "n";
- json.Msg = "购买人不能为空!";
- return Json(json);
- }
- if (userTel.IsEmpty())
- {
- json.Status = "n";
- json.Msg = "购买人手机不能为空!";
- return Json(json);
- }
- var count = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid && p.state == 0).Count(); //查看是否有回款记录
- if (count > 0)
- {
- json.Status = "n";
- json.Msg = "这台农机已申请解除围栏,等待审核!";
- return Json(json);
- }
- YW_CarPurchaser enty = new YW_CarPurchaser();
- enty.ID = Guid.NewGuid();
- enty.imei = Request["CarID"];
- enty.userName = username;
- enty.userTel = userTel;
- enty.userAddress = userAddress;
- enty.carId = Request["CarID"];
- enty.carBar = Request["CarBar"];
- enty.addName = CurrentUser.Name;
- enty.SaleDate = buyTime.ToDateTime();
- enty.addDate = DateTime.Now;
- var reslutPurchaser = orm.Save(enty, request);
- }
- if (marktype == "40")//其他
- {
- mod.MarkStartDate = markstartdate;
- mod.MarkEndDate = markenddate;
- }
- mod.id = Guid.NewGuid();
- mod.MarkFenceType = marktype.ToInt32();
- mod.notes = Request["notes"];
- mod.imei = Request["CarID"];
- mod.CarBar = Request["CarBar"];
- mod.add_name = CurrentUser.Name;
- mod.state = 0;
- var reslut = orm.Save(mod, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- }
- return Json(json);
- }
- /// <summary>
- /// 保存审核结果
- /// </summary>
- /// <returns></returns>
- public ActionResult SaveApplyCheck(string apply_id)
- {
- ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "标记审核成功", Status = "n", ReUrl = "/Car/DistributorCarList" };
- var notes = Request["notes"];
- var state = Request["checkstate"];
- try
- {
- if (state == "1")
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
- Guid guid = new Guid(apply_id);
- var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.id == guid).FirstOrDefault(res);
- if (reslut.IsSuccess)
- {
- YW_MarkAlarmFence mod = reslut.ResultModel;
- if (mod.MarkFenceType == 10 || mod.MarkFenceType == 40)//外出参展 //其它
- {
- var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 1 }, f => f.id == guid, res);
- json.Status = "y";
- }
- if (mod.MarkFenceType == 30 || mod.MarkFenceType == 20)//销售已回款//销售未回款
- {
- using (TransactionScope ts = new TransactionScope())
- {
- int carstate = CarState.Sales.ToInt32();
- var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, FenceState = 1, UpdateDate = DateTime.Now }, f => f.CarID == mod.imei, res);
- if (reslutcar.IsSuccess)
- {
- string strdate = "审核通过时间:" + DateTime.Now;
- var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 1, noPassNote = strdate }, f => f.id == guid, res);
- }
- ts.Complete(); //完成事务,这个必须加上,要不然事务不会有效
- json.Status = "y";
- WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
- try
- {
- Utility.SocketClient client = new Utility.SocketClient();
- var str = DataHelper.sendRemoveFence(Convert.ToInt64(mod.imei));
- var body = DataHelper.HexToByte(str);
- string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
- int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
- client.Connect(ip, port);
- var flag = client.SendData(body);
- client.Disconnect();
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
- }
- }
- else
- {
- if (notes.IsEmpty())
- {
- json.Msg = "审核不通过,不通过原因必填!";
- json.Msg = "n";
- return Json(json);
- }
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
- Guid guid = new Guid(apply_id);
- var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 2, noPassNote = notes }, f => f.id == guid, res);
- if (reslutapply.IsSuccess)
- {
- json.Msg = "审核不通过!";
- json.Status = "y";
- return Json(json);
- }
- }
- }
- }
- catch (Exception ex)
- {
- json.Msg = "审核失败:" + ex.Message;
- }
- return Json(json);
- }
- /// <summary>
- /// 解除电子围栏作废
- /// </summary>
- /// <returns></returns>
- public ActionResult RemoveFence(string id)
- {
- RemoveFenceEntity model = new RemoveFenceEntity();
- model.bicycle = new EntYW_Bicycle();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
- string gid = id.Split(';')[0]; string carid = id.Split(';')[1];
- var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == carid).FirstOrDefault();
- if (reslut.IsSuccess)
- {
- EntYW_Bicycle mod = reslut.ResultModel;
- model.bicycle = mod;
- model.bicycle.Createper = GetCarState(mod.CarSate.ToInt32());
- }
- }
- ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetail();
- return View(model);
- }
- /// <summary>
- /// 解除电子围栏审核
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult RemoveAlarmFenceCheck(string idList)
- {
- ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "解除电子围栏成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
- var idList1 = idList.Split(';').ToList();
- if (idList1.Count > 0)
- {
- string carid = idList1[1];
- Guid id = new Guid(idList1[0]);
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid).FirstOrDefault(res); //查看是否有回款记录
- if (reslut.IsSuccess)
- {
- YW_MarkAlarmFence mod = reslut.ResultModel;
- if (mod.MarkFenceType == 10)
- {
- }
- if (mod.MarkFenceType == 20)
- {
- }
- if (mod.MarkFenceType == 30)
- {
- int carstate = CarState.Sales.ToInt32();
- var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, FenceState = 1 }, f => f.ID == id, res);
- if (reslutcar.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
- try
- {
- Utility.SocketClient client = new Utility.SocketClient();
- var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid));
- var body = DataHelper.HexToByte(str);
- string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
- int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
- client.Connect(ip, port);
- var flag = client.SendData(body);
- client.Disconnect();
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
- else
- {
- json.Status = "n";
- json.Msg = "未回款的农机,无法解除电子围栏!";
- }
- }
- }
- else
- {
- json.Status = "n";
- json.Msg = "选择不正确,请重新选择!";
- }
- return Json(json);
- }
- public static string GetFenceMarkType(string carid)
- {
- string str = string.Empty;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid).FirstOrDefault(res); //查看是否有回款记录
- if (reslut.IsSuccess)
- {
- YW_MarkAlarmFence markAlarmFence = reslut.ResultModel;
- switch (markAlarmFence.MarkFenceType)
- {
- case 10:
- {
- str = "外出参展";
- }
- break;
- case 20:
- {
- str = "销售未回款";
- }
- break;
- case 30:
- {
- str = "销售已回款";
- }
- break;
- case 40:
- {
- str = "其它";
- }
- break;
- }
- return str;
- }
- }
- return "";
- }
- /// <summary>
- /// 加载列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "MarkCheckList", OperaAction = "View")]
- public ActionResult MarkCheckList()
- {
- try
- {
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- #region 处理查询参数
- var posttype = Request.QueryString["PostType"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- string CarSate = Request.QueryString["CarSate"];
- string barcode = Request.QueryString["txt_barcode"];
- string imei = Request.QueryString["txt_imei"];
- string factoryNumber = Request.QueryString["txt_factoryNumber"];
- int markType = Request.QueryString["LeaseStatus"].ToInt32();
- int fenceCheck = Request.QueryString["FenceState"].ToInt32();
- int prov = Request.QueryString["hkprov"].ToInt32();
- int state = -1;
- if (!CarSate.IsEmpty())
- {
- state = CarSate.ToInt32();
- }
- #endregion
- #region 加载列表
- List<AlarmFenceModel> carlist = new List<AlarmFenceModel>();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
- var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
- .LeftJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID)
- .LeftJoin<EntSYS_DISTRIBUTORS>((user, city, province) => city.DistributorsID == province.ID);
- int pageno = (base.page - 1) * base.pagesize;
- var views = usercarlist.Select((strip, sbicycle, sdis) => new { Users = sbicycle, trip = strip, dis = sdis });
- if (posttype != "-1" && !posttype.IsEmpty())
- {
- var type = posttype.ToInt32();
- views = views.Where(p => p.trip.MarkFenceType == type);
- }
- if (state > 0)
- {
- views = views.Where(p => p.Users.CarSate == state);
- }
- else
- {
- views = views.Where(p => p.Users.CarSate > 0);
- }
- if (!factoryNumber.IsEmpty())
- {
- views = views.Where(p => p.Users.FactoryNumber.Contains(factoryNumber));
- }
- if (!imei.IsEmpty())
- {
- views = views.Where(p => p.Users.CarID.Contains(imei));
- }
- if (prov > 0)
- {
- views = views.Where(p => p.dis.Province == prov);
- }
- if (!FK_DPTID.IsEmpty())
- {
- views = views.Where(p => p.Users.DistributorsID == FK_DPTID);
- }
- if (fenceCheck >= 0)
- {
- views = views.Where(p => p.trip.state == fenceCheck);
- }
- if (markType > 10)
- {
- views = views.Where(p => p.trip.MarkFenceType == markType);
- }
- views = views.Where(p => p.trip.imei != "");
- var reslut = views.OrderBy(p => p.trip.imei).ThenByDesc(p => p.trip.state).ThenByDesc(p => p.trip.add_time).Skip(pageno).Top(pagesize).ToList(res);
- //.Where(p => p.Users.UserId == usermod.userInfo.uid)
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = views.Count();
- foreach (var list in reslut.ResultModel)
- {
- AlarmFenceModel carReturn = new AlarmFenceModel();
- YW_MarkAlarmFence mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
- carReturn.bicycle = carmod;
- carReturn.fenceMark = mod;
- carlist.Add(carReturn);
- }
- pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, Common.JsonConverter.JsonClass(carlist));
- }
- }
- ViewBag.Search = base.keywords;
- ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
- ViewData["dptid"] = FK_DPTID;
- ViewData["CarSate"] = CarSate;
- ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
- ViewData["typecar"] = markType;
- ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
- ViewData["barcode"] = barcode;
- ViewData["factoryNumber"] = factoryNumber;
- ViewData["FenceState"] = fenceCheck;
- ViewData["imei"] = imei;
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- ViewData["hkprov"] = Request.QueryString["hkprov"];
- }
- return View(pageInfo);
- #endregion
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 导出报警审核EXECL
- /// </summary>
- /// <returns></returns>
- public FileResult MarkChecExecl()
- {
- try
- {
- NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
- //添加一个sheet
- NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
- //给sheet1添加第一行的头部标题
- NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
- row1.CreateCell(0).SetCellValue("农机IMEI号");
- row1.CreateCell(1).SetCellValue("农机名称");
- row1.CreateCell(2).SetCellValue("农机型号");
- row1.CreateCell(3).SetCellValue("车架号");
- row1.CreateCell(4).SetCellValue("所属经销商");
- row1.CreateCell(5).SetCellValue("围栏状态");
- row1.CreateCell(6).SetCellValue("出厂日期");
- row1.CreateCell(7).SetCellValue("出厂编号");
- row1.CreateCell(8).SetCellValue("超出围栏时间");
- row1.CreateCell(9).SetCellValue("超出时长");
- //row1.CreateCell(10).SetCellValue("报警次数");
- //row1.CreateCell(11).SetCellValue("最后一次点火时间");
- //row1.CreateCell(12).SetCellValue("最后一次点火地址");
- row1.CreateCell(10).SetCellValue("标记类型");
- row1.CreateCell(11).SetCellValue("标记人");
- row1.CreateCell(12).SetCellValue("标记时间");
- row1.CreateCell(13).SetCellValue("审核状态");
- #region 处理查询参数
- //var posttype = Request.QueryString["PostType"];
- //string FK_DPTID = Request.QueryString["FK_DPTID"];
- string CarSate = Request.QueryString["CarSate"];
- int markType = Request.QueryString["fencetype"].ToInt32();
- int fenceCheck = Request.QueryString["checktype"].ToInt32();
- int prov = Request.QueryString["hkprov"].ToInt32();
- int state = -1;
- if (!CarSate.IsEmpty())
- {
- state = CarSate.ToInt32();
- }
- #endregion
- #region 加载列表
- List<AlarmFenceModel> carlist = new List<AlarmFenceModel>();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
- var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
- .LeftJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID)
- .LeftJoin<EntSYS_DISTRIBUTORS>((alarm, car, dis) => car.DistributorsID == dis.ID)
- .LeftJoin<DeviceManage>((alarm, car, dis, device) => alarm.imei == device.IMEI);
- var views = usercarlist.Select((strip, sbicycle, sdis, sdevice) => new { Users = sbicycle, trip = strip, dis = sdis, device = sdevice });
- if (markType > 0)
- {
- views = views.Where(p => p.trip.MarkFenceType == markType);
- }
- if (state > 0)
- {
- views = views.Where(p => p.Users.CarSate == state);
- }
- else
- {
- views = views.Where(p => p.Users.CarSate > 0);
- }
- if (prov > 0)
- {
- views = views.Where(p => p.dis.Province == prov);
- }
- //if (!FK_DPTID.IsEmpty())
- //{
- // views = views.Where(p => p.Users.DistributorsID == FK_DPTID);
- //}
- if (fenceCheck >= 0)
- {
- views = views.Where(p => p.trip.state == fenceCheck);
- }
- if (markType > 10)
- {
- views = views.Where(p => p.trip.MarkFenceType == markType);
- }
- views = views.Where(p => p.trip.imei != "");
- var reslut = views.OrderBy(p => p.trip.imei).ThenByDesc(p => p.trip.state).ThenByDesc(p => p.trip.add_time).ToList(res);
- //.Where(p => p.Users.UserId == usermod.userInfo.uid)
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = views.Count(); int i = 0;
- foreach (var list in reslut.ResultModel)
- {
- AlarmFenceModel carReturn = new AlarmFenceModel();
- YW_MarkAlarmFence mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
- DeviceManage device = list.device;
- carReturn.bicycle = carmod;
- carReturn.fenceMark = mod;
- carlist.Add(carReturn);
- i++;
- NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
- rowtemp.CreateCell(0).SetCellValue(carmod.CarID);
- rowtemp.CreateCell(1).SetCellValue(carmod.CarName);
- rowtemp.CreateCell(2).SetCellValue(carmod.CarModel);
- rowtemp.CreateCell(3).SetCellValue(carmod.carBar);
- rowtemp.CreateCell(4).SetCellValue(carmod.DistributorsName);
- string carstatestr = "";
- switch (carmod.FenceState)
- {
- case 0:
- carstatestr = "未点火"; break;
- case 1:
- carstatestr = "围栏内"; break;
- case 2:
- carstatestr = "围栏外"; break;
- }
- rowtemp.CreateCell(5).SetCellValue(carstatestr);
- rowtemp.CreateCell(6).SetCellValue(carmod.productionDate.ToString());
- rowtemp.CreateCell(7).SetCellValue(carmod.FactoryNumber);
- rowtemp.CreateCell(8).SetCellValue(carmod.OutFenceDate.ToString());
- var num = Utility.DateTimeUtility.DateTimeDifference(Convert.ToDateTime(carmod.OutFenceDate), DateTime.Now);
- rowtemp.CreateCell(9).SetCellValue(num);
- //try
- //{
- // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- // string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + carmod.CarID + "' group by CarId";
- // var sum = orm.db.ExecuteScalar(sql).ToInt32();
- // rowtemp.CreateCell(10).SetCellValue(sum.ToString());
- //}
- //catch
- //{
- // rowtemp.CreateCell(10).SetCellValue(0);
- //}
- //var lng = device.longitude.ToDou(); var lat = device.latitude.ToDou();
- //var root = Utility.ToolGPSamap.GPS2Position(lng, lat);
- //string address = "";
- //if (root.IfNotNull())
- //{
- // address = root.formatted_address;
- // rowtemp.CreateCell(11).SetCellValue(device.LastOnlineTime.ToString());
- // rowtemp.CreateCell(12).SetCellValue(address);
- //}
- var mark = mod.MarkFenceType.ToString();
- if (mark == "20")
- {
- rowtemp.CreateCell(10).SetCellValue("销售未回款 ");
- }
- else
- {
- if (mark == "30")
- {
- rowtemp.CreateCell(10).SetCellValue("销售已回款 ");
- }
- }
- rowtemp.CreateCell(11).SetCellValue(mod.add_name.ToString());
- rowtemp.CreateCell(12).SetCellValue(mod.add_time.ToString());
- var states = mod.state.ToString();
- if (states == "1")
- {
- rowtemp.CreateCell(13).SetCellValue("已通过");
- }
- else
- {
- if (states == "2")
- {
- rowtemp.CreateCell(13).SetCellValue("未通过");
- }
- else
- rowtemp.CreateCell(13).SetCellValue("未审核");
- }
- }
- }
- }
- #endregion
- // 写入到客户端
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- book.Write(ms);
- ms.Seek(0, SeekOrigin.Begin);
- return File(ms, "application/vnd.ms-excel", "农机标记审核.xls");
- }
- catch (Exception e)
- {
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 添加购买人的信息
- /// </summary>
- /// <param name="removeFence"></param>
- /// <returns></returns>
- public ActionResult Save(RemoveFenceEntity removeFence)
- {
- ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "解除电子围栏成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
- string carid = removeFence.bicycle.CarID;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var datesale = removeFence.userCode.ToDateTime();
- YW_CarPurchaser mod = new YW_CarPurchaser();
- mod.ID = Guid.NewGuid();
- mod.imei = removeFence.bicycle.CarID;
- mod.userName = removeFence.userName;
- mod.userTel = removeFence.userTel;
- mod.userAddress = removeFence.userAddress;
- mod.carId = removeFence.bicycle.CarID;
- mod.carBar = removeFence.bicycle.carBar;
- mod.addName = CurrentUser.Name;
- mod.SaleDate = datesale;
- mod.addDate = DateTime.Now;
- var reslutPurchaser = orm.Save(mod, res);
- int carstate = CarState.Sales.ToInt32();
- var reslut = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, SaleDate = datesale }, f => f.ID == removeFence.bicycle.ID, res);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
- try
- {
- Utility.SocketClient client = new Utility.SocketClient();
- var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid));
- var body = DataHelper.HexToByte(str);
- string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
- int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
- client.Connect(ip, port);
- var flag = client.SendData(body);
- client.Disconnect();
- }
- catch (Exception ex)
- {
- }
- }
- }
- return Json(json);
- }
- /// <summary>
- /// 加载农机报警列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "carAlarmList", OperaAction = "View")]
- public ActionResult CarAlarmList()
- {
- try
- {
- string posttype = Request.QueryString["posttype"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- string CarSate = Request.QueryString["CarSate"];
- int carType = Request.QueryString["LeaseStatus"].ToInt32();
- string barcode = Request.QueryString["txt_barcode"];
- string imei = Request.QueryString["txt_imei"];
- string factoryNumber = Request.QueryString["txt_factoryNumber"];
- string alarmDate = Request.QueryString["txt_AlarmDate"];
- int car_state = CarState.SalesNoReturned.GetHashCode();
- int prov = Request.QueryString["hkprov"].ToInt32();
- int FenceState = -1;
- if (!Request.QueryString["FenceState"].IsEmpty())
- {
- FenceState = Request.QueryString["FenceState"].ToInt32();
- }
- int state = -1;
- if (!CarSate.IsEmpty())
- {
- state = CarSate.ToInt32();
- }
- string distributorsID = string.Empty;
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var q = orm.Queryable<EntYW_Bicycle>().LeftJoin<EntSYS_DISTRIBUTORS>((car, dis) => car.DistributorsID == dis.ID);
- var view = q.Select((scar, sdis) => new { Car = scar, dis = sdis });
- view = view.Where(p => p.Car.CarSate < car_state);
- if (carType > 0)
- view = view.Where(p => p.Car.ProductLine == carType);
- if (!FK_DPTID.IsEmpty())
- view = view.Where(p => p.Car.DistributorsID == FK_DPTID);
- if (!barcode.IsEmpty())
- {
- view = view.Where(p => p.Car.carBar.Contains(barcode));
- }
- if (!imei.IsEmpty())
- {
- view = view.Where(p => p.Car.CarID.Contains(imei));
- }
- view = view.Where(p => p.Car.FenceState == 2);
- if (state >= 0)
- {
- view = view.Where(p => p.Car.CarSate == state);
- }
- if (!factoryNumber.IsEmpty())
- {
- view = view.Where(p => p.Car.FactoryNumber == factoryNumber);
- }
- if (prov > 0)
- {
- view = view.Where(p => p.dis.Province == prov);
- }
- if (!alarmDate.IsEmpty())
- {
- DateTime fromdate = alarmDate.ToDateTime().ToString("yyyy-MM-dd").ToDateTime().AddSeconds(-1);
- DateTime todate = alarmDate.ToDateTime();
- view = view.Where(p => p.Car.OutFenceDate > fromdate && p.Car.OutFenceDate < todate);
- }
- int pageno = (page - 1) * pagesize;
- var bicycleList = view.OrderByDesc(a => a.Car.OutFenceDate).Skip(pageno).Top(pagesize).ToList();
- if (bicycleList.IsSuccess)
- {
- bicycleList.RecordNum = view.Count();
- List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
- foreach (var item in bicycleList.ResultModel)
- {
- EntYW_Bicycle bicycle = item.Car;
- listcar.Add(bicycle);
- }
- pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, Common.JsonConverter.JsonClass(listcar));
- }
- }
- }
- else
- {
- if (CurrentUser.USERTYPE == 2) //业务员
- {
- int saleid = CurrentUser.Id;
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- IQuery<EntYW_Bicycle> car = orm.Queryable<EntYW_Bicycle>();
- IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
- IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor> user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId && (user.ProductLine == city.ProductLine || user.ProductLine == city.ProductLine1 || user.ProductLine == city.ProductLine2 || user.ProductLine == city.ProductLine3 || user.ProductLine == city.ProductLine4 || user.ProductLine == city.ProductLine5));
- var qq = user_city.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.userId == saleid);
- if (!Request.QueryString["CarSate"].IsEmpty())
- {
- int carstate = CarState.Storage.ToInt32();
- }
- if (carType > 0)
- {
- qq = qq.Where(p => p.Users.ProductLine == carType);
- }
- if (!barcode.IsEmpty())
- {
- qq = qq.Where(p => p.Users.carBar.Contains(barcode));
- }
- if (!imei.IsEmpty())
- {
- qq = qq.Where(p => p.Users.CarID.Contains(imei));
- }
- qq = qq.Where(p => p.Users.FenceState == 2);
- if (state >= 0)
- {
- qq = qq.Where(p => p.Users.CarSate == state);
- }
- qq = qq.Where(p => p.Users.CarSate < car_state && p.Users.FenceState == 2);
- if (!factoryNumber.IsEmpty())
- {
- qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber);
- }
- if (!alarmDate.IsEmpty())
- {
- DateTime fromdate = alarmDate.ToDateTime().ToString("yyyy-MM-dd").ToDateTime().AddSeconds(-1);
- DateTime todate = alarmDate.ToDateTime();
- qq = qq.Where(p => p.Users.OutFenceDate > fromdate && p.Users.OutFenceDate < todate);
- }
- int pageno = (page - 1) * pagesize;
- var bicycleList = qq.OrderByDesc(p => p.Users.OutFenceDate).Skip(pageno).Top(pagesize).ToList();
- if (bicycleList.IsSuccess)
- {
- bicycleList.RecordNum = qq.Count();
- List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
- foreach (var item in bicycleList.ResultModel)
- {
- EntYW_Bicycle carmode = item.Users;
- listcar.Add(carmode);
- }
- pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, Common.JsonConverter.JsonClass(listcar));
- }
- }
- }
- }
- int uid = 0;
- if (CurrentUser.USERTYPE == 2)
- {
- uid = CurrentUser.Id;
- }
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid, prov);
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- ViewData["hkprov"] = Request.QueryString["hkprov"];
- }
- ViewData["dptid"] = FK_DPTID;
- ViewData["CarSate"] = CarSate;
- ViewData["FenceState"] = FenceState;
- ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
- ViewData["typecar"] = carType;
- ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
- ViewData["barcode"] = barcode;
- ViewData["factoryNumber"] = factoryNumber;
- ViewData["alarmDate"] = alarmDate;
- ViewData["imei"] = imei;
- return View(pageInfo);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 加载农机报警列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "carAlarmList", OperaAction = "View")]
- public ActionResult CarAlarmListbak()
- {
- try
- {
- string posttype = Request.QueryString["posttype"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- string CarSate = Request.QueryString["CarSate"];
- string barcode = Request.QueryString["txt_barcode"];
- string imei = Request.QueryString["txt_imei"];
- int FenceState = -1;
- if (!Request.QueryString["FenceState"].IsEmpty())
- {
- FenceState = Request.QueryString["FenceState"].ToInt32();
- }
- int carType = Request.QueryString["LeaseStatus"].ToInt32();
- int state = -1;
- if (!CarSate.IsEmpty())
- {
- state = CarSate.ToInt32();
- }
- string distributorsID = string.Empty;
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) //管理员
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
- strsql.AppendFormat("select top {0} * from ", pagesize);
- strsql.Append("(select *,ROW_NUMBER() OVER(ORDER BY [OutFenceDate] desc) AS [ROW_NUMBER_0],count(1) over() as total from ");
- //sqlcount.Append("select count(1) from ");
- //sqlcount.Append("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a left join YW_Bicycle as b on a.imei = b.CarID where b.CarID <> ''");
- var num = CarState.Sales.GetHashCode();
- strsql.AppendFormat("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a right join YW_Bicycle as b on a.imei = b.CarID where b.CarID <> '' and b.FenceState=2 and b.CarSate<{0} ", num);
- if (!barcode.IsEmpty())
- {
- strsql.AppendFormat(" and b.FactoryNumber like '%{0}%'", barcode);
- }
- if (!imei.IsEmpty())
- {
- strsql.AppendFormat(" and b.CarID like '%{0}%' ", imei);
- }
- if (carType > 0)
- {
- strsql.AppendFormat(" and b.carType = '{0}' ", carType);
- }
- if (!FK_DPTID.IsEmpty())
- {
- strsql.AppendFormat(" and b.DistributorsID = '{0}' ", FK_DPTID);
- }
- int pageno = (page - 1) * pagesize;
- strsql.AppendFormat(" ) as T where[T].[ROW_NUMBER_0] > {0}", pageno);
- RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
- requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
- requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- requestItemSql.StrSql = strsql.ToString();
- var bicycleList = orm.GetDataTableList(requestItemSql);
- if (bicycleList.IsSuccess)
- {
- DataTable dtt = bicycleList.DataTable;
- bicycleList.RecordNum = dtt.Rows[0]["total"].ToInt32();
- var jsondata = Common.JsonConverter.ConvertJson(Common.JsonConverter.ToJson(dtt));
- pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, jsondata);
- }
- }
- }
- else
- {
- if (CurrentUser.DptInfo.IfNotNull()) //经销商
- {
- if (!CurrentUser.DptInfo.ID.IsEmpty())
- {
- distributorsID = CurrentUser.DptInfo.ID;
- }
- }
- else
- {
- string saleid = CurrentUser.Id.ToString(); //业务员
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var q = orm.Queryable<EntYW_Bicycle>();
- StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
- strsql.AppendFormat("select top {0} * from ", pagesize);
- strsql.Append("(select b.*,a.num,ROW_NUMBER() OVER(ORDER BY [OutFenceDate] desc) AS [ROW_NUMBER_0],count(1) over() as total from ");
- var num = CarState.Sales.GetHashCode();
- strsql.AppendFormat("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a right join YW_Bicycle as b on a.imei = b.CarID left join [YW_UserDistributor] as c on (c.ProductLine=b.ProductLine or c.ProductLine1=b.ProductLine or c.ProductLine2=b.ProductLine or c.ProductLine4=b.ProductLine or c.ProductLine5=b.ProductLine) and c.distributorId=b.DistributorsID where b.CarID <> '' and b.FenceState=2 and b.CarSate<{0} ", num);
- if (!barcode.IsEmpty())
- {
- strsql.AppendFormat(" and b.FactoryNumber like '%{0}%'", barcode);
- }
- if (!imei.IsEmpty())
- {
- strsql.AppendFormat(" and b.CarID like '%{0}%' ", imei);
- }
- if (carType > 0)
- {
- strsql.AppendFormat(" and b.carType = '{0}' ", carType);
- }
- if (!FK_DPTID.IsEmpty())
- {
- strsql.AppendFormat(" and b.DistributorsID = '{0}' ", FK_DPTID);
- }
- else
- {
- strsql.AppendFormat(" and c.userId ='{0}'", saleid);
- }
- int pageno = (page - 1) * pagesize;
- strsql.AppendFormat(" ) as T where[T].[ROW_NUMBER_0] > {0}", pageno);
- RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
- requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
- requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- requestItemSql.StrSql = strsql.ToString();
- var bicycleList = orm.GetDataTableList(requestItemSql);
- if (bicycleList.IsSuccess)
- {
- DataTable dtt = bicycleList.DataTable;
- bicycleList.RecordNum = dtt.Rows[0]["total"].ToInt32();
- var jsondata = Common.JsonConverter.ConvertJson(Common.JsonConverter.ToJson(dtt));
- pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, jsondata);
- }
- }
- }
- }
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
- //ViewData["Department"] = new List<EntSYS_DISTRIBUTORS>();
- //using (AntORM orm = new AntORM())
- //{
- // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- // RequestModel res = new RequestModel
- // {
- // newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- // };
- // string saleid = CurrentUser.Id.ToString();
- // if (CurrentUser.USERTYPE == 3)
- // {
- // var reslut = orm.Queryable<YW_UserDistributor>().Where(p => p.userId == saleid).Select(p => new { p.distributorId }).ToList(res);
- // if (reslut.IsSuccess)
- // {
- // var listdis = reslut.ResultModel;
- // List<string> Names = new List<string>();
- // foreach (var mod in listdis)
- // {
- // Names.Add(mod.distributorId);
- // }
- // var dq = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => Names.Contains(p.ID)).ToList();
- // if (dq.IsSuccess)
- // {
- // ViewData["Department"] = dq.ResultModel;
- // }
- // }
- // }
- // else
- // {
- // var reslut = orm.Queryable<YW_UserDistributor>().Select(p => new { p.distributorId }).ToList(res);
- // if (reslut.IsSuccess)
- // {
- // var listdis = reslut.ResultModel;
- // List<string> Names = new List<string>();
- // foreach (var mod in listdis)
- // {
- // Names.Add(mod.distributorId);
- // }
- // var dq = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => Names.Contains(p.ID)).ToList();
- // if (dq.IsSuccess)
- // {
- // ViewData["Department"] = dq.ResultModel;
- // }
- // }
- // }
- //}
- ViewData["dptid"] = FK_DPTID;
- ViewData["CarSate"] = CarSate;
- ViewData["FenceState"] = FenceState;
- ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
- ViewData["typecar"] = carType;
- ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
- //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
- ViewData["barcode"] = barcode;
- ViewData["imei"] = imei;
- return View(pageInfo);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 导出报警数据
- /// </summary>
- /// <returns></returns>
- public FileResult ExportFenceExcel()
- {
- //获取list数据
- List<string> list = new List<string>();
- //创建Excel文件的对象
- NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
- var cartype = Request.QueryString["cartype"];
- var fencetype = Request.QueryString["fencetype"];
- var dptid = Request.QueryString["dptid"];
- //添加一个sheet
- NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
- //给sheet1添加第一行的头部标题
- NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
- row1.CreateCell(0).SetCellValue("农机IMEI号");
- row1.CreateCell(1).SetCellValue("农机名称");
- row1.CreateCell(2).SetCellValue("农机型号");
- row1.CreateCell(3).SetCellValue("车架号");
- row1.CreateCell(4).SetCellValue("所属经销商");
- row1.CreateCell(5).SetCellValue("围栏状态");
- row1.CreateCell(6).SetCellValue("出厂日期");
- row1.CreateCell(7).SetCellValue("出厂编号");
- row1.CreateCell(8).SetCellValue("超出围栏时间");
- row1.CreateCell(9).SetCellValue("超出时长");
- row1.CreateCell(10).SetCellValue("报警次数");
- row1.CreateCell(11).SetCellValue("最后一次点火时间");
- row1.CreateCell(12).SetCellValue("最后一次点火地址");
- //将数据逐步写入sheet1各个行
- if (!Request.QueryString["distributorsid"].IsEmpty())
- {
- distributorsID = Request.QueryString["distributorsid"].ToString();
- }
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
- strsql.AppendFormat("select * from YW_Bicycle as b left join DeviceManage as c on b.CarID=c.IMEI where b.CarID <> '' and b.CarSate<{0} and b.FenceState=2 ", CarState.Sales.GetHashCode());
- RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
- requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
- requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- requestItemSql.StrSql = strsql.ToString();
- var bicycleList = orm.GetDataTableList(requestItemSql);
- if (bicycleList.IsSuccess)
- {
- DataTable dtt = bicycleList.DataTable; int i = 0;
- foreach (DataRow dr in dtt.Rows)
- {
- i++;
- NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
- rowtemp.CreateCell(0).SetCellValue(dr["CarID"].ToString());
- rowtemp.CreateCell(1).SetCellValue(dr["CarName"].ToString());
- rowtemp.CreateCell(2).SetCellValue(dr["CarModel"].ToString());
- rowtemp.CreateCell(3).SetCellValue(dr["carBar"].ToString());
- rowtemp.CreateCell(4).SetCellValue(dr["DistributorsName"].ToString());
- string carstatestr = "";
- switch (dr["FenceState"].ToInt32())
- {
- case 0:
- carstatestr = "未点火"; break;
- case 1:
- carstatestr = "围栏内"; break;
- case 2:
- carstatestr = "围栏外"; break;
- }
- rowtemp.CreateCell(5).SetCellValue(carstatestr);
- rowtemp.CreateCell(6).SetCellValue(dr["productionDate"].ToString());
- rowtemp.CreateCell(7).SetCellValue(dr["FactoryNumber"].ToString());
- rowtemp.CreateCell(8).SetCellValue(dr["OutFenceDate"].ToDateTime().ToString());
- var num = Utility.DateTimeUtility.DateTimeDifference(Convert.ToDateTime(dr["OutFenceDate"]), DateTime.Now);
- rowtemp.CreateCell(9).SetCellValue(num);
- //orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
- //string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + dr["CarID"].ToString() + "' group by CarId";
- //var sum = orm.db.ExecuteScalar(sql);
- //if (sum.IsNullOrEmpty())
- //{
- // rowtemp.CreateCell(10).SetCellValue(0);
- //}
- //else
- //{
- // rowtemp.CreateCell(10).SetCellValue(sum.ToString());
- //}
- var sum = 0;//BundleConfig.OutFenceNum(dr["CarID"].ToString());
- rowtemp.CreateCell(10).SetCellValue(sum.ToString());
- var lng = dr["longitude"].ToDou(); var lat = dr["latitude"].ToDou();
- var root = Utility.ToolGPSamap.GPS2Position(lng, lat);
- string address = "";
- if (root.IfNotNull())
- {
- address = root.formatted_address;
- rowtemp.CreateCell(11).SetCellValue(dr["LastOnlineTime"].ToString());
- rowtemp.CreateCell(12).SetCellValue(address);
- }
- }
- }
- }
- // 写入到客户端
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- book.Write(ms);
- ms.Seek(0, SeekOrigin.Begin);
- return File(ms, "application/vnd.ms-excel", "农机报警信息.xls");
- }
- /// <summary>
- /// 获取车辆状态
- /// </summary>
- /// <param name="carState"></param>
- /// <returns></returns>
- private string GetCarState(int carState)
- {
- string strcar = "";
- switch (carState)
- {
- case 1:
- {
- strcar = "已绑定";
- }
- break;
- case 2:
- {
- strcar = "已出库";
- }
- break;
- case 3:
- {
- strcar = "在途中";
- }
- break;
- case 4:
- {
- strcar = "已入库";
- }
- break;
- case 5:
- {
- strcar = "已销售";
- }
- break;
- case 6:
- {
- strcar = "退货中";
- }
- break;
- case 7:
- {
- strcar = "调拨中";
- }
- break;
- case 8:
- {
- strcar = "返厂中";
- }
- break;
- default:
- {
- strcar = "初始值";
- }
- break;
- }
- return strcar;
- }
- }
- }
|