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 * 描述:支给件维护 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Services { /// /// 菜单业务处理类 /// public class SupportingCustomerService : BaseService, ISupportingCustomerService { private readonly ISupportingCustomerRepository repository; public SupportingCustomerService(ISupportingCustomerRepository _repository) : base(_repository) { repository = _repository; } /// /// 根据分页条件获取分页菜单数据 /// /// /// /// /// /// public Hashtable GetListByPage(String customerNo, String hzCustomerNo, String partSpec, Pager pager, String direction, String sort, String enabled) { Hashtable result = new Hashtable(); String strWhere = " 1=1 "; if (customerNo != null && !customerNo.Trim().Equals("")) { strWhere += " and customer_no like '%" + customerNo.Trim() + "%'"; } if (hzCustomerNo != null && !hzCustomerNo.Trim().Equals("")) { strWhere += " and hz_customer_no like '%" + hzCustomerNo.Trim() + "%'"; } if (partSpec != null && !partSpec.Trim().Equals("")) { strWhere += " and part_spec like '%" + partSpec.Trim() + "%'"; } if (enabled != null && !enabled.Trim().Equals("")) { strWhere += " and enabled = '" + enabled + "'"; } String orderBy = ""; if (sort != null && !"".Equals(sort.Trim())) { orderBy += " " + typeof(WmsCustomerToStock).GetEntityColumnName(sort.Trim()) + " " + direction; } else { orderBy += " " + typeof(WmsCustomerToStock).GetEntityColumnName("ruid") + " " + direction; } result = repository.GetListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy); return result; } /// /// 获取下拉框中的菜单数据 /// /// public List GetSelect() { return repository.GetSelect(); } /// /// 查看零件详情 /// /// 零件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 ruid) { return repository.ifExemptionList(ruid); } public List ifExemptionList(String customerPart, String partNo) { return repository.ifExemptionList(customerPart, partNo); } //导出查询 public List getExportList(String customerNo, String enabled) { Hashtable result = new Hashtable(); String strWhere = " 1=1 "; if (customerNo != null && !customerNo.Trim().Equals("")) { strWhere += " and customer_no like '%" + customerNo.Trim() + "%'"; } if (enabled != null && !enabled.Trim().Equals("")) { strWhere += " and enabled = '" + enabled + "'"; } String orderBy = " order by customer_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; } //判断零件号是否存在 for (int i = 0; i < inputStream.Count; i++) { string CustomerNo = inputStream[i].CustomerNo.ToString(); string HzCustomerNo = inputStream[i].HzCustomerNo.ToString(); string partSpec = inputStream[i].partSpec.ToString(); string partSpec2 = inputStream[i].partSpec2.ToString(); if (CustomerNo.Trim() == "" || HzCustomerNo.Trim() == "") { result.Add("message", "导入失败,第" + (i+1) + "行不能为空"); result.Add("flag", "error"); } List sysExemptions = repository.ifExemptionList(CustomerNo, HzCustomerNo); if (sysExemptions.Count <= 0) { StringBuilder querySen = new StringBuilder(1024); querySen.AppendLine("INSERT INTO dbo.wms_customer_to_supplier "); querySen.AppendLine(" ( customer_no , "); querySen.AppendLine(" hz_customer_id , "); querySen.AppendLine(" hz_customer_no , "); querySen.AppendLine(" part_spec , "); querySen.AppendLine(" part_spec2 , "); querySen.AppendLine(" enabled , "); querySen.AppendLine(" factory_id , "); querySen.AppendLine(" factory_code , "); querySen.AppendLine(" create_userid , "); querySen.AppendLine(" create_time "); querySen.AppendLine(" ) "); querySen.AppendLine("VALUES ( @customer_no ,"); querySen.AppendLine(" @hz_customer_id , "); querySen.AppendLine(" @hz_customer_no,"); querySen.AppendLine(" @partSpec,"); querySen.AppendLine(" @partSpec2,"); querySen.AppendLine(" @enabled,"); querySen.AppendLine(" @factoryId ,"); querySen.AppendLine(" @factoryCode ,"); querySen.AppendLine(" @createUserid,"); querySen.AppendLine(" @createTime"); querySen.AppendLine(" ) "); Params = new DynamicParameters(); Params.Add("@customer_no", CustomerNo); Params.Add("@hz_customer_id", ""); Params.Add("@hz_customer_no", HzCustomerNo); Params.Add("@partSpec", partSpec); Params.Add("@partSpec2", partSpec2); 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); } else { StringBuilder querySen = new StringBuilder(1024); querySen.AppendLine("update dbo.wms_customer_to_supplier set "); querySen.AppendLine(" part_spec=@partSpec , part_spec2=@partSpec2 "); querySen.AppendLine(" where customer_no=@customer_no and hz_customer_no=@hz_customer_no"); Params = new DynamicParameters(); Params.Add("@customer_no", CustomerNo); Params.Add("@hz_customer_no", HzCustomerNo); Params.Add("@partSpec", partSpec); Params.Add("@partSpec2", partSpec2); 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(WmsCustomerToSupplier htParams) { return repository.Insert(htParams); } /// /// 更新菜单数据 /// /// /// public int Update(WmsCustomerToSupplier htParams) { return repository.Update(htParams); } /// /// 启用 /// /// /// 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); } } }