123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Caching.Memory;
- using Microsoft.Extensions.Configuration;
- using Newtonsoft.Json;
- using NLog;
- using Sugar.Enties;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net.Http;
- using WebAPIBase.Utils;
- namespace WebAPIBase.API.Controllers
- {
- /// <summary>
- /// 供应商申请相关
- /// </summary>
- [Produces("application/json;charset=UTF-8")]
- [Route("api/SupplierApply")]
- [ServiceFilter(typeof(Filter.TokenAuthorize))]
- public class SupplierApplyController : Controller
- {
- private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
- #region 供应商扩展信息
- /// <summary>
- /// 根据供应商编码获取供应商扩展信息
- /// </summary>
- /// <param name="supplierCode">供应商编号</param>
- /// <returns></returns>
- [HttpGet]
- [Route("GetzzSupplierExList")]
- public JsonResult GetzzSupplierExList(string supplierCode)
- {
- if (supplierCode.IsNullOrEmpty())
- {
- return Json("-1");
- }
- try
- {
- var service = new zzSupplierExManager();
- var list = service.GetzzSupplierExDTOList(supplierCode);
- return Json(list);
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json("-2");
- }
- }
- /// <summary>
- /// 根据项目获取供应商申请的信息
- /// </summary>
- /// <param name="projectCode"></param>
- /// <returns></returns>
- [HttpGet]
- [Route("GetzzSupplierExListByProject")]
- public JsonResult GetzzSupplierExListByProject(string projectCode)
- {
- if (projectCode.IsNullOrEmpty())
- {
- return Json("参数错误");
- }
- try
- {
- var service = new zzSupplierExManager();
- var list = service.GetzzSupplierExListByProject(projectCode);
- return Json(list);
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 获取供应商扩展实例信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- [Route("GetzzSupplierEx")]
- public JsonResult GetzzSupplierEx(int id)
- {
- if (id.IsNullOrEmpty())
- {
- return Json("参数错误");
- }
- try
- {
- var bll = new RequisitionManager();
- var service = new zzSupplierExManager();
- var entity = service.GetzzSupplierExDTO(id);
- var attachments = bll.GetAttachMents(id.ToString(), "zzSupplierExAttach");
- var data = new
- {
- entity = entity,
- attachments = attachments
- };
- return Json(data);
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 供应商扩展信息添加
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("InsertzzSupplierEx")]
- public JsonResult InsertzzSupplierEx([FromBody] zzSupplierEx dto)
- {
- logger.Info($"【InsertzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
- if (dto.Title.IsNullOrEmpty())
- {
- return Json("标题不能为空");
- }
- if (dto.Title.Length > 200)
- {
- return Json("标题不能超过200字");
- }
- if (dto.Reason.IsNullOrEmpty())
- {
- return Json("原因不能为空");
- }
- if (dto.Reason.Length > 500)
- {
- return Json("原因不能超过500字");
- }
- try
- {
- dto.CheckDate = null;
- dto.CheckPerson = "";
- var service = new zzSupplierExManager();
- var id = service.Db.Insertable(dto).ExecuteReturnIdentity();
- if (id > 0)
- {
- return Json(id);
- }
- else
- {
- return Json("插入失败");
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message);
- }
- }
- /// <summary>
- /// 更新供应商申请
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("UpdatezzSupplierEx")]
- public JsonResult UpdatezzSupplierEx([FromBody] zzSupplierEx dto)
- {
- logger.Info($"【UpdatezzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
- if (dto.ID.IsNullOrEmpty())
- {
- return Json("参数错误,不能审核");
- }
- if (dto.Title.IsNullOrEmpty())
- {
- return Json("标题不能为空");
- }
- if (dto.Title.Length > 200)
- {
- return Json("标题不能超过200字");
- }
- if (dto.Reason.IsNullOrEmpty())
- {
- return Json("原因不能为空");
- }
- if (dto.Reason.Length > 500)
- {
- return Json("原因不能超过500字");
- }
- try
- {
- var service = new zzSupplierExManager();
- dto.CheckDate = DateTime.Now;
- var row = service.Db.Updateable(dto).ExecuteCommand();
- if (row > 0)
- {
- return Json("success");
- }
- else
- {
- return Json("更新失败");
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 管理员审核供应商提交的信息
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("AuditzzSupplierEx")]
- public JsonResult AuditzzSupplierEx([FromBody] zzSupplierEx dto)
- {
- logger.Info($"【AuditzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
- if (dto.ID.IsNullOrEmpty()||dto.ProjectCode.IsNullOrEmpty())
- {
- return Json("参数错误或无权限,不能审核");
- }
- try
- {
- var service = new zzSupplierExManager();
- var model = service.GetById(dto.ID);
- if(model.ProjectCode!=dto.ProjectCode)
- {
- return Json("无权限操作");
- }
- if(model.State!=1)
- {
- return Json("非审核中状态,不能操作");
- }
- var success = service.AuditzzSupplierEx(dto);
- if (success)
- {
- return Json("success");
- }
- else
- {
- return Json("审核失败");
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 提交供应商申请信息
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("SubmitzzSupplierEx")]
- public JsonResult SubmitzzSupplierEx([FromBody] zzSupplierEx dto)
- {
- logger.Info($"【SubmitzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
- if (dto.ID.IsNullOrEmpty() || dto.SupplierCode.IsNullOrEmpty())
- {
- return Json("参数错误或无权限,不能审核");
- }
- try
- {
- var service = new zzSupplierExManager();
- var model = service.GetById(dto.ID);
- if (model.SupplierCode != dto.SupplierCode)
- {
- return Json("无权限操作");
- }
- if (model.State != 0)
- {
- return Json("非待审核状态,不能操作");
- }
- var success = service.SubmitzzSupplierEx(dto);
- if (success)
- {
- return Json("success");
- }
- else
- {
- return Json("提交失败");
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 删除供应商扩展信息
- /// </summary>
- /// <param name="suppliercode"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- [Route("DeletezzSupplierEx")]
- public JsonResult DeletezzSupplierEx(string suppliercode, int id)
- {
- if (suppliercode.IsNullOrEmpty())
- {
- return Json("参数错误,不能删除");
- }
- if (id <= 0)
- {
- return Json("参数错误,不能删除");
- }
- try
- {
- var service = new zzSupplierExManager();
- var success = service.Delete(m => m.SupplierCode == suppliercode && m.ID == id);
- if (success)
- {
- return Json("success");
- }
- else
- {
- return Json("删除失败");
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- /// <summary>
- /// 根据供应商编号获取其对应所有项目
- /// </summary>
- /// <param name="supplierCode"></param>
- /// <returns></returns>
- [HttpGet]
- [Route("GetProjectBySupplierCode")]
- public JsonResult GetProjectBySupplierCode(string supplierCode)
- {
- if (supplierCode.IsNullOrEmpty())
- {
- return Json("请输入供应商编号");
- }
- try
- {
- var service = new zzSupplierExManager();
- var list = service.GetProjectBySupplierCode(supplierCode);
- logger.Info($"【GetProjectBySupplierCode】list:" + JsonConvert.SerializeObject(list));
- return Json(list);
- }
- catch (Exception ex)
- {
- return Json(ex.Message + "\r\n" + ex.StackTrace);
- }
- }
- #endregion
- }
- }
|