You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

451 lines
22 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using ibk.IPD.Common;
using ibk.IPD.Entity;
using ibk.IPD.Entity.IPD_MR.HotRoll;
using ibk.IPD.Entity.IPD_MR.HotRoll.QueryArgs;
using log4net;
using SOA.Objects;
using SOA.Persistent;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
/********************************************************
* 简 介:南钢热轧制造规范管理
* 标准头表维护后端接口
* 版本号V1.0
* 日 期2022年04月22日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class StandardHeadController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 参数校验
/// </summary>
/// <param name="cncs"></param>
/// /// <param name="result"></param>
/// <returns>是否通过参数校验</returns>
public bool ParameterCalibration(QP_STD_HEAD cncs, RequestEntity result)
{
#region 参数判断
if (string.IsNullOrEmpty(cncs.STDSPEC) || cncs.STDSPEC.Length > 60)
{
result.msg = "标准号不可为空且长度不可超过60";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.STDSPEC_YY) ||!CommonUtils.IsNumber(cncs.STDSPEC_YY) || cncs.STDSPEC_YY.Length > 6)
{
result.msg = "标准号发布年度不可为空且长度不可超过6 或不是数字!";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_NAME_ENG))
if (cncs.STDSPEC_NAME_ENG.Length > 160)
{
result.msg = "标准名称(英文)长度不可超过160";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_NAME_CHN))
if (cncs.STDSPEC_NAME_CHN.Length > 100)
{
result.msg = "标准名称(中文)长度不可超过100";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_CHR_CD))
if (!"Y".Equals(cncs.STDSPEC_CHR_CD) && !"N".Equals(cncs.STDSPEC_CHR_CD))
{
result.msg = "是否在用 只能是 Y(是) 或 N(否) ";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.DEV_STD_CD))
if (cncs.DEV_STD_CD.Length > 30)
{
result.msg = "交付条件长度不可超过30";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.GRAVITY))
if (!CommonUtils.IsNumber(cncs.GRAVITY) || cncs.GRAVITY.Length > 4)
{
result.msg = "比重是长度不可超过4的数字";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_STLGRD))
if (cncs.STDSPEC_STLGRD.Length > 60)
{
result.msg = "打印钢种长度不可超过60";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.CERT_TYPE))
if (cncs.CERT_TYPE.Length > 1)
{
result.msg = "质保书类型长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_ORG_KND))
if (cncs.STDSPEC_ORG_KND.Length > 1)
{
result.msg = "打印标准编号长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_KND))
if (cncs.STDSPEC_KND.Length > 1)
{
result.msg = "标准种类长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.PAINTNUM))
if (!CommonUtils.IsNumber(cncs.PAINTNUM) || cncs.PAINTNUM.Length > 1)
{
result.msg = "标印次数是长度不可超过1的数字";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STDSPEC_STAMP))
if (cncs.STDSPEC_STAMP.Length > 60)
{
result.msg = "标印牌号长度不可超过60";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.GRAVITY_A))
if (!CommonUtils.IsNumber(cncs.GRAVITY_A) || cncs.GRAVITY_A.Length > 4)
{
result.msg = "比重基材是长度不可超过4的数字";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.GRAVITY_B))
if (!CommonUtils.IsNumber(cncs.GRAVITY_B) || cncs.GRAVITY_B.Length > 4)
{
result.msg = "比重覆材是长度不可超过4的数字";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.MAIN_CLASS_NO))
if (cncs.MAIN_CLASS_NO.Length > 1)
{
result.msg = "产品大类长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.SUB_CLASS_NO))
if (cncs.SUB_CLASS_NO.Length > 2)
{
result.msg = "产品细分类长度不可超过2";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.DEPART_NO))
if (cncs.DEPART_NO.Length > 1)
{
result.msg = "部门长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.GROUP_NO))
if (cncs.GROUP_NO.Length > 2)
{
result.msg = "课题组长度不可超过2";
result.code = "0";
return false;
}
return true;
#endregion
}
/// <summary>
/// 获取主键的条件
/// </summary>
/// <param name="primaryKeyEntity"></param>
/// <returns>AND 开头的 主键条件字符串</returns>
public string GetPrimaryKeyString(QP_STD_HEAD primaryKeyEntity)
{
StringBuilder strSql = new StringBuilder();
//if (!string.IsNullOrWhiteSpace(primaryKeyEntity.APLY_ITEM))
strSql.AppendLine(" AND STDSPEC = '" + primaryKeyEntity.STDSPEC + "'");
strSql.AppendLine(" AND STDSPEC_YY = '" + primaryKeyEntity.STDSPEC_YY + "'");
return strSql.ToString();
}
/// <summary>
/// 获取主键查询的sql
/// </summary>
/// <param name="checkEntity"></param>
/// <returns>主键查询sql</returns>
public string GetCheckString(QP_STD_HEAD checkEntity)
{
string strSql = "SELECT * FROM QP_STD_HEAD WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
return strSql;
}
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getStandardHead")]
public RequestEntity GetStandardHead(QpStdHeadQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询字段
//STDSPEC , STDSPEC_YY , STDSPEC_NAME_ENG , STDSPEC_NAME_CHN , STDSPEC_CHR_CD , DEV_STD_CD , GRAVITY , STDSPEC_STLGRD , CERT_TYPE , STDSPEC_ORG_KND , STDSPEC_KND , PAINTNUM , STDSPEC_STAMP , GRAVITY_A , GRAVITY_B , MAIN_CLASS_NO , SUB_CLASS_NO , DEPART_NO , GROUP_NO
strSql.AppendLine("SELECT STDSPEC , STDSPEC_YY , STDSPEC_NAME_ENG , STDSPEC_NAME_CHN , STDSPEC_CHR_CD , DEV_STD_CD , GRAVITY , STDSPEC_STLGRD , CERT_TYPE , STDSPEC_ORG_KND , STDSPEC_KND , PAINTNUM , STDSPEC_STAMP , GRAVITY_A , GRAVITY_B , MAIN_CLASS_NO , SUB_CLASS_NO , DEPART_NO , GROUP_NO ,TO_DATE(NVL(INS_DATE, '19910101') || NVL(INS_TIME, '000000'), 'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_TIME,INS_EMP , to_date(UPD_DATE || UPD_TIME ,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE, UPD_TIME,UPD_EMP FROM QP_STD_HEAD WHERE 1 = 1 ");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC)) strSql.AppendLine(" AND STDSPEC LIKE '%" + queryArgs.STDSPEC + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_YY)) strSql.AppendLine(" AND STDSPEC_YY LIKE '%" + queryArgs.STDSPEC_YY + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_NAME_ENG)) strSql.AppendLine(" AND STDSPEC_NAME_ENG LIKE '%" + queryArgs.STDSPEC_NAME_ENG + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_NAME_CHN)) strSql.AppendLine(" AND STDSPEC_NAME_CHN LIKE '%" + queryArgs.STDSPEC_NAME_CHN + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_CHR_CD)) strSql.AppendLine(" AND STDSPEC_CHR_CD LIKE '%" + queryArgs.STDSPEC_CHR_CD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.DEV_STD_CD)) strSql.AppendLine(" AND DEV_STD_CD LIKE '%" + queryArgs.DEV_STD_CD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_GRAVITY) && CommonUtils.IsNumber(queryArgs.START_GRAVITY)) strSql.AppendLine(" AND GRAVITY >=" + queryArgs.START_GRAVITY);
if (!string.IsNullOrWhiteSpace(queryArgs.END_GRAVITY) && CommonUtils.IsNumber(queryArgs.END_GRAVITY)) strSql.AppendLine(" AND GRAVITY <=" + queryArgs.END_GRAVITY);
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_STLGRD)) strSql.AppendLine(" AND STDSPEC_STLGRD LIKE '%" + queryArgs.STDSPEC_STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.CERT_TYPE)) strSql.AppendLine(" AND CERT_TYPE LIKE '%" + queryArgs.CERT_TYPE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_ORG_KND)) strSql.AppendLine(" AND STDSPEC_ORG_KND LIKE '%" + queryArgs.STDSPEC_ORG_KND + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_KND)) strSql.AppendLine(" AND STDSPEC_KND LIKE '%" + queryArgs.STDSPEC_KND + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_PAINTNUM) && CommonUtils.IsNumber(queryArgs.START_PAINTNUM)) strSql.AppendLine(" AND PAINTNUM >=" + queryArgs.START_PAINTNUM);
if (!string.IsNullOrWhiteSpace(queryArgs.END_PAINTNUM) && CommonUtils.IsNumber(queryArgs.END_PAINTNUM)) strSql.AppendLine(" AND PAINTNUM <=" + queryArgs.END_PAINTNUM);
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC_STAMP)) strSql.AppendLine(" AND STDSPEC_STAMP LIKE '%" + queryArgs.STDSPEC_STAMP + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_GRAVITY_A) && CommonUtils.IsNumber(queryArgs.START_GRAVITY_A)) strSql.AppendLine(" AND GRAVITY_A >=" + queryArgs.START_GRAVITY_A);
if (!string.IsNullOrWhiteSpace(queryArgs.END_GRAVITY_A) && CommonUtils.IsNumber(queryArgs.END_GRAVITY_A)) strSql.AppendLine(" AND GRAVITY_A <=" + queryArgs.END_GRAVITY_A);
if (!string.IsNullOrWhiteSpace(queryArgs.START_GRAVITY_B) && CommonUtils.IsNumber(queryArgs.START_GRAVITY_B)) strSql.AppendLine(" AND GRAVITY_B >=" + queryArgs.START_GRAVITY_B);
if (!string.IsNullOrWhiteSpace(queryArgs.END_GRAVITY_B) && CommonUtils.IsNumber(queryArgs.END_GRAVITY_B)) strSql.AppendLine(" AND GRAVITY_B <=" + queryArgs.END_GRAVITY_B);
if (!string.IsNullOrWhiteSpace(queryArgs.MAIN_CLASS_NO)) strSql.AppendLine(" AND MAIN_CLASS_NO LIKE '%" + queryArgs.MAIN_CLASS_NO + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.SUB_CLASS_NO)) strSql.AppendLine(" AND SUB_CLASS_NO LIKE '%" + queryArgs.SUB_CLASS_NO + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.DEPART_NO)) strSql.AppendLine(" AND DEPART_NO LIKE '%" + queryArgs.DEPART_NO + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.GROUP_NO)) strSql.AppendLine(" AND GROUP_NO LIKE '%" + queryArgs.GROUP_NO + "%'");
if (!string.IsNullOrWhiteSpace(CommonUtils.ObjectToStr(queryArgs.START_TIME)) && CommonUtils.ObjectToStr(queryArgs.START_TIME) != "0001/1/1 0:00:00") strSql.AppendLine(" AND to_date(INS_DATE ,'yyyy-mm-dd hh24:mi:ss') >= to_date('" + CommonUtils.ObjectToStr(queryArgs.START_TIME) + "','yyyy-mm-dd hh24:mi:ss')");
if (!string.IsNullOrWhiteSpace(CommonUtils.ObjectToStr(queryArgs.END_TIME)) && CommonUtils.ObjectToStr(queryArgs.END_TIME) != "0001/1/1 0:00:00") strSql.AppendLine(" AND to_date(INS_DATE ,'yyyy-mm-dd hh24:mi:ss') <= to_date('" + CommonUtils.ObjectToStr(queryArgs.END_TIME) + "','yyyy-mm-dd hh24:mi:ss')");
}
try
{
//开启数据库连接查询数据
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
strSql.AppendLine("Order By INS_DATE DESC ");
dtCheck = db.Query(strSql.ToString());
result.data = db.Query<QP_STD_HEAD>(strSql.ToString());
if (dtCheck.Rows.Count > 0)
{
result.msg = "操作成功!";
result.code = "1";
}
else
{
result.msg = "未找到查询所需数据!";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("GetStandardHead 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addStandardHead")]
public RequestEntity AddStandardHead(QP_STD_HEAD insertModel)
{
RequestEntity result = new RequestEntity();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
if (!ParameterCalibration(insertModel, result))
return result;
#endregion
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
insertModel.INS_TIME = dtNow.ToString("HHmmss");
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 执行主键重复查询
DataTable dtCheck = db.Query(GetCheckString(insertModel));
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "数据已存在,请确认后重试!";
result.code = "0";
return result;
}
if (db.Insert<QP_STD_HEAD>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddStandardHead 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updStandardHead")]
public RequestEntity UpdStandardHead(IList<QP_STD_HEAD> requestData)
{
RequestEntity result = new RequestEntity();
DataTable dtCheck = new DataTable();
DataTable dtCheckSelf = new DataTable();
StringBuilder strSql = new StringBuilder();
StringBuilder strSqlSelf = new StringBuilder();
DateTime dtNow = DateTime.Now;
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
#region 参数判断
if (!ParameterCalibration(requestData[1], result))
return result;
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 执行主键重复查询
dtCheck = db.Query(GetCheckString(requestData[1]));
dtCheckSelf = db.Query(GetCheckString(requestData[0]));
if (dtCheck.Rows.Count > 0 && !CommonUtils.CompareDataTable(dtCheck, dtCheckSelf)) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "主键数据已存在,请确认后重试!";
result.code = "0";
}
else
{
//更新哪些字段
//STDSPEC , STDSPEC_YY , STDSPEC_NAME_ENG , STDSPEC_NAME_CHN , STDSPEC_CHR_CD , DEV_STD_CD , GRAVITY , STDSPEC_STLGRD , CERT_TYPE , STDSPEC_ORG_KND , STDSPEC_KND ,
//PAINTNUM , STDSPEC_STAMP , GRAVITY_A , GRAVITY_B , MAIN_CLASS_NO , SUB_CLASS_NO , DEPART_NO , GROUP_NO
if (db.Execute("UPDATE QP_STD_HEAD SET " + string.Format(" STDSPEC = '{0}' , STDSPEC_YY = '{1}' , STDSPEC_NAME_ENG = '{2}' , STDSPEC_NAME_CHN = '{3}' , STDSPEC_CHR_CD = '{4}',DEV_STD_CD = '{5}',GRAVITY = '{6}', STDSPEC_STLGRD = '{7}', CERT_TYPE = '{8}', STDSPEC_ORG_KND = '{9}', STDSPEC_KND = '{10}' " +
", PAINTNUM = '{11}' , STDSPEC_STAMP = '{12}' , GRAVITY_A = '{13}' , GRAVITY_B = '{14}' , MAIN_CLASS_NO = '{15}' , SUB_CLASS_NO = '{16}' , DEPART_NO = '{17}' , GROUP_NO = '{18}' , UPD_DATE = '{19}' , UPD_TIME='{20}',UPD_EMP = '{21}' WHERE 1 = 1 ",
requestData[1].STDSPEC, requestData[1].STDSPEC_YY, requestData[1].STDSPEC_NAME_ENG, requestData[1].STDSPEC_NAME_CHN, requestData[1].STDSPEC_CHR_CD, requestData[1].DEV_STD_CD, requestData[1].GRAVITY, requestData[1].STDSPEC_STLGRD, requestData[1].CERT_TYPE, requestData[1].STDSPEC_ORG_KND, requestData[1].STDSPEC_KND,
requestData[1].PAINTNUM, requestData[1].STDSPEC_STAMP, requestData[1].GRAVITY_A, requestData[1].GRAVITY_B, requestData[1].MAIN_CLASS_NO, requestData[1].SUB_CLASS_NO, requestData[1].DEPART_NO, requestData[1].GROUP_NO, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
GetPrimaryKeyString(requestData[0])) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
}
return result;
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdStandardHead 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delStandardHead")]
public RequestEntity DelStandardHead(QP_STD_HEAD delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
strSql.AppendLine("DELETE FROM QP_STD_HEAD WHERE 1=1 ");
strSql.AppendLine(GetPrimaryKeyString(delModel));
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.Execute(strSql.ToString()); // 执行删除数据操作
result.msg = "操作成功";
result.code = "1";
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("DelStandardHead 报错", ex);
}
return result;
}
}
}