Browse Source

存为静态表,查询版本号

xyxie 9 months ago
parent
commit
610b274dea

+ 165 - 0
controllers/data_manage/excel/balance_table.go

@@ -919,3 +919,168 @@ func (c *ExcelInfoController) AddStaticExcel() {
 	br.Data = resp
 	br.IsAddLog = true
 }
+
+// BalanceVersionList
+// @Title 查询平衡表版本号列表
+// @Description 查询平衡表版本号列表
+// @Param	request	body request.EditExcelInfoReq true "type json string"
+// @Success 200 {object} response.AddExcelInfoResp
+// @router /excel_info/balance/version [get]
+func (c *ExcelInfoController) BalanceVersionList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	sysUser := c.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	excelInfoId, _ := c.GetInt("ExcelInfoId")
+	if excelInfoId <= 0 {
+		br.Msg = "请选择表格"
+		br.ErrMsg = "ExcelInfoId未传"
+		br.IsSendEmail = false
+		return
+	}
+	excelInfo, err := excel.GetExcelInfoById(excelInfoId)
+	if err != nil {
+		br.Msg = "获取ETA表格失败"
+		br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
+		return
+	}
+	if excelInfo.Source != utils.BALANCE_TABLE {
+		br.Msg = "请选择平衡表"
+		return
+	}
+	if excelInfo.BalanceType != 0 && excelInfo.ParentId != 0 {
+		br.Msg = "请选择动态平衡表"
+		return
+	}
+	list := make([]*response.BalanceTableVersionListItem, 0)
+	list = append(list, &response.BalanceTableVersionListItem{
+		ExcelInfoId:    excelInfo.ExcelInfoId,
+		UniqueCode:     excelInfo.UniqueCode,
+		BalanceType:    excelInfo.BalanceType,
+		RelExcelInfoId: excelInfo.RelExcelInfoId,
+		VersionName:    "动态表", //todo 有个默认的版本名称
+	})
+	//查询动态表所有的子表,并复制为静态表
+	condition := " AND rel_excel_info_id=? AND parent_id = 0 AND balance_type = 1 "
+	var pars []interface{}
+	pars = append(pars, excelInfoId)
+
+	staticList, err := excel.GetNoContentExcelInfoListByConditionNoPage(condition, pars)
+	if err != nil {
+		br.Msg = "获取子表失败"
+		br.ErrMsg = fmt.Sprintf("获取子表失败 %s", err.Error())
+		return
+	}
+
+	for _, staticInfo := range staticList {
+		tmp := &response.BalanceTableVersionListItem{
+			ExcelInfoId:    staticInfo.ExcelInfoId,
+			UniqueCode:     staticInfo.UniqueCode,
+			BalanceType:    staticInfo.BalanceType,
+			RelExcelInfoId: staticInfo.RelExcelInfoId,
+			VersionName:    staticInfo.VersionName,
+		}
+		list = append(list, tmp)
+	}
+	ret := &response.BalanceTableVersionListResp{List: list}
+	br.Data = ret
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// ModifyBalanceExcelVersion
+// @Title 版本号重命名
+// @Description 版本号重命名
+// @Param	request	body request.AddBalanceStaticExcelInfoReq true "type json string"
+// @Success 200 {object} response.AddExcelInfoResp
+// @router /excel_info/balance/version/modify [post]
+func (c *ExcelInfoController) ModifyBalanceExcelVersion() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	sysUser := c.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req request.AddBalanceStaticExcelInfoReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ExcelInfoId <= 0 {
+		br.Msg = "请传入ETA表格标识!"
+		return
+	}
+
+	req.VersionName = strings.Trim(req.VersionName, " ")
+	if req.VersionName == "" {
+		br.Msg = "请填写版本名称!"
+		br.IsSendEmail = false
+		return
+	}
+	excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
+	if err != nil {
+		br.Msg = "获取ETA表格失败"
+		br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
+		return
+	}
+	if excelInfo.Source != utils.BALANCE_TABLE {
+		br.Msg = "请选择平衡表"
+		return
+	}
+	if excelInfo.BalanceType != 1 && excelInfo.ParentId != 0 {
+		br.Msg = "请选择静态表"
+		return
+	}
+	// 检验分类下是否存在该版本号
+	{
+		var condition string
+		var pars []interface{}
+		condition += " AND rel_excel_info_id=? "
+		pars = append(pars, req.ExcelInfoId)
+
+		condition += " AND version_name=? "
+		pars = append(pars, req.VersionName)
+
+		count, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
+		if tmpErr != nil {
+			br.Msg = "查询版本号失败"
+			br.ErrMsg = tmpErr.Error()
+			return
+		}
+		if count > 0 {
+			br.Msg = "表格版本号已存在,请重新填写表格名称"
+			br.IsSendEmail = false
+			return
+		}
+	}
+
+	excelInfo.ModifyTime = time.Now()
+	excelInfo.VersionName = req.VersionName
+	updateExcelInfoParams := []string{"ModifyTime", "VersionName"}
+	// 同步修改静态表中的图表和指标名称
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.IsAddLog = true
+}

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

@@ -230,6 +230,19 @@ func GetNoContentExcelInfoListByCondition(condition string, pars []interface{},
 	return
 }
 
+func GetNoContentExcelInfoListByConditionNoPage(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT excel_info_id,excel_classify_id,excel_name,
+             unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission, parent_id, balance_type, update_user_id,update_user_real_name,rel_excel_info_id,version_name FROM excel_info WHERE is_delete=0 `
+	if condition != "" {
+		sql += condition
+	}
+
+	sql += ` ORDER BY excel_info_id DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
@@ -669,3 +682,47 @@ func GetChildExcelInfoByParentId(parentId int) (items []*ExcelInfo, err error) {
 	_, err = o.Raw(sql, parentId).QueryRows(&items)
 	return
 }
+
+// ExcelInfoVersionRename 平衡表版本号重命名
+func ExcelInfoVersionRename(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+
+	// ETA表格信息变更
+	_, err = o.Update(excelInfo, updateExcelInfoParams...)
+	if err != nil {
+		return
+	}
+
+	// 同步更新图表数据
+	//更新父级分类时,同时更新子集分类
+	if excelInfo.Source == utils.BALANCE_TABLE && excelInfo.ParentId == 0 {
+		// 同步更新子表分类
+		sql := `UPDATE FROM excel_info set excel_classify_id = ? WHERE parent_id=? `
+		_, err = o.Raw(sql, excelInfo.ExcelClassifyId, excelInfo.ExcelInfoId).Exec()
+	}
+	// 删除关系表
+	sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
+	_, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
+
+	// excel与指标的关联关系
+	dataNum := len(excelEdbMappingList)
+	if dataNum > 0 {
+		for k, v := range excelEdbMappingList {
+			v.ExcelInfoId = excelInfo.ExcelInfoId
+			excelEdbMappingList[k] = v
+		}
+		_, err = o.InsertMulti(dataNum, excelEdbMappingList)
+	}
+
+	return
+}

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

@@ -101,3 +101,15 @@ type BalanceChildTableResp struct {
 type BalanceTableWorkerResp struct {
 	List []*excel2.ExcelWorker
 }
+
+type BalanceTableVersionListItem struct {
+	ExcelInfoId    int    `description:"表格id"`
+	UniqueCode     string `description:"表格唯一编码"`
+	BalanceType    int    `description:"平衡表类型:0 动态表,1静态表"`
+	RelExcelInfoId int    `description:"平衡表里静态表关联的动态表excel id"`
+	VersionName    string `description:"静态表版本名称"`
+}
+
+type BalanceTableVersionListResp struct {
+	List []*BalanceTableVersionListItem
+}

+ 9 - 0
routers/commentsRouter.go

@@ -853,6 +853,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: "BalanceVersionList",
+            Router: `/excel_info/balance/version`,
+            AllowHTTPMethods: []string{"get"},
+            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: "GetBaseEdbInfo",

+ 2 - 2
services/data/chart_info_excel_balance.go

@@ -1243,12 +1243,12 @@ func AddBalanceStaticExcel(oldExcelInfoId int, versionName string, sysUser *syst
 
 		count, tmpErr := excelModel.GetExcelInfoCountByCondition(condition, pars)
 		if tmpErr != nil {
-			errMsg = "判断表格名称是否存在失败"
+			errMsg = "查询版本号失败"
 			err = tmpErr
 			return
 		}
 		if count > 0 {
-			errMsg = "表格名称已存在,请重新填写表格名称"
+			errMsg = "表格版本号已存在,请重新填写表格名称"
 			err = errors.New(errMsg)
 			isSendEmail = false
 			return