|
@@ -14,7 +14,10 @@ import (
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
)
|
|
|
|
|
|
// GetExcelDetailInfoByExcelInfoId 根据表格id获取表格详情
|
|
@@ -650,66 +653,201 @@ func GetCustomAnalysisOpButton(sysUser *system.Admin, belongUserId int, permissi
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func AddExcelRule(leftValue, rightValue string, leftValueType, rightValueType, ruleType int, scope, fontColor, backgroundColor, remark, lang string) (err error) {
|
|
|
- // 发生日期
|
|
|
- tmpExcelRule := new(excel.ExcelInfoRuleMapping)
|
|
|
- switch ruleType {
|
|
|
- // 大于
|
|
|
- case 1:
|
|
|
- tmpExcelRule.LeftValueShow = "大于" + leftValue
|
|
|
- // 小于
|
|
|
- case 2:
|
|
|
- tmpExcelRule.LeftValueShow = "小于" + leftValue
|
|
|
- // 介于
|
|
|
- case 3:
|
|
|
- tmpExcelRule.LeftValueShow = "介于" + leftValue + "到" + rightValue
|
|
|
- tmpExcelRule.RightValueShow = rightValue
|
|
|
- // 等于
|
|
|
- case 4:
|
|
|
- tmpExcelRule.LeftValueShow = "等于" + leftValue
|
|
|
- // 发生日期
|
|
|
- case 5:
|
|
|
- switch leftValue {
|
|
|
+func parseExcelScopeCoord(scopeList []string) (scopeCoord string, err error) {
|
|
|
+ if len(scopeList) == 2 {
|
|
|
+ x1, y1, er := excelize.CellNameToCoordinates(scopeList[0])
|
|
|
+ if er != nil {
|
|
|
+ return "", er
|
|
|
+ }
|
|
|
+ x2, y2, er := excelize.CellNameToCoordinates(scopeList[1])
|
|
|
+ if er != nil {
|
|
|
+ return "", er
|
|
|
+ }
|
|
|
+ scopeCoord = fmt.Sprintf("%d,%d,%d,%d", x1, y1, x2, y2)
|
|
|
+ }
|
|
|
+ if len(scopeCoord) == 1 {
|
|
|
+ x1, y1, er := excelize.CellNameToCoordinates(scopeList[0])
|
|
|
+ if er != nil {
|
|
|
+ return "", er
|
|
|
+ }
|
|
|
+ scopeCoord = fmt.Sprintf("%d,%d", x1, y1)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func ExcelRuleFormat(req *request.ExcelRuleMappingReq, lang string) (res *excel.ExcelInfoRuleMapping, err error) {
|
|
|
+ res = new(excel.ExcelInfoRuleMapping)
|
|
|
+ if req.RuleType == 5 {
|
|
|
+ switch req.LeftValue {
|
|
|
+ // 今天
|
|
|
case "today":
|
|
|
- tmpExcelRule.LeftValueShow = "今天"
|
|
|
+ res.LeftValueShow = "今天"
|
|
|
// 明天
|
|
|
case "tomorrow":
|
|
|
- tmpExcelRule.LeftValueShow = "明天"
|
|
|
+ res.LeftValueShow = "明天"
|
|
|
// 最近7天
|
|
|
case "last7days":
|
|
|
- tmpExcelRule.LeftValueShow = "最近7天"
|
|
|
+ res.LeftValueShow = "最近7天"
|
|
|
// 上周
|
|
|
case "lastweek":
|
|
|
- tmpExcelRule.LeftValueShow = "上周"
|
|
|
+ res.LeftValueShow = "上周"
|
|
|
// 本周
|
|
|
case "thisweek":
|
|
|
- tmpExcelRule.LeftValueShow = "本周"
|
|
|
+ res.LeftValueShow = "本周"
|
|
|
// 下周
|
|
|
case "nextweek":
|
|
|
- tmpExcelRule.LeftValueShow = "下周"
|
|
|
+ res.LeftValueShow = "下周"
|
|
|
// 上月
|
|
|
case "lastmonth":
|
|
|
- tmpExcelRule.LeftValueShow = "上月"
|
|
|
+ res.LeftValueShow = "上月"
|
|
|
// 本月
|
|
|
case "thismonth":
|
|
|
- tmpExcelRule.LeftValueShow = "本月"
|
|
|
+ res.LeftValueShow = "本月"
|
|
|
// 下月
|
|
|
case "nextmonth":
|
|
|
- tmpExcelRule.LeftValueShow = "下月"
|
|
|
+ res.LeftValueShow = "下月"
|
|
|
default:
|
|
|
err = errors.New("发生日期规则错误")
|
|
|
return
|
|
|
}
|
|
|
+ }
|
|
|
+ // 格式化条件值
|
|
|
+ switch req.LeftValueType {
|
|
|
+ // 坐标
|
|
|
+ case 2:
|
|
|
+ x, y, err := excelize.CellNameToCoordinates(req.LeftValue)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ res.LeftValue = fmt.Sprintf("%d,%d", x, y)
|
|
|
+ res.LeftValueShow = req.LeftValue
|
|
|
+ default:
|
|
|
+ res.LeftValue = req.LeftValue
|
|
|
+ res.LeftValueShow = req.LeftValue
|
|
|
+ }
|
|
|
+ switch req.RightValueType {
|
|
|
+ // 坐标
|
|
|
+ case 2:
|
|
|
+ x, y, err := excelize.CellNameToCoordinates(req.RightValue)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ res.RightValue = fmt.Sprintf("%d,%d", x, y)
|
|
|
+ res.RightValueShow = req.RightValue
|
|
|
+ default:
|
|
|
+ res.RightValue = req.LeftValue
|
|
|
+ res.RightValueShow = req.RightValue
|
|
|
+ }
|
|
|
+
|
|
|
+ res.ExcelInfoId = req.ExcelInfoId
|
|
|
+ res.ExcelInfoRuleMappingId = req.ExcelRuleMappingId
|
|
|
+ res.LeftValueType = req.LeftValueType
|
|
|
+ res.RightValueType = req.RightValueType
|
|
|
+ res.FontColor = req.FontColor
|
|
|
+ res.BackgroundColor = req.BackgroundColor
|
|
|
+ res.Remark = req.Remark
|
|
|
+ res.RemarkEn = req.Remark
|
|
|
+ res.ScopeShow = req.Scope
|
|
|
+ scopeList := strings.Split(req.Scope, ":")
|
|
|
+ res.ScopeCoord, err = parseExcelScopeCoord(scopeList)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func AddExcelRule(req *request.ExcelRuleMappingReq, lang string) (err error) {
|
|
|
+ excelRule, err := ExcelRuleFormat(req, lang)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if excelRule.ExcelInfoRuleMappingId != 0 {
|
|
|
+ return errors.New("规则已存在")
|
|
|
+ }
|
|
|
+ excelRule.CreateTime = time.Now()
|
|
|
+ _, err = excelRule.Insert()
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
+func ModifyExcelRule(req *request.ExcelRuleMappingReq, lang string) (err error) {
|
|
|
+ excelInfo, err := excel.GetExcelRuleMappingById(req.ExcelRuleMappingId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ editExcelInfo, err := ExcelRuleFormat(req, lang)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var updateCols []string
|
|
|
+ if excelInfo.LeftValue != editExcelInfo.LeftValue {
|
|
|
+ updateCols = append(updateCols, "LeftValue")
|
|
|
+ updateCols = append(updateCols, "LeftValueShow")
|
|
|
+ }
|
|
|
+ if excelInfo.LeftValueType != editExcelInfo.LeftValueType {
|
|
|
+ updateCols = append(updateCols, "LeftValueType")
|
|
|
+ }
|
|
|
+ if excelInfo.RightValue != editExcelInfo.RightValue {
|
|
|
+ updateCols = append(updateCols, "RightValue")
|
|
|
+ updateCols = append(updateCols, "RightValueShow")
|
|
|
+ }
|
|
|
+ if excelInfo.RightValueType != editExcelInfo.RightValueType {
|
|
|
+ updateCols = append(updateCols, "RightValueType")
|
|
|
+ }
|
|
|
+ if excelInfo.FontColor != editExcelInfo.FontColor {
|
|
|
+ updateCols = append(updateCols, "FontColor")
|
|
|
+ }
|
|
|
+ if excelInfo.BackgroundColor != editExcelInfo.BackgroundColor {
|
|
|
+ updateCols = append(updateCols, "BackgroundColor")
|
|
|
+ }
|
|
|
+ if excelInfo.Remark != editExcelInfo.Remark {
|
|
|
+ updateCols = append(updateCols, "Remark")
|
|
|
+ }
|
|
|
+ if excelInfo.RemarkEn != editExcelInfo.RemarkEn {
|
|
|
+ updateCols = append(updateCols, "RemarkEn")
|
|
|
+ }
|
|
|
+ if excelInfo.Scope != editExcelInfo.Scope {
|
|
|
+ updateCols = append(updateCols, "ScopeCoord")
|
|
|
+ updateCols = append(updateCols, "ScopeShow")
|
|
|
+ }
|
|
|
+ if len(updateCols) > 0 {
|
|
|
+ err = editExcelInfo.Update(updateCols)
|
|
|
}
|
|
|
- tmpExcelRule.LeftValueType = leftValueType
|
|
|
- tmpExcelRule.FontColor = fontColor
|
|
|
- tmpExcelRule.BackgroundColor = backgroundColor
|
|
|
- tmpExcelRule.Remark = remark
|
|
|
- tmpExcelRule.RemarkEn = remark
|
|
|
- tmpExcelRule.ScopeShow = scope
|
|
|
|
|
|
- tmpExcelRule.CreateTime = time.Now()
|
|
|
- _, err = tmpExcelRule.Insert()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetExcelRuleList 获取规则列表
|
|
|
+func GetExcelRuleList(excelInfoId int) (resp *response.ExcelRuleListResp, err error) {
|
|
|
+ resp = new(response.ExcelRuleListResp)
|
|
|
+ excelInfoList, err := excel.GetExcelRuleMappingByExcelInfoId(excelInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range excelInfoList {
|
|
|
+ switch v.RuleType {
|
|
|
+ // 大于
|
|
|
+ case 1:
|
|
|
+ v.LeftValueShow = "大于" + v.LeftValueShow
|
|
|
+ // 小于
|
|
|
+ case 2:
|
|
|
+ v.LeftValueShow = "小于" + v.LeftValueShow
|
|
|
+ // 介于
|
|
|
+ case 3:
|
|
|
+ v.LeftValueShow = "介于" + v.LeftValueShow + "到" + v.RightValueShow
|
|
|
+ // 等于
|
|
|
+ case 4:
|
|
|
+ v.LeftValueShow = "等于" + v.LeftValueShow
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.List = excelInfoList
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetExcelRuleDetail 获取规则列表
|
|
|
+func GetExcelRuleDetail(excelInfoMappingId int) (resp *excel.ExcelInfoRuleMappingView, err error) {
|
|
|
+ resp = new(excel.ExcelInfoRuleMappingView)
|
|
|
+ excelInfoDetail, err := excel.GetExcelRuleMappingById(excelInfoMappingId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp = excelInfoDetail
|
|
|
return
|
|
|
}
|