|
|
using System.Collections;
|
|
|
using Estsh.Core.Util;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Dapper;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:库位管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
public class ZoneDefineService : BaseService<SysZone>, IZoneDefineService
|
|
|
{
|
|
|
private readonly IZoneDefineRepository repository;
|
|
|
public ZoneDefineService(IZoneDefineRepository _repository) : base(_repository)
|
|
|
{
|
|
|
repository = _repository;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="menuName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getZoneListByPage(string zoneName, string zoneDesc, string enabled, int factoryId, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (zoneName != null && !zoneName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and zone_name like '%" + zoneName.Trim() + "%'";
|
|
|
}
|
|
|
if (zoneDesc != null && !zoneDesc.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and zone_desc like '%" + zoneDesc.Trim() + "%'";
|
|
|
}
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.enabled like '%" + enabled + "%'";
|
|
|
}
|
|
|
strWhere += " and a.factory_id = " + factoryId + " ";
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(SysZone).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += typeof(SysZone).GetEntityColumnName("zoneId") + " " + direction;
|
|
|
}
|
|
|
|
|
|
result = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框中的菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectWarehouse(string factoryID)
|
|
|
{
|
|
|
return repository.getSelectWarehouse(factoryID);
|
|
|
}
|
|
|
|
|
|
public List<SysWarehouse> getSelectWarehouseInfo(string warehouseId)
|
|
|
{
|
|
|
return repository.getSelectWarehouseInfo(warehouseId);
|
|
|
}
|
|
|
|
|
|
public SysWarehouse getWarehouseByExistName(string warehouseName)
|
|
|
{
|
|
|
return repository.getWarehouseByExistName(warehouseName);
|
|
|
}
|
|
|
|
|
|
public SysZone getZoneByExistName(string zoneName)
|
|
|
{
|
|
|
return repository.getZoneByExistName(zoneName);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveZone(SysZone htParams)
|
|
|
{
|
|
|
return repository.saveZone(htParams);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateZone(SysZone htParams)
|
|
|
{
|
|
|
return repository.updateZone(htParams);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getZoneDetail(String zone_id)
|
|
|
{
|
|
|
zone_id = " zone_id = " + zone_id;
|
|
|
List<SysZone> dt = repository.getList(zone_id, "");
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("zoneId", dt[0].ZoneId);
|
|
|
result.Add("zoneName", dt[0].ZoneName);
|
|
|
result.Add("zoneDesc", dt[0].ZoneDesc);
|
|
|
|
|
|
result.Add("factoryId", dt[0].FactoryId);
|
|
|
|
|
|
result.Add("warehouseId", dt[0].WarehouseId);
|
|
|
result.Add("warehouseName", dt[0].WarehouseName);
|
|
|
result.Add("erpWarehouse", dt[0].ErpWarehouse);
|
|
|
result.Add("enabled", dt[0].Enabled);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteZone(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteZone(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableZone(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.EnableZone(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableZone(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.DisableZone(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
public List<ZoneDefine> getExportList(string zoneName, string zoneDesc, string enabled, int factoryId)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (zoneName != null && !zoneName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and zone_name like '%" + zoneName.Trim() + "%' ";
|
|
|
}
|
|
|
if (zoneDesc != null && !zoneDesc.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and zone_desc like '%" + zoneDesc.Trim() + "%' ";
|
|
|
}
|
|
|
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and enabled = '" + enabled.Trim() + "' ";
|
|
|
}
|
|
|
strWhere += " and factory_id = " + factoryId + " ";
|
|
|
String orderBy = " order by zone_name ";
|
|
|
|
|
|
return repository.getExportList(strWhere, orderBy);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导入
|
|
|
/// </summary>
|
|
|
public Hashtable ImportExcel(List<ZoneDefine> inputStream, int factoryId, string factoryCode, int empId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
List<string> SqlStrings = new List<string>();
|
|
|
List<DynamicParameters> Parameters = new List<DynamicParameters>();
|
|
|
|
|
|
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 ZoneName = inputStream[i].ZoneName.ToString();
|
|
|
ZoneDefine sysExemptions = repository.ifExistsZone(ZoneName);
|
|
|
if (sysExemptions == null)
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_zone ");
|
|
|
SqlStringBuilder.Append(" (zone_name,zone_desc ");
|
|
|
SqlStringBuilder.Append(" ,warehouse_id,warehouse_name ");
|
|
|
SqlStringBuilder.Append(" ,erp_warehouse,factory_id ");
|
|
|
SqlStringBuilder.Append(" ,factory_code,enabled ");
|
|
|
SqlStringBuilder.Append(" ,create_userid,create_time,guid) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@zoneName,@zoneDesc ");
|
|
|
SqlStringBuilder.Append(" ,@warehouseId,@warehouseName ");
|
|
|
SqlStringBuilder.Append(" ,@erpWarehouse,@factoryId ");
|
|
|
SqlStringBuilder.Append(" ,@factoryCode,@enabled ");
|
|
|
SqlStringBuilder.Append(" ,@createUserid,@createTime,@guid) ");
|
|
|
|
|
|
|
|
|
Params = new DynamicParameters();
|
|
|
Params.Add("@zoneName", ZoneName);
|
|
|
Params.Add("@zoneDesc", inputStream[i].ZoneDesc);
|
|
|
|
|
|
SysWarehouse sysWarehouse = repository.getWarehouseByExistName(inputStream[i].WarehouseName);
|
|
|
if (sysWarehouse != null)
|
|
|
{
|
|
|
Params.Add("@warehouseId", sysWarehouse.WarehouseId);
|
|
|
Params.Add("@warehouseName", sysWarehouse.WarehouseName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,仓库代码不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Params.Add("@erpWarehouse", inputStream[i].ErpWarehouse);
|
|
|
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"));
|
|
|
Params.Add("@guid",Guid.NewGuid().ToString());
|
|
|
SqlStrings.Add(SqlStringBuilder.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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |