Commit acce1397 by zonevg

bug fix

parent c434458c
......@@ -228,8 +228,8 @@ namespace JunmpPoliceStation.Controllers
bool result = false;
if (polices.Count() > 0)
{
_unitOfWork.CabinetRepository.Delete(cabinets, false);
result = _unitOfWork.PolicemanRepository.Update(polices, true);
_unitOfWork.PolicemanRepository.Update(polices, false);
result = _unitOfWork.CabinetRepository.Delete(cabinets, true);
}
else
{
......
......@@ -14,8 +14,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using JunmpPoliceStation.Extensions;
namespace JunmpPoliceStation.Controllers
{
......@@ -26,13 +29,15 @@ namespace JunmpPoliceStation.Controllers
//private ICabinetRepository _CabinetRepository;
private ILogger<WarehouseController> _logger;
UnitOfWork _unitOfWork;
HttpHelper _httpHelper;
public List<BaseJpOrganization> ListEq = new List<BaseJpOrganization>();
public WarehouseController(ILogger<WarehouseController> logger, UnitOfWork unitOfWork)
public WarehouseController(ILogger<WarehouseController> logger, UnitOfWork unitOfWork, HttpHelper httpHelper)
{
_logger = logger;
//_CabinetRepository = CabinetRepository;
_unitOfWork = unitOfWork;
_httpHelper = httpHelper;
}
/// <summary>
......@@ -841,80 +846,166 @@ namespace JunmpPoliceStation.Controllers
{
return JsonManager.SimpleCustResponse($"OrgizationId is require");
}
else if (!string.IsNullOrEmpty(id))
{
Expression<Func<BaseJpWarehouse, bool>> expression = t => t.Id.Equals(id);
BaseJpWarehouse updateObject = _unitOfWork.WarehouseRepository.Get(expression);
if (updateObject != null)
{
updateObject.Name = entity.name;
updateObject.Location = entity.location;
updateObject.LocationDetail = entity.locationDetail;
updateObject.OrgizationId = entity.orgizationId;
updateObject.Phone = entity.phone;
updateObject.UpdateTime = System.DateTime.Now;
updateObject.UpdateUser = entity.updateUser;
updateObject.CameraUrl = entity.cameraUrl;
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
bool result = _unitOfWork.WarehouseRepository.Update(updateObject);
if (result)
{
return JsonManager.ReturnSuccessResponse(new
{
id = updateObject.Id,
name = updateObject.Name,
orgizationId = updateObject.OrgizationId,
location = updateObject.Location,
phone = updateObject.Phone,
cameraUrl= updateObject.CameraUrl
});
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else
using (var scope = _unitOfWork.BeginTransaction())
{
//新增数据
BaseJpWarehouse addObject = new BaseJpWarehouse()
{
Id = Guid.NewGuid().ToString(),
Sort = null,
Name = entity.name,
Location = entity.location,
LocationDetail = entity.locationDetail,
OrgizationId = entity.orgizationId,
Phone = entity.phone,
CreateTime = System.DateTime.Now,
UpdateTime = System.DateTime.Now,
UpdateUser = entity.updateUser,
CameraUrl = entity.cameraUrl
};
bool result = _unitOfWork.WarehouseRepository.Insert(addObject);
if (result)
try
{
return JsonManager.ReturnSuccessResponse(new
if (!string.IsNullOrEmpty(id))
{
id = addObject.Id,
name = addObject.Name,
orgizationId = addObject.OrgizationId,
location = addObject.Location,
phone = addObject.Phone,
cameraUrl = addObject.CameraUrl
});
Expression<Func<BaseJpWarehouse, bool>> expression = t => t.Id.Equals(id);
BaseJpWarehouse updateObject = _unitOfWork.WarehouseRepository.Get(expression);
if (updateObject != null)
{
updateObject.Name = entity.name;
updateObject.Location = entity.location;
updateObject.LocationDetail = entity.locationDetail;
updateObject.OrgizationId = entity.orgizationId;
updateObject.Phone = entity.phone;
updateObject.UpdateTime = System.DateTime.Now;
updateObject.UpdateUser = entity.updateUser;
updateObject.CameraUrl = entity.cameraUrl;
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
bool result = _unitOfWork.WarehouseRepository.Update(updateObject);
if (result)
{
//上报更新数据
var pushdata = new
{
id = updateObject.Id,
name = updateObject.Name,
location = updateObject.Location,
locationDetail = updateObject.LocationDetail,
orgizationId = updateObject.OrgizationId,
phone = updateObject.Phone,
updateUser = updateObject.UpdateUser,
cameraUrl = updateObject.CameraUrl,
};
var res = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Warehouse/AddOrUpdateWarehouse",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(pushdata)),
Timeout = 5000
});
if (res.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(res.Html))
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REMOTE_REPORTING_ERROR);
}
var obj = JsonConvert.DeserializeObject<dynamic>(res.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg ?? "操作失败");
}
scope.Commit();
return JsonManager.ReturnSuccessResponse(new
{
id = updateObject.Id,
name = updateObject.Name,
orgizationId = updateObject.OrgizationId,
location = updateObject.Location,
phone = updateObject.Phone,
cameraUrl = updateObject.CameraUrl
});
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else
{
//新增数据
BaseJpWarehouse addObject = new BaseJpWarehouse()
{
Id = Guid.NewGuid().ToString(),
Sort = null,
Name = entity.name,
Location = entity.location,
LocationDetail = entity.locationDetail,
OrgizationId = entity.orgizationId,
Phone = entity.phone,
CreateTime = System.DateTime.Now,
UpdateTime = System.DateTime.Now,
UpdateUser = entity.updateUser,
CameraUrl = entity.cameraUrl
};
bool result = _unitOfWork.WarehouseRepository.Insert(addObject);
if (result)
{
//上报新增数据
var pushdata = new
{
name = addObject.Name,
location = addObject.Location,
locationDetail = addObject.LocationDetail,
orgizationId = addObject.OrgizationId,
phone = addObject.Phone,
updateUser = addObject.UpdateUser,
cameraUrl = addObject.CameraUrl,
thirdWarehouseId = addObject.Id
};
var res = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Warehouse/AddOrUpdateWarehouse",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(pushdata)),
Timeout = 5000
});
if (res.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(res.Html))
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REMOTE_REPORTING_ERROR);
}
var obj = JsonConvert.DeserializeObject<dynamic>(res.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg ?? "操作失败");
}
scope.Commit();
return JsonManager.ReturnSuccessResponse(new
{
id = addObject.Id,
name = addObject.Name,
orgizationId = addObject.OrgizationId,
location = addObject.Location,
phone = addObject.Phone,
cameraUrl = addObject.CameraUrl
});
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
}
else
catch (Exception e)
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
scope.Rollback();
throw;
}
}
}
......@@ -1045,38 +1136,81 @@ namespace JunmpPoliceStation.Controllers
return JsonManager.SimpleCustResponse($"isDisabled is require");
}
BaseJpWarehouse warehouse = _unitOfWork.WarehouseRepository.Get(t => t.Id.Equals(id));
if (warehouse != null)
using (var scope = _unitOfWork.BeginTransaction())
{
if (isDisabled)
try
{
//停用
if (_unitOfWork.EquipmentInventoryRepository.Count(x => x.WarehouseCode == warehouse.Id) > 0)
BaseJpWarehouse warehouse = _unitOfWork.WarehouseRepository.Get(t => t.Id.Equals(id));
if (warehouse != null)
{
return JsonManager.SimpleCustResponse($"当前仓库存在装备,禁止停用");
if (isDisabled)
{
//停用
if (_unitOfWork.EquipmentInventoryRepository.Count(x => x.WarehouseCode == warehouse.Id) > 0)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"当前仓库存在装备,禁止停用");
}
warehouse.IsDisabled = true;
}
else
{
//启用
warehouse.IsDisabled = false;
}
if (_unitOfWork.WarehouseRepository.Update(warehouse))
{
//上报更新数据
var pushdata = new
{
id = warehouse.Id,
isDisabled = warehouse.IsDisabled,
};
var res = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Warehouse/DisabledWarehouse",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(pushdata)),
Timeout = 5000
});
if (res.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(res.Html))
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REMOTE_REPORTING_ERROR);
}
var obj = JsonConvert.DeserializeObject<dynamic>(res.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg ?? "操作失败");
}
scope.Commit();
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
warehouse.IsDisabled = true;
}
else
{
//启用
warehouse.IsDisabled = false;
}
if (_unitOfWork.WarehouseRepository.Update(warehouse))
{
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
catch (Exception e)
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
scope.Rollback();
throw;
}
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else
{
......
......@@ -468,7 +468,7 @@ namespace JunmpPoliceStation.Extensions
sign = body_result.Item2,
timestamp = body_result.Item3,
version = _apiVersion,
orgId = _organizationId,
orgId = "",
});
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论