Commit 902183f3 by Seniorious

新增图片下载接口

parent 6be37453
...@@ -40,6 +40,62 @@ namespace APIs.Controllers ...@@ -40,6 +40,62 @@ namespace APIs.Controllers
} }
/// <summary> /// <summary>
/// 人员照片下载
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult> DownloadPicture([FromForm] DownloadPicReq req)
{
try
{
var pic = await _policeService.QueryOne(p => !string.IsNullOrEmpty(p.picUrl) && p.picUrl.Equals(req.picUrl));
//不存在
if (pic == null)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "照片不存在",
};
return error;
}
//读取图片
byte[] imageBytes;
string url = pic.picUrl;
using (FileStream fileStream = new FileStream(url, FileMode.Open))
{
using (BinaryReader reader = new BinaryReader(fileStream))
{
imageBytes = reader.ReadBytes((int)fileStream.Length);
}
}
var res = new DownloadPicRes() { picture = imageBytes };
var src = new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
data = res
};
return src;
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return error;
}
}
/// <summary>
/// 人员照片上传 /// 人员照片上传
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
...@@ -82,13 +138,16 @@ namespace APIs.Controllers ...@@ -82,13 +138,16 @@ namespace APIs.Controllers
//更新警员照片地址 //更新警员照片地址
police.picUrl = filePath; police.picUrl = filePath;
police.updateTime = DateTime.Now; police.updateTime = DateTime.Now;
police.picUpdateTime = police.updateTime;
bool rs = await _policeService.Update(police); bool rs = await _policeService.Update(police);
var reply = new UploadPictureReply() { picUrl = filePath, updateTime = (DateTime)police.picUpdateTime };
var src = rs ? new ApiResult var src = rs ? new ApiResult
{ {
code = ResultCode.OPERATE_SUCCESS.Code, code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg, msg = ResultCode.OPERATE_SUCCESS.Msg,
data = filePath data = reply
} : new ApiResult } : new ApiResult
{ {
code = ResultCode.OPERATE_FAILED.Code, code = ResultCode.OPERATE_FAILED.Code,
...@@ -105,11 +164,16 @@ namespace APIs.Controllers ...@@ -105,11 +164,16 @@ namespace APIs.Controllers
{ {
code = ResultCode.OPERATE_FAILED.Code, code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message, msg = ex.Message,
}; };
return error; return error;
} }
} }
class UploadPictureReply
{
public string picUrl { get; set; }
public DateTime updateTime { get; set; }
}
/// <summary> /// <summary>
/// 新增基础信息 /// 新增基础信息
......
...@@ -5,4 +5,14 @@ ...@@ -5,4 +5,14 @@
public string policeId { get; set; } public string policeId { get; set; }
public IFormFile picture { get; set; } public IFormFile picture { get; set; }
} }
public class DownloadPicReq
{
public string picUrl { get; set; }
}
public class DownloadPicRes
{
public byte[] picture { get; set; }
}
} }
...@@ -29,5 +29,7 @@ namespace Models.Table ...@@ -29,5 +29,7 @@ namespace Models.Table
public String? sex { get; set; } public String? sex { get; set; }
public String? faceInfo { get; set; } public String? faceInfo { get; set; }
public String? fingerInfo { get; set; } public String? fingerInfo { get; set; }
[SugarColumn(ColumnName = "pic_update_time")]
public DateTime? picUpdateTime { get; set; }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论