|
|
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.Data;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:配置管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 菜单业务处理类
|
|
|
/// </summary>
|
|
|
public class ModelPartService : BaseService<SysModel>, IModelPartService
|
|
|
{
|
|
|
private readonly IModelPartRepository repository;
|
|
|
|
|
|
public ModelPartService(IModelPartRepository _repository) : base(_repository)
|
|
|
{
|
|
|
repository = _repository;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="ModelPartName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getModelPartListByPage(string TypeName, string ModelName, string txtEnabled, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
string strWhere = " 1=1 ";
|
|
|
//if (!string.IsNullOrEmpty(part_no))
|
|
|
//{
|
|
|
// strWhere = " a.model_name LIKE '%" + part_no.Trim() + "%' ";
|
|
|
//}
|
|
|
if (!string.IsNullOrEmpty(TypeName))
|
|
|
{
|
|
|
strWhere += " and c.type_name = '" + TypeName.Trim() + "' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(ModelName))
|
|
|
{
|
|
|
strWhere += " and a.model_name = '" + ModelName.Trim() + "' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(txtEnabled))
|
|
|
{
|
|
|
strWhere += " and a.enabled = '" + txtEnabled.Trim() + "' ";
|
|
|
}
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(SysModel).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += " a." + typeof(SysModel).GetEntityColumnName("ModelId") + " " + direction;
|
|
|
}
|
|
|
result = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据(导出时使用)
|
|
|
/// </summary>
|
|
|
/// <param name="ModelPartName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getModelPartListByPage2(string TypeName, string ModelName, string txtEnabled, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
string strWhere = " 1=1 ";
|
|
|
if (!string.IsNullOrEmpty(TypeName))
|
|
|
{
|
|
|
strWhere += " and c.type_name = '" + TypeName.Trim() + "' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(ModelName))
|
|
|
{
|
|
|
strWhere += " and a.model_name = '" + ModelName.Trim() + "' ";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(txtEnabled))
|
|
|
{
|
|
|
strWhere += " and a.enabled = '" + txtEnabled.Trim() + "' ";
|
|
|
}
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(SysModel).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += " a." + typeof(SysModel).GetEntityColumnName("ModelId") + " " + direction;
|
|
|
}
|
|
|
return repository.getListByPage2(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveModelPart(SysModel htParams)
|
|
|
{
|
|
|
return repository.saveModelPart(htParams);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveModelPart_Sys_part(SysPart htParams)
|
|
|
{
|
|
|
return repository.saveModelPart_Sys_part(htParams);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新配置管理
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateModelPart(SysModel htParams)
|
|
|
{
|
|
|
return repository.updateModelPart(htParams);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新配置管理
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateModelPart_Sys_part(SysPart htParams)
|
|
|
{
|
|
|
return repository.updateModelPart_Sys_part(htParams);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看详情
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public List<SysModel> getModelPart(String model_id)
|
|
|
{
|
|
|
return repository.getList(model_id, "");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteModelPart(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.deleteModelPart(ids);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.EnableData(ids);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableData(String ids)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
return this.repository.DisableData(ids);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 变更状态
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int onState(String model_id, String enabled, string userID)
|
|
|
{
|
|
|
return this.repository.onState(model_id, enabled,userID);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 配置集合
|
|
|
/// </summary>
|
|
|
/// <returns>数据集</returns>
|
|
|
public List<KeyValueResult> GetModelName(string typeName)
|
|
|
{
|
|
|
return repository.GetModelName(typeName);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///车型集合
|
|
|
/// </summary>
|
|
|
/// <returns>数据集</returns>
|
|
|
public List<KeyValueResult> GetTypeName()
|
|
|
{
|
|
|
return repository.GetTypeName();
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
|
///// 变更状态
|
|
|
///// </summary>
|
|
|
///// <param name="ids"></param>
|
|
|
///// <returns></returns>
|
|
|
//public int deleteModelPart(String mode_id)
|
|
|
//{
|
|
|
// String[] idArray = mode_id.Split(',');
|
|
|
// int count = 0;
|
|
|
// foreach (String id in idArray)
|
|
|
// {
|
|
|
// if (!"".Equals(id))
|
|
|
// {
|
|
|
// count += this.repository.deleteModelPart(id);
|
|
|
// }
|
|
|
// }
|
|
|
// return count;
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框中的菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectModelPart()
|
|
|
{
|
|
|
return repository.getSelectModelPart();
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取文件并更新至数据库
|
|
|
/// </summary>
|
|
|
/// <param name="inputStream">文件全路径</param>
|
|
|
/// <param name="userInfo">登录用户信息</param>
|
|
|
public Hashtable ImportExcel(List<ModelPart> inputStream, int userId)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
Hashtable Cache = new Hashtable();
|
|
|
|
|
|
|
|
|
if (inputStream == null || inputStream.Count == 0)
|
|
|
{
|
|
|
result.Add("message", "导入数据为空,请重新导入");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
|
|
|
// 验证数据
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
{
|
|
|
string ModelName = inputStream[i].ModelName.ToString().Trim();
|
|
|
int ModelID = repository.GetModelID(ModelName);
|
|
|
int ModelTypeID = repository.GetModelTypeID(inputStream[i].TypeName.ToString().Trim());
|
|
|
|
|
|
if (ModelTypeID == 0)
|
|
|
{
|
|
|
result.Add("message", string.Format("车型 {0} 不存在,请检查数据后重新导入", inputStream[i].ModelType.ToString().Trim()));
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 处理表身数据
|
|
|
if (repository.InsertData(inputStream, userId.ToString()))
|
|
|
{
|
|
|
//勿删,重复导入目的是使sys_part表中的model_id和sys_model表中的model_id保持一致
|
|
|
repository.InsertData(inputStream, userId.ToString());
|
|
|
result.Add("message", "导入成功");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |