using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace Mvc.Controllers
{
///
/// 质量共检
///
public class JointCheckController : ApiController
{
///
/// 质量共检
///
///
///
///
///
///
[HttpGet]
public ResponseData> Index(string projectId, int index, int page, string name = null)
{
ResponseData> res = new ResponseData>();
res.successful = true;
res.resultValue = BLL.JointCheckService.GetListDataForApi(name, projectId, index, page);
return res;
}
[HttpGet]
public ResponseData> Search(string projectId, int index, int page, string name = null, string code = null, string unitId = null, string proposeUnitId = null, string type = null, string dateA = null, string dateZ = null, string state = null)
{
ResponseData> res = new ResponseData>();
res.successful = true;
res.resultValue = BLL.JointCheckService.GetListDataForApi(name, code, unitId, proposeUnitId, type, dateA, dateZ, projectId, state, index, page);
return res;
}
//
// 质量共检
// GET: /Draw/
[HttpGet]
public ResponseData GetJointCheck(string id)
{
ResponseData res = new ResponseData();
Check_JointCheck jc = BLL.JointCheckService.GetJointCheckForApi(id);
res.successful = true;
res.resultValue = BeanUtil.CopyOjbect(jc, true);
return res;
}
[HttpGet]
public ResponseData> GetApproveByJcid(string id, string detailId)
{
ResponseData> res = new ResponseData>();
res.successful = true;
res.resultValue = BLL.JointCheckApproveService.getListDataByJcidForApi(id, detailId);
return res;
}
[HttpGet]
public ResponseData getCurrApproveByDetailId(string id)
{
ResponseData res = new ResponseData();
res.successful = true;
res.resultValue = BeanUtil.CopyOjbect(BLL.JointCheckApproveService.getCurrApproveByDetailIdForApi(id), true);
return res;
}
[HttpGet]
public ResponseData> GetCurrApproveById(string id)
{
ResponseData> res = new ResponseData>();
res.successful = true;
res.resultValue = BLL.JointCheckApproveService.getCurrApproveForApi(id);
return res;
}
[HttpGet]
public ResponseData GetCurrApproveByJoinCheckId(string id)
{
ResponseData res = new ResponseData();
res.successful = true;
res.resultValue = BLL.JointCheckApproveService.getCurrApproveByJoinCheckIdForApi(id);
return res;
}
[HttpGet]
public ResponseData> GetJointCheckDetail(string id)
{
ResponseData> res = new ResponseData>();
res.successful = true;
res.resultValue = BLL.JointCheckDetailService.getListDataForApi(id);
return res;
}
[HttpGet]
public ResponseData delJointCheckDetail(string id)
{
ResponseData res = new ResponseData();
res.successful = true;
BLL.JointCheckDetailService.DeleteJointCheckDetailById(id);
res.resultValue = id;
return res;
}
[HttpPost]
public ResponseData AddJointCheckDetail([FromBody] Model.Check_JointCheckDetail CheckControl)
{
ResponseData res = new ResponseData();
try
{
if (string.IsNullOrEmpty(CheckControl.JointCheckDetailId))
{
CheckControl.JointCheckDetailId = Guid.NewGuid().ToString();
CheckControl.CreateDate = DateTime.Now;
BLL.JointCheckDetailService.AddJointCheckDetailForApi(CheckControl);
//BLL.AttachFileService.updateAttachFile(CheckControl.ReAttachUrl, CheckControl.JointCheckDetailId + "r", Const.JointCheckMenuId);
//BLL.AttachFileService.updateAttachFile(CheckControl.AttachUrl, CheckControl.JointCheckDetailId, Const.JointCheckMenuId);
SaveAttachFile(CheckControl.JointCheckDetailId + "r", BLL.Const.JointCheckMenuId, CheckControl.ReAttachUrl);
SaveAttachFile(CheckControl.JointCheckDetailId, BLL.Const.JointCheckMenuId, CheckControl.AttachUrl);
res.resultValue = CheckControl.JointCheckDetailId;
res.successful = true;
}
else
{
BLL.JointCheckDetailService.UpdateJointCheckDetailForApi(CheckControl);
res.resultValue = CheckControl.JointCheckDetailId;
//BLL.AttachFileService.updateAttachFile(CheckControl.ReAttachUrl, CheckControl.JointCheckDetailId + "r", Const.JointCheckMenuId);
//BLL.AttachFileService.updateAttachFile(CheckControl.AttachUrl, CheckControl.JointCheckDetailId, Const.JointCheckMenuId);
SaveAttachFile(CheckControl.JointCheckDetailId + "r", BLL.Const.JointCheckMenuId, CheckControl.ReAttachUrl);
SaveAttachFile(CheckControl.JointCheckDetailId, BLL.Const.JointCheckMenuId, CheckControl.AttachUrl);
res.successful = true;
}
}
catch (Exception e)
{
res.resultHint = e.StackTrace;
res.successful = false;
}
return res;
}
///
///
///
public static void SaveAttachFile(string dataId, string menuId, string url)
{
Model.ToDoItem toDoItem = new Model.ToDoItem
{
MenuId = menuId,
DataId = dataId,
UrlStr = url,
};
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
[HttpPost]
// 共检--添加
public ResponseData AddJointCheck([FromBody] Model.Check_JointCheck CheckControl)
{
ResponseData res = new ResponseData();
try
{
if (string.IsNullOrEmpty(CheckControl.JointCheckId))
{
var project = BLL.ProjectService.GetProjectByProjectId(CheckControl.ProjectId);
string projectCode = string.Empty;
string prefix = string.Empty;
if (project != null)
{
projectCode = project.ProjectCode;
}
prefix = projectCode + "-GJ-";
CheckControl.JointCheckCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode3", "dbo.Check_JointCheck", "JointCheckCode", prefix);
CheckControl.JointCheckId = Guid.NewGuid().ToString();
BLL.JointCheckService.AddJointCheckForApi(CheckControl);
res.resultValue = CheckControl.JointCheckId;
}
else
{
BLL.JointCheckService.UpdateJointCheckForApi(CheckControl);
res.resultValue = CheckControl.JointCheckId;
}
}
catch (Exception e)
{
res.successful = false;
}
res.successful = true;
return res;
}
[HttpPost]
public ResponseData AddApprove([FromBody] Model.Check_JointCheckApprove approve)
{
ResponseData res = new ResponseData();
try
{
//Model.Check_JointCheck CheckControl = new Model.Check_JointCheck();
//CheckControl.JointCheckId = approve.JointCheckId;
//CheckControl.State = approve.ApproveType;
//BLL.JointCheckService.UpdateJointCheckForApi(CheckControl);
Check_JointCheckDetail joinCheckDetail = new Check_JointCheckDetail();// BLL.JointCheckDetailService.GetJointCheckDetailByJointCheckDetailIdForApi(approve.JointCheckDetailId);
joinCheckDetail.State = approve.ApproveType;
joinCheckDetail.HandleMan = approve.ApproveMan;
joinCheckDetail.SaveHandleMan = "";
joinCheckDetail.JointCheckDetailId = approve.JointCheckDetailId;
BLL.JointCheckDetailService.UpdateJointCheckDetailForApi(joinCheckDetail);
var joinCheckDetailList = BLL.JointCheckDetailService.GetListsForApi(approve.JointCheckId);
bool isFinished = true;
bool isEditing = true;
foreach (var item in joinCheckDetailList)
{
if ("6" != item.State) isFinished = false;
if ("1" != item.State) isEditing = false;
}
var joinCheck = BLL.JointCheckService.GetJointCheckForApi(approve.JointCheckId);
Check_JointCheck cj = new Check_JointCheck();
cj.JointCheckId = joinCheck.JointCheckId;
if (approve.ApproveType != "1")
{
if (isFinished)
{
cj.State = "6";
}
else if (isEditing)
{
cj.State = "1";
}
else
{
cj.State = "Z";
}
BLL.JointCheckService.UpdateJointCheckForApi(cj);
}
else
{
cj.State = "1";
BLL.JointCheckService.UpdateJointCheckForApi(cj);
}
res.resultValue = BLL.JointCheckApproveService.AddJointCheckApproveForApi(approve);
}
catch (Exception e)
{
res.successful = false;
res.resultValue = e.Message;
}
res.successful = true;
return res;
}
[HttpPost]
public ResponseData UpdateApprove([FromBody] Model.Check_JointCheckApprove approve)
{
ResponseData res = new ResponseData();
try
{
approve.ApproveDate = DateTime.Now;
var resApprove = BLL.JointCheckApproveService.UpdateJointCheckApproveForApi(approve);
if (approve.ApproveType == "1")
{
var jointCheck = BLL.JointCheckService.GetJointCheckForApi(resApprove.JointCheckId);
var jointCheckDetails = BLL.JointCheckDetailService.getListDataForApi(resApprove.JointCheckId);
List seeUsers = new List();
foreach (var a in jointCheckDetails)
{
a.JointCheckId = approve.JointCheckId;
if (string.IsNullOrEmpty(approve.JointCheckId))
{
seeUsers.AddRange(SitePerson_PersonService.GetSeeUserList2(jointCheck.ProjectId, jointCheck.UnitId, a.CNProfessionalCode, a.UnitWorkId.ToString(), approve.ApproveMan, string.Empty));
}
}
if (string.IsNullOrEmpty(approve.JointCheckId))
{
seeUsers = seeUsers.Distinct().ToList();
foreach (var seeUser in seeUsers)
{
Model.Check_JointCheckApprove approves = new Model.Check_JointCheckApprove
{
JointCheckId = approve.JointCheckId,
ApproveMan = seeUser.PersonId,
ApproveType = "S"
};
BLL.JointCheckApproveService.AddJointCheckApproveForApi(approve);
}
}
}
}
catch (Exception e)
{
res.successful = false;
}
res.successful = true;
return res;
}
[HttpGet]
public ResponseData see(string dataId, string userId)
{
ResponseData res = new ResponseData();
res.successful = true;
BLL.JointCheckApproveService.See(dataId, userId);
return res;
}
}
}