ziwen 1 年之前
父节点
当前提交
7c07fe819a

+ 43 - 16
controllers/data_manage/excel/excel_info.go

@@ -9,6 +9,7 @@ import (
 	excel3 "eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/data_manage/excel/response"
+	"eta/eta_api/services"
 	"eta/eta_api/services/data"
 	excel2 "eta/eta_api/services/data/excel"
 	"eta/eta_api/services/excel"
@@ -241,7 +242,12 @@ func (c *ExcelInfoController) Add() {
 	if req.Source == 1 {
 		go excel2.UpdateExcelInfoFileUrl(excelInfo)
 	}
-
+	_, err = services.UpdateExcelEditMark(excelInfo.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
+	if err != nil {
+		br.Msg = "查询标记状态失败"
+		br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+		return
+	}
 	resp := new(response.AddExcelInfoResp)
 	resp.ExcelInfoId = excelInfo.ExcelInfoId
 	resp.UniqueCode = excelInfo.UniqueCode
@@ -366,19 +372,6 @@ func (c *ExcelInfoController) List() {
 	if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
 		list = make([]*excel3.MyExcelInfoList, 0)
 	}
-	for _, v := range list {
-		markStatus, err := services.UpdateExcelEditMark(v.ExcelInfoId, sysUser.AdminId, 2, sysUser.RealName)
-		if err != nil {
-			br.Msg = "查询标记状态失败"
-			br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
-			return
-		}
-		if markStatus.Status == 0 {
-			v.CanEdit = true
-		} else {
-			v.Editor = markStatus.Editor
-		}
-	}
 	// 总数据量
 	dataCount, err := excel3.GetExcelListCountByCondition(condition, pars)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -434,6 +427,19 @@ func (c *ExcelInfoController) Detail() {
 		return
 	}
 
+	// 编辑状态
+	markStatus, err := services.UpdateExcelEditMark(excelInfoId, sysUser.AdminId, 2, sysUser.RealName)
+	if err != nil {
+		br.Msg = "查询标记状态失败"
+		br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+		return
+	}
+	if markStatus.Status == 0 {
+		excelDetail.CanEdit = true
+	} else {
+		excelDetail.Editor = markStatus.Editor
+	}
+
 	// excel表格按钮权限
 	excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source)
 
@@ -637,7 +643,13 @@ func (c *ExcelInfoController) Edit() {
 	excelInfo.ExcelImage = req.ExcelImage
 	excelInfo.Content = content
 
-	updateExcelInfoParams := []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content"}
+	// 自动保存时不会传缩略图,也就不更新这个字段
+	var updateExcelInfoParams []string
+	if req.ExcelImage != "" {
+		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content"}
+	} else {
+		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content"}
+	}
 
 	excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
 	if len(edbInfoIdList) > 0 {
@@ -680,6 +692,14 @@ func (c *ExcelInfoController) Edit() {
 		err = excel3.AddExcelDraft(excelDraftInfo)
 	}
 
+	// 标记编辑状态
+	_, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
+	if err != nil {
+		br.Msg = "查询标记状态失败"
+		br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+		return
+	}
+
 	resp := response.AddExcelInfoResp{
 		ExcelInfoId: excelInfo.ExcelInfoId,
 		UniqueCode:  excelInfo.UniqueCode,
@@ -1110,6 +1130,13 @@ func (c *ExcelInfoController) AddDraft() {
 		return
 	}
 
+	_, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
+	if err != nil {
+		br.Msg = "查询标记状态失败"
+		br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+		return
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "添加成功"
@@ -2162,7 +2189,7 @@ func decompressZip(src string) error {
 // @Description 标记沙盘编辑状态接口
 // @Param	request	body request.MarkEditSandbox true "type json string"
 // @Success 200 标记成功 ;202 标记成功
-// @router /mark [post]
+// @router /excel_info/mark [post]
 func (this *ExcelInfoController) MarkEditStatus() {
 	br := new(models.BaseResponse).Init()
 	defer func() {

+ 0 - 2
models/data_manage/excel/excel_info.go

@@ -46,8 +46,6 @@ type MyExcelInfoList struct {
 	Sort            int       `description:"排序字段,数字越小越排前面"`
 	ModifyTime      time.Time `description:"最近修改日期"`
 	CreateTime      time.Time `description:"创建日期"`
-	CanEdit         bool      `description:"是否可编辑"`
-	Editor          string    `description:"编辑人"`
 }
 
 // AddExcelInfo 新增表格

+ 2 - 0
models/data_manage/excel/response/excel_info.go

@@ -66,6 +66,8 @@ type ExcelInfoDetail struct {
 	CreateTime      time.Time             `description:"创建日期"`
 	TableData       interface{}           `description:"表格内容"`
 	Button          ExcelInfoDetailButton `description:"操作权限"`
+	CanEdit         bool                  `description:"是否可编辑"`
+	Editor          string                `description:"编辑人"`
 }
 
 // ExcelInfoDetailButton 操作按钮

+ 9 - 0
routers/commentsRouter.go

@@ -385,6 +385,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"],
+        beego.ControllerComments{
+            Method: "MarkEditStatus",
+            Router: `/excel_info/mark`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"],
         beego.ControllerComments{
             Method: "Move",

+ 63 - 0
services/excel_info.go

@@ -0,0 +1,63 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_api/models"
+	"eta/eta_api/models/system"
+	"eta/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// UpdateExcelEditMark 更新表格当前更新状态
+// status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
+func UpdateExcelEditMark(excelInfoId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
+	//更新标记key
+	key := fmt.Sprint(`crm:excel:edit:`, excelInfoId)
+	opUserId, e := utils.Rc.RedisInt(key)
+	var opUser models.MarkReportItem
+	if e != nil {
+		opUserInfoStr, tErr := utils.Rc.RedisString(key)
+		if tErr == nil {
+			tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
+			if tErr == nil {
+				opUserId = opUser.AdminId
+			}
+		}
+	}
+	if opUserId > 0 && opUserId != nowUserId {
+		editor := opUser.Editor
+		if editor == "" {
+			//查询账号的用户姓名
+			otherInfo, e := system.GetSysAdminById(opUserId)
+			if e != nil {
+				err = fmt.Errorf("查询其他编辑者信息失败")
+				return
+			}
+			editor = otherInfo.RealName
+		}
+
+		ret.Status = 1
+		ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor)
+		ret.Editor = editor
+		return
+	}
+	if status == 1 {
+		nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName}
+		bt, e := json.Marshal(nowUser)
+		if e != nil {
+			err = fmt.Errorf("格式化编辑者信息失败")
+			return
+		}
+		if opUserId > 0 {
+			utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存
+		} else {
+			utils.Rc.SetNX(key, string(bt), time.Second*60*5) //3分钟缓存
+		}
+	} else if status == 0 {
+		//清除编辑缓存
+		_ = utils.Rc.Delete(key)
+	}
+	return
+}
+