作者 tangxvhui

提交保存

package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/protocol"
serveachievement "oppmg/services/achievement"
)
type AchievementController struct {
BaseController
}
//List 成果列表
//@router /achievement/list
func (c AchievementController) List() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
Status int `json:"status"`
}
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.GetAchievementList(param.PageIndex, param.PageSize, companyid, param.Status)
msg = protocol.NewReturnResponse(rspdata, nil)
return
}
... ...
... ... @@ -191,12 +191,14 @@ func (c RankController) RankSeasonEdit() {
)
t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
if err != nil {
log.Error(err.Error())
msg = protocol.BadRequestParam("1")
return
}
beginTime = t1.Unix()
t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
if err != nil {
log.Error(err.Error())
msg = protocol.BadRequestParam("1")
return
}
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type AchievementChance struct {
Id int `orm:"column(id);pk"`
Id int64 `orm:"column(id);pk"`
AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
... ... @@ -36,7 +33,7 @@ func AddAchievementChance(m *AchievementChance) (id int64, err error) {
// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
// Id doesn't exist
func GetAchievementChanceById(id int) (v *AchievementChance, err error) {
func GetAchievementChanceById(id int64) (v *AchievementChance, err error) {
o := orm.NewOrm()
v = &AchievementChance{Id: id}
if err = o.Read(v); err == nil {
... ... @@ -45,84 +42,6 @@ func GetAchievementChanceById(id int) (v *AchievementChance, err error) {
return nil, err
}
// GetAllAchievementChance retrieves all AchievementChance matches certain condition. Returns empty list if
// no records exist
func GetAllAchievementChance(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(AchievementChance))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []AchievementChance
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAchievementChance updates AchievementChance by Id and returns error if
// the record to be updated doesn't exist
func UpdateAchievementChanceById(m *AchievementChance) (err error) {
... ... @@ -140,7 +59,7 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) {
// DeleteAchievementChance deletes AchievementChance by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementChance(id int) (err error) {
func DeleteAchievementChance(id int64) (err error) {
o := orm.NewOrm()
v := AchievementChance{Id: id}
// ascertain id exists in the database
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type AchievementProvider struct {
Id int `orm:"column(id);pk" description:"主键id"`
Id int64 `orm:"column(id);pk" description:"主键id"`
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:"把握人得分"`
... ... @@ -36,7 +33,7 @@ func AddAchievementProvider(m *AchievementProvider) (id int64, err error) {
// GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if
// Id doesn't exist
func GetAchievementProviderById(id int) (v *AchievementProvider, err error) {
func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) {
o := orm.NewOrm()
v = &AchievementProvider{Id: id}
if err = o.Read(v); err == nil {
... ... @@ -45,84 +42,6 @@ func GetAchievementProviderById(id int) (v *AchievementProvider, err error) {
return nil, err
}
// GetAllAchievementProvider retrieves all AchievementProvider matches certain condition. Returns empty list if
// no records exist
func GetAllAchievementProvider(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(AchievementProvider))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []AchievementProvider
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAchievementProvider updates AchievementProvider by Id and returns error if
// the record to be updated doesn't exist
func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
... ... @@ -140,7 +59,7 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
// DeleteAchievementProvider deletes AchievementProvider by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementProvider(id int) (err error) {
func DeleteAchievementProvider(id int64) (err error) {
o := orm.NewOrm()
v := AchievementProvider{Id: id}
// ascertain id exists in the database
... ...
... ... @@ -156,8 +156,8 @@ func GetUserCompanyReal(ids []int64) ([]UserCompany, error) {
func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) {
o := orm.NewOrm()
sql := `select a.*,b.nick_name from (
select id,user_id from user_company where company_id=? and enable=1
)a inner join user b on a.user_id = b.id`
select id,user_id from user_company where company_id=? and enable=1
)a inner join user b on a.user_id = b.id`
if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
return v, nil
}
... ...
package protocol
//RequestAddAchievement 添加成果
type RequestAddAchievement struct {
ChanceData []AchievementChance `json:"chance_data"`
TypeA int `json:"type_a"` //机会一级分类 chance_type
TypeB int `json:"type_b"` //机会二级分类
DepartmentId int64 `json:"department_id"` //把握人的部门
UserCompanyId int64 `json:"user_company_id"` //把握人的id
GraspScore int `json:"grasp_score"` //把握分
UserGraspScore int `json:"user_grasp_score"` //把握人总得分
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []string `json:"image"` //图片
}
//ProviderData 成果提供者
type AchievementProvider struct {
UserCompanyId int64 `json:"user_company_id"` //用户的id
UserName string `json:"user_name"` //用户名称
DepartmentId int64 `json:"department_id"` //部门id
UserGraspScore int64 `json:"user_grasp_score"` //把握人得分
}
//AchievementChance 成果的机会列表
type AchievementChance struct {
Id int64 `json:"id"`
Code string `json:"code"`
}
// ResponseRankSeasonList 赛季列表
type AchievementList struct {
ResponsePageInfo
List []AchievementListItem `json:"lists"`
}
//AchievementListItem 成果列表
type AchievementListItem struct {
Id int64 `json:"id"`
CreateTime string `json:"create_time"`
TypeA string `json:"type_a"`
TypeB string `json:"type_b"`
GraspScore string `json:"grasp_score"`
Status int `json:"status"`
UserGrasp string `json:"user_grasp"`
}
... ...
... ... @@ -26,6 +26,8 @@ type RankRangeItem struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
RangeType int8 `json:"range_type" orm:"column(type)"`
Status int8 `json:"status" orm:"column(status)"`
RangeData string `json:"range_data" orm:"-"`
}
//ResponseRankRangeInfo 赛季参与人详情
... ...
... ... @@ -120,7 +120,9 @@ func init() {
beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"),
beego.NSRouter("/item/edit", &controllers.RankController{}, "post:RankItemEdit"),
),
beego.NSNamespace("/achievement"),
beego.NSNamespace("/achievement",
beego.NSRouter("/list", &controllers.AchievementController{}, "post:List"),
),
)
nsAuth := beego.NewNamespace("/auth",
... ...
package achievement
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
)
func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error {
//操作achievement 成果表
//操作 achievement_chance 机会来源表
//操作achievement_provider 成果提供人表
return nil
}
func EditAchievement() error {
return nil
}
func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int) protocol.AchievementList {
dataSql := `SELECT a.id,a.chance_type_id,a.grasp_score,user_company_id
,a.create_at,a.status,a.audit_template_id
FROM achievement AS a WHERE a.company_id=? `
countSql := ` SELECT COUNT(*) FROM achievement AS a WHERE a.company_id=? `
pageStart := (pageIndex - 1) * pageSize
cond := []interface{}{companyId}
if status > 0 {
dataSql += ` AND a.status=? `
countSql += ` AND a.status=? `
cond = append(cond, status)
} else {
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)
type SqlData struct {
Id int64 `orm:"column(id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
GraspScore string `orm:"column(grasp_score)"`
UserCompanyId int64 `orm:"column(user_company_id)"`
CreateAt string `orm:"column(create_at)"`
Status int `orm:"column(status)"`
AuditTemplateId int64 `orm:"column(audit_template_id)"`
}
var (
sqldata []SqlData
cnt int
err error
)
rspData := protocol.AchievementList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0, CurrentPage: pageIndex,
},
List: make([]protocol.AchievementListItem, 0),
}
err = utils.ExecuteQueryOne(&cnt, countSql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
if cnt == 0 {
return rspData
}
err = utils.ExecuteQueryOne(&sqldata, dataSql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
for i := range sqldata {
m := protocol.AchievementListItem{
Id: sqldata[i].Id,
CreateTime: sqldata[i].CreateAt,
GraspScore: sqldata[i].GraspScore,
Status: sqldata[i].Status,
}
var (
chanceTypeA *models.ChanceType //一级分类
chanceTypeB *models.AuditTemplate //二级分类
usercompany *models.UserCompany
err error
)
chanceTypeA, err = models.GetChanceTypeById(sqldata[i].ChanceTypeId)
if err == nil {
m.TypeA = chanceTypeA.Name
} else {
log.Error(err.Error())
}
chanceTypeB, err = models.GetAuditTemplateById(sqldata[i].AuditTemplateId)
if err == nil {
m.TypeB = chanceTypeB.Name
} else {
log.Error(err.Error())
}
usercompany, err = models.GetUserCompanyById(sqldata[i].UserCompanyId)
if err == nil {
usr, err := models.GetUserById(usercompany.UserId)
if err == nil {
m.UserGrasp = usr.NickName
} else {
log.Error(err.Error())
}
} else {
log.Error(err.Error())
}
rspData.List = append(rspData.List, m)
}
return rspData
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"oppmg/protocol"
"oppmg/utils"
"sort"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -252,14 +253,61 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem {
err error
rspData = make([]protocol.RankRangeItem, 0)
)
datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?`
datasql := `SELECT a.id ,a.name,a.type,a.status FROM rank_range AS a WHERE company_id=?`
err = utils.ExecuteQueryAll(&rspData, datasql, companyid)
if err != nil {
log.Error("获取参与人列表失败:%s", err)
}
for i := range rspData {
var nameList []string
relations := getRangeDataRelationLsit(rspData[i].Id, rspData[i].RangeType)
for ii := range relations {
nameList = append(nameList, relations[ii].Name)
}
rspData[i].RangeData = strings.Join(nameList, ",")
}
return rspData
}
//getRangeDataLsit 获取range_data的数据
func getRangeDataRelationLsit(rankRangeId int64, rangeType int8) []protocol.RankRangeRelation {
rankRangeData, _ := models.GetRankRangeDataByRangeId(rankRangeId)
var relationIds []int64
for i := range rankRangeData {
relationIds = append(relationIds, rankRangeData[i].RelationId)
}
datalist := make([]protocol.RankRangeRelation, 0)
switch rangeType {
case models.RANK_RANGE_TYPE_DEPARTMENT:
//员工
users, err := models.GetUserCompanyByIds(relationIds)
if err != nil {
log.Error("获取员工数据失败")
}
for i := range users {
m := protocol.RankRangeRelation{
Id: users[i].Id,
Name: users[i].NickName,
}
datalist = append(datalist, m)
}
case models.RANK_RANGE_TYPE_EMPLAYEE:
//部门
departments, err := models.GetDepartmentByIds(relationIds)
if err != nil {
log.Error("获取部门数据失败")
}
for i := range departments {
m := protocol.RankRangeRelation{
Id: departments[i].Id,
Name: departments[i].Name,
}
datalist = append(datalist, m)
}
}
return datalist
}
func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []int64, companyid int64) error {
var (
rankRangeDatas []models.RankRangeData
... ...