123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.SuperSocket.Common;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using Central.Control.Domain;
- using MES.Production.Entity;
- using MES.Production.Entity.Entity;
- using MES.Production.Entity.Enum;
- using MES.Production.Entity.Extensions;
- using Ant.Service.Mongodb;
- using MES.Production.Service.IService;
- using MES.Production.Service.ServiceImp;
- using Ant.Service.Utility;
- using ChangFa.Machinery.WebPage.Areas.SysManage.Models;
- using ChangFa.Machinery.WebPage.Controllers;
- using MongoDB.Driver.Builders;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class ProductController : BaseController
- {
- [UserAuthorizeAttribute(ModuleAlias = "productList", OperaAction = "View")]
- public ActionResult ProductList()
- {
- try
- {
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- #region 处理查询参数
- var nameOrCode = Request.QueryString["nameOrCode"];
- int saleStatus = -1;
- if (!string.IsNullOrWhiteSpace(Request.QueryString["saleStatus"]))
- {
- saleStatus = Convert.ToInt32(Request.QueryString["saleStatus"]);
- }
- #endregion
- #region 加载列表
- 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 = "获取运动员列表" };
- int pageno = (base.page - 1) * base.pagesize;
- var productQuery = orm.Queryable<YW_Product>().Where(p => p.IsDelete == 0);
- productQuery = productQuery.WhereIf(!string.IsNullOrWhiteSpace(nameOrCode), p => p.Name.Contains(nameOrCode));
- productQuery = productQuery.WhereIf(saleStatus >= 0, p => p.Sale == (SaleEnum)saleStatus);
- var reslut = productQuery.OrderByDesc(p => p.ModifyDT).Skip(pageno).Top(pagesize).ToList(res);
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = productQuery.Count();
- pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
- }
- }
- ViewBag.Search = base.keywords;
- ViewData["nameOrCode"] = nameOrCode;
- ViewData["saleStatus"] = saleStatus;
- return View(pageInfo);
- #endregion
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "获取裁判员列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="idList"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "productList", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除商品成功" };
- try
- {
- //是否为空
- if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的商品"; return Json(json); }
- string[] id = idList.Trim(',').Split(',');
- using (AntORM orm = new AntORM())
- {
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "删除商品" }
- };
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- List<YW_Product> olds = new List<YW_Product>();
- for (int i = 0; i < id.Length; i++)
- {
- var userId = id[i];
- request.Oid = userId;
- var oldResult = orm.GetEntity<YW_Product>(request);
- YW_Product old = oldResult?.ResultModel;
- if (old != null)
- {
- if (old.Sale == SaleEnum.On)
- {
- json.Msg = "已上架的商品不能修改";
- return Json(json);
- }
- olds.Add(old);
- }
- }
- olds.ForEach(old => {
- old.IsDelete = 1;
- old.ModifyBY = CurrentUser.Id.ToString();
- old.ModifyDT = DateTime.Now;
- request.Oid = string.Empty;
- var updateResult = orm.UpdateByLambda(old,p=>p.Id == old.Id, request);
- if (updateResult.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Remove, json.Msg, enumLog4net.WARN);
- }
- });
- }
- }
- catch (Exception e)
- {
- json.Msg = "删除商品发生内部错误!";
- WriteLog(enumOperator.Remove, "删除商品:", e);
- }
- return Json(json);
- }
- [UserAuthorize(ModuleAlias = "productList", OperaAction = "Add,Edit")]
- [ValidateInput(false)]
- [HttpPost]
- public ActionResult Save(YW_Product entity)
- {
- JsonHelper json = new JsonHelper() { Msg = "保存商品成功", Status = "n", ReUrl = "/Sys/Product/ProductList" };
- try
- {
- 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 = "保存商品" };
- entity.Name = entity.Name.Trim();
- entity.Code = entity.Code.Trim();
- entity.Name = entity.Name.Trim();
- entity.Sale = SaleEnum.Off;
- entity.Info = entity.Info?.Trim() ?? string.Empty;
- entity.IsDelete = 0;
- entity.Img = Request.Form["hidfilename"];
- if (!string.IsNullOrEmpty(entity.Id))
- {
- // 修改
- var resultProductCount = orm.Queryable<YW_Product>().Where(p => p.Code == entity.Code && p.IsDelete == 0 && p.Id != entity.Id).Count();
- if (resultProductCount > 0)
- {
- json.Status = "n";
- json.Msg = "商品编码不能重复!";
- return Json(json);
- }
- var onSaleCount = orm.Queryable<YW_Product>().Where(p => p.Id == entity.Id && p.Sale == SaleEnum.On).Count();
- if (onSaleCount > 0)
- {
- json.Status = "n";
- json.Msg = "已上架的商品不能修改!";
- return Json(json);
- }
- request.Oid = entity.Id;
- entity.ModifyBY = CurrentUser.Id.ToString();
- entity.ModifyDT = DateTime.Now;
- var reslut = orm.UpdateById(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存商品失败";
- }
- }
- else
- {
- // 删除
- var resultSportCount = orm.Queryable<YW_Product>().Where(p => p.Code == entity.Code && p.IsDelete == 0).Count();
- if (resultSportCount > 0)
- {
- json.Status = "n";
- json.Msg = "商品编码不能重复!";
- return Json(json);
- }
- entity.Id = IdGenerator.NewId();
- entity.CreateDT = DateTime.Now;
- entity.CreateBY = CurrentUser.Id.ToString();
- entity.ModifyDT = DateTime.Now;
- var reslut = orm.Save(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存商品失败";
- }
- }
- }
- }
- catch (Exception ex)
- {
- json.Msg = "保存商品发生内部错误!";
- WriteLog(enumOperator.None, "保存商品员:", ex);
- }
- return Json(json);
- }
- /// <summary>
- /// 查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "productList", OperaAction = "Detail")]
- public ActionResult Detail(string id)
- {
- YW_Product mod = new YW_Product();
- if (id != null)
- {
- using (AntORM orm = new AntORM())
- {
- try
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询单个商品" },
- Oid = id.ToString()
- };
- var reslut = orm.GetEntity<YW_Product>(request);
- if (reslut.IsSuccess)
- {
- mod = reslut.ResultModel;
- }
- }
- catch (Exception e)
- {
- }
- }
- }
- return View(mod);
- }
- /// <summary>
- /// 上架
- /// </summary>
- /// <param name="idList"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "productList", OperaAction = "OnSale")]
- public ActionResult OnSale(string idList)
- {
- return OnOffSale(SaleEnum.On, idList);
- }
- /// <summary>
- /// 下架
- /// </summary>
- /// <param name="idList"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "productList", OperaAction = "OffSale")]
- public ActionResult OffSale(string idList)
- {
- return OnOffSale(SaleEnum.Off, idList);
- }
- /// <summary>
- /// 上下架功能
- /// </summary>
- /// <param name="idList"></param>
- /// <returns></returns>
- private ActionResult OnOffSale(SaleEnum saleEnum, string idList)
- {
- string msg = "上架";
- if (saleEnum == SaleEnum.Off)
- {
- msg = "下架";
- }
- JsonHelper json = new JsonHelper() { Status = "n", Msg = $"{msg}商品成功" };
- try
- {
- //是否为空
- if (string.IsNullOrEmpty(idList)) { json.Msg = $"未找到要{msg}的商品"; return Json(json); }
- string[] id = idList.Trim(',').Split(',');
- using (AntORM orm = new AntORM())
- {
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = $"{msg}商品" }
- };
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- List<YW_Product> olds = new List<YW_Product>();
- for (int i = 0; i < id.Length; i++)
- {
- var userId = id[i];
- request.Oid = userId;
- var oldResult = orm.GetEntity<YW_Product>(request);
- YW_Product old = oldResult?.ResultModel;
- if (old != null)
- {
- olds.Add(old);
- }
- }
- olds.ForEach(old =>
- {
- old.Sale = saleEnum;
- old.ModifyBY = CurrentUser.Id.ToString();
- old.ModifyDT = DateTime.Now;
- request.Oid = string.Empty;
- var updateResult = orm.UpdateByLambda(old, p => p.Id == old.Id, request);
- if (updateResult.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Edit, json.Msg, enumLog4net.WARN);
- }
- });
- }
- }
- catch (Exception e)
- {
- json.Msg = "删除裁判发生内部错误!";
- WriteLog(enumOperator.Remove, "删除教练:", e);
- }
- return Json(json);
- }
- }
- }
|