1
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using BLL;
|
||||
using Model;
|
||||
|
||||
namespace WebAPI.Controllers.DataPenetrate
|
||||
{
|
||||
/// <summary>
|
||||
/// 项目控制器
|
||||
/// </summary>
|
||||
public class ProjectPenetrateController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据项目名称模糊查询项目信息
|
||||
/// </summary>
|
||||
/// <param name="projectName"></param>
|
||||
/// <returns></returns>
|
||||
public Model.ResponeData getInfoByProjectName(string projectName = "")
|
||||
{
|
||||
var responeData = new Model.ResponeData();
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(projectName))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目名称不能为空";
|
||||
return responeData;
|
||||
}
|
||||
var getDataList = Funs.DB.Base_Project.Where(x => x.ProjectName.Contains(projectName))
|
||||
.Select(s => new newBase_Project() {
|
||||
ProjectId = s.ProjectId,
|
||||
ProjectName = s.ProjectName,
|
||||
UnitId = s.UnitId,
|
||||
ProjectCode = s.ProjectCode
|
||||
}).ToList();
|
||||
responeData.data = new { getDataList };
|
||||
if (getDataList.Count == 0)
|
||||
{
|
||||
responeData.code = 1;
|
||||
responeData.message = "根据条件未查询到数据。";
|
||||
return responeData;
|
||||
}
|
||||
else {
|
||||
responeData.code = 0;
|
||||
responeData.message = "查询成功。";
|
||||
return responeData;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = ex.Message;
|
||||
}
|
||||
|
||||
return responeData;
|
||||
}
|
||||
|
||||
public class newBase_Project {
|
||||
public string ProjectId { get; set; }
|
||||
public string ProjectName { get; set; }
|
||||
public string UnitId { get; set; }
|
||||
public string ProjectCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加项目
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public Model.ResponeData saveProject([FromBody] Base_ProjectDto dto)
|
||||
{
|
||||
using (var db = new Model.SUBQHSEDB(Funs.ConnString))
|
||||
{
|
||||
var responeData = new Model.ResponeData();
|
||||
var mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<Base_ProjectDto, Model.Base_Project>();
|
||||
var model = mapper.Map(dto);
|
||||
|
||||
#region 判断是否未填
|
||||
if (string.IsNullOrEmpty(model.ProjectName))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目名称(ProjectName)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ProjectAttribute))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目属性(ProjectAttribute)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ProjectCode))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目编号(ProjectCode)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ShortName))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目简称(ShortName)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.UnitId))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "所属单位(UnitId)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
else
|
||||
{
|
||||
//判断userid是否有数据
|
||||
var umodel = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitName == model.UnitId);
|
||||
if (umodel == null)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "所属单位名称未查询到数据,请检查是否正确。";
|
||||
return responeData;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.UnitId = umodel.UnitId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(model.ProjectState))
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目状态(ProjectState)不能为空";
|
||||
return responeData;
|
||||
}
|
||||
|
||||
var oldProject1 = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId != (model.ProjectId ?? "") && x.ProjectCode == model.ProjectCode);
|
||||
if (oldProject1 != null)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目编号已存在";
|
||||
return responeData;
|
||||
}
|
||||
var oldProject2 = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId != (model.ProjectId ?? "") && x.ProjectName == model.ProjectName);
|
||||
if (oldProject2 != null)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "项目名称已存在";
|
||||
return responeData;
|
||||
}
|
||||
#endregion
|
||||
|
||||
try
|
||||
{
|
||||
model.ProjectId = SQLHelper.GetNewID(); ;
|
||||
ProjectService.AddProject(model);
|
||||
// 初始化焊接环境变量设置
|
||||
BLL.Project_SysSetService.InsertHjglInit(model.ProjectId);
|
||||
responeData.message = "操作成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = ex.Message;
|
||||
}
|
||||
return responeData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user