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 { /// /// 菜单业务处理类 /// public class ModelPartService : BaseService, IModelPartService { private readonly IModelPartRepository repository; public ModelPartService(IModelPartRepository _repository) : base(_repository) { repository = _repository; } /// /// 根据分页条件获取分页菜单数据 /// /// /// /// /// /// 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; } /// /// 根据分页条件获取分页菜单数据(导出时使用) /// /// /// /// /// /// 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); } /// /// 保存菜单数据 /// /// /// public int saveModelPart(SysModel htParams) { return repository.saveModelPart(htParams); } /// /// 保存菜单数据 /// /// /// public int saveModelPart_Sys_part(SysPart htParams) { return repository.saveModelPart_Sys_part(htParams); } /// /// 更新配置管理 /// /// /// public int updateModelPart(SysModel htParams) { return repository.updateModelPart(htParams); } /// /// 更新配置管理 /// /// /// public int updateModelPart_Sys_part(SysPart htParams) { return repository.updateModelPart_Sys_part(htParams); } /// /// 查看详情 /// /// /// public List getModelPart(String model_id) { return repository.getList(model_id, ""); } /// /// 删除菜单 /// /// /// public int deleteModelPart(String ids) { ids = ids.Substring(0, ids.Length - 1); return this.repository.deleteModelPart(ids); } /// /// 启用 /// /// /// 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); } /// /// 变更状态 /// /// /// public int onState(String model_id, String enabled, string userID) { return this.repository.onState(model_id, enabled,userID); } /// /// 配置集合 /// /// 数据集 public List GetModelName(string typeName) { return repository.GetModelName(typeName); } /// ///车型集合 /// /// 数据集 public List GetTypeName() { return repository.GetTypeName(); } ///// ///// 变更状态 ///// ///// ///// //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; //} /// /// 获取下拉框中的菜单数据 /// /// public List getSelectModelPart() { return repository.getSelectModelPart(); } /// /// 读取文件并更新至数据库 /// /// 文件全路径 /// 登录用户信息 public Hashtable ImportExcel(List 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; } } } }