using Dapper;
using Estsh.Core.Dapper;
using Estsh.Core.Model.ExcelModel;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Repository.IRepositories;
using Estsh.Core.Services.IServices;
using Estsh.Core.Util;
using System.Collections;
using System.Text;
/***************************************************************************************************
*
* 更新人:sitong.dong
* 描述:零件免检清单模块Service类
* 修改时间:2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Services
{
///
/// 菜单业务处理类
///
public class PartExemptionListDefineService : BaseService, IPartExemptionListDefineService
{
private readonly IPartExemptionListDefineRepository repository;
public PartExemptionListDefineService(IPartExemptionListDefineRepository _repository) : base(_repository)
{
repository = _repository;
}
///
/// 根据分页条件获取分页菜单数据
///
///
///
///
///
///
public Hashtable GetListByPage(String part_no, String partSpec, Pager pager, String direction, String sort, String enabled)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (part_no != null && !part_no.Trim().Equals(""))
{
strWhere += " and b.part_no like '%" + part_no.Trim() + "%'";
}
if (partSpec != null && !partSpec.Trim().Equals(""))
{
strWhere += " and b.part_spec like '%" + partSpec.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " and b.enabled = '" + enabled + "'";
}
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += " b." + typeof(SysPart).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += " b." + typeof(SysPart).GetEntityColumnName("PartId") + " " + direction;
}
result = repository.GetListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
return result;
}
///
/// 获取下拉框中的菜单数据
///
///
public List GetSelect()
{
return repository.GetSelect();
}
///
/// 查看菜单详情
///
///
///
public List GetDetail(String part_id)
{
part_id = " a.part_id = " + part_id;
return repository.GetList(part_id, "");
}
///
/// 查看零件详情
///
/// 零件ID
///
public List GetDetailByName(String part_no)
{
part_no = "part_no = '" + part_no + "' ";
List dt = repository.GetListFromPart(part_no);
return dt;
}
public List ifExemptionList(String part_no)
{
return repository.ifExemptionList(part_no);
}
//导出查询
public List getExportList(String partNo, String enabled)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (partNo != null && !partNo.Trim().Equals(""))
{
strWhere += " and part_no like '%" + partNo.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " and enabled = '" + enabled + "'";
}
String orderBy = " order by part_no ";
return repository.getExportList(strWhere, orderBy);
}
///
/// 导入零件免检
///
public Hashtable ImportExcel(List inputStream, int factoryId, string factoryCode, int empId)
{
try
{
Hashtable result = new Hashtable();
List SqlStrings = new List();
List Parameters = new List();
DynamicParameters Params = new DynamicParameters();
//判断EXCEL是否存在数据
if (inputStream == null || inputStream.Count == 0)
{
result.Add("message", "导入数据为空,请重新导入!");
result.Add("flag", "error");
return result;
}
this.repository.DeleteAll();//清空免检清单列表
//判断零件号是否存在
for (int i = 0; i < inputStream.Count; i++)
{
string partNo = inputStream[i].PartNo.ToString();
List sysExemptions = repository.ifExemptionList(partNo);
if (sysExemptions.Count <= 0)
{
StringBuilder querySen = new StringBuilder(1024);
querySen.AppendLine("INSERT INTO dbo.sys_exemption_list ");
querySen.AppendLine(" ( part_id , ");
querySen.AppendLine(" part_no , ");
querySen.AppendLine(" enabled , ");
querySen.AppendLine(" factory_id , ");
querySen.AppendLine(" factory_code , ");
querySen.AppendLine(" create_userid , ");
querySen.AppendLine(" create_time ");
querySen.AppendLine(" ) ");
querySen.AppendLine("VALUES ( @partId ,");
querySen.AppendLine(" @partNo,");
querySen.AppendLine(" @enabled,");
querySen.AppendLine(" @factoryId ,");
querySen.AppendLine(" @factoryCode ,");
querySen.AppendLine(" @createUserid,");
querySen.AppendLine(" @createTime");
querySen.AppendLine(" ) ");
Params = new DynamicParameters();
List dtPart = repository.ifPartNo(inputStream[i].PartNo);
if (dtPart.Count > 0)
{
Params.Add("@partId", dtPart[0].PartId);
Params.Add("@partNo", dtPart[0].PartNo);
}
else
{
result.Add("message", "导入失败,零件号不存在,请检查");
result.Add("flag", "error");
return result;
}
Params.Add("@enabled", "Y");
Params.Add("@factoryId", factoryId);
Params.Add("@factoryCode", factoryCode);
Params.Add("@createUserid", empId);
Params.Add("@createTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
SqlStrings.Add(querySen.ToString());
Parameters.Add(Params);
}
}
if (repository.InsertData(SqlStrings, Parameters))
{
result.Add("message", "导入成功");
result.Add("flag", "OK");
}
else
{
result.Add("message", "导入失败");
result.Add("flag", "error");
}
return result;
}
catch (Exception ex)
{
Hashtable result = new Hashtable();
result.Add("message", "导入失败");
result.Add("flag", "error");
return result;
}
}
///
/// 保存菜单数据
///
///
///
public int Insert(SysExemptionList htParams)
{
return repository.Insert(htParams);
}
///
/// 更新菜单数据
///
///
///
public int Update(SysExemptionList htParams)
{
return repository.Update(htParams);
}
///
/// 删除菜单
///
///
///
public int Delete(String ids)
{
String[] idArray = ids.Split(',');
int count = 0;
foreach (String id in idArray)
{
if (!"".Equals(id))
{
count += this.repository.Delete(id);
}
}
return count;
}
///
/// 启用
///
///
///
public int EnableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.EnableData(ids);
}
///
/// 禁用
///
///
///
public int DisableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.DisableData(ids);
}
}
}