feat: 新增预警定时扫描器,移除附件归档字段并为角色表补充更新时间
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ImportProductTypesHandler POST /product-types/import 物料档案 Excel 批量导入
|
||||
// 请求体 multipart/form-data,字段名 file(.xlsx)。返回 {total,success,failed,errors}。
|
||||
func ImportProductTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||
httpx.BadRequest(w, "表单解析失败,请使用 multipart/form-data 上传文件")
|
||||
return
|
||||
}
|
||||
file, _, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
httpx.BadRequest(w, "未找到上传文件(字段名 file)")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3016, "读取文件失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
res, err := logic.New(svcCtx).ImportProductTypes(r.Context(), data)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3016, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadProductTypeTemplateHandler GET /product-types/template 物料档案 Excel 导入模板下载
|
||||
func DownloadProductTypeTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
b, err := logic.New(svcCtx).BuildProductTypeTemplate()
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3017, "生成模板失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape("物料档案导入模板.xlsx"))
|
||||
_, _ = w.Write(b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user