1031 lines
40 KiB
C#
1031 lines
40 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using System.IO;
|
|
using PagedList;
|
|
using Weee.Models;
|
|
using Weee.Service;
|
|
using Weee.Supports;
|
|
using Weee.ViewModels;
|
|
using Weee.DataTransferObject;
|
|
using Microsoft.AspNet.Identity;
|
|
using System.Web;
|
|
using Weee.DAL;
|
|
using Qcarbon.ViewModels.DTO;
|
|
using NLog;
|
|
using Qcarbon.Database.Lca;
|
|
using NPOI.SS.Formula.Functions;
|
|
using Qcarbon.Interfaces.adminCheck;
|
|
using System.Web.Http.Controllers;
|
|
using Qcarbon.Database.adminCheck;
|
|
using Weee.Models.Paramemter;
|
|
using Qcarbon.ViewModels.admin;
|
|
using Weee.Models.ExtensionMethods;
|
|
using System.Security.Principal;
|
|
using Customize.Insynerger.Interfaces;
|
|
using Customize.Insynerger;
|
|
using Qcarbon.ExcelImportExport.LcaOrganization;
|
|
using Qcarbon.ViewModels.ExcelImportExport.LcaOrganization.excelExportOrgLCAdata;
|
|
using Qcarbon.ExcelImportExport.LcaOrganization.excelImportLCAdata;
|
|
|
|
namespace Weee.Controllers
|
|
{
|
|
public class LCAController : ApiControllerBase
|
|
{
|
|
private WeeeDataContext db;
|
|
private WeeeSheetDataService service;
|
|
private UserService userService;
|
|
private LCAcommonService _LCAcommonService;
|
|
private WeeeProductDataService productDataService;
|
|
protected IadminCheckService _adminCheckService;
|
|
protected IcompanyAdminCheckService _companyAdminCheckService;
|
|
protected Logger log;
|
|
|
|
public LCAController(WeeeDataContext db, WeeeSheetDataService s, WeeeProductDataService p, UserManager<User> m)
|
|
: base(s)
|
|
{
|
|
this.db = db;
|
|
service = s;
|
|
userService = new UserService(db, m);
|
|
_LCAcommonService = new LCAcommonService(db);
|
|
productDataService = p;
|
|
}
|
|
|
|
protected override void Initialize(HttpControllerContext controllerContext)
|
|
{
|
|
base.Initialize(controllerContext);
|
|
var userid = User.Identity.GetUserId();
|
|
_adminCheckService = new adminCheckService(db, userid);
|
|
_companyAdminCheckService = new companyAdminCheckService(db, userid);
|
|
log = NLog.LogManager.GetCurrentClassLogger();
|
|
}
|
|
|
|
#region For landing page
|
|
|
|
/// <summary>
|
|
/// 我的盤查 查詢資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/GetMyLCAs")]
|
|
[HttpPost]
|
|
public Object GetMyLCAs()
|
|
{
|
|
string userID = User.Identity.GetUserId();
|
|
if (userService.isCompanyAdmin(userID))
|
|
userID = "";
|
|
var currentUserName = User.Identity.GetUserName(); //DL-51
|
|
var currentName = userService.GetNameByUserName(currentUserName);
|
|
var lcas = service.GetLCAs(userID);
|
|
foreach (var rec in lcas)
|
|
rec.Description = rec.Description + "";
|
|
var lcaList = service.GetLCAsForUser(currentUserName); //DL-51
|
|
var sendRequests0 = lcas
|
|
.Where(x => x.LCAType == typeof(ProductLCA));
|
|
var sendRequests = sendRequests0
|
|
.Cast<ProductLCA>()
|
|
.SelectMany(x => x.SentRequests).ToList();
|
|
var result = service.GetRequestForUser(currentUserName, currentName, sendRequests);
|
|
var resultToLocalDTList =
|
|
(from r in result
|
|
select new
|
|
{
|
|
r.ID,
|
|
AcceptDate = r.AcceptDate != null ? ((DateTime)r.AcceptDate) : r.AcceptDate,
|
|
r.AcceptReplyDate,
|
|
r.AnonymousReplyLink,
|
|
r.CanBeApply,
|
|
r.CanBeDelete,
|
|
r.CanBeReplied,
|
|
r.CreatedDate,
|
|
r.DescriptionFromReceiver,
|
|
r.DescriptionFromSender,
|
|
r.Distribute,
|
|
r.DivideBy,
|
|
r.LastResentDate,
|
|
r.MaterialName,
|
|
r.MaterialPartNumber,
|
|
r.MaterialSupplierEmail,
|
|
r.MaterialSupplierName,
|
|
r.ReceiveBy,
|
|
r.ReceiverCompanyID,
|
|
r.ReferenceFileLink,
|
|
r.RepliedByWhichLCA,
|
|
r.RepliedLCAID,
|
|
r.RepliedValue,
|
|
ReplyDate = r.ReplyDate != null ? ((DateTime)r.ReplyDate) : r.ReplyDate,
|
|
r.ReplyStatusDisplay,
|
|
r.RequestLink,
|
|
r.SenderCompanyName,
|
|
r.SendLCAID,
|
|
r.SentByWhichMaterial,
|
|
r.SupplierLCAStatus,
|
|
r.Uid
|
|
}).ToList();//CFT-23指令回復時間轉為lcoal
|
|
Object ret = new
|
|
{
|
|
LCAs = lcas.ToList(), // 我的盤查
|
|
SendRequests = resultToLocalDTList.ToList() // 發送的盤查指令
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
[Route("api/LCA/GetLCADetail/{LCAID}")]
|
|
[HttpGet]
|
|
public object GetLCADetail(int LCAID)
|
|
{
|
|
if (HttpContext.Current.Session != null)
|
|
HttpContext.Current.Session["LCAid"] = LCAID;
|
|
var qry = service.GetLCAs()
|
|
.Where(x => x.ID == LCAID)
|
|
.FirstOrDefault();
|
|
string userID = User.Identity.GetUserId();
|
|
//LCAcompanyAdmin ret = CScommon.JsonUtl.jsonCopy<LCA, LCAcompanyAdmin>(qry);
|
|
//ret.isCompanyAdmin = userService.isCompanyAdmin(userID);
|
|
if (qry!=null && qry.LCAType.Name.Contains("Product"))
|
|
{
|
|
var productLCA = service.GetProductLCA(LCAID);
|
|
var product = productDataService.GetProduct((int)productLCA.ProductID);
|
|
object ret = new
|
|
{
|
|
isCompanyAdmin = userService.isCompanyAdmin(userID),
|
|
LCAobj = qry,
|
|
productLCA = productLCA,
|
|
product = product
|
|
};
|
|
return ret;
|
|
}
|
|
else
|
|
{
|
|
object ret = new
|
|
{
|
|
isCompanyAdmin = userService.isCompanyAdmin(userID),
|
|
LCAobj = qry,
|
|
productLCA = new ProductLCA(),
|
|
product = new Product()
|
|
};
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
[Route("api/LCA/GetCertificationCompanyFile/{Type}/{VerifierCompanyID}")]
|
|
[HttpGet]
|
|
public object GetCertificationCompanyFile(String Type, int VerifierCompanyID)
|
|
{
|
|
String companyUsername = _LCAcommonService.companyUserName(VerifierCompanyID);
|
|
string actPath = HttpContext.Current.Request.Url.Authority;
|
|
string protocolName;
|
|
if (HttpContext.Current.Request.IsSecureConnection)
|
|
protocolName = "https://";
|
|
else
|
|
protocolName = "http://";
|
|
string url = protocolName + actPath + getBaseUrl()+ "/Browser_Local/WebFilesRoot/" + companyUsername + "/";
|
|
|
|
if (Type.Equals("ProductLCA"))
|
|
{
|
|
url = url + CScommon.ProgramConstants.ProductLCAApplicationFile;
|
|
}
|
|
else if (Type.Equals("OrganizationLCA"))
|
|
{
|
|
url = url + CScommon.ProgramConstants.OrganizationLCAApplicationFile;
|
|
}
|
|
else
|
|
{
|
|
url = "";
|
|
}
|
|
|
|
if (!url.Equals(""))
|
|
{
|
|
try
|
|
{
|
|
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
|
request.Method = "HEAD";
|
|
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
|
|
response.Close();
|
|
return new { Url = url };
|
|
}
|
|
catch
|
|
{
|
|
return new { Url = "" };
|
|
}
|
|
|
|
}
|
|
return new { Url = url };
|
|
}
|
|
|
|
[Route("api/LCA/GetMyReports")]
|
|
[HttpGet]
|
|
public Object GetMyReports()
|
|
{
|
|
string userID = User.Identity.GetUserId();
|
|
if (userService.isCompanyAdmin(userID))
|
|
userID = "";
|
|
var lcas = service.GetLCAs(userID);
|
|
//.Where(x => x.Status == LCAStatus.Completed ||
|
|
// x.Status == LCAStatus.Confirmed);//.ToList();
|
|
//Start CFT-6
|
|
//return lcas.ToList();
|
|
var listLCA = (from l in lcas select new {
|
|
l.ID,
|
|
l.LCAname,
|
|
l.Description,
|
|
LCAdataRptUrl = this.FormatReportUrl(l.LCAdataRptUrl), // 盤查表
|
|
InterrogationResultUrl = this.FormatReportUrl(l.InterrogationResultUrl), // 清冊
|
|
CarbonFootprintDocxUrl = this.FormatReportUrl(l.CarbonFootprintDocxUrl), // 報告書
|
|
LCAriskRptUrl = this.FormatReportUrl(l.LCAriskRptUrl), // 風險評估表
|
|
ProductInventoryResultUrl = this.FormatReportUrl(l.ProductInventoryResultUrl), // 产品碳足迹清册, no longer used
|
|
}).ToList();//CFT-88
|
|
return listLCA;
|
|
//End CFT-6
|
|
}
|
|
|
|
private string FormatReportUrl(string url)
|
|
{
|
|
return url != null && url.Contains("/Browser_Local") ? url.Substring(url.IndexOf("/Browser_Local")) : null;
|
|
}
|
|
|
|
[Route("api/LCA/GetMyLCAforQuote")]
|
|
[HttpGet]
|
|
public IEnumerable<LCA> GetMyLCAforQuote()
|
|
{
|
|
return service.GetLCAs();
|
|
}
|
|
|
|
[Route("api/LCA/GetMyProductLCA")]
|
|
[HttpGet]
|
|
public IEnumerable<LCA> GetMyProductLCA()
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
int companyId = userService.getCompanyId(userId);
|
|
bool IsCompanyAdmin = userService.isCompanyAdmin(userId);// User.Identity.IsCompanyAdmin();
|
|
IEnumerable<LCA> ret = service.GetLCAs()
|
|
.Where(x => x.LCAType == typeof(ProductLCA)
|
|
&& (x.Status== LCAStatus.Confirmed || x.Status==LCAStatus.Completed)
|
|
&& (x.UserId==userId
|
|
|| (IsCompanyAdmin && (int)x.OwnerID== companyId)));
|
|
foreach (var rec in ret)
|
|
rec.Description = rec.Description + "";
|
|
return ret;
|
|
}
|
|
|
|
[Route("api/LCA/GetMyOrganizationLCA")]
|
|
[HttpGet]
|
|
public IEnumerable<LCA> GetMyOrganizationLCA()
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
var ret= service.GetLCAs()
|
|
.Where(x => x.LCAType == typeof(OrganizationLCA)
|
|
&& x.UserId == userId);
|
|
return ret;
|
|
}
|
|
/// <summary>
|
|
/// 接收盤查指令
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/GetMyReceiveLCAs")]
|
|
[HttpPost]
|
|
public Object GetMyReceiveLCAByPage()
|
|
{
|
|
//DL-49 begin
|
|
var currentUserName = User.Identity.GetUserName();
|
|
var receiveLcas = service.GetReceivedRequests(currentUserName);//DL-50
|
|
Object ret= receiveLcas.ToList();//接收盤查指令
|
|
return ret;
|
|
}
|
|
|
|
[Route("api/LCA/GetComments/{LCAID}")]
|
|
[HttpGet]
|
|
public IEnumerable<Comment> GetComments(int LCAID)
|
|
{
|
|
var productLca = service.GetLCAs().Where(x => x.ID == LCAID).FirstOrDefault();
|
|
if (productLca == null)
|
|
return null;
|
|
return productLca.Comments.Where(x => x.CommentText != "" && x.CommentText != null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected string checkOrganizationLCA(OrganizationLCA lca)
|
|
{
|
|
string err = "";
|
|
TimeSpan ts=lca.EndDate-lca.StartDate;
|
|
if (lca.StartDate >= lca.EndDate)
|
|
err = "起日必須小於迄日";
|
|
else if (lca.StartDate.Year < lca.EndDate.Year)
|
|
err = "起日迄日必須同一年";
|
|
else if ((lca.EndDate.Month == lca.StartDate.Month && (lca.StartDate.Day != 1 || lca.EndDate.AddDays(1).Day != 1)) || (lca.EndDate.Month - 1 == lca.StartDate.Month && lca.EndDate.Day < lca.StartDate.Day - 1))
|
|
err = "起迄區間最少一個月";
|
|
else if (lca.EndDate.Year > DateTime.Today.Year ||
|
|
((lca.EndDate.Year == DateTime.Today.Year) &&
|
|
(lca.EndDate.Month > DateTime.Today.Month)))
|
|
err = "迄日不得為未來時間(年月)";
|
|
// 檢查基準年盤查單號是否是有權限的盤查單,是否為基準年
|
|
return err;
|
|
}
|
|
private string _recalculateOrganizationLCA(OrganizationLCA toBeCreated)
|
|
{
|
|
string err = service.RecalculateOrganizationLCA(toBeCreated.ID, false);
|
|
return err;
|
|
}
|
|
[Route("api/LCA/RecalculateOrganizationLCA")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpResponseMessage RecalculateOrganizationLCA(OrganizationLCA toBeCreated)
|
|
{
|
|
ModelState.Remove("toBeCreated.ARversion");
|
|
string err = _recalculateOrganizationLCA(toBeCreated);
|
|
if (!string.IsNullOrWhiteSpace(err))
|
|
ModelState.AddModelError("", err);
|
|
if (!ModelState.IsValid)
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
return Request.CreateResponse(HttpStatusCode.OK, toBeCreated.ID);
|
|
}
|
|
#region Create and Edit LCA
|
|
[Route("api/LCA/SaveOrganizationLCA")]
|
|
[Route("api/LCA/CreateOrganizationLCA")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpResponseMessage CreateOrganizationLCA(OrganizationLCA toBeCreated)
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
if (!_adminCheckService.adminCheckPass() && toBeCreated.ID<=0)//僅新增時檢查
|
|
{
|
|
AdminAccess aa = _adminCheckService.getAdminAccess();
|
|
int lcaQuantity = _adminCheckService.getLcaQuantity();
|
|
if (lcaQuantity >= aa.lcaLimit
|
|
&& aa.lcaLimit!=-1)
|
|
{
|
|
ModelState.AddModelError("",
|
|
$"盤查單數({lcaQuantity})已達或超過全站限制" +
|
|
$"({aa.lcaLimit}),請系統管理員更新金鑰限制重新匯入");
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
companyAdminAccessVM uaaVM = _companyAdminCheckService
|
|
.getCompanyAdminAccessVM(
|
|
_companyAdminCheckService.userId2companyID(userId));
|
|
int lcaQuantityByUserId =
|
|
_companyAdminCheckService.getLcaQuantityByUserId(userId);
|
|
if (lcaQuantityByUserId >= uaaVM.lcaLimit
|
|
&& uaaVM.lcaLimit!=-1)
|
|
{
|
|
ModelState.AddModelError("",
|
|
$"盤查單數({lcaQuantityByUserId})已達或超過公司限制" +
|
|
$"({uaaVM.lcaLimit}),請公司管理員更新限制重新嘗試");
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
}
|
|
string err = checkOrganizationLCA(toBeCreated);
|
|
if (!string.IsNullOrWhiteSpace(err))
|
|
{
|
|
ModelState.Clear();
|
|
ModelState.AddModelError("", err);
|
|
}
|
|
if (!toBeCreated.isBaseYear && toBeCreated.BaseYearLCAID == null)
|
|
toBeCreated.isBaseYear = true;
|
|
if (!service.CheckOrganizationBaseYearIsCorrect(toBeCreated , User.Identity.GetUserId()))
|
|
{
|
|
if (string.IsNullOrWhiteSpace(err))
|
|
ModelState.Clear();
|
|
ModelState.AddModelError("", "基準年盤查單號不正確");
|
|
}
|
|
//Logger log = NLog.LogManager.GetCurrentClassLogger();
|
|
//log.Info("CreateOrganizationLCA toBeCreated::" + CScommon.JsonUtl.fromT(toBeCreated));
|
|
if (ModelState.IsValid)
|
|
{
|
|
if (toBeCreated.ID <= 0)
|
|
toBeCreated.UserId = userId;
|
|
service.SaveOrganizationLCA(toBeCreated);
|
|
return Request.CreateResponse(HttpStatusCode.OK, toBeCreated.ID);
|
|
}
|
|
//var allErrors = ModelState.Values.SelectMany(v => v.Errors);
|
|
//foreach (var error in allErrors)
|
|
// log.Info(error.ErrorMessage);
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
|
|
protected string checkProductDates(DateTime startDate, DateTime endDate)
|
|
{
|
|
string err = "";
|
|
if (startDate >= endDate)
|
|
err = "起日必須小於迄日";
|
|
//else if (startDate.Year < endDate.Year)
|
|
// err = "起日迄日必須同一年";
|
|
else if ((endDate.Month == startDate.Month && (startDate.Day != 1 || endDate.AddDays(1).Day != 1)) || (endDate.Month -1 == startDate.Month && endDate.Day < startDate.Day - 1))
|
|
err = "起迄區間最少一個月";
|
|
else if (endDate.Year > DateTime.Today.Year ||
|
|
((endDate.Year == DateTime.Today.Year) &&
|
|
(endDate.Month > DateTime.Today.Month)))
|
|
err = "迄日不得為未來時間(年月)";
|
|
return err;
|
|
}
|
|
private string _recalculateProductLCA(ProductLCA toBeCreated)
|
|
{
|
|
string err = service.RecalculateProductLCA(toBeCreated.ID, false);
|
|
return err;
|
|
}
|
|
[Route("api/LCA/RecalculateProductLCA")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpResponseMessage RecalculateProductLCA(ProductLCA toBeCreated)
|
|
{
|
|
//string err = checkProductDates(toBeCreated.StartDate, toBeCreated.EndDate);
|
|
//if (!string.IsNullOrWhiteSpace(err))
|
|
//{
|
|
// ModelState.Clear();
|
|
// ModelState.AddModelError("", err);
|
|
//}
|
|
//var userId = User.Identity.GetUserId();
|
|
//toBeCreated.UserId = userId;
|
|
//service.SaveProductLCA(toBeCreated);
|
|
string err = _recalculateProductLCA(toBeCreated);
|
|
if (!string.IsNullOrWhiteSpace(err))
|
|
ModelState.AddModelError("", err);
|
|
if (!ModelState.IsValid)
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
return Request.CreateResponse(HttpStatusCode.OK, toBeCreated);
|
|
}
|
|
[Route("api/LCA/SaveProductLCA")]
|
|
[Route("api/LCA/CreateProductLCA")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpResponseMessage CreateProductLCA(ProductLCA toBeCreated)
|
|
{
|
|
string err = checkProductDates(toBeCreated.StartDate, toBeCreated.EndDate);
|
|
if (!string.IsNullOrWhiteSpace(err)) {
|
|
ModelState.Clear();
|
|
ModelState.AddModelError("", err);
|
|
}
|
|
else if (string.IsNullOrWhiteSpace(toBeCreated.FunctionalUnit)) {
|
|
ModelState.Clear();
|
|
ModelState.AddModelError("", "功能單位不得為空!");
|
|
}
|
|
if (ModelState.IsValid)
|
|
{
|
|
var userId = User.Identity.GetUserId();
|
|
if (toBeCreated.ID <= 0)
|
|
toBeCreated.UserId = userId;
|
|
if (!toBeCreated.HasProductLifeCycle_MaterialsObtained)
|
|
// new product CFP study needs high-level analyse.
|
|
toBeCreated.Status = LCAStatus.New;
|
|
service.SaveProductLCA(toBeCreated);
|
|
return Request.CreateResponse(HttpStatusCode.OK, toBeCreated);
|
|
}
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region For product lca status update
|
|
|
|
[Route("api/LCA/NewProcessing/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog("完成高階分析", "LCA")]
|
|
public HttpStatusCode NewProcessing(int LCAID)
|
|
{
|
|
var userName = User.Identity.GetUserName();//DL-41
|
|
service.ProductLCANewToProcessing(LCAID, userName, getBaseUrl());//DL-41
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
[Route("api/LCA/RejectProcessing/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode RejectProcessing(int LCAID)
|
|
{
|
|
service.ProductLCARejectedToProcessing(LCAID);
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
[Route("api/LCA/ProcessWaiting/{LCAID}/{changeStatus}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public string ProcessWaiting(int LCAID, int changeStatus)
|
|
{
|
|
string userName = User.Identity.GetUserName();
|
|
string url = service.ProductLCAProcessingToWait(""
|
|
, "", LCAID, userName,getBaseUrl(), changeStatus==1);
|
|
// 產品型 報告書 還要修改成可以直接下載檔案,參考組織型報告書
|
|
return url;// HttpStatusCode.OK;
|
|
}
|
|
/// <summary>
|
|
/// 產品型 報告書
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/ProductGenerateLCAReport/{LCAID}")]
|
|
public string ProductGenerateLCAReport(int LCAID)
|
|
{
|
|
// 這裡作廢,移到 ProcessWaiting, 約上方 44? 行
|
|
string downloadUrl = "";
|
|
return downloadUrl;
|
|
}
|
|
|
|
[Route("api/LCA/ConfirmCompleting/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode ConfirmCompleted(int LCAID)
|
|
{
|
|
// test
|
|
service.ProductLCAConfirmedToCompleted(LCAID);
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Organization lca status update
|
|
|
|
[Route("api/LCA/OrganizationRejectProcessing/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode OrganizationRejectProcessing(int LCAID)
|
|
{
|
|
service.OrganizationLCARejectedToProcessing(LCAID);
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
[Route("api/LCA/OrganizationProcessWaiting/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode OrganizationProcessWaiting(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
service.OrganizationLCAProcessingToWait(LCAID, UserId, UserName, getBaseUrl());
|
|
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
[Route("api/LCA/OrganizationNewCompleting/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode OrganizationNewCompleting(int LCAID)
|
|
{
|
|
service.OrganizationLCANewToCompleted(LCAID);
|
|
return HttpStatusCode.OK;
|
|
}
|
|
|
|
[Route("api/LCA/OrganizationConfirmCompleting/{LCAID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public HttpStatusCode OrganizationConfirmCompleting(int LCAID)
|
|
{
|
|
service.OrganizationLCAConfirmedToCompleted(LCAID);
|
|
return HttpStatusCode.OK;
|
|
}
|
|
#endregion
|
|
|
|
#region For reply request
|
|
[Route("api/LCA/ApplyRepliedRequest/{requestID}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public object ApplyRepliedRequest(Guid requestID)
|
|
{
|
|
var result = service.ApplyRepliedRequest(requestID);
|
|
return result;
|
|
}
|
|
|
|
[Route("api/LCA/ReplyRequest/{requestID}/{LCAID}/{DivideBy}")]
|
|
[HttpPost]
|
|
[Filter.ApiLog]
|
|
public object ReplyRequest(Guid requestID, int LCAID, ProductLCAReplyRequest.DivideByOptions divideBy)
|
|
{
|
|
var result = service.ReplyRequest(requestID, LCAID, divideBy);
|
|
return result;
|
|
}
|
|
|
|
[Route("api/LCA/DeleteRequest/{uid}")]
|
|
[HttpDelete]
|
|
[Filter.ApiLog]
|
|
public int DeleteRequest(Guid uid)
|
|
{
|
|
service.DeleteRequest(uid);
|
|
return 0;
|
|
}
|
|
|
|
[Route("api/LCA/ResendRequest/{uid}")]
|
|
[HttpPost]
|
|
public int ResendRequest(Guid uid)
|
|
{
|
|
service.DeleteRequest(uid);
|
|
return 0;
|
|
}
|
|
|
|
[Route("api/LCA/ResetRequest/{id}")]
|
|
[HttpPost]
|
|
public ProductLCAReplyRequest ResetRequest(int id)
|
|
{
|
|
return service.ResetRequest(id);
|
|
}
|
|
#endregion
|
|
|
|
//CFT-89
|
|
/// <summary>
|
|
/// 產生所有報表 在未發給查證單位之前 產生報告書
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateReport/{LCAID}")]
|
|
public string OrganizationGenerateReport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
string downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db,"","",LCAID, UserId, UserName, getBaseUrl());
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 拆分產生報告書,此為盤查表
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateLCAdataReport/{LCAID}")]
|
|
public string OrganizationGenerateLCAdataReport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl="";
|
|
// 加上精簡的參數
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db,"","",LCAID, UserId, UserName,getBaseUrl(), 1);
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 拆分產生報告書,此為清冊
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateLCAlistReport/{LCAID}")]
|
|
public string OrganizationGenerateLCAlistReport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl = "";
|
|
// 加上精簡的參數
|
|
try
|
|
{
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName,getBaseUrl(), 2);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
log.Error(ex);
|
|
ex = CScommon.Exceptions.inner(ex);
|
|
log.Error(ex);
|
|
log.Error(ex.StackTrace);
|
|
return "err:"+ ex.Message;
|
|
}
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 合併清冊
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateMergedLCAlistReport/{LCAID}")]
|
|
public string OrganizationGenerateMergedLCAlistReport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl = "";
|
|
// 加上精簡的參數
|
|
try
|
|
{
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName,getBaseUrl(), 12);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex);
|
|
ex = CScommon.Exceptions.inner(ex);
|
|
log.Error(ex);
|
|
log.Error(ex.StackTrace);
|
|
return "err:" + ex.Message;
|
|
}
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 合併報告書
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateMergedLCAreport/{LCAID}")]
|
|
public string OrganizationGenerateMergedLCAreport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl = "";
|
|
// 加上精簡的參數
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName,getBaseUrl(), 13);
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 拆分產生報告書,此為報告書
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/OrganizationGenerateLCAreport/{LCAID}")]
|
|
public string OrganizationGenerateLCAreport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl = "";
|
|
// 加上精簡的參數
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db,"","",LCAID, UserId, UserName,getBaseUrl(), 3);
|
|
return downloadUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆分產生報告書,此為風險評估報表
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/GenerateRiskAssessmentReport/{LCAID}")]
|
|
public string GenerateRiskAssessmentReport(int LCAID)
|
|
{
|
|
//CFT-89
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl = "";
|
|
// 加上精簡的參數
|
|
try {
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.OrganizationLCAGenerateReport(
|
|
db,"","",LCAID, UserId, UserName,getBaseUrl(), 4);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex);
|
|
ex = CScommon.Exceptions.inner(ex);
|
|
log.Error(ex);
|
|
log.Error(ex.StackTrace);
|
|
return "err:" + ex.Message;
|
|
}
|
|
return downloadUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 產品型,盤查表
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/ProductGenerateLCAdataReport/{LCAID}")]
|
|
public string ProductGenerateLCAdataReport(int LCAID)
|
|
{
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl ;
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.ProductLCAdataGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName, getBaseUrl());
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 產品型 清冊
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/ProductGenerateLCAlistReport/{LCAID}")]
|
|
public string ProductGenerateLCAlistReport(int LCAID)
|
|
{
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl;
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.ProductListGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName, getBaseUrl());
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 產品型 敏感性分析表
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/GenerateSensitivityAnalysis/{LCAID}")]
|
|
public string GenerateSensitivityAnalysis(int LCAID)
|
|
{
|
|
string UserId = User.Identity.GetUserId();
|
|
string UserName = User.Identity.GetUserName();
|
|
string downloadUrl;
|
|
WeeeLCADataService srv = new WeeeLCADataService(db);
|
|
downloadUrl = srv.ProductSensitivityGenerateReport(
|
|
db, "", "", LCAID, UserId, UserName, getBaseUrl());
|
|
return downloadUrl;
|
|
}
|
|
/// <summary>
|
|
/// 判斷是否啟用思納捷客製,原本不能用在...\Weee\Controllers\Api\Customize\InsynergerController.cs
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/InsynergerIsOn")]
|
|
[HttpGet]
|
|
public bool InsynergerIsOn()
|
|
{
|
|
IinsynergerAuthenticate isa = new insynergerAuthenticate(
|
|
service.GetDbContext());
|
|
bool ret = isa.IsSynergerOn();
|
|
return ret;
|
|
}
|
|
/// <summary>
|
|
/// 取得圖表資料
|
|
/// </summary>
|
|
/// <param name="LCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/GetChartData/{LCAID}")]
|
|
public object GetChartData(int LCAID)
|
|
{
|
|
var qry = (from a in db.OrganizationLCAs
|
|
where a.ID == LCAID
|
|
select a).FirstOrDefault();
|
|
if (qry == null)
|
|
return null;
|
|
var ret = new
|
|
{
|
|
lcaDAta = service.GetRptLCAdata(LCAID),
|
|
list = service.GetRptList(LCAID)
|
|
};
|
|
return ret;
|
|
}
|
|
[Route("api/LCA/SaveAllocation/{LCAID}/{detailType}/{allocation}")]
|
|
[HttpPost]
|
|
public HttpResponseMessage SaveAllocation(int LCAID, string detailType, int allocation)
|
|
{
|
|
var productLCA = service.GetProductLCA(LCAID);
|
|
switch (detailType)
|
|
{
|
|
case "WorkHour":
|
|
productLCA.ProductAllocationWorkHour = (ProductAllocation)allocation;
|
|
break;
|
|
case "PowerUsage":
|
|
productLCA.ProductAllocationPowerUsage = (ProductAllocation)allocation;
|
|
break;
|
|
case "WaterUsage":
|
|
productLCA.ProductAllocationWaterUsage = (ProductAllocation)allocation;
|
|
break;
|
|
case "Waste":
|
|
productLCA.ProductAllocationWaste = (ProductAllocation)allocation;
|
|
break;
|
|
case "WasteWater":
|
|
productLCA.ProductAllocationWasteWater = (ProductAllocation)allocation;
|
|
break;
|
|
case "WasteTransport":
|
|
productLCA.ProductAllocationWasteTransport = (ProductAllocation)allocation;
|
|
break;
|
|
case "Vehicle":
|
|
productLCA.ProductAllocationVehicle = (ProductAllocation)allocation;
|
|
break;
|
|
case "GasolineEquipment":
|
|
productLCA.ProductAllocationGasolineEquipment = (ProductAllocation)allocation;
|
|
break;
|
|
case "Kitchen":
|
|
productLCA.ProductAllocationKitchen = (ProductAllocation)allocation;
|
|
break;
|
|
case "FireEquipment":
|
|
productLCA.ProductAllocationFireEquipment = (ProductAllocation)allocation;
|
|
break;
|
|
case "Refrigerant":
|
|
productLCA.ProductAllocationRefrigerant = (ProductAllocation)allocation;
|
|
break;
|
|
case "SteamUsage":
|
|
productLCA.ProductAllocationSteamUsage = (ProductAllocation)allocation;
|
|
break;
|
|
case "OtherCompound":
|
|
productLCA.ProductAllocationOtherCompound = (ProductAllocation)allocation;
|
|
break;
|
|
case "TransportUpstream":
|
|
productLCA.ProductAllocationTransportUpstream = (ProductAllocation)allocation;
|
|
break;
|
|
case "TransportDownstream":
|
|
productLCA.ProductAllocationTransportDownstream = (ProductAllocation)allocation;
|
|
break;
|
|
default:
|
|
return Request.CreateResponse(HttpStatusCode.BadRequest, 0);
|
|
}
|
|
service.SaveProductLCA(productLCA);
|
|
return Request.CreateResponse(HttpStatusCode.OK, 1);
|
|
}
|
|
|
|
[Route("api/Report/SaveSheetHeader")]
|
|
[HttpPost]
|
|
public HttpResponseMessage SaveHeaderReport(SheetHeader header)
|
|
{
|
|
return this.SaveSheetHeader(service, Categories.Report, header);
|
|
}
|
|
|
|
[Route("api/RiskAssmtLayout/SaveSheetHeader")]
|
|
[HttpPost]
|
|
public HttpResponseMessage SaveHeaderRiskAssmtLayout(SheetHeader header)
|
|
{
|
|
return this.SaveSheetHeader(service, Categories.RiskAssmtLayout, header);
|
|
}
|
|
|
|
[Route("api/LCA/GetReportSheetHeaderByLcaId/{LCAID}")]
|
|
public object GetReportSheetHeaderByLcaId(int LCAID)
|
|
{
|
|
object ret = new
|
|
{
|
|
SheetHeader = service.GetSheetHeader(LCAID, Categories.Report),
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
[Route("api/LCA/GetRiskAssmtLayoutSheetHeaderByLcaId/{LCAID}")]
|
|
public object GetRiskAssmtLayoutSheetHeaderByLcaId(int LCAID)
|
|
{
|
|
object ret = new
|
|
{
|
|
SheetHeader = service.GetSheetHeader(LCAID, Categories.RiskAssmtLayout),
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
/// <summary>
|
|
/// parentLCAID是否合法
|
|
/// </summary>
|
|
/// <param name="parentLCAID"></param>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/CkParentLcaId/{parentLCAID}")]
|
|
[HttpGet]
|
|
public string CkParentLcaId(int parentLCAID)
|
|
{
|
|
string re = "";
|
|
var list = db.LCAs.Where(x => x.ID == parentLCAID).ToList();
|
|
if (list != null && list.Count > 0)
|
|
{
|
|
var it = list.FirstOrDefault();
|
|
if (it.parentLCAID != null || it.parentLCAID > 0)
|
|
re = "該單號已設定為子系LCA盤查單號, 不可使用";
|
|
}
|
|
else
|
|
re = "父系LCA盤查單號不存在";
|
|
return re;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 匯入組織型所有功表的資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("api/LCA/ImportOrganizationAllData/{LCAID}")]
|
|
[HttpPost]
|
|
public HttpResponseMessage ImportAllData(int LCAID)
|
|
{
|
|
try
|
|
{
|
|
var httpRequest = HttpContext.Current.Request;
|
|
var ret = "";
|
|
if (httpRequest.Files.Count == 1)
|
|
{
|
|
var vm = new excelExportOrgLCAdataVM();
|
|
foreach (string file in httpRequest.Files)
|
|
{
|
|
//資料匯入
|
|
var postedFile = httpRequest.Files[file];
|
|
var excelImport = new excelImportLCAdataWrapper(postedFile.InputStream);
|
|
var err = excelImport.parsingExcel(ref vm);
|
|
if (err.Count > 0)
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Join("\r\n", err));
|
|
else
|
|
{
|
|
// 資料驗證
|
|
err.AddRange(service.ExcelImportCheckAndSave(LCAID, vm, out ImportOrganizationLCA importLCA));
|
|
if (err.Count > 0)
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Join("\r\n", err));
|
|
// 資料儲存
|
|
if (!service.SaveImportData(vm, importLCA, LCAID))
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "儲存失敗");
|
|
}
|
|
}
|
|
return Request.CreateResponse(HttpStatusCode.OK, "匯入成功");
|
|
}
|
|
else
|
|
{
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "請正確上傳檔案");
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
log.Error(ex);
|
|
log.Error(CScommon.Exceptions.inner(ex));
|
|
log.Error(ex.StackTrace);
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, CScommon.Exceptions.inner(ex));
|
|
}
|
|
}
|
|
}
|
|
} |