fix: 使用 Excel 生成日期导入档口入库码 (#237)

This commit is contained in:
chengma
2026-08-15 10:38:34 +08:00
parent 3bd2473e8f
commit 74856deff7
4 changed files with 149 additions and 37 deletions
+4 -9
View File
@@ -57,11 +57,6 @@ func (h *Handler) InnerCodeList(c *gin.Context) {
// InnerCodeImport 接收一次性 xlsx,导入完成后总会删除临时文件。
func (h *Handler) InnerCodeImport(c *gin.Context) {
businessDate := strings.TrimSpace(c.PostForm("date"))
if _, err := time.Parse("2006-01-02", businessDate); err != nil {
fail(c, http.StatusBadRequest, "请选择合法的业务日期;没有导入任何数据。")
return
}
fileHeader, err := c.FormFile("file")
if err != nil {
fail(c, http.StatusBadRequest, "没有收到 Excel(也可能超过 10MB);没有导入任何数据。")
@@ -104,7 +99,7 @@ func (h *Handler) InnerCodeImport(c *gin.Context) {
fail(c, http.StatusInternalServerError, "保存临时上传文件失败;没有导入任何数据。")
return
}
result, err := service.ImportInnerCodeExcel(h.db, tmpPath, businessDate, currentUser(c).UserID)
result, err := service.ImportInnerCodeExcel(h.db, tmpPath, fileHeader.Filename, currentUser(c).UserID)
if err != nil {
if service.IsInvalidInnerCodeImport(err) {
fail(c, http.StatusBadRequest, err.Error()+";请修正文件后重新导入。")
@@ -113,9 +108,9 @@ func (h *Handler) InnerCodeImport(c *gin.Context) {
fail(c, http.StatusInternalServerError, "档口入库码写库失败,本次导入已整体回滚,请稍后重试。")
return
}
message := fmt.Sprintf("导入完成:读取 %d 行,新增 %d 条,更新 %d 条,文件内重复 %d 行。",
result.TotalRows, result.CreatedCount, result.UpdatedCount, result.DuplicateRows)
h.innerCodeRedirect(c, businessDate, "", "", 1, message)
message := fmt.Sprintf("导入完成:业务日期 %s,读取 %d 行,新增 %d 条,更新 %d 条,文件内重复 %d 行。",
result.BusinessDate, result.TotalRows, result.CreatedCount, result.UpdatedCount, result.DuplicateRows)
h.innerCodeRedirect(c, result.BusinessDate, "", "", 1, message)
}
// InnerCodeMatch 读取远端最新详情并保存只读规划,不执行任何回写。