正在显示
14 个修改的文件
包含
227 行增加
和
10 行删除
| @@ -2,7 +2,7 @@ package main | @@ -2,7 +2,7 @@ package main | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/beego/beego/v2/server/web" | 4 | "github.com/beego/beego/v2/server/web" |
| 5 | - service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" | 5 | + serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" |
| 7 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" | 7 | _ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" | 8 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer" |
| @@ -24,7 +24,7 @@ func main() { | @@ -24,7 +24,7 @@ func main() { | ||
| 24 | // 定时任务-间隔发送评估环节 | 24 | // 定时任务-间隔发送评估环节 |
| 25 | func startNodeTask() { | 25 | func startNodeTask() { |
| 26 | go func() { | 26 | go func() { |
| 27 | - nodeTaskService := service.NewNodeTaskService() | 27 | + nodeTaskService := serviceTask.NewNodeTaskService() |
| 28 | for { | 28 | for { |
| 29 | timer := time.NewTimer(time.Second * 60) | 29 | timer := time.NewTimer(time.Second * 60) |
| 30 | <-timer.C | 30 | <-timer.C |
| @@ -328,7 +328,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | @@ -328,7 +328,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf | ||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface{}, error) { | 330 | func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface{}, error) { |
| 331 | - transactionContext, err := factory.StartTransaction() | 331 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 332 | if err != nil { | 332 | if err != nil { |
| 333 | return nil, err | 333 | return nil, err |
| 334 | } | 334 | } |
| @@ -301,7 +301,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | @@ -301,7 +301,7 @@ func (rs *EvaluationProjectService) Remove(in *command.DeleteProjectCommand) (in | ||
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (interface{}, error) { | 303 | func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (interface{}, error) { |
| 304 | - transactionContext, err := factory.StartTransaction() | 304 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 305 | if err != nil { | 305 | if err != nil { |
| 306 | return nil, err | 306 | return nil, err |
| 307 | } | 307 | } |
| @@ -51,6 +51,7 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac | @@ -51,6 +51,7 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac | ||
| 51 | CompanyId: in.CompanyId, | 51 | CompanyId: in.CompanyId, |
| 52 | CreatorId: in.CreatorId, | 52 | CreatorId: in.CreatorId, |
| 53 | Type: in.Type, | 53 | Type: in.Type, |
| 54 | + SysType: domain.EvaluationSysTypeCommon, | ||
| 54 | Rating: in.Rating, | 55 | Rating: in.Rating, |
| 55 | Score: in.Score, | 56 | Score: in.Score, |
| 56 | } | 57 | } |
| @@ -147,6 +148,10 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac | @@ -147,6 +148,10 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac | ||
| 147 | if err != nil { | 148 | if err != nil { |
| 148 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 149 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 149 | } | 150 | } |
| 151 | + if rule.SysType == domain.EvaluationSysTypeSystem { | ||
| 152 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "系统默认规则不可删除") | ||
| 153 | + } | ||
| 154 | + | ||
| 150 | if _, err := ruleRepository.Remove(rule); err != nil { | 155 | if _, err := ruleRepository.Remove(rule); err != nil { |
| 151 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 156 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 152 | } | 157 | } |
| @@ -175,7 +180,7 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac | @@ -175,7 +180,7 @@ func (rs *EvaluationRuleService) Remove(in *command.DeleteRuleCommand) (interfac | ||
| 175 | //} | 180 | //} |
| 176 | 181 | ||
| 177 | func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) { | 182 | func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (interface{}, error) { |
| 178 | - transactionContext, err := factory.StartTransaction() | 183 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 179 | if err != nil { | 184 | if err != nil { |
| 180 | return nil, err | 185 | return nil, err |
| 181 | } | 186 | } |
| @@ -192,12 +197,31 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i | @@ -192,12 +197,31 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i | ||
| 192 | 197 | ||
| 193 | ras := make([]*adapter.RuleAdapter, 0) | 198 | ras := make([]*adapter.RuleAdapter, 0) |
| 194 | creatorIds := make([]int64, 0) | 199 | creatorIds := make([]int64, 0) |
| 200 | + var havaSystemType = false | ||
| 195 | for i := range rules { | 201 | for i := range rules { |
| 196 | ra := &adapter.RuleAdapter{} | 202 | ra := &adapter.RuleAdapter{} |
| 197 | ra.EvaluationRule = rules[i] | 203 | ra.EvaluationRule = rules[i] |
| 198 | ras = append(ras, ra) | 204 | ras = append(ras, ra) |
| 199 | creatorIds = append(creatorIds, rules[i].CreatorId) | 205 | creatorIds = append(creatorIds, rules[i].CreatorId) |
| 206 | + | ||
| 207 | + if rules[i].SysType == domain.EvaluationSysTypeSystem { | ||
| 208 | + havaSystemType = true | ||
| 209 | + break | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + // 如果不存在系统默认就生成一个 | ||
| 214 | + if !havaSystemType { | ||
| 215 | + newRule := domain.GenerateSysRule(in.CompanyId) | ||
| 216 | + rule, err := ruleRepository.Insert(newRule) | ||
| 217 | + if err != nil { | ||
| 218 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 219 | + } | ||
| 220 | + ra := &adapter.RuleAdapter{} | ||
| 221 | + ra.EvaluationRule = rule | ||
| 222 | + ras = append(ras, ra) | ||
| 200 | } | 223 | } |
| 224 | + | ||
| 201 | _, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)}) | 225 | _, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)}) |
| 202 | userNameMap := map[int64]string{} | 226 | userNameMap := map[int64]string{} |
| 203 | if users != nil { | 227 | if users != nil { |
| @@ -214,7 +238,7 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i | @@ -214,7 +238,7 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i | ||
| 214 | } | 238 | } |
| 215 | 239 | ||
| 216 | func (rs *EvaluationRuleService) ListCreator(in *command.QueryCreatorCommand) (interface{}, error) { | 240 | func (rs *EvaluationRuleService) ListCreator(in *command.QueryCreatorCommand) (interface{}, error) { |
| 217 | - transactionContext, err := factory.StartTransaction() | 241 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 218 | if err != nil { | 242 | if err != nil { |
| 219 | return nil, err | 243 | return nil, err |
| 220 | } | 244 | } |
| @@ -186,7 +186,7 @@ func (rs *EvaluationTemplateService) Remove(in *command.DeleteTemplateCommand) ( | @@ -186,7 +186,7 @@ func (rs *EvaluationTemplateService) Remove(in *command.DeleteTemplateCommand) ( | ||
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (interface{}, error) { | 188 | func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (interface{}, error) { |
| 189 | - transactionContext, err := factory.StartTransaction() | 189 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 190 | if err != nil { | 190 | if err != nil { |
| 191 | return nil, err | 191 | return nil, err |
| 192 | } | 192 | } |
| @@ -141,7 +141,7 @@ func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error | @@ -141,7 +141,7 @@ func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error | ||
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) { | 143 | func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) { |
| 144 | - transactionContext, err := factory.StartTransaction() | 144 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 145 | if err != nil { | 145 | if err != nil { |
| 146 | return nil, err | 146 | return nil, err |
| 147 | } | 147 | } |
| @@ -95,7 +95,7 @@ func (rs *RoleUserService) Remove(in *command.UserRoleDeleteCommand) (interface{ | @@ -95,7 +95,7 @@ func (rs *RoleUserService) Remove(in *command.UserRoleDeleteCommand) (interface{ | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface{}, error) { | 97 | func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface{}, error) { |
| 98 | - transactionContext, err := factory.StartTransaction() | 98 | + transactionContext, err := factory.ValidateStartTransaction(in) |
| 99 | if err != nil { | 99 | if err != nil { |
| 100 | return nil, err | 100 | return nil, err |
| 101 | } | 101 | } |
| @@ -9,6 +9,11 @@ const ( | @@ -9,6 +9,11 @@ const ( | ||
| 9 | EvaluationTypeScore int = 1 // 评估方式-评分 | 9 | EvaluationTypeScore int = 1 // 评估方式-评分 |
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | +const ( | ||
| 13 | + EvaluationSysTypeCommon int = 0 // 系统类型-系统添加 | ||
| 14 | + EvaluationSysTypeSystem int = 1 // 系统类型-系统预制(不可删除、编辑) | ||
| 15 | +) | ||
| 16 | + | ||
| 12 | type Rating struct { | 17 | type Rating struct { |
| 13 | Levels []*RatingLevel `json:"levels" comment:"配置等级"` | 18 | Levels []*RatingLevel `json:"levels" comment:"配置等级"` |
| 14 | } | 19 | } |
| @@ -42,6 +47,7 @@ type EvaluationRule struct { | @@ -42,6 +47,7 @@ type EvaluationRule struct { | ||
| 42 | CompanyId int64 `json:"companyId,string" comment:"公司ID"` | 47 | CompanyId int64 `json:"companyId,string" comment:"公司ID"` |
| 43 | CreatorId int64 `json:"creatorId,string" comment:"创建人ID"` | 48 | CreatorId int64 `json:"creatorId,string" comment:"创建人ID"` |
| 44 | Type int `json:"type" comment:"评估方式(0评级、1评分)"` | 49 | Type int `json:"type" comment:"评估方式(0评级、1评分)"` |
| 50 | + SysType int `json:"sysType" comment:"系统类型(0普通、1系统固定)" pg:",use_zero"` | ||
| 45 | Rating Rating `json:"rating" comment:"评级"` | 51 | Rating Rating `json:"rating" comment:"评级"` |
| 46 | Score Score `json:"score" comment:"评分"` | 52 | Score Score `json:"score" comment:"评分"` |
| 47 | CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | 53 | CreatedAt time.Time `json:"createdAt" comment:"创建时间"` |
| @@ -49,6 +55,58 @@ type EvaluationRule struct { | @@ -49,6 +55,58 @@ type EvaluationRule struct { | ||
| 49 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | 55 | DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` |
| 50 | } | 56 | } |
| 51 | 57 | ||
| 58 | +// GenerateSysRule 当前公司下的生成默认规则 | ||
| 59 | +func GenerateSysRule(companyId int64) *EvaluationRule { | ||
| 60 | + levels := make([]*RatingLevel, 0) | ||
| 61 | + levels = append(levels, &RatingLevel{ | ||
| 62 | + Code: "S", | ||
| 63 | + Name: "SS", | ||
| 64 | + Color: 1, | ||
| 65 | + QuantizedValue: 90, | ||
| 66 | + }) | ||
| 67 | + levels = append(levels, &RatingLevel{ | ||
| 68 | + Code: "A", | ||
| 69 | + Name: "AA", | ||
| 70 | + Color: 2, | ||
| 71 | + QuantizedValue: 80, | ||
| 72 | + }) | ||
| 73 | + levels = append(levels, &RatingLevel{ | ||
| 74 | + Code: "B", | ||
| 75 | + Name: "BB", | ||
| 76 | + Color: 3, | ||
| 77 | + QuantizedValue: 70, | ||
| 78 | + }) | ||
| 79 | + | ||
| 80 | + levels = append(levels, &RatingLevel{ | ||
| 81 | + Code: "C", | ||
| 82 | + Name: "CC", | ||
| 83 | + Color: 4, | ||
| 84 | + QuantizedValue: 60, | ||
| 85 | + }) | ||
| 86 | + | ||
| 87 | + levels = append(levels, &RatingLevel{ | ||
| 88 | + Code: "D", | ||
| 89 | + Name: "DD", | ||
| 90 | + Color: 5, | ||
| 91 | + QuantizedValue: 50, | ||
| 92 | + }) | ||
| 93 | + | ||
| 94 | + newRule := &EvaluationRule{ | ||
| 95 | + Id: 0, | ||
| 96 | + Name: "评级(默认)", | ||
| 97 | + Remark: "", | ||
| 98 | + CompanyId: companyId, | ||
| 99 | + CreatorId: 0, | ||
| 100 | + Type: EvaluationTypeRating, | ||
| 101 | + SysType: EvaluationSysTypeSystem, | ||
| 102 | + Rating: Rating{ | ||
| 103 | + Levels: levels, | ||
| 104 | + }, | ||
| 105 | + Score: Score{}, | ||
| 106 | + } | ||
| 107 | + return newRule | ||
| 108 | +} | ||
| 109 | + | ||
| 52 | type EvaluationRuleRepository interface { | 110 | type EvaluationRuleRepository interface { |
| 53 | Insert(rule *EvaluationRule) (*EvaluationRule, error) | 111 | Insert(rule *EvaluationRule) (*EvaluationRule, error) |
| 54 | Remove(rule *EvaluationRule) (*EvaluationRule, error) | 112 | Remove(rule *EvaluationRule) (*EvaluationRule, error) |
| @@ -13,6 +13,7 @@ type EvaluationRule struct { | @@ -13,6 +13,7 @@ type EvaluationRule struct { | ||
| 13 | CompanyId int64 `comment:"公司ID"` | 13 | CompanyId int64 `comment:"公司ID"` |
| 14 | CreatorId int64 `comment:"创建人ID"` | 14 | CreatorId int64 `comment:"创建人ID"` |
| 15 | Type int `comment:"评估方式(0评级、1评分)" pg:",use_zero"` | 15 | Type int `comment:"评估方式(0评级、1评分)" pg:",use_zero"` |
| 16 | + SysType int `comment:"系统类型(0普通、1系统固定)" pg:",use_zero"` | ||
| 16 | Rating domain.Rating `comment:"评级"` | 17 | Rating domain.Rating `comment:"评级"` |
| 17 | Score domain.Score `comment:"评分"` | 18 | Score domain.Score `comment:"评分"` |
| 18 | CreatedAt time.Time `comment:"创建时间"` | 19 | CreatedAt time.Time `comment:"创建时间"` |
| @@ -28,6 +28,7 @@ func (repo *EvaluationRuleRepository) TransformToDomain(m *models.EvaluationRule | @@ -28,6 +28,7 @@ func (repo *EvaluationRuleRepository) TransformToDomain(m *models.EvaluationRule | ||
| 28 | CompanyId: m.CompanyId, | 28 | CompanyId: m.CompanyId, |
| 29 | CreatorId: m.CreatorId, | 29 | CreatorId: m.CreatorId, |
| 30 | Type: m.Type, | 30 | Type: m.Type, |
| 31 | + SysType: m.SysType, | ||
| 31 | Rating: m.Rating, | 32 | Rating: m.Rating, |
| 32 | Score: m.Score, | 33 | Score: m.Score, |
| 33 | CreatedAt: m.CreatedAt, | 34 | CreatedAt: m.CreatedAt, |
| @@ -44,6 +45,7 @@ func (repo *EvaluationRuleRepository) TransformToModel(d *domain.EvaluationRule) | @@ -44,6 +45,7 @@ func (repo *EvaluationRuleRepository) TransformToModel(d *domain.EvaluationRule) | ||
| 44 | CompanyId: d.CompanyId, | 45 | CompanyId: d.CompanyId, |
| 45 | CreatorId: d.CreatorId, | 46 | CreatorId: d.CreatorId, |
| 46 | Type: d.Type, | 47 | Type: d.Type, |
| 48 | + SysType: d.SysType, | ||
| 47 | Rating: d.Rating, | 49 | Rating: d.Rating, |
| 48 | Score: d.Score, | 50 | Score: d.Score, |
| 49 | CreatedAt: d.CreatedAt, | 51 | CreatedAt: d.CreatedAt, |
| @@ -143,6 +145,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{}) | @@ -143,6 +145,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{}) | ||
| 143 | query.Where("type = ?", v) | 145 | query.Where("type = ?", v) |
| 144 | } | 146 | } |
| 145 | 147 | ||
| 148 | + if v, ok := queryOptions["sysType"]; ok && v.(int) >= 0 { | ||
| 149 | + query.Where("sys_type = ?", v) | ||
| 150 | + } | ||
| 151 | + | ||
| 146 | if v, ok := queryOptions["limit"].(int64); ok { | 152 | if v, ok := queryOptions["limit"].(int64); ok { |
| 147 | query.Limit(int(v)) | 153 | query.Limit(int(v)) |
| 148 | } | 154 | } |
| @@ -2,9 +2,14 @@ package controllers | @@ -2,9 +2,14 @@ package controllers | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
| 5 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
| 5 | "github.com/linmadan/egglib-go/web/beego" | 6 | "github.com/linmadan/egglib-go/web/beego" |
| 6 | "github.com/xuri/excelize/v2" | 7 | "github.com/xuri/excelize/v2" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares" | ||
| 11 | + "strconv" | ||
| 12 | + "strings" | ||
| 8 | ) | 13 | ) |
| 9 | 14 | ||
| 10 | type ImportController struct { | 15 | type ImportController struct { |
| @@ -37,8 +42,82 @@ func (controller *ImportController) Import() { | @@ -37,8 +42,82 @@ func (controller *ImportController) Import() { | ||
| 37 | switch formType { | 42 | switch formType { |
| 38 | case "PerformanceDimension": | 43 | case "PerformanceDimension": |
| 39 | dimensions, _ := domain.LoadPerformanceDimensions(rows) | 44 | dimensions, _ := domain.LoadPerformanceDimensions(rows) |
| 40 | - controller.Response(dimensions, nil) | 45 | + list := controller.parseTemplateNodeContent(dimensions) |
| 46 | + controller.Response(tool_funs.SimpleWrapGridMap(int64(len(list)), list), nil) | ||
| 41 | default: | 47 | default: |
| 42 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, "请确认您导入的表单类型")) | 48 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, "请确认您导入的表单类型")) |
| 43 | } | 49 | } |
| 44 | } | 50 | } |
| 51 | + | ||
| 52 | +func (controller *ImportController) parseTemplateNodeContent(data []*domain.PerformanceDimension) []*domain.NodeContent { | ||
| 53 | + nodeContents := make([]*domain.NodeContent, 0) | ||
| 54 | + | ||
| 55 | + transactionContext, err := factory.StartTransaction() | ||
| 56 | + if err != nil { | ||
| 57 | + return nodeContents | ||
| 58 | + } | ||
| 59 | + defer func() { | ||
| 60 | + transactionContext.RollbackTransaction() | ||
| 61 | + }() | ||
| 62 | + // 获取当前公司下的默认规则 | ||
| 63 | + ua := middlewares.GetUser(controller.Ctx) | ||
| 64 | + ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 65 | + _, rules, err := ruleRepository.Find(map[string]interface{}{"companyId": ua.CompanyId, "sysType": domain.EvaluationSysTypeSystem, "limit": 1}) | ||
| 66 | + if err != nil { | ||
| 67 | + return nodeContents | ||
| 68 | + } | ||
| 69 | + var ruleId = int64(0) | ||
| 70 | + if len(rules) == 0 { | ||
| 71 | + newRule := domain.GenerateSysRule(ua.CompanyId) // 生成一个系统默认规则 | ||
| 72 | + if rule, err := ruleRepository.Insert(newRule); err != nil { | ||
| 73 | + return nodeContents | ||
| 74 | + } else { | ||
| 75 | + ruleId = rule.Id | ||
| 76 | + } | ||
| 77 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 78 | + return nodeContents | ||
| 79 | + } | ||
| 80 | + } else { | ||
| 81 | + ruleId = rules[0].Id | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + for i := range data { | ||
| 85 | + dimension := data[i] | ||
| 86 | + for i2 := range dimension.PerformanceModule { | ||
| 87 | + nc := &domain.NodeContent{} | ||
| 88 | + nc.Category = dimension.Name // 类别 | ||
| 89 | + | ||
| 90 | + module := dimension.PerformanceModule[i2] | ||
| 91 | + nc.Name = module.ModuleName // 名称 | ||
| 92 | + nc.RuleId = ruleId // 规则ID | ||
| 93 | + sIndex := strings.Index(module.Weight, "%") // 权重 | ||
| 94 | + if sIndex != -1 { | ||
| 95 | + iWeight, _ := strconv.Atoi(module.Weight[:sIndex]) | ||
| 96 | + nc.Weight = iWeight | ||
| 97 | + } else { | ||
| 98 | + nc.Weight = 0 | ||
| 99 | + } | ||
| 100 | + nc.PromptTitle = "" // 提示项标题 | ||
| 101 | + nc.PromptText = module.Standard // 提示项内容 | ||
| 102 | + nc.EntryItems = make([]*domain.EntryItem, 0) // 输入项 | ||
| 103 | + for i3 := range module.Target { | ||
| 104 | + target := module.Target[i3] | ||
| 105 | + nc.EntryItems = append(nc.EntryItems, &domain.EntryItem{ | ||
| 106 | + Title: target.Task, // 输入型标题 | ||
| 107 | + HintText: "", // 输入项提示文本 | ||
| 108 | + }) | ||
| 109 | + } | ||
| 110 | + // 没有任何输入项时,默认1个 | ||
| 111 | + if len(nc.EntryItems) == 0 { | ||
| 112 | + nc.EntryItems = append(nc.EntryItems, &domain.EntryItem{ | ||
| 113 | + Title: "填写反馈", | ||
| 114 | + HintText: "", | ||
| 115 | + }) | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + nodeContents = append(nodeContents, nc) | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + return nodeContents | ||
| 123 | +} |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "io/ioutil" | ||
| 5 | + | ||
| 6 | + "github.com/linmadan/egglib-go/core/application" | ||
| 7 | + "github.com/linmadan/egglib-go/web/beego" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type TemplateImplController struct { | ||
| 11 | + beego.BaseController | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (controller *TemplateImplController) TemplateQuestion() { | ||
| 15 | + fileBytes, err := ioutil.ReadFile("./templates/tpl_template_question.xlsx") | ||
| 16 | + if err != nil { | ||
| 17 | + controller.Response(nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未读取到模板文件")) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + controller.WriteExcel(fileBytes, "评估导入模板.xlsx") | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func (controller *TemplateImplController) WriteExcel(fileBytes []byte, fileName string) { | ||
| 24 | + controller.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName) | ||
| 25 | + controller.Ctx.Output.Header("Content-Description", "FileTransfer") | ||
| 26 | + controller.Ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") | ||
| 27 | + controller.Ctx.Output.Header("Content-Transfer-Encoding", "binary") | ||
| 28 | + controller.Ctx.Output.Header("Expires", "0") | ||
| 29 | + _, _ = controller.Ctx.ResponseWriter.Write(fileBytes) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +func (controller *TemplateImplController) WriteBinary(fileBytes []byte, fileName string) { | ||
| 33 | + controller.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName) | ||
| 34 | + controller.Ctx.Output.Header("Content-Description", "FileTransfer") | ||
| 35 | + controller.Ctx.Output.Header("Content-Type", "application/octet-stream") | ||
| 36 | + controller.Ctx.Output.Header("Content-Transfer-Encoding", "binary") | ||
| 37 | + controller.Ctx.Output.Header("Expires", "0") | ||
| 38 | + _, _ = controller.Ctx.ResponseWriter.Write(fileBytes) | ||
| 39 | +} |
pkg/port/beego/routers/template_router.go
0 → 100644
| 1 | +package routers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/beego/beego/v2/server/web" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func init() { | ||
| 9 | + web.Router("/templates/tpl_template_question.xlsx", &controllers.TemplateImplController{}, "Get:TemplateQuestion") | ||
| 10 | +} |
templates/tpl_template_question.xlsx
0 → 100644
不能预览此文件类型
-
请 注册 或 登录 后发表评论