作者 yangfu

增加 多部门统计,机会补充详情

... ... @@ -614,3 +614,24 @@ func (this *ChanceController) ChancePool() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
}
//ChanceReviseDetail 机会补充详情
//@router /chanceReviseDetail [post]
func (this *ChanceController) ChanceReviseDetail() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceReviseDetailRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceReviseDetail(header, request))
}
... ...
... ... @@ -34,7 +34,7 @@ func (this *DepartmentController) Departments() {
msg = protocol.NewReturnResponse(department.Departments(header, request))
}
//DepartmentStatistics 部门统计
//DepartmentStatistics 部门统计
//@router /statistics [post]
func (this *DepartmentController) DepartmentStatistics() {
var msg *protocol.ResponseMessage
... ... @@ -52,5 +52,26 @@ func (this *DepartmentController) DepartmentStatistics() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(department.DepartmentStatistics(header, request))
msg = protocol.NewReturnResponse(department.Statistics(header, request))
}
//DepartmentStatistic 单部门统计
//@router /statistic [post]
func (this *DepartmentController) DepartmentStatistic() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.DepartmentStatisticRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(department.DepartmentStatistic(header, request))
}
... ...
... ... @@ -244,3 +244,26 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? and send
}
return
}
func GetChanceReviseMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.status from (
select id msg_id,message content,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg
where receive_user_id =? and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.source_id = b.chance_id
order by id
LIMIT ?`
sqlCount := `select count(0)
from user_msg where receive_user_id=? and msg_type=?`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, msgType); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, uid, lastId, lastId, msgType, pageSize); err != nil {
return
}
}
return
}
... ...
... ... @@ -617,3 +617,23 @@ type CommentData struct {
//IsRead bool `json:"isRead"` //是否已读
Provider interface{} `json:"provider,omitempty"`
}
type ChanceReviseLog struct {
Provider *BaseUserInfo `json:"provider,omitempty"`
DiffContents []ReviseContent `json:"reviseContents"`
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
}
type ReviseContent struct {
Content string `json:"content"`
}
/*ChanceReviseDetail 机会补充详情*/
type ChanceReviseDetailRequest struct {
Id int64 `json:"id"`
}
type ChanceReviseDetailResponse struct {
ChanceReviseData ChanceReviseLog `json:"chanceReviseData"`
}
... ...
... ... @@ -108,3 +108,11 @@ type DepartmentStatistics struct {
ACTotal int `json:"-"` //机会成果总数 (显示)
}
/*DepartmentStatistic 单部门统计*/
type DepartmentStatisticRequest struct {
DepartmentId int `json:"did"`
}
type DepartmentStatisticResponse struct {
DepartmentStatistic DepartmentStatistics `json:"departmentStatistic"`
}
... ...
... ... @@ -113,6 +113,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceReviseDetail",
Router: `/chanceReviseDetail`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceType",
Router: `/chanceType`,
AllowHTTPMethods: []string{"post"},
... ... @@ -313,6 +321,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
beego.ControllerComments{
Method: "DepartmentStatistic",
Router: `/statistic`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
beego.ControllerComments{
Method: "DepartmentStatistics",
Router: `/statistics`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -235,4 +235,5 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte
commItem.MsgTime = msg.MsgTime.Unix() * 1000
commItem.IsRead = msg.IsRead == 1
commItem.SourceId = msg.SourceId
commItem.SourceType = msg.SourceType
}
... ...
... ... @@ -578,7 +578,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
go CheckChanceUpdate(header, chance, request)
CheckChanceDifferent(header, chance, request)
orm := orm.NewOrm()
orm.Begin()
... ... @@ -712,9 +712,8 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
}
//检查机会更新
func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
var (
//chanceData *models.ChanceData
isSaveLog bool = false
chanceReviseLog *models.ChanceReviseLog
message string
... ... @@ -729,21 +728,18 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
if header.UserId == chance.UserId {
return
}
type ChanceModifyLog struct {
DiffContents interface{} `json:"diffContents"`
Speechs []protocol.Speech `json:"speechs"`
Pictures []protocol.Picture `json:"pictures"`
Videos []protocol.Video `json:"videos"`
var modifyLog = protocol.ChanceReviseLog{}
checkIsSaveLog := func() {
if !isSaveLog {
isSaveLog = true
}
}
var modifyLog = ChanceModifyLog{}
diffFormList := func(source string, dis []*protocol.Form) {
type DiffContent struct {
Content string `json:"content"`
}
var (
src []*protocol.Form
mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
diffStructs = []DiffContent{}
src []*protocol.Form
mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
reviseContents []protocol.ReviseContent
)
jsonUnmarshal(source, &src)
for i := range src {
... ... @@ -761,16 +757,13 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
isDiff = true
}
if isDiff {
diffStructs = append(diffStructs, DiffContent{
reviseContents = append(reviseContents, protocol.ReviseContent{
Content: fmt.Sprintf("将“%v”由“%v”改为 “%v“", dis[i].Label, srcValue, dis[i].Value)})
if !isSaveLog {
isSaveLog = true
}
checkIsSaveLog()
}
}
modifyLog.DiffContents = diffStructs
modifyLog.DiffContents = reviseContents
}
diffChanceData := func() {
var (
speechs []protocol.Speech
... ... @@ -782,27 +775,19 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
jsonUnmarshal(chanceData.Images, &pictures)
jsonUnmarshal(chanceData.Videos, &videos)
if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
if !isSaveLog {
isSaveLog = true
}
checkIsSaveLog()
modifyLog.Videos = request.Videos
}
if !reflect.DeepEqual(request.Pictures, pictures) {
if !isSaveLog {
isSaveLog = true
}
checkIsSaveLog()
modifyLog.Pictures = request.Pictures
}
if !reflect.DeepEqual(request.Speechs, speechs) {
if !isSaveLog {
isSaveLog = true
}
checkIsSaveLog()
modifyLog.Speechs = request.Speechs
}
} else {
if !isSaveLog {
isSaveLog = true
}
checkIsSaveLog()
modifyLog.Speechs = request.Speechs
modifyLog.Videos = request.Videos
modifyLog.Speechs = request.Speechs
... ... @@ -2264,3 +2249,23 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
}
return
}
//机会补充详情
func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.ChanceReviseDetailRequest) (rsp *protocol.ChanceReviseDetailResponse, err error) {
var (
detail *models.ChanceReviseLog
provider *protocol.BaseUserInfo
)
if detail, err = models.GetChanceReviseLogById(request.Id); err != nil {
log.Error(err)
return
}
rsp = &protocol.ChanceReviseDetailResponse{}
if provider, err = agg.GetUserBaseInfo(detail.UserCompanyId, header.CompanyId); err != nil {
log.Error(err)
return
}
json.Unmarshal([]byte(detail.Data), &rsp.ChanceReviseData)
rsp.ChanceReviseData.Provider = provider
return
}
... ...
... ... @@ -74,8 +74,8 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
return nil
}
//部门统计
func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) {
//多部门统计
func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) {
var (
departmentsResponse *protocol.DepartmentsResponse
)
... ... @@ -127,3 +127,31 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa
sort.Sort(rsp)
return
}
//单部门统计
func DepartmentStatistic(header *protocol.RequestHeader, request *protocol.DepartmentStatisticRequest) (rsp *protocol.DepartmentStatisticResponse, err error) {
var (
dIds []int
deparment *models.Department
)
rsp = &protocol.DepartmentStatisticResponse{}
if deparment, err = models.GetDepartmentById(request.DepartmentId); err != nil {
log.Error(err)
return
}
departmentStatistic := protocol.DepartmentStatistics{}
departmentStatistic.Dep = protocol.Dep{
Id: deparment.Id,
Name: deparment.Name,
}
if dIds, err = agg.GetDepartmentIds(header.CompanyId, request.DepartmentId); err != nil {
log.Error(err)
return
}
departmentStatistic.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds)
departmentStatistic.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, request.DepartmentId, 0, 0, nil)
departmentStatistic.ACTotal = departmentStatistic.AchievementTotal + departmentStatistic.ChanceApprovedTotal
departmentStatistic.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, dIds)
rsp.DepartmentStatistic = departmentStatistic
return
}
... ...
... ... @@ -593,7 +593,7 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance
total int
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil {
if total, err = models.GetChanceReviseMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeChanceRevise, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -611,7 +611,6 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance
commItem.ChanceId = chance.ChanceId
commItem.ReviewStatus = chance.ReviewStatus
//commItem.ChanceReviseLogId = chance.SourceId
rsp.List = append(rsp.List, commItem)
}
return
... ...