using OASystem.Infrastructure.Repositories.System;
namespace OASystem.API.Controllers
{
///
/// 资料相关
///
//[Authorize]
[Route("api/[controller]/[action]")]
public class ResourceController : ControllerBase
{
private readonly IMapper _mapper;
private readonly IConfiguration _config;
private readonly CarDataRepository _carDataRep;
private readonly LocalGuideDataRepository _localGuideDataRep;
private readonly ThreeCodeRepository _ThreeCodeRep;
private readonly HotelDataRepository _hotelDataRep;
private readonly ResItemInfoRepository _resItemInfoRep;
private readonly SetDataRepository _setDataRepository;
private readonly CountryFeeRepository _countryFeeRep;
private readonly SetDataTypeRepository _setDataTypeRep;
public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep,
LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep,
HotelDataRepository hotelDataRep, ResItemInfoRepository resItemInfoRep, SetDataRepository setDataRepository,
CountryFeeRepository countryFeeRep, SetDataTypeRepository setDataTypeRep)
{
_mapper = mapper;
_config = config;
_carDataRep = carDataRep;
_localGuideDataRep = localGuideDataRep;
_ThreeCodeRep = threeCodeRep;
_hotelDataRep = hotelDataRep;
_resItemInfoRep = resItemInfoRep;
_setDataRepository = setDataRepository;
_countryFeeRep = countryFeeRep;
_setDataTypeRep = setDataTypeRep;
}
#region 数据类型资料
///
/// 根据类型查询数据
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QuerySetData(SetDataDto dto)
{
try
{
if (dto.DataType == 0)
{
return Ok(JsonView(false, "请传类型Id!"));
}
var setData = _setDataRepository.QueryDto(s => s.STid == dto.DataType).ToList();
if (setData.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
return Ok(JsonView(true, "查询成功!", setData));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 数据类型大全
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QuerySetDataType(DtoBase dto)
{
try
{
var setDataType = _setDataTypeRep.QueryDto().ToList();
if (setDataType.Count==0)
{
return Ok(JsonView(false, "暂无数据!"));
}
setDataType = setDataType.OrderByDescending(s => s.CreateTime).ToList();
return Ok(JsonView(true, "查询成功!", setDataType));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 车公司资料板块
///
/// 车公司信息查询
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryCarData(QueryCarDataDto dto)
{
try
{
Result LocalGuide = await _carDataRep.QueryCarData(dto);
if (LocalGuide.Code == 0)
{
return Ok(JsonView(true, "查询成功", LocalGuide.Data));
}
else
{
return Ok(JsonView(false, LocalGuide.Msg));
}
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 车公司资料下拉框数据
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryCarSelect()
{
try
{
var CarData = _carDataRep.QueryDto().ToList();
if (CarData.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
CarData.Add(new CarDataSelectView { Id = 0, UnitArea = "全部" });
CarData = CarData.Where((x, i) => CarData.FindIndex(z => z.UnitArea == x.UnitArea) == i).ToList();
CarData = CarData.OrderBy(x => x.Id).ToList();
List data= new List();
foreach (CarDataSelectView car in CarData)
{
if (!string.IsNullOrWhiteSpace(car.UnitArea))
{
data.Add(car);
}
}
return Ok(JsonView(true, "查询成功", data));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 车公司信息添加
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task AddCarData(AddCarDataDto dto)
{
try
{
if (dto.UnitArea == "")
{
return Ok(JsonView(false, "请检查单位区域是否填写!"));
}
if (dto.UnitName == "")
{
return Ok(JsonView(false, "请检查单位名称是否填写!"));
}
if (dto.Contact == "")
{
return Ok(JsonView(false, "请检查单位联系人是否填写!"));
}
if (dto.ContactTel == "")
{
return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
}
var carDada = _carDataRep.QueryDto(a => a.UnitArea == dto.UnitArea && a.UnitName == dto.UnitName && a.Contact == dto.Contact && a.ContactTel == dto.ContactTel).ToList();
if (carDada.Count != 0)
{
return Ok(JsonView(false, "该信息已存在,请勿重复添加!"));
}
Res_CarData _CarData = _mapper.Map(dto);
int id = await _carDataRep.AddAsyncReturnId(_CarData);
if (id == 0)
{
return Ok(JsonView(false, "添加失败!"));
}
return Ok(JsonView(true, "添加成功", new { Id = id }));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 车公司信息修改
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task UpCarData(UpCarDataDto dto)
{
try
{
if (dto.UnitArea == "")
{
return Ok(JsonView(false, "请检查单位区域是否填写!"));
}
if (dto.UnitName == "")
{
return Ok(JsonView(false, "请检查单位名称是否填写!"));
}
if (dto.Contact == "")
{
return Ok(JsonView(false, "请检查单位联系人是否填写!"));
}
if (dto.ContactTel == "")
{
return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
}
bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
{
UnitArea = dto.UnitArea,
UnitName = dto.UnitName,
Address = dto.Address,
Contact = dto.Contact,
ContactTel = dto.ContactTel,
ContactEmail = dto.ContactEmail,
ContactFax = dto.ContactFax,
CarDes = dto.CarDes,
CarPicPaths = dto.CarPicPaths,
OtherInfo = dto.OtherInfo,
Score = dto.Score,
QualificationScore = dto.QualificationScore,
CarAgeScore = dto.CarAgeScore,
CleanImgScore = dto.CleanImgScore,
SmellScore = dto.SmellScore,
WaterPaperScore = dto.WaterPaperScore,
HardwareScore = dto.HardwareScore,
TimeScore = dto.TimeScore,
SafetyScore = dto.SafetyScore,
DrivingAgeScore = dto.DrivingAgeScore,
Remark = dto.Remark,
});
if (!res) { return Ok(JsonView(false, "修改失败!")); }
return Ok(JsonView(true, "修改成功"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 车公司信息删除
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelCarData(DelCarDataDto dto)
{
try
{
bool res = await _carDataRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res) { return Ok(JsonView(false, "删除失败!")); }
return Ok(JsonView(true, "删除成功"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 导游地接资料板块
///
/// 导游地接资料查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryLocalGuide(QueryLocalGuide dto)
{
try
{
Result LocalGuide = await _localGuideDataRep.QueryLocalGuide(dto);
if (LocalGuide.Code == 0)
{
return Ok(JsonView(true, "查询成功", LocalGuide.Data));
}
else
{
return Ok(JsonView(false, LocalGuide.Msg));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 导游地接资料下拉框数据
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryLocalGuideSelect()
{
try
{
var LocalGuide = _carDataRep.QueryDto().ToList();
if (LocalGuide.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
LocalGuide.Add(new QueryLocalGuideSelectView { Id = 0, UnitArea = "全部" });
LocalGuide = LocalGuide.Where((x, i) => LocalGuide.FindIndex(z => z.UnitArea == x.UnitArea && z.UnitArea != "") == i).ToList();
LocalGuide = LocalGuide.OrderBy(x => x.Id).ToList();
List data = new List();
foreach (QueryLocalGuideSelectView Local in LocalGuide)
{
if (!string.IsNullOrWhiteSpace(Local.UnitArea))
{
data.Add(Local);
}
}
return Ok(JsonView(true, "查询成功", data));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 导游地接信息操作(Status:1.新增,2.修改)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationLocalGuide(LocalGuideOperationDto dto)
{
try
{
if (dto.UnitArea == "")
{
return Ok(JsonView(false, "请检查单位区域是否填写!"));
}
if (dto.UnitName == "")
{
return Ok(JsonView(false, "请检查单位名称是否填写!"));
}
if (dto.Contact == "")
{
return Ok(JsonView(false, "请检查单位联系人是否填写!"));
}
if (dto.ContactTel == "")
{
return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
}
Result result = await _localGuideDataRep.LocalGuideOperation(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 导游地接信息操作(删除)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelLocalGuide(LocalGuideDelDto dto)
{
try
{
var res = await _localGuideDataRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 机场三字码信息
///
/// 机场三字码查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryThreeCode(QueryThreeCodeDto dto)
{
try
{
Result LocalGuide = await _ThreeCodeRep.QueryThreeCode(dto);
if (LocalGuide.Code == 0)
{
return Ok(JsonView(true, "查询成功", LocalGuide.Data));
}
else
{
return Ok(JsonView(false, LocalGuide.Msg));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 机场三字码数据城市下拉框数据
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryThreeCodeSelect()
{
try
{
var ThreeCode = _carDataRep.QueryDto().ToList();
if (ThreeCode.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
ThreeCode.Add(new ThreeCodeSelectView { Id = 0, City = "全部" });
ThreeCode = ThreeCode.Where((x, i) => ThreeCode.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
ThreeCode = ThreeCode.OrderBy(x => x.Id).ToList();
List data = new List();
foreach (ThreeCodeSelectView _ThreeCode in ThreeCode)
{
if (!string.IsNullOrWhiteSpace(_ThreeCode.City))
{
data.Add(_ThreeCode);
}
}
return Ok(JsonView(true, "查询成功", data));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 机场三字码资料操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationThreeCode(ThreeCodeOperationDto dto)
{
try
{
if (dto.Three == "")
{
return Ok(JsonView(false, "请检查三字码是否填写!"));
}
if (dto.Country == "")
{
return Ok(JsonView(false, "请检查国家是否填写!"));
}
if (dto.City == "")
{
return Ok(JsonView(false, "请检查城市是否填写正确!"));
}
if (dto.AirPort == "")
{
return Ok(JsonView(false, "请检查机场是否填写正确!"));
}
Result result = await _ThreeCodeRep.ThreeCodeOperation(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 机场三字码资料操作(删除)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelThreeCode(ThreeCodeDelDto dto)
{
try
{
var res = await _ThreeCodeRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 酒店资料数据
///
/// 酒店信息查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryHotelData(QueryHotelDataDto dto)
{
try
{
Result hotelData = await _hotelDataRep.QueryHotelData(dto);
if (hotelData.Code == 0)
{
return Ok(JsonView(true, "查询成功", hotelData.Data));
}
else
{
return Ok(JsonView(false, hotelData.Msg));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 酒店资料下拉框数据
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryHotelDataSelect()
{
try
{
var HotelData = _carDataRep.QueryDto().ToList();
if (HotelData.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
HotelData.Add(new QueryHotelDataSelect { Id = 0, City = "全部" });
HotelData = HotelData.Where((x, i) => HotelData.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
HotelData = HotelData.OrderBy(x => x.Id).ToList();
List data = new List();
foreach (QueryHotelDataSelect Hotel in HotelData)
{
if (!string.IsNullOrWhiteSpace(Hotel.City))
{
data.Add(Hotel);
}
}
return Ok(JsonView(true, "查询成功", data));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 酒店资料操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationHotelData(OperationHotelDto dto)
{
try
{
if (dto.City == "")
{
return Ok(JsonView(false, "请检查酒店所在城市是否填写!"));
}
if (dto.Name == "")
{
return Ok(JsonView(false, "请检查酒店名称是否填写!"));
}
if (dto.Address == "")
{
return Ok(JsonView(false, "请检查酒店地址是否填写正确!"));
}
if (dto.Tel == "")
{
return Ok(JsonView(false, "请检查酒店联系方式是否填写正确!"));
}
Result result = await _hotelDataRep.OperationHotelData(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 酒店资料操作(删除)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelHotelData(DelHotelDataDto dto)
{
try
{
var res = await _hotelDataRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 签证费用资料
///
/// 签证费用资料查询
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryCountryFeeCost(DtoBase dto)
{
try
{
if (dto.PortType == 1)
{
var CountryFee = _countryFeeRep.QueryDto().ToList();
if (CountryFee.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
return Ok(JsonView(true, "查询成功", CountryFee));
}
else if (dto.PortType == 2)
{
var CountryFee = _countryFeeRep.QueryDto().ToList();
if (CountryFee.Count == 0)
{
return Ok(JsonView(false, "暂无数据!"));
}
CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
return Ok(JsonView(true, "查询成功", CountryFee));
}
else
{
return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
}
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 签证费用资料操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task OperationCountryFeeCost(OperationCountryFeeCostDto dto)
{
try
{
if (dto.VisaContinent == "")
{
return Ok(JsonView(false, "请检查州名是否填写!"));
}
if (dto.VisaCountry == "")
{
return Ok(JsonView(false, "请检查国家名是否填写!"));
}
if (dto.VisaTime == "1")
{
return Ok(JsonView(false, "请检一般签证时间是否填写正确!"));
}
if (dto.UrgentTime == "1")
{
return Ok(JsonView(false, "请检加急时间是否填写正确!"));
}
if (dto.VisaPrice == 0)
{
return Ok(JsonView(false, "请检查签证费用是否填写正确,小数点后可1到2位!"));
}
if (dto.VisaPrice == 1)
{
return Ok(JsonView(false, "请检查签证加急费用是否填写正确,小数点后可1到2位!"));
}
Result result = await _countryFeeRep.OperationCountryFeeCost(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 签证费用资料操作(删除)
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task DelCountryFeeCost(DelCountryFeeCostDto dto)
{
try
{
var res = await _countryFeeRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
#endregion
#region 物料信息、供应商维护
#region 供应商
///
/// 物料供应商查询
///
/// Json序列化
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostSearchItemVendor(string paras)
{
if (string.IsNullOrEmpty(paras))
{
return Ok(JsonView(false, "参数为空"));
}
Search_ResItemVendorDto _ItemVendorDto = System.Text.Json.JsonSerializer.Deserialize(paras);
if (_ItemVendorDto != null)
{
if (_ItemVendorDto.SearchType == 2) //获取列表
{
Res_ItemVendorListView rstList = _resItemInfoRep.GetVendorList(_ItemVendorDto);
return Ok(rstList);
}
else
{
Res_ItemVendorView rstInfo = _resItemInfoRep.getVendorInfo(_ItemVendorDto);
return Ok(rstInfo);
}
}
else
{
return Ok(JsonView(false, "参数反序列化失败"));
}
return Ok(JsonView(false));
}
///
/// 创建/编辑/删除供应商信息
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostEditItemVendor(Edit_ResItemVendorDto _dto)
{
bool rst = false;
if (_dto.EditType >= 0)
{
if (string.IsNullOrEmpty(_dto.VendorFullName))
{
return Ok(JsonView(false, "全称未填写"));
}
if (string.IsNullOrEmpty(_dto.VendorLinker))
{
return Ok(JsonView(false, "联系人未填写"));
}
if (string.IsNullOrEmpty(_dto.VendorMobile))
{
return Ok(JsonView(false, "联系人手机号未填写"));
}
if (_dto.EditType == 0)
{
var checkEmpty = _resItemInfoRep.Query(s => s.FullName == _dto.VendorFullName).First();
if (checkEmpty != null)
{
return Ok(JsonView(false, "已存在同名供应商"));
}
rst = await _resItemInfoRep.addVendorInfo(_dto);
}
else if (_dto.EditType == 1)
{
if (_dto.VendorId > 0)
{
Res_ItemVendor _entity = _mapper.Map(_dto);
rst = await _resItemInfoRep.updVendorInfo(_entity);
}
else
{
return Ok(JsonView(false, "供应商不存在"));
}
}
}
else
{
if (_dto.VendorId < 1 || _dto.SysUserId < 1)
{
return Ok(JsonView(false, "用户Id或供应商Id不存在"));
}
Res_ItemVendor _entity = _mapper.Map(_dto);
rst = await _resItemInfoRep.delVendorInfo(_entity);
}
return Ok(JsonView(rst));
}
#endregion
#region 物料信息
///
/// 物料信息查询
///
/// Json序列化
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostSearchItemInfo(string paras)
{
if (string.IsNullOrEmpty(paras))
{
return Ok(JsonView(false, "参数为空"));
}
Search_ItemInfoDto _ItemInfoDto = System.Text.Json.JsonSerializer.Deserialize(paras);
if (_ItemInfoDto != null)
{
if (_ItemInfoDto.SearchType == 2) //获取列表
{
Res_ItemInfoListView rstList = _resItemInfoRep.GetItemList(_ItemInfoDto);
return Ok(rstList);
}
else
{
Res_ItemInfoView rstInfo = _resItemInfoRep.getItemInfo(_ItemInfoDto);
return Ok(rstInfo);
}
}
else
{
return Ok(JsonView(false, "参数反序列化失败"));
}
return Ok(JsonView(false));
}
///
/// 创建/编辑/删除物料信息
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostEditItemInfo(Edit_ResItemInfoDto _dto)
{
bool rst = false;
if (_dto.EditType >= 0)
{
if (_dto.VendorId < 1)
{
return Ok(JsonView(false, "未选择供应商"));
}
if (string.IsNullOrEmpty(_dto.ItemName))
{
return Ok(JsonView(false, "物料名称为空"));
}
if (_dto.SetDataId < 1)
{
return Ok(JsonView(false, "未选择物料类型"));
}
if (_dto.SysUserId < 1)
{
return Ok(JsonView(false, "当前操作用户Id为空"));
}
if (_dto.CurrRate <= 0)
{
return Ok(JsonView(false, "物料录入价格不能小于等于0"));
}
if (_dto.EditType == 0)
{
//判断物料名称、类型、供应商全部重复
var checkEmpty = _resItemInfoRep.Query(s => s.ItemName == _dto.ItemName && s.SetDataId == _dto.SetDataId && s.VendorId == _dto.VendorId).First();
if (checkEmpty != null)
{
return Ok(JsonView(false, "已存在重复物料信息"));
}
Res_ItemDetailInfo _entity = _mapper.Map(_dto);
DateTime dtNow = DateTime.Now;
_entity.CreateUserId = _dto.SysUserId;
_entity.IsDel = 0;
_entity.MaxRate = _dto.CurrRate;
_entity.MaxDt = dtNow;
_entity.CurrRate = _dto.CurrRate;
_entity.CurrDt = dtNow;
_entity.MinRate = _dto.CurrRate;
_entity.MinDt = dtNow;
rst = await _resItemInfoRep.AddAsync(_entity) > 0;
}
else if (_dto.EditType == 1)
{
if (_dto.ItemId > 0)
{
Res_ItemDetailInfo _entity = _mapper.Map(_dto);
_entity.Id = _dto.ItemId;
rst = await _resItemInfoRep.updItemInfo(_entity);
}
else
{
return Ok(JsonView(false, "供应商不存在"));
}
}
}
else
{
if (_dto.ItemId < 1 || _dto.SysUserId < 1)
{
return Ok(JsonView(false, "用户Id或物料信息Id不存在"));
}
Res_ItemDetailInfo _entity = _mapper.Map(_dto);
rst = await _resItemInfoRep.delItemInfo(_entity);
}
return Ok(JsonView(rst));
}
#endregion
#region 物料类型获取
///
/// 物料类型列表获取
///
/// Json序列化
///
[HttpGet]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task GetItemTypeListBySetData()
{
List list = _resItemInfoRep.GetItemTypeListBySetData();
return Ok(JsonView(list));
}
#endregion
#endregion
}
}