作者 tangxvhui

成果管理

@@ -73,3 +73,25 @@ func (c AchievementController) EditAchievement() { @@ -73,3 +73,25 @@ func (c AchievementController) EditAchievement() {
73 msg = protocol.NewReturnResponse(nil, err) 73 msg = protocol.NewReturnResponse(nil, err)
74 return 74 return
75 } 75 }
  76 +
  77 +//EditAchievement 成果详情
  78 +//@router /achievement/info
  79 +func (c AchievementController) AchievementInfo() {
  80 + var msg *protocol.ResponseMessage
  81 + defer func() {
  82 + c.ResposeJson(msg)
  83 + }()
  84 + type Parameter struct {
  85 + Id int64 `json:"id"`
  86 + }
  87 + var param Parameter
  88 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  89 + log.Error("json 解析失败 err:%s", err)
  90 + msg = protocol.BadRequestParam("1")
  91 + return
  92 + }
  93 + companyid := c.GetCompanyId()
  94 + rspData := serveachievement.GetAchievementInfo(param.Id, companyid)
  95 + msg = protocol.NewReturnResponse(rspData, nil)
  96 + return
  97 +}
@@ -13,8 +13,8 @@ type Achievement struct { @@ -13,8 +13,8 @@ type Achievement struct {
13 CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"` 13 CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
14 DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"` 14 DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"`
15 UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"` 15 UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"`
16 - ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`  
17 - AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"` 16 + ChanceTypeId int64 `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
  17 + AuditTemplateId int64 `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
18 SourceContent string `orm:"column(source_content);null" description:"成果详情文本"` 18 SourceContent string `orm:"column(source_content);null" description:"成果详情文本"`
19 GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"` 19 GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"`
20 UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"` 20 UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"`
@@ -57,17 +57,17 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) { @@ -57,17 +57,17 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) {
57 return 57 return
58 } 58 }
59 59
60 -// DeleteAchievementChance deletes AchievementChance by Id and returns error if  
61 -// the record to be deleted doesn't exist  
62 -func DeleteAchievementChance(id int64) (err error) { 60 +func GetAchievementChanceByAchieve(achievementid int64) ([]AchievementChance, error) {
  61 + var (
  62 + err error
  63 + data []AchievementChance
  64 + )
63 o := orm.NewOrm() 65 o := orm.NewOrm()
64 - v := AchievementChance{Id: id}  
65 - // ascertain id exists in the database  
66 - if err = o.Read(&v); err == nil {  
67 - var num int64  
68 - if num, err = o.Delete(&AchievementChance{Id: id}); err == nil {  
69 - fmt.Println("Number of records deleted in database:", num)  
70 - } 66 + _, err = o.QueryTable(&AchievementChance{}).
  67 + Filter("achievement_id", achievementid).
  68 + All(&data)
  69 + if err == orm.ErrNoRows {
  70 + return data, nil
71 } 71 }
72 - return 72 + return data, err
73 } 73 }
@@ -12,6 +12,7 @@ type AchievementProvider struct { @@ -12,6 +12,7 @@ type AchievementProvider struct {
12 AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"` 12 AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
13 UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"` 13 UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"`
14 UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"` 14 UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
  15 + DepartmentId int64 `orm:"column(department_id)"`
15 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` 16 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
16 } 17 }
17 18
@@ -57,17 +58,17 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) { @@ -57,17 +58,17 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
57 return 58 return
58 } 59 }
59 60
60 -// DeleteAchievementProvider deletes AchievementProvider by Id and returns error if  
61 -// the record to be deleted doesn't exist  
62 -func DeleteAchievementProvider(id int64) (err error) { 61 +func GetAchievementProviderByAchieve(achievementid int64) ([]AchievementProvider, error) {
  62 + var (
  63 + err error
  64 + data []AchievementProvider
  65 + )
63 o := orm.NewOrm() 66 o := orm.NewOrm()
64 - v := AchievementProvider{Id: id}  
65 - // ascertain id exists in the database  
66 - if err = o.Read(&v); err == nil {  
67 - var num int64  
68 - if num, err = o.Delete(&AchievementProvider{Id: id}); err == nil {  
69 - fmt.Println("Number of records deleted in database:", num)  
70 - } 67 + _, err = o.QueryTable(&AchievementProvider{}).
  68 + Filter("achievement_id", achievementid).
  69 + All(&data)
  70 + if err == orm.ErrNoRows {
  71 + return data, nil
71 } 72 }
72 - return 73 + return data, err
73 } 74 }
@@ -11,37 +11,43 @@ type AchievementProvider struct { @@ -11,37 +11,43 @@ type AchievementProvider struct {
11 11
12 //AchievementChance 成果的机会列表 12 //AchievementChance 成果的机会列表
13 type AchievementChance struct { 13 type AchievementChance struct {
14 - Id int64 `json:"id"` 14 + Id string `json:"id"` //大整数特别处理
15 Code string `json:"code"` 15 Code string `json:"code"`
16 } 16 }
17 17
  18 +type AchievementImage struct {
  19 + Path string `json:"path"`
  20 + W int `json:"-"`
  21 + H int `json:"-"`
  22 +}
  23 +
18 //RequestAddAchievement 添加成果 24 //RequestAddAchievement 添加成果
19 type RequestAddAchievement struct { 25 type RequestAddAchievement struct {
20 - ChanceData []AchievementChance `json:"chance_data"`  
21 - TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type  
22 - TypeIdB int `json:"type_id_b"` //机会二级分类  
23 - DepartmentId int64 `json:"department_id"` //把握人的部门  
24 - UserCompanyId int64 `json:"user_company_id"` //把握人的id  
25 - GraspScore float64 `json:"grasp_score"` //把握分  
26 - UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分  
27 - Provider []AchievementProvider `json:"provider"` //机会提供者  
28 - SourceContent string `json:"source_content"` //成果描述文本  
29 - Images []string `json:"image"` //图片 26 + ChanceData []AchievementChance `json:"chance_data"`
  27 + ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
  28 + AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
  29 + DepartmentId int64 `json:"department_id"` //把握人的部门
  30 + UserCompanyId int64 `json:"user_company_id"` //把握人的id
  31 + GraspScore float64 `json:"grasp_score"` //把握分
  32 + UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
  33 + Provider []AchievementProvider `json:"provider"` //机会提供者
  34 + SourceContent string `json:"source_content"` //成果描述文本
  35 + Images []AchievementImage `json:"image"` //图片
30 } 36 }
31 37
32 //RequestAddAchievement 添加成果 38 //RequestAddAchievement 添加成果
33 type RequestEditAchievement struct { 39 type RequestEditAchievement struct {
34 - AchievementId int64 `json:"achievement_id"`  
35 - ChanceData []AchievementChance `json:"chance_data"`  
36 - TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type  
37 - TypeIdB int `json:"type_id_b"` //机会二级分类  
38 - DepartmentId int64 `json:"department_id"` //把握人的部门  
39 - UserCompanyId int64 `json:"user_company_id"` //把握人的id  
40 - GraspScore float64 `json:"grasp_score"` //把握分  
41 - UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分  
42 - Provider []AchievementProvider `json:"provider"` //机会提供者  
43 - SourceContent string `json:"source_content"` //成果描述文本  
44 - Images []string `json:"image"` //图片 40 + AchievementId int64 `json:"achievement_id"`
  41 + ChanceData []AchievementChance `json:"chance_data"`
  42 + ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
  43 + AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
  44 + DepartmentId int64 `json:"department_id"` //把握人的部门
  45 + UserCompanyId int64 `json:"user_company_id"` //把握人的id
  46 + GraspScore float64 `json:"grasp_score"` //把握分
  47 + UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
  48 + Provider []AchievementProvider `json:"provider"` //机会提供者
  49 + SourceContent string `json:"source_content"` //成果描述文本
  50 + Images []AchievementImage `json:"image"` //图片
45 } 51 }
46 52
47 // ResponseRankSeasonList 赛季列表 53 // ResponseRankSeasonList 赛季列表
@@ -63,19 +69,19 @@ type AchievementListItem struct { @@ -63,19 +69,19 @@ type AchievementListItem struct {
63 69
64 //ResponseAchievementInfo 成果详情 70 //ResponseAchievementInfo 成果详情
65 type ResponseAchievementInfo struct { 71 type ResponseAchievementInfo struct {
66 - AchievementId int64 `json:"achievement_id"`  
67 - ChanceData []AchievementChance `json:"chance_data"`  
68 - TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type  
69 - TypeNameA string `json:"type_name_a"`  
70 - TypeIdB int `json:"type_id_b"` //机会二级分类  
71 - TypeNameB string `json:"type_name_b"`  
72 - DepartmentId int64 `json:"department_id"` //把握人的部门  
73 - DeparmentName string `json:"department_name"`  
74 - UserCompanyId int64 `json:"user_company_id"` //把握人的id  
75 - UserName string `json:"user_name"`  
76 - GraspScore float64 `json:"grasp_score"` //把握分  
77 - UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分  
78 - Provider []AchievementProvider `json:"provider"` //机会提供者  
79 - SourceContent string `json:"source_content"` //成果描述文本  
80 - Images []string `json:"image"` //图片 72 + AchievementId int64 `json:"achievement_id"`
  73 + ChanceData []AchievementChance `json:"chance_data"`
  74 + ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
  75 + AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
  76 + ChanceTypeName string `json:"chance_type_name"` //机会一级分类 chance_type
  77 + AuditTemplateName string `json:"audit_template_name"` //机会二级分类
  78 + DepartmentId int64 `json:"department_id"` //把握人的部门
  79 + DeparmentName string `json:"department_name"`
  80 + UserCompanyId int64 `json:"user_company_id"` //把握人的id
  81 + UserName string `json:"user_name"`
  82 + GraspScore float64 `json:"grasp_score"` //把握分
  83 + UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
  84 + Provider []AchievementProvider `json:"provider"` //机会提供者
  85 + SourceContent string `json:"source_content"` //成果描述文本
  86 + Images []AchievementImage `json:"image"` //图片
81 } 87 }
@@ -124,6 +124,7 @@ func init() { @@ -124,6 +124,7 @@ func init() {
124 beego.NSRouter("/list", &controllers.AchievementController{}, "post:AchievementList"), 124 beego.NSRouter("/list", &controllers.AchievementController{}, "post:AchievementList"),
125 beego.NSRouter("/add", &controllers.AchievementController{}, "post:AddAchievement"), 125 beego.NSRouter("/add", &controllers.AchievementController{}, "post:AddAchievement"),
126 beego.NSRouter("/edit", &controllers.AchievementController{}, "post:EditAchievement"), 126 beego.NSRouter("/edit", &controllers.AchievementController{}, "post:EditAchievement"),
  127 + beego.NSRouter("/info", &controllers.AchievementController{}, "post:AchievementInfo"),
127 ), 128 ),
128 ) 129 )
129 130
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "oppmg/models" 7 "oppmg/models"
8 "oppmg/protocol" 8 "oppmg/protocol"
9 "oppmg/utils" 9 "oppmg/utils"
  10 + "strconv"
10 "time" 11 "time"
11 12
12 "github.com/astaxie/beego/orm" 13 "github.com/astaxie/beego/orm"
@@ -40,9 +41,10 @@ func addAchievementChance(addData []protocol.AchievementChance, achievementId in @@ -40,9 +41,10 @@ func addAchievementChance(addData []protocol.AchievementChance, achievementId in
40 ) 41 )
41 nowTime := time.Now() 42 nowTime := time.Now()
42 for _, v := range addData { 43 for _, v := range addData {
  44 + chanceId, _ := strconv.ParseInt(v.Id, 10, 64)
43 m := models.AchievementChance{ 45 m := models.AchievementChance{
44 AchievementId: achievementId, 46 AchievementId: achievementId,
45 - ChanceId: v.Id, 47 + ChanceId: chanceId,
46 ChanceCode: v.Code, 48 ChanceCode: v.Code,
47 CreateAt: nowTime, 49 CreateAt: nowTime,
48 } 50 }
@@ -63,8 +65,8 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er @@ -63,8 +65,8 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er
63 CompanyId: companyid, 65 CompanyId: companyid,
64 DepartmentId: addData.DepartmentId, 66 DepartmentId: addData.DepartmentId,
65 UserCompanyId: addData.UserCompanyId, 67 UserCompanyId: addData.UserCompanyId,
66 - ChanceTypeId: addData.TypeIdA,  
67 - AuditTemplateId: addData.TypeIdB, 68 + ChanceTypeId: addData.ChanceTypeId,
  69 + AuditTemplateId: addData.AuditTemplateId,
68 SourceContent: addData.SourceContent, 70 SourceContent: addData.SourceContent,
69 GraspScore: addData.GraspScore, 71 GraspScore: addData.GraspScore,
70 UserGraspScore: addData.UserGraspScore, 72 UserGraspScore: addData.UserGraspScore,
@@ -117,8 +119,8 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64) @@ -117,8 +119,8 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64)
117 achievementData.UpdateAt = nowTime 119 achievementData.UpdateAt = nowTime
118 achievementData.DepartmentId = editData.DepartmentId 120 achievementData.DepartmentId = editData.DepartmentId
119 achievementData.UserCompanyId = editData.UserCompanyId 121 achievementData.UserCompanyId = editData.UserCompanyId
120 - achievementData.ChanceTypeId = editData.TypeIdA  
121 - achievementData.AuditTemplateId = editData.TypeIdB 122 + achievementData.ChanceTypeId = editData.ChanceTypeId
  123 + achievementData.AuditTemplateId = editData.AuditTemplateId
122 achievementData.SourceContent = editData.SourceContent 124 achievementData.SourceContent = editData.SourceContent
123 achievementData.GraspScore = editData.GraspScore 125 achievementData.GraspScore = editData.GraspScore
124 achievementData.UserGraspScore = editData.UserGraspScore 126 achievementData.UserGraspScore = editData.UserGraspScore
@@ -262,17 +264,83 @@ func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int @@ -262,17 +264,83 @@ func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int
262 } 264 }
263 265
264 func GetAchievementInfo(id int64, companyId int64) *protocol.ResponseAchievementInfo { 266 func GetAchievementInfo(id int64, companyId int64) *protocol.ResponseAchievementInfo {
265 - // rspData := &protocol.ResponseAchievementInfo{  
266 - // Images: make([]string, 0),  
267 - // Provider: make([]protocol.AchievementProvider, 0),  
268 - // ChanceData: make([]protocol.AchievementChance, 0),  
269 - // }  
270 - // var (  
271 - // achievementData *models.Achievement  
272 - // providerData []models.AchievementProvider  
273 - // chanceData []models.AchievementChance  
274 - // ) 267 + rspData := &protocol.ResponseAchievementInfo{
  268 + Images: make([]protocol.AchievementImage, 0),
  269 + Provider: make([]protocol.AchievementProvider, 0),
  270 + ChanceData: make([]protocol.AchievementChance, 0),
  271 + }
  272 + var (
  273 + achievementData *models.Achievement
  274 + chanceData []models.AchievementChance
  275 + err error
  276 + )
  277 + achievementData, err = models.GetAchievementById(id)
  278 + if err == nil {
  279 + rspData.AchievementId = achievementData.Id
  280 + rspData.AuditTemplateId = achievementData.AuditTemplateId
  281 + rspData.ChanceTypeId = achievementData.ChanceTypeId
  282 + rspData.DepartmentId = achievementData.DepartmentId
  283 + rspData.SourceContent = achievementData.SourceContent
  284 + img := make([]protocol.AchievementImage, 0)
  285 + json.Unmarshal([]byte(achievementData.Images), &img)
  286 + rspData.Images = img
  287 + rspData.GraspScore = achievementData.GraspScore
  288 + rspData.UserCompanyId = achievementData.UserCompanyId
  289 + } else {
  290 + log.Error("获取achievement数据失败:%s", err)
  291 + }
  292 + chanceData, err = models.GetAchievementChanceByAchieve(id)
  293 + if err == nil {
  294 + for _, v := range chanceData {
  295 + m := protocol.AchievementChance{
  296 + Id: fmt.Sprint(v.ChanceId),
  297 + Code: v.ChanceCode,
  298 + }
  299 + rspData.ChanceData = append(rspData.ChanceData, m)
  300 + }
  301 + } else {
  302 + log.Error("获取achievement_chance数据失败:%s", err)
  303 + }
  304 + rspData.Provider = getAchievementProvider(rspData.AchievementId)
  305 + var (
  306 + usercompanyData *models.UserCompany
  307 + departmentData *models.Department
  308 + chaneTypeData *models.ChanceType
  309 + auditTempData *models.AuditTemplate
  310 + )
  311 + departmentData, err = models.GetDepartmentById(rspData.DepartmentId)
  312 + if err == nil {
  313 + rspData.DeparmentName = departmentData.Name
  314 + }
  315 + usercompanyData, err = models.GetUserCompanyById(rspData.UserCompanyId)
  316 + if err == nil {
  317 + rspData.UserName = usercompanyData.NickName
  318 + }
  319 + chaneTypeData, err = models.GetChanceTypeById(int(rspData.ChanceTypeId))
  320 + if err == nil {
  321 + rspData.ChanceTypeName = chaneTypeData.Name
  322 + }
  323 + auditTempData, err = models.GetAuditTemplateById(rspData.AuditTemplateId)
  324 + if err == nil {
  325 + rspData.AuditTemplateName = auditTempData.Name
  326 + }
  327 + return rspData
  328 +}
275 329
276 - // models.GetAchievementById(id)  
277 - return nil 330 +func getAchievementProvider(achievementId int64) []protocol.AchievementProvider {
  331 + sql := `SELECT a.achievement_id,a.department_id,a.user_company_id,a.user_grasp_score
  332 + ,b.nick_name,c.name
  333 + FROM achievement_provider AS a
  334 + LEFT JOIN user_company AS b on a.user_company_id = b.id
  335 + LEFT JOIN department AS c ON a.department_id = c.id
  336 + WHERE achievement_id=? `
  337 + var (
  338 + err error
  339 + sqldata = make([]protocol.AchievementProvider, 0)
  340 + )
  341 + err = utils.ExecuteQueryAll(&sqldata, sql, achievementId)
  342 + if err != nil {
  343 + log.Error("SQL EXECUTE ERR:%s", err)
  344 + }
  345 + return sqldata
278 } 346 }