作者 tangxvhui

成果管理

... ... @@ -73,3 +73,25 @@ func (c AchievementController) EditAchievement() {
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditAchievement 成果详情
//@router /achievement/info
func (c AchievementController) AchievementInfo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspData := serveachievement.GetAchievementInfo(param.Id, companyid)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
... ...
... ... @@ -13,8 +13,8 @@ type Achievement struct {
CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"`
UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"`
ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
ChanceTypeId int64 `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
AuditTemplateId int64 `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
SourceContent string `orm:"column(source_content);null" description:"成果详情文本"`
GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"`
UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"`
... ...
... ... @@ -57,17 +57,17 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) {
return
}
// DeleteAchievementChance deletes AchievementChance by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementChance(id int64) (err error) {
func GetAchievementChanceByAchieve(achievementid int64) ([]AchievementChance, error) {
var (
err error
data []AchievementChance
)
o := orm.NewOrm()
v := AchievementChance{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AchievementChance{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
_, err = o.QueryTable(&AchievementChance{}).
Filter("achievement_id", achievementid).
All(&data)
if err == orm.ErrNoRows {
return data, nil
}
return
return data, err
}
... ...
... ... @@ -12,6 +12,7 @@ type AchievementProvider struct {
AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"`
UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
DepartmentId int64 `orm:"column(department_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
}
... ... @@ -57,17 +58,17 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
return
}
// DeleteAchievementProvider deletes AchievementProvider by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementProvider(id int64) (err error) {
func GetAchievementProviderByAchieve(achievementid int64) ([]AchievementProvider, error) {
var (
err error
data []AchievementProvider
)
o := orm.NewOrm()
v := AchievementProvider{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AchievementProvider{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
_, err = o.QueryTable(&AchievementProvider{}).
Filter("achievement_id", achievementid).
All(&data)
if err == orm.ErrNoRows {
return data, nil
}
return
return data, err
}
... ...
... ... @@ -11,37 +11,43 @@ type AchievementProvider struct {
//AchievementChance 成果的机会列表
type AchievementChance struct {
Id int64 `json:"id"`
Id string `json:"id"` //大整数特别处理
Code string `json:"code"`
}
type AchievementImage struct {
Path string `json:"path"`
W int `json:"-"`
H int `json:"-"`
}
//RequestAddAchievement 添加成果
type RequestAddAchievement struct {
ChanceData []AchievementChance `json:"chance_data"`
TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type
TypeIdB int `json:"type_id_b"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
UserCompanyId int64 `json:"user_company_id"` //把握人的id
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []string `json:"image"` //图片
ChanceData []AchievementChance `json:"chance_data"`
ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
UserCompanyId int64 `json:"user_company_id"` //把握人的id
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []AchievementImage `json:"image"` //图片
}
//RequestAddAchievement 添加成果
type RequestEditAchievement struct {
AchievementId int64 `json:"achievement_id"`
ChanceData []AchievementChance `json:"chance_data"`
TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type
TypeIdB int `json:"type_id_b"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
UserCompanyId int64 `json:"user_company_id"` //把握人的id
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []string `json:"image"` //图片
AchievementId int64 `json:"achievement_id"`
ChanceData []AchievementChance `json:"chance_data"`
ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
UserCompanyId int64 `json:"user_company_id"` //把握人的id
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []AchievementImage `json:"image"` //图片
}
// ResponseRankSeasonList 赛季列表
... ... @@ -63,19 +69,19 @@ type AchievementListItem struct {
//ResponseAchievementInfo 成果详情
type ResponseAchievementInfo struct {
AchievementId int64 `json:"achievement_id"`
ChanceData []AchievementChance `json:"chance_data"`
TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type
TypeNameA string `json:"type_name_a"`
TypeIdB int `json:"type_id_b"` //机会二级分类
TypeNameB string `json:"type_name_b"`
DepartmentId int64 `json:"department_id"` //把握人的部门
DeparmentName string `json:"department_name"`
UserCompanyId int64 `json:"user_company_id"` //把握人的id
UserName string `json:"user_name"`
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []string `json:"image"` //图片
AchievementId int64 `json:"achievement_id"`
ChanceData []AchievementChance `json:"chance_data"`
ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
ChanceTypeName string `json:"chance_type_name"` //机会一级分类 chance_type
AuditTemplateName string `json:"audit_template_name"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
DeparmentName string `json:"department_name"`
UserCompanyId int64 `json:"user_company_id"` //把握人的id
UserName string `json:"user_name"`
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []AchievementImage `json:"image"` //图片
}
... ...
... ... @@ -124,6 +124,7 @@ func init() {
beego.NSRouter("/list", &controllers.AchievementController{}, "post:AchievementList"),
beego.NSRouter("/add", &controllers.AchievementController{}, "post:AddAchievement"),
beego.NSRouter("/edit", &controllers.AchievementController{}, "post:EditAchievement"),
beego.NSRouter("/info", &controllers.AchievementController{}, "post:AchievementInfo"),
),
)
... ...
... ... @@ -7,6 +7,7 @@ import (
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strconv"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -40,9 +41,10 @@ func addAchievementChance(addData []protocol.AchievementChance, achievementId in
)
nowTime := time.Now()
for _, v := range addData {
chanceId, _ := strconv.ParseInt(v.Id, 10, 64)
m := models.AchievementChance{
AchievementId: achievementId,
ChanceId: v.Id,
ChanceId: chanceId,
ChanceCode: v.Code,
CreateAt: nowTime,
}
... ... @@ -63,8 +65,8 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er
CompanyId: companyid,
DepartmentId: addData.DepartmentId,
UserCompanyId: addData.UserCompanyId,
ChanceTypeId: addData.TypeIdA,
AuditTemplateId: addData.TypeIdB,
ChanceTypeId: addData.ChanceTypeId,
AuditTemplateId: addData.AuditTemplateId,
SourceContent: addData.SourceContent,
GraspScore: addData.GraspScore,
UserGraspScore: addData.UserGraspScore,
... ... @@ -117,8 +119,8 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64)
achievementData.UpdateAt = nowTime
achievementData.DepartmentId = editData.DepartmentId
achievementData.UserCompanyId = editData.UserCompanyId
achievementData.ChanceTypeId = editData.TypeIdA
achievementData.AuditTemplateId = editData.TypeIdB
achievementData.ChanceTypeId = editData.ChanceTypeId
achievementData.AuditTemplateId = editData.AuditTemplateId
achievementData.SourceContent = editData.SourceContent
achievementData.GraspScore = editData.GraspScore
achievementData.UserGraspScore = editData.UserGraspScore
... ... @@ -262,17 +264,83 @@ func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int
}
func GetAchievementInfo(id int64, companyId int64) *protocol.ResponseAchievementInfo {
// rspData := &protocol.ResponseAchievementInfo{
// Images: make([]string, 0),
// Provider: make([]protocol.AchievementProvider, 0),
// ChanceData: make([]protocol.AchievementChance, 0),
// }
// var (
// achievementData *models.Achievement
// providerData []models.AchievementProvider
// chanceData []models.AchievementChance
// )
rspData := &protocol.ResponseAchievementInfo{
Images: make([]protocol.AchievementImage, 0),
Provider: make([]protocol.AchievementProvider, 0),
ChanceData: make([]protocol.AchievementChance, 0),
}
var (
achievementData *models.Achievement
chanceData []models.AchievementChance
err error
)
achievementData, err = models.GetAchievementById(id)
if err == nil {
rspData.AchievementId = achievementData.Id
rspData.AuditTemplateId = achievementData.AuditTemplateId
rspData.ChanceTypeId = achievementData.ChanceTypeId
rspData.DepartmentId = achievementData.DepartmentId
rspData.SourceContent = achievementData.SourceContent
img := make([]protocol.AchievementImage, 0)
json.Unmarshal([]byte(achievementData.Images), &img)
rspData.Images = img
rspData.GraspScore = achievementData.GraspScore
rspData.UserCompanyId = achievementData.UserCompanyId
} else {
log.Error("获取achievement数据失败:%s", err)
}
chanceData, err = models.GetAchievementChanceByAchieve(id)
if err == nil {
for _, v := range chanceData {
m := protocol.AchievementChance{
Id: fmt.Sprint(v.ChanceId),
Code: v.ChanceCode,
}
rspData.ChanceData = append(rspData.ChanceData, m)
}
} else {
log.Error("获取achievement_chance数据失败:%s", err)
}
rspData.Provider = getAchievementProvider(rspData.AchievementId)
var (
usercompanyData *models.UserCompany
departmentData *models.Department
chaneTypeData *models.ChanceType
auditTempData *models.AuditTemplate
)
departmentData, err = models.GetDepartmentById(rspData.DepartmentId)
if err == nil {
rspData.DeparmentName = departmentData.Name
}
usercompanyData, err = models.GetUserCompanyById(rspData.UserCompanyId)
if err == nil {
rspData.UserName = usercompanyData.NickName
}
chaneTypeData, err = models.GetChanceTypeById(int(rspData.ChanceTypeId))
if err == nil {
rspData.ChanceTypeName = chaneTypeData.Name
}
auditTempData, err = models.GetAuditTemplateById(rspData.AuditTemplateId)
if err == nil {
rspData.AuditTemplateName = auditTempData.Name
}
return rspData
}
// models.GetAchievementById(id)
return nil
func getAchievementProvider(achievementId int64) []protocol.AchievementProvider {
sql := `SELECT a.achievement_id,a.department_id,a.user_company_id,a.user_grasp_score
,b.nick_name,c.name
FROM achievement_provider AS a
LEFT JOIN user_company AS b on a.user_company_id = b.id
LEFT JOIN department AS c ON a.department_id = c.id
WHERE achievement_id=? `
var (
err error
sqldata = make([]protocol.AchievementProvider, 0)
)
err = utils.ExecuteQueryAll(&sqldata, sql, achievementId)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
}
return sqldata
}
... ...