作者 tangxvhui

bug 修复

... ... @@ -7,6 +7,8 @@ import (
"oppmg/models"
"oppmg/protocol"
serveachievement "oppmg/services/achievement"
"github.com/astaxie/beego/orm"
)
type AchievementController struct {
... ... @@ -93,7 +95,6 @@ func (c AchievementController) EditAchievement() {
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestEditAchievement
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
... ... @@ -110,6 +111,25 @@ func (c AchievementController) EditAchievement() {
msg = protocol.BadRequestParam("10108")
return
}
if param.GraspScore < 0 || param.GraspScore > 100 {
log.Error(" param.GraspScore < 0 || param.GraspScore > 100 ")
msg = protocol.BadRequestParam("10121")
return
}
if param.UserGraspScore < 0 || param.UserGraspScore > 100 {
log.Error("param.UserGraspScore < 0 || param.UserGraspScore > 100")
msg = protocol.BadRequestParam("10122")
}
var providerScore float64
for _, v := range param.Provider {
providerScore += v.UserGraspScore
}
remainScore := param.GraspScore - param.UserGraspScore - providerScore
if remainScore < 0 {
log.Error("分配的总分不可大于把握分")
msg = protocol.BadRequestParam("10122")
return
}
companyid := c.GetCompanyId()
err := serveachievement.EditAchievement(&param, companyid)
msg = protocol.NewReturnResponse(nil, err)
... ... @@ -171,10 +191,19 @@ func (c AchievementController) DeleteAchievement() {
return
}
achievementData.Status = models.ACHIEVEMENT_STATUS_DEL
o := orm.NewOrm()
o.Begin()
err = models.UpdateAchievementById(achievementData, []string{"Status"})
if err != nil {
o.Rollback()
log.Error("更新achievement数据失败:%s", err)
}
err = models.IncreaseAchevementScore(companyid, -achievementData.GraspScoreRemain, o)
if err != nil {
o.Rollback()
log.Error("更新福利池失败数据失败:%s", err)
}
o.Commit()
msg = protocol.NewReturnResponse(nil, nil)
return
}
... ...
... ... @@ -499,6 +499,10 @@ func (c RankController) RankItemEdit() {
msg = protocol.BadRequestParam("1")
return
}
if len(param.ItemKey) > 4 {
msg = protocol.BadRequestParam("10123")
return
}
companyid := c.GetCompanyId()
err := serverank.GetRankItemEdit(companyid, param.RankTypeId, param.ItemKey)
msg = protocol.NewReturnResponse(nil, err)
... ...
... ... @@ -9,22 +9,23 @@ import (
)
type Achievement struct {
Id int64 `orm:"column(id);auto" description:"id 主键"`
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 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:"把握人得分"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
ViewTotal int `orm:"column(view_total);null" description:"查看总数"`
CommentTotal int `orm:"column(comment_total);null" description:"评论总数"`
ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"`
Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"`
Images string `orm:"column(images);null" description:"图片 json"`
Id int64 `orm:"column(id);auto" description:"id 主键"`
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 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:"把握人得分"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
ViewTotal int `orm:"column(view_total);null" description:"查看总数"`
CommentTotal int `orm:"column(comment_total);null" description:"评论总数"`
ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"`
Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"`
Images string `orm:"column(images);null" description:"图片 json"`
GraspScoreRemain float64 `orm:"column(grasp_score_remain);digits(4);decimals(1)" `
}
func (t *Achievement) TableName() string {
... ...
... ... @@ -38,14 +38,15 @@ type RequestAddAchievement struct {
//RequestAddAchievement 添加成果
type RequestEditAchievement struct {
AchievementId int64 `json:"achievement_id"`
ChanceData []AchievementChance `json:"chance_data"`
ChanceTypeId int64 `json:"chance_type_id"` //机会一级分类 chance_type
AuditTemplateId int64 `json:"audit_template_id"` //机会二级分类
GraspScore float64 `json:"grasp_score"` //把握分
// UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
SourceContent string `json:"source_content"` //成果描述文本
Images []AchievementImage `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"` //机会二级分类
GraspScore float64 `json:"grasp_score"` //把握分
UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分
SourceContent string `json:"source_content"` //成果描述文本
Provider []AchievementProvider `json:"provider"` //机会提供者
Images []AchievementImage `json:"image"` //图片
}
// ResponseRankSeasonList 赛季列表
... ...
... ... @@ -120,6 +120,7 @@ var errmessge ErrorMap = map[string]string{
"10110": "把握人得分不可大于把握得分",
"10121": "把握得分必填,0.1-100",
"10122": "分配的总分不可大于把握分",
"10123": "排行榜评比项最多4项",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -25,6 +25,7 @@ func addAchievementProvider(addData []protocol.AchievementProvider, achievementI
AchievementId: achievementId,
UserCompanyId: v.UserCompanyId,
UserGraspScore: v.UserGraspScore,
DepartmentId: v.DepartmentId,
CreateAt: nowTime,
}
providerList = append(providerList, m)
... ... @@ -54,6 +55,10 @@ func addAchievementChance(addData []protocol.AchievementChance, achievementId in
return err
}
func achievementGraspScoreRemain(graspScore, userGraspScore, providerScoreAll float64) float64 {
return graspScore - userGraspScore - providerScoreAll
}
//AddAchievement 添加成果
func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error {
var (
... ... @@ -61,18 +66,24 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er
err error
)
nowTime := time.Now()
var providerScore float64
for _, v := range addData.Provider {
providerScore += v.UserGraspScore
}
scoreRemain := achievementGraspScoreRemain(addData.GraspScore, addData.UserGraspScore, providerScore)
achievementData = &models.Achievement{
CompanyId: companyid,
DepartmentId: addData.DepartmentId,
UserCompanyId: addData.UserCompanyId,
ChanceTypeId: addData.ChanceTypeId,
AuditTemplateId: addData.AuditTemplateId,
SourceContent: addData.SourceContent,
GraspScore: addData.GraspScore,
UserGraspScore: addData.UserGraspScore,
CreateAt: nowTime,
UpdateAt: nowTime,
Status: models.ACHIEVEMENT_STATUS_YES,
CompanyId: companyid,
DepartmentId: addData.DepartmentId,
UserCompanyId: addData.UserCompanyId,
ChanceTypeId: addData.ChanceTypeId,
AuditTemplateId: addData.AuditTemplateId,
SourceContent: addData.SourceContent,
GraspScore: addData.GraspScore,
UserGraspScore: addData.UserGraspScore,
CreateAt: nowTime,
UpdateAt: nowTime,
Status: models.ACHIEVEMENT_STATUS_YES,
GraspScoreRemain: scoreRemain,
}
if imgData, err := json.Marshal(addData.Images); err == nil {
achievementData.Images = string(imgData)
... ... @@ -105,12 +116,8 @@ func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) er
}
}
//操作achievement_score福利池数据
var providerScore float64
for _, v := range addData.Provider {
providerScore += v.UserGraspScore
}
addScore := addData.GraspScore - addData.UserGraspScore - providerScore
err = models.IncreaseAchevementScore(companyid, addScore, o)
err = models.IncreaseAchevementScore(companyid, scoreRemain, o)
if err != nil {
o.Rollback()
log.Error("更新福利池分数achevement_score失败")
... ... @@ -130,6 +137,16 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64)
log.Error("获取achievement失败:%s", err)
return protocol.NewErrWithMessage("1")
}
var (
oldRemain float64
newRamain float64
providerScore float64
)
oldRemain = achievementData.GraspScoreRemain
for _, v := range editData.Provider {
providerScore += v.UserGraspScore
}
newRamain = achievementGraspScoreRemain(editData.GraspScore, editData.UserGraspScore, providerScore)
nowTime := time.Now()
achievementData.UpdateAt = nowTime
achievementData.ChanceTypeId = editData.ChanceTypeId
... ... @@ -137,8 +154,11 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64)
achievementData.SourceContent = editData.SourceContent
achievementData.GraspScore = editData.GraspScore
achievementData.UpdateAt = nowTime
achievementData.UserGraspScore = editData.UserGraspScore
achievementData.GraspScoreRemain = newRamain
cols := []string{
"UpdateAt", "ChanceTypeId", "AuditTemplateId", "SourceContent", "GraspScore",
"UserGraspScore",
}
o := orm.NewOrm()
o.Begin()
... ... @@ -158,13 +178,33 @@ func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64)
log.Info("删除achievement_chance数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
err = addAchievementChance(editData.ChanceData, achievementData.Id, o)
if err != nil {
log.Error("添加achievement_chance失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
}
//删除提供者分数
_, err = o.QueryTable(&models.AchievementProvider{}).
Filter("achievement_id", editData.AchievementId).
Delete()
if err != nil {
o.Rollback()
log.Info("删除achievement_provider数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
err = addAchievementProvider(editData.Provider, achievementData.Id, o)
if err != nil {
log.Error("添加achievement_provider失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
}
err = models.IncreaseAchevementScore(companyid, newRamain-oldRemain, o)
if err != nil {
o.Rollback()
log.Error("更新福利池分数achevement_score失败")
return protocol.NewErrWithMessage("1")
}
o.Commit()
return nil
}
... ... @@ -184,7 +224,7 @@ func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int
dataSql += ` AND a.status>0 `
countSql += ` AND a.status>0 `
}
dataSql = fmt.Sprintf("%s ORDER BY a.create_at LIMIT %d,%d", dataSql, pageStart, pageSize)
dataSql = fmt.Sprintf("%s ORDER BY a.create_at DESC LIMIT %d,%d", dataSql, pageStart, pageSize)
type SqlData struct {
Id int64 `orm:"column(id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
... ...
... ... @@ -186,13 +186,13 @@ func SeleteGetChanceTypeList(companyid int64) []protocol.ChanceTypeBase {
func SelectCompanyUserList(pageIndex int, pageSize int, companyid int64, userName string) protocol.SelectCompanyUserList {
datasql := `SELECT b.id,a.id as user_company_id,d.nick_name,c.name AS department_name,c.id AS department_id
FROM user_company AS a
LEFT JOIN user_department AS b ON a.id = b.user_company_id and a.enable=1
LEFT JOIN user_department AS b ON a.id = b.user_company_id AND b.enable_status=1
LEFT JOIN department AS c ON b.department_id = c.id
LEFT JOIN user AS d ON a.user_id = d.id
WHERE a.delete_at = 0 AND c.company_id = ? `
countsql := `SELECT count(*)
FROM user_company AS a
LEFT JOIN user_department AS b ON a.id = b.user_company_id AND a.enable=1
LEFT JOIN user_department AS b ON a.id = b.user_company_id AND b.enable_status=1
LEFT JOIN department AS c ON b.department_id = c.id
LEFT JOIN user AS d ON a.user_id = d.id
WHERE a.delete_at = 0 AND c.company_id =? `
... ... @@ -241,12 +241,12 @@ func SelectChanceList(pageIndex int, pageSize int, companyid int64, searchType i
FROM chance as a
LEFT JOIN user_company AS b ON a.user_id = b.id
JOIN user AS c ON b.user_id = c.id
WHERE a.company_id =? `
WHERE a.company_id =? AND a.status=1 AND a.enable_status=1 AND a.review_status=3 `
countsql := `SELECT count(*)
FROM chance as a
LEFT JOIN user_company AS b ON a.user_id = b.id
JOIN user AS c ON b.user_id = c.id
WHERE a.company_id =? `
WHERE a.company_id =? AND a.status=1 AND a.enable_status=1 AND a.review_status=3 `
cond := []interface{}{companyid}
where := ""
if len(chanceCode) > 0 {
... ...
... ... @@ -191,6 +191,7 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string
EndTime: time.Unix(endTime, 0).Local(),
Status: 0,
}
_, err = models.AddRankPeriod(m)
if err != nil {
log.Error("添加赛季失败;%s", err)
... ... @@ -208,9 +209,13 @@ func RankPeriodCheckTime(rankTypeId int64, beginTime int64, endTime int64, idNot
(UNIX_TIMESTAMP(begin_time) BETWEEN %d AND %d)
OR
(UNIX_TIMESTAMP(end_time) BETWEEN %d AND %d)
OR
(%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
OR
(%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
)
LIMIT 1 `
sql = fmt.Sprintf(sql, rankTypeId, idNot, beginTime, endTime, beginTime, endTime)
sql = fmt.Sprintf(sql, rankTypeId, idNot, beginTime, endTime, beginTime, endTime, beginTime, endTime)
var cnt int
err := utils.ExecuteQueryOne(&cnt, sql)
if err != nil {
... ... @@ -240,6 +245,7 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa
m.SeasonName = name
m.BeginTime = time.Unix(beginTime, 0)
m.EndTime = time.Unix(endTime, 0)
err = models.UpdateRankPeriodById(m, []string{"SeasonName", "BeginTime", "EndTime"})
if err != nil {
log.Error("更新赛季失败;%s", err)
... ... @@ -386,7 +392,7 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
oldids []int64
)
for i := range rankRangeDatas {
oldids = append(oldids, rankRangeDatas[i].RelationId)
oldids = append(oldids, rankRangeDatas[i].Id)
}
var (
addRangeData []models.RankRangeData
... ... @@ -403,7 +409,6 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
rankRange.Type = rangetype
o := orm.NewOrm()
o.Begin()
err = models.UpdateRankRangeById(rankRange, []string{"Name", "Type"}, o)
if err != nil {
o.Rollback()
... ...