|
|
package chance
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"opp/internal/repository"
|
...
|
...
|
@@ -16,7 +18,7 @@ import ( |
|
|
func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) {
|
|
|
var (
|
|
|
favorites []*models.ChanceFavorite
|
|
|
chance *protocol.Chance
|
|
|
chance *protocol.ChanceDetail
|
|
|
)
|
|
|
rsp = &protocol.FavoriteResponse{}
|
|
|
favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites(
|
...
|
...
|
@@ -54,7 +56,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) |
|
|
}
|
|
|
|
|
|
//点赞/收藏 取消点赞/收藏
|
|
|
func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyActionRequest)(rsp *protocol.SympathyActionResponse,err error){
|
|
|
func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyActionRequest) (rsp *protocol.SympathyActionResponse, err error) {
|
|
|
var (
|
|
|
exists bool
|
|
|
chanceFavoirte *models.ChanceFavorite
|
...
|
...
|
@@ -63,78 +65,454 @@ func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyAct |
|
|
incre int = 1
|
|
|
table string = "comment"
|
|
|
)
|
|
|
rsp =&protocol.SympathyActionResponse{}
|
|
|
if chanceFavoirte,err = repository.ChanceFavorite.GetChanceFavorite(header.Uid,header.CompanyId,request.Id,request.SourceType);err!=nil && err!=orm.ErrNoRows{
|
|
|
rsp = &protocol.SympathyActionResponse{}
|
|
|
if chanceFavoirte, err = repository.ChanceFavorite.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if request.SourceType == protocol.SourceType_Chance{
|
|
|
if chance,err = repository.Chance.GetChanceById(request.Id);err!=nil{
|
|
|
log.Error("机会不存在",err)
|
|
|
if request.SourceType == protocol.SourceType_Chance {
|
|
|
if chance, err = repository.Chance.GetChanceById(request.Id); err != nil {
|
|
|
log.Error("机会不存在", err)
|
|
|
return
|
|
|
}
|
|
|
chanceType = chance.ChanceType
|
|
|
table = "chance"
|
|
|
}
|
|
|
if chanceFavoirte!=nil{
|
|
|
if chanceFavoirte != nil {
|
|
|
exists = true
|
|
|
if request.MarkType ==protocol.MarkFlag_Zan {
|
|
|
if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)==0{
|
|
|
if request.MarkType == protocol.MarkFlag_Zan {
|
|
|
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) == 0 {
|
|
|
err = protocol.NewSuccessWithMessage("已经取消赞,不能重复取消赞")
|
|
|
return
|
|
|
}
|
|
|
if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)>0{
|
|
|
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) > 0 {
|
|
|
err = protocol.NewSuccessWithMessage("已经赞,不能重复点赞")
|
|
|
return
|
|
|
}
|
|
|
}else if (request.MarkType==protocol.MarkFlag_Collect){
|
|
|
if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)==0{
|
|
|
} else if request.MarkType == protocol.MarkFlag_Collect {
|
|
|
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) == 0 {
|
|
|
err = protocol.NewSuccessWithMessage("已经取消收藏,不能重复取消收藏")
|
|
|
return
|
|
|
}
|
|
|
if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)>0{
|
|
|
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) > 0 {
|
|
|
err = protocol.NewSuccessWithMessage("已经收藏,不能重复收藏")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if exists{
|
|
|
if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid,header.CompanyId,request.Id,1<<(uint(request.MarkType-1)));err!=nil{
|
|
|
log.Error(request.MarkType,err)
|
|
|
if exists {
|
|
|
if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
|
|
|
log.Error(request.MarkType, err)
|
|
|
return
|
|
|
}
|
|
|
goto END
|
|
|
}
|
|
|
//add
|
|
|
chanceFavoirte = &models.ChanceFavorite{
|
|
|
Id:idgen.Next(),
|
|
|
UserId:header.Uid,
|
|
|
CompanyId:header.CompanyId,
|
|
|
MarkFlag:request.SympathyType,
|
|
|
SourceType:request.SourceType,
|
|
|
SourceId:request.Id,
|
|
|
ChanceType:chanceType,
|
|
|
CreateAt:time.Now(),
|
|
|
EnableStatus:1,
|
|
|
Id: idgen.Next(),
|
|
|
UserId: header.Uid,
|
|
|
CompanyId: header.CompanyId,
|
|
|
MarkFlag: request.SympathyType,
|
|
|
SourceType: request.SourceType,
|
|
|
SourceId: request.Id,
|
|
|
ChanceType: chanceType,
|
|
|
CreateAt: time.Now(),
|
|
|
EnableStatus: 1,
|
|
|
}
|
|
|
if _,err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte);err!=nil{
|
|
|
if _, err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}else{
|
|
|
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v",header.Uid,request.Id,request.SympathyType))
|
|
|
} else {
|
|
|
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v", header.Uid, request.Id, request.SympathyType))
|
|
|
goto END
|
|
|
}
|
|
|
END:
|
|
|
END:
|
|
|
{
|
|
|
if request.MarkType!=protocol.MarkFlag_Zan {
|
|
|
if request.MarkType != protocol.MarkFlag_Zan {
|
|
|
return
|
|
|
}
|
|
|
if request.SympathyType==protocol.UnMarkFlag{
|
|
|
if request.SympathyType == protocol.UnMarkFlag {
|
|
|
incre = -1
|
|
|
}
|
|
|
if !utils.ExecuteSqlByRoll(true,agg.GetIncrementSql(table,"zan_total",incre,request.Id)){
|
|
|
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
|
|
|
//
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//机会类型
|
|
|
func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) {
|
|
|
var ()
|
|
|
rsp = &protocol.ChanceTypeResponse{}
|
|
|
if rsp.List, err = models.GetChanceTypeAll(); err != nil {
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取机会对应的模板列表
|
|
|
func Templates(header *protocol.RequestHeader, request *protocol.TemplatesRequest) (rsp *protocol.TemplatesResponse, err error) {
|
|
|
var (
|
|
|
templates []*models.AuditTemplate
|
|
|
forms []*models.AuditForm
|
|
|
)
|
|
|
rsp = &protocol.TemplatesResponse{}
|
|
|
if templates, err = models.GetAuditTemplates(header.CompanyId, request.ChanceType); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if len(templates) == 0 {
|
|
|
return
|
|
|
}
|
|
|
for i := range templates {
|
|
|
item := templates[i]
|
|
|
//TODO:检查模板可见
|
|
|
//
|
|
|
//查询表单
|
|
|
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
|
|
|
continue
|
|
|
}
|
|
|
template := &protocol.Template{
|
|
|
Id: item.Id,
|
|
|
Name: item.Name,
|
|
|
Icon: item.Icon,
|
|
|
Doc: item.Doc,
|
|
|
FormList: make([]*protocol.Form, len(forms)),
|
|
|
}
|
|
|
for j := range forms {
|
|
|
form := forms[j]
|
|
|
template.FormList[j] = &protocol.Form{
|
|
|
Id: form.Id,
|
|
|
Lable: form.Label,
|
|
|
Value: "",
|
|
|
InputType: form.InputType,
|
|
|
SectionType: form.Section,
|
|
|
Required: form.Required,
|
|
|
}
|
|
|
}
|
|
|
rsp.Templates = append(rsp.Templates, template)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
|
|
|
//if template.VisibleType ==
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//提交机会
|
|
|
func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
chance *models.Chance
|
|
|
auditConfig *protocol.AuditConfig
|
|
|
auditFlows []*models.AuditFlowProcess
|
|
|
)
|
|
|
//1.模板是否存在
|
|
|
if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
//2.检查模板是否有权限
|
|
|
|
|
|
//3.添加机会 添加文件
|
|
|
chance = &models.Chance{
|
|
|
Id: idgen.Next(),
|
|
|
UserId: header.Uid,
|
|
|
CompanyId: header.CompanyId,
|
|
|
ChanceType: template.ChanceType,
|
|
|
AuditTemplateId: template.Id,
|
|
|
AuditTemplateConfig: common.AssertJson(auditConfig),
|
|
|
Content: request.Content,
|
|
|
SourceContent: common.AssertJson(request.FormList),
|
|
|
EnableStatus: 1,
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
AuditLevel: 1,
|
|
|
DepartmentId: request.RelatedDepartment,
|
|
|
}
|
|
|
if _, err = orm.Insert(chance); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//4.查询审核配置
|
|
|
//5.生成审核流
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(auditFlows); i++ {
|
|
|
if _, err = orm.Insert(auditFlows[i]); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//6.文件
|
|
|
for _, v := range GenSpeechs(chance.Id, request.Speechs) {
|
|
|
if _, err = orm.Insert(v); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
for _, v := range GenVideos(chance.Id, request.Videos) {
|
|
|
if _, err = orm.Insert(v); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
for _, v := range GenImages(chance.Id, request.Pictures) {
|
|
|
if _, err = orm.Insert(v); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
|
|
|
//6.激活审核流
|
|
|
//TODO:7.发送消息通知给审核人(审核消息)
|
|
|
rsp = &protocol.ChanceSubmitResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//生成审批流
|
|
|
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
|
|
|
var (
|
|
|
configs []*models.AuditFlowConfig
|
|
|
IsSpecailAuditFlow bool = false
|
|
|
ids []int64
|
|
|
groupId int64
|
|
|
company *models.Company
|
|
|
)
|
|
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//1.检查是否是特殊审核人
|
|
|
for i := range configs {
|
|
|
config := configs[i]
|
|
|
if groupId == 0 && config.FlowType == protocol.FlowType_Normal {
|
|
|
groupId = config.AuditGroupId
|
|
|
continue
|
|
|
}
|
|
|
if len(config.FromSpecialUser) > 0 {
|
|
|
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for j := range ids {
|
|
|
if ids[j] == header.Uid {
|
|
|
groupId = config.AuditGroupId
|
|
|
IsSpecailAuditFlow = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if IsSpecailAuditFlow {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if groupId == 0 {
|
|
|
err = fmt.Errorf("group_id=0 template_id:%v", templateId)
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//2.查询特定的审核列表
|
|
|
if configs, err = models.GetAuditFlowConfigs(templateId, groupId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if company, err = repository.Company.GetCompanyById(header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if company.AdminId == 0 {
|
|
|
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//3.生成审核列表
|
|
|
for i := range configs {
|
|
|
config := configs[i]
|
|
|
var userIds []int64
|
|
|
switch config.AuditFlowType {
|
|
|
case protocol.AuditFlowType_Departmentor:
|
|
|
if userIds, err = getDepartmentors(header); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
case protocol.AuditFlowType_User:
|
|
|
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
case protocol.AuditFlowType_Role:
|
|
|
|
|
|
}
|
|
|
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
|
|
|
userIds = append(userIds, 0)
|
|
|
}
|
|
|
for j := 0; j < len(userIds); j++ {
|
|
|
uid := userIds[j]
|
|
|
if uid == 0 && auditConfig.NoApprover == protocol.NoApprover_ToAdmin { //审批人为空 转交给管理员
|
|
|
uid = company.AdminId
|
|
|
}
|
|
|
if uid == header.Uid { //审核人自己 转交给管理员
|
|
|
log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
|
|
|
uid = company.AdminId
|
|
|
}
|
|
|
item := &models.AuditFlowProcess{
|
|
|
Id: idgen.Next(),
|
|
|
ChanceId: chanceId,
|
|
|
Uid: uid,
|
|
|
Level: config.Level,
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
AuditFlowType: config.AuditFlowType,
|
|
|
FlowType: config.FlowType,
|
|
|
ActionType: int(config.ActionType),
|
|
|
EnableStatus: 1,
|
|
|
}
|
|
|
//if uid==0 && auditConfig.NoApprover==1{//审批人为空 自动通过
|
|
|
// item.
|
|
|
//}
|
|
|
if config.Level == 1 {
|
|
|
item.IsActive = 1
|
|
|
//通知 user_msg
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
|
|
|
v = append(v, item)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func resolveActionType(t uint) string {
|
|
|
if t == 1 {
|
|
|
return "or"
|
|
|
}
|
|
|
if t == 2 {
|
|
|
return "and"
|
|
|
}
|
|
|
return fmt.Sprintf("%v", t)
|
|
|
}
|
|
|
|
|
|
//获取部门长用户列表
|
|
|
func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
|
|
|
var (
|
|
|
departments []*protocol.Department
|
|
|
)
|
|
|
if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &departments); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
for i := 0; i < len(departments); i++ {
|
|
|
d := departments[i]
|
|
|
//部门长存在
|
|
|
if len(d.ManagerString) > 0 {
|
|
|
var tmpIds []int64
|
|
|
if err = json.Unmarshal([]byte(d.ManagerString), &tmpIds); err == nil && len(ids) > 0 {
|
|
|
ids = append(ids, tmpIds...)
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
//部门长不存在
|
|
|
if d.PId == 0 {
|
|
|
ids = append(ids, 0)
|
|
|
continue
|
|
|
} else {
|
|
|
ids = append(ids, getParentDepartmentors(d.PId)...)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//递归寻找上一级部门长
|
|
|
func getParentDepartmentors(pid int) (ids []int64) {
|
|
|
var (
|
|
|
department *models.Department
|
|
|
err error
|
|
|
)
|
|
|
if department.ParentId == 0 {
|
|
|
return
|
|
|
}
|
|
|
if department, err = repository.Department.GetDepartmentById(pid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if len(department.Managers) != 0 {
|
|
|
if err = json.Unmarshal([]byte(department.Managers), &ids); err == nil && len(ids) > 0 {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return getParentDepartmentors(department.ParentId)
|
|
|
}
|
|
|
|
|
|
////获取角色对应用户列表
|
|
|
//func getRolesUser(header *protocol.RequestHeader,toRoles string)(ids []int64){
|
|
|
// var roles []int
|
|
|
// if err :=json.Unmarshal([]byte(toRoles),&roles);err!=nil{
|
|
|
// log.Error(err)
|
|
|
// return
|
|
|
// }
|
|
|
// for i:=range roles{
|
|
|
//
|
|
|
// }
|
|
|
// return
|
|
|
//}
|
|
|
|
|
|
func GenSpeechs(id int64, objs []protocol.Speech) (v []*models.ChanceSpeech) {
|
|
|
for i := range objs {
|
|
|
v = append(v, &models.ChanceSpeech{
|
|
|
Id: idgen.Next(),
|
|
|
Duration: objs[i].Duration,
|
|
|
Path: objs[i].Path,
|
|
|
ChanceId: id,
|
|
|
CreateAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GenVideos(id int64, objs []protocol.Video) (v []*models.ChanceVideo) {
|
|
|
for i := range objs {
|
|
|
v = append(v, &models.ChanceVideo{
|
|
|
Id: idgen.Next(),
|
|
|
Path: objs[i].Path,
|
|
|
ChanceId: id,
|
|
|
Cover: objs[i].Cover,
|
|
|
CreateAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GenImages(id int64, objs []protocol.Picture) (v []*models.ChanceImage) {
|
|
|
for i := range objs {
|
|
|
v = append(v, &models.ChanceImage{
|
|
|
Id: idgen.Next(),
|
|
|
Path: objs[i].Path,
|
|
|
ChanceId: id,
|
|
|
W: objs[i].W,
|
|
|
H: objs[i].H,
|
|
|
CreateAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|