作者 yangfu

Squashed commit : 机会版本 v0.14.0

commit abd918ea
Author: yangfu <785409885@qq.com>
Date:   Thu Jun 4 18:23:25 2020 +0800

    机会池权限修改

commit 4037796f
Author: yangfu <785409885@qq.com>
Date:   Wed Jun 3 21:20:33 2020 +0800

    机会审核修改

commit eb95837a
Author: yangfu <785409885@qq.com>
Date:   Wed Jun 3 15:35:04 2020 +0800

    搜索修改

commit 350b3e1c
Author: yangfu <785409885@qq.com>
Date:   Wed Jun 3 11:34:39 2020 +0800

    机会详情修改

commit b689b20f
Author: yangfu <785409885@qq.com>
Date:   Wed Jun 3 11:33:26 2020 +0800

    机会详情修改

commit cc0930c0
Author: yangfu <785409885@qq.com>
Date:   Wed Jun 3 10:23:24 2020 +0800

    机会补充修改

commit 846b0ea0
Author: yangfu <785409885@qq.com>
Date:   Mon Jun 1 10:04:07 2020 +0800

    机会池修改

commit d8e7e218
Author: yangfu <785409885@qq.com>
Date:   Sun May 31 13:45:41 2020 +0800

    草稿箱修改

commit 35c458d9
Author: yangfu <785409885@qq.com>
Date:   Sat May 30 22:22:14 2020 +0800

    草稿箱修改

commit ab49d03a
Author: yangfu <785409885@qq.com>
Date:   Fri May 29 15:08:10 2020 +0800

    修改模板列表,单选表单赋值

commit 01cca9d6
Author: yangfu <785409885@qq.com>
Date:   Fri May 29 13:53:04 2020 +0800

    列表过滤

commit c46f5ca1
Author: yangfu <785409885@qq.com>
Date:   Fri May 29 11:36:02 2020 +0800

    fix error

commit bab101df
Author: yangfu <785409885@qq.com>
Date:   Thu May 28 17:12:39 2020 +0800

    1.修改机会变更详情

commit 73419bbf
Author: yangfu <785409885@qq.com>
Date:   Tue May 26 17:33:06 2020 +0800

    1.机会搜索  2.审核是否需要提交自查

commit ba285a34
Merge: d833d2d4 2a22d230
Author: yangfu <785409885@qq.com>
Date:   Tue May 26 10:35:50 2020 +0800

    Merge remote-tracking branch 'origin/test' into dev

commit d833d2d4
Author: yangfu <785409885@qq.com>
Date:   Mon May 18 14:12:16 2020 +0800

    修改权限过期时间

commit d72f9c03
Author: yangfu <785409885@qq.com>
Date:   Mon May 18 14:00:10 2020 +0800

    修改权限过期时间

commit de50130d
Author: yangfu <785409885@qq.com>
Date:   Mon May 18 11:14:08 2020 +0800

    修改权限过期时间
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/controllers"
"opp/protocol"
"opp/services/agg"
"opp/services/chance"
"strings"
)
... ... @@ -292,6 +293,7 @@ func (this *ChanceController) ChanceSubmit() {
msg = protocol.NewReturnResponse(nil, e)
return
}
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
}
... ... @@ -318,6 +320,7 @@ func (this *ChanceController) ChanceUpdate() {
msg = protocol.NewReturnResponse(nil, e)
return
}
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
}
... ... @@ -671,6 +674,31 @@ func (this *ChanceController) ChanceReservePool() {
msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
}
//SearchChance 搜索
//@router /search [post]
func (this *ChanceController) SearchChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChancePoolRequest
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
}
if len(strings.TrimSpace(request.KeyWord)) == 0 {
msg = protocol.BadRequestParamWithMessage(2, "请输入机会内容、员工姓名")
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
}
//ChanceReviseDetail 机会补充详情
//@router /chanceReviseDetail [post]
func (this *ChanceController) ChanceReviseDetail() {
... ... @@ -841,6 +869,7 @@ func (this *ChanceController) DraftSaveChance() {
}
header := controllers.GetRequestHeader(this.Ctx)
request.SelfChecks.SetSelfChecksLevel1ByRule()
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
msg = protocol.NewReturnResponse(chance.DraftSaveChance(header, request))
}
... ...
... ... @@ -17,6 +17,7 @@ type AuditTemplate struct {
Code string `orm:"column(code);size(50);null" description:" 编码"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SelfCheckNeed int8 `orm:"column(self_check_need)" description:"是否需要自查内容 【1:需要自查内容】【2:不需要】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
VisibleObject string `orm:"column(visible_object);size(1000);null" description:"可见的对象 部门 指定人 json"`
... ...
... ... @@ -59,6 +59,8 @@ type ChancePoolOption struct {
DIds []int //部门编号列表
Type int8 //机会类型
ReserveTypeId int //机会储备类型编号
KeyWord string //搜索特定内容的机会 (基础/附加)
InUsers []int64 //搜索特定User的机会
}
//机会池查询选项
... ... @@ -74,6 +76,17 @@ func NewChancePoolOption(chanceTypeId int, deps []int, t int8, rt int) *ChancePo
ReserveTypeId: rt,
}
}
func (o *ChancePoolOption) SetKeyWord(keyWord string) *ChancePoolOption {
o.KeyWord = keyWord
return o
}
func (o *ChancePoolOption) SetInUsers(inUsers []int64) *ChancePoolOption {
if len(inUsers) == 0 {
return o
}
o.InUsers = inUsers
return o
}
var (
SqlGetChanceSelfChecks = `select user_id,review_status,self_checks from chance where id =?` //机会自查数据
... ... @@ -569,6 +582,11 @@ func getFilterSql(option *ChancePoolOption) string {
if option.ReserveTypeId > 0 {
rsp.WriteString(fmt.Sprintf(" and reserve_type_id =%v ", option.ReserveTypeId))
}
if len(option.KeyWord) > 0 && len(option.InUsers) > 0 {
rsp.WriteString(fmt.Sprintf(" and (user_id in (%v) or source_content like '%%%v%%' )", utils.JoinInt64s(option.InUsers, ","), option.KeyWord))
} else if len(option.KeyWord) > 0 {
rsp.WriteString(fmt.Sprintf(" and source_content like '%%%v%%' ", option.KeyWord))
}
return rsp.String()
}
... ...
... ... @@ -129,3 +129,20 @@ func GetUserAllCompany(uid int64) (v []*UserCompany, err error) {
}
return nil, err
}
//获取用户Id列表
//@key CompanyId NickName
func GetUserCompanyIdAllBy(options map[string]interface{}) (v []int64, err error) {
o := orm.NewOrm()
sql := "select id from user_company where 1=1 "
if _, ok := options["CompanyId"]; ok {
sql += fmt.Sprintf(" and company_id=%v ", options["CompanyId"])
}
if _, ok := options["NickName"]; ok {
sql += fmt.Sprintf(" and nick_name like '%%%v%%' ", options["NickName"])
}
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -205,6 +205,7 @@ type ChancePoolRequest struct {
IncludeSubDepartment bool
Type int8 `json:"type"` //0:机会池 1:储备池
ReserveTypeId int `json:"reserveTypeId"` //储备类型编号
KeyWord string `json:"keyWord"` //搜索特定内容的机会
}
type ChancePoolResponse struct {
List []CommonListItem `json:"list"`
... ... @@ -512,8 +513,24 @@ type Form struct {
Label string `json:"label"`
InputType string `json:"inputType"`
SectionType int8 `json:"sectionType"`
Value string `json:"value"`
Required int8 `json:"required"`
Value string `json:"value"`
ValueList []*ValueListItem `json:"valueList"`
Data []*FormDataItem `json:"data"`
}
type ValueListItem struct {
Type string `json:"type"`
Value string `json:"value"`
}
type FormDataItem struct {
Type string `json:"type"`
Value string `json:"value"`
Path string `json:"path,omitempty"`
Cover *Cover `json:"cover,omitempty"`
Duration int `json:"duration,omitempty"`
Remark string `json:"remark,omitempty"`
}
//清楚未填写的表单数据
... ... @@ -543,7 +560,7 @@ type Picture struct {
Path string `json:"path"`
W int `json:"-"` //w
H int `json:"-"` //h
ImageId string `json:"imageId"` //imageId
ImageId string `json:"imageId,omitempty"` //imageId
PathBak string `json:"-"`
//JobId string `json:"job_id"`
}
... ... @@ -564,6 +581,17 @@ type Video struct {
//审批配置
type AuditConfig struct {
NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】
SelfCheckNeed int8 `json:"self_check_need"` //审核人是否需要提交自查 1:需要 0:不需要
}
func (c AuditConfig) GetSelfCheckNeed() int {
if c.SelfCheckNeed == 1 {
return 1
}
if c.SelfCheckNeed == 2 {
return 0
}
return 1
}
//机会池 - 统计
... ... @@ -700,7 +728,11 @@ type ChanceReviseLog struct {
}
type ReviseContent struct {
InputType string `json:"inputType"`
Label string `json:"label"`
Content string `json:"content"`
Data []*FormDataItem `json:"data"`
RemoveAllPhotoVideo bool `json:"removeAllPhotoVideo"` //是否移除所有媒体数据
}
/*ChanceReviseDetail 机会补充详情*/
... ...
... ... @@ -53,6 +53,7 @@ type ApproveAccess struct {
ProcessId int64 `json:"processId"`
AllowApprove int `json:"allowApprove"`
AllowReject int `json:"allowReject"`
SelfCheckNeed int `json:"selfCheckNeed"` //是否需要提交自查
}
//审核数据 审核通过
... ...
... ... @@ -44,6 +44,16 @@ const (
MyGraspAchievement //我把握的成果
)
//输入类型
const (
InputRadio = "radio"
InputFiles = "files"
InputCheckbox = "checkbox"
InputText = "text"
InputImage = "image"
InputVideo = "video"
)
var MapStaticName map[int64]string
func init() {
... ...
... ... @@ -178,7 +178,7 @@ type Cover struct {
Path string `json:"path" valid:"Required"`
H int `json:"-"`
W int `json:"-"`
ImageId string `json:"imageId"`
ImageId string `json:"-"`
}
/*公告列表 BulletinList */
... ...
... ... @@ -305,6 +305,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SearchChance",
Router: `/search`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SiftingPool",
Router: `/siftingPool`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -249,16 +249,119 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64)
}
}
//清楚未填写的表单数据
func ClearEmptyForm(inputFormList []*protocol.Form) (FormList []*protocol.Form) {
type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form)
type SetFormValue func(form *protocol.Form)
func SetRadioFormValue(form *protocol.Form) {
if form.InputType != protocol.InputRadio {
return
}
if len(form.Data) > 0 && form.Data[0].Type == protocol.InputText {
form.Value = form.Data[0].Value
}
}
func SetFormDefaultValue(inputFormList []*protocol.Form, funcSetForm ...SetFormValue) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
for j := range funcSetForm {
funcSetForm[j](inputFormList[i])
}
}
}
//清除未填写的表单数据
func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
item := inputFormList[i]
if len(item.Data) == 0 {
item.Data = make([]*protocol.FormDataItem, 0)
}
if len(item.ValueList) == 0 {
item.ValueList = make([]*protocol.ValueListItem, 0)
}
if len(item.Value) > 0 {
FormList = append(FormList, item)
forms = append(forms, item)
}
}
return
}
//清楚文件表单数据
func ClearFilesForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
item := inputFormList[i]
if strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
continue
}
forms = append(forms, item)
}
return
}
func FormFilter(inputFormList []*protocol.Form, fiters ...Filters) (forms []*protocol.Form) {
for i := range fiters {
inputFormList = fiters[i](inputFormList)
}
forms = inputFormList
return
}
//表单所有媒体文件
func FormsAllFiles(inputFormList []*protocol.Form) ([]protocol.Picture, []protocol.Video) {
var (
pictures []protocol.Picture = make([]protocol.Picture, 0)
videos []protocol.Video = make([]protocol.Video, 0)
)
for i := range inputFormList {
item := inputFormList[i]
if !strings.EqualFold(strings.TrimSpace(item.InputType), protocol.InputFiles) {
continue
}
for j := range item.Data {
var (
path string = item.Data[j].Path
cover *protocol.Cover = &protocol.Cover{}
duration int = item.Data[j].Duration
)
if len(strings.TrimSpace(item.Data[j].Path)) == 0 {
continue
}
switch item.Data[j].Type {
case protocol.InputImage:
pictures = append(pictures, protocol.Picture{
Path: path,
})
break
case protocol.InputVideo:
if item.Data[j].Cover == nil {
continue
}
cover = item.Data[j].Cover
videos = append(videos, protocol.Video{
Path: path,
Duration: duration,
Cover: *cover,
})
break
}
}
}
return pictures, videos
}
func CombineAllFiles(inputFormList []*protocol.Form, pics []protocol.Picture, vids []protocol.Video) ([]protocol.Picture, []protocol.Video) {
formPics, formVids := FormsAllFiles(inputFormList)
formPics = append(formPics, pics...)
formVids = append(formVids, vids...)
return formPics, formVids
}
... ...
... ... @@ -53,3 +53,14 @@ func Test_GetTopPosition(t *testing.T) {
t.Fatal("top department error")
}
}
func TestSetFormValue(t *testing.T) {
input := []*protocol.Form{
{Label: "1", InputType: "radio", Data: []*protocol.FormDataItem{{Type: protocol.InputText, Value: "选项A"}}},
}
SetFormDefaultValue(input, SetRadioFormValue)
t.Log(input[0].Value)
if input[0].Value != "选项A" {
t.Fatal("input:", input[0].Value, " except:", "选项A")
}
}
... ...
... ... @@ -56,6 +56,13 @@ func GetChancePool(uid, cid int64, o *models.ChancePoolOption, departmentId int,
}
log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid))
option := models.NewChancePoolOption(chanceTypeId, dIds, o.Type, o.ReserveTypeId)
if len(o.KeyWord) > 0 {
option.SetKeyWord(o.KeyWord)
ids, _ := models.GetUserCompanyIdAllBy(map[string]interface{}{"CompanyId": cid, "NickName": o.KeyWord})
if len(ids) > 0 {
option.SetInUsers(ids)
}
}
switch check {
case OpportunityCheckLv1:
return models.GetChancePoolMyself(uid, cid, option, lastId, pageSize, v)
... ... @@ -76,6 +83,8 @@ func GetChancePool(uid, cid int64, o *models.ChancePoolOption, departmentId int,
return models.GetChancePoolSpecialDepartment(uid, cid, option, lastId, pageSize, v, specialDIds)
case OpportunityCheckLv4:
return models.GetChancePoolAll(uid, cid, option, lastId, pageSize, v)
case OpportunityCheckLv5:
return models.GetChancePoolMyself(uid, cid, option, lastId, pageSize, v)
default:
return models.GetChancePoolAll(uid, cid, option, lastId, pageSize, v)
}
... ... @@ -233,10 +242,11 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
item.UpdateTime = 0
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
item.Pictures, item.Videos = CombineAllFiles(item.FormList, item.Pictures, item.Videos)
item.FormList = FormFilter(item.FormList, ClearEmptyForm, ClearFilesForm)
return item, chanceStatus
}
func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) {
... ...
... ... @@ -151,13 +151,14 @@ type OptionOpportunity struct {
2:仅查看自己部门和公开机会:查看对自己部门公开的机会+公司公开的机会 -> 仅查看自己部门和公开机会:查看对自己所在部门公开的机会+公司公开的机会;
3:特定部门的机会:自由配置选定部门的待审核、公司公开、部门公开的机会+查看对自己部门公开的机会 -> 特定部门的公开机会:选定部门提交的公司公开、部门公开的机会;>只选择部门
4:查看所有机会:查看所有部门的待审核机会、公开机会及部门公开机会 -> 查看所有公开机会:查看所有部门的公开机会及部门公开机会;
5. -> 特定部门的待审核机会:选定部门提交的待审核机会。>只选择部门(这条这期可以先不做)
5:特定部门的待审核机会:选定部门提交的待审核机会。>只选择部门 (只配置该权限,则机会池查看权限是 1)
*/
const (
OpportunityCheckLv1 int = 1
OpportunityCheckLv2 int = 2
OpportunityCheckLv3 int = 3
OpportunityCheckLv4 int = 4
OpportunityCheckLv5 int = 5
)
var (
... ... @@ -351,6 +352,15 @@ func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionOb
return getPermissionMap(list)
}
//权限权重 值越大,权重越大
var PermissionWeight map[int]int = map[int]int{
OpportunityCheckLv1: 1,
OpportunityCheckLv2: 2,
OpportunityCheckLv3: 3,
OpportunityCheckLv4: 4,
OpportunityCheckLv5: 1,
}
//获取机会权限map
func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
var (
... ... @@ -371,7 +381,7 @@ func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObje
specialDepIds := make(map[int64]CheckDeparment) //特定部门
for i := range list {
tmp := list[i]
if tmp.Check > obj.Check {
if tmp.Check > 0 && checkPermissionWeight(obj.Check, tmp.Check) {
obj.Check = tmp.Check
}
if _, ok := obj.CheckMap[tmp.Check]; !ok { //所有的check都加进来
... ... @@ -397,3 +407,15 @@ func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObje
objMap[M_SYSTEM_OPPORTUNITY] = obj
return objMap, nil
}
//@return true:比当前权限更大 false:比当前权限小
func checkPermissionWeight(oldCheck, newCheck int) bool {
var ow, nw int
if v, ok := PermissionWeight[oldCheck]; ok {
ow = v
}
if v, ok := PermissionWeight[newCheck]; ok {
nw = v
}
return nw > ow
}
... ...
... ... @@ -357,9 +357,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
mapProcess["EnableStatus"] = int8(1)
mapChance["Type"] = request.Type
mapChance["ReserveTypeId"] = request.ReserveTypeId
if len(request.SelfChecks) > 0 {
mapChance["SelfChecks"] = common.AssertJson(request.SelfChecks)
}
}
}
log.Info(fmt.Sprintf("用户:%v 提交审核 机会编号:%v 审批流编号:%v 审批状态:%v", header.UserId, chance.Id, process.Id, request.ReviewStatus))
if approveItemResponse, err = suplusApprove.ApproveItem(header, approveType, chance.Id, process.Id); err != nil {
log.Error(err)
... ... @@ -538,7 +540,9 @@ func ConverTypeToReviewStaus(approveType int) (reviewStatus int) {
func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance) (rsp *protocol.ChanceApproveProcessResponse, err error) {
var (
processList []*models.AuditFlowProcess
config *protocol.AuditConfig
)
utils.JsonUnmarshal(chance.AuditTemplateConfig, &config)
if processList, err = models.GetAuditFlowProcessList(chance.Id); err != nil {
log.Error(fmt.Sprintf("chance_id :%v 未查询到审核流信息", chance.Id), err)
if err == orm.ErrNoRows {
... ... @@ -592,6 +596,7 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
rsp.ApproveAccess = &protocol.ApproveAccess{
AllowApprove: 1,
AllowReject: 1,
SelfCheckNeed: config.GetSelfCheckNeed(),
ProcessId: process.Id,
}
}
... ...
... ... @@ -270,14 +270,20 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques
}
for j := range forms {
form := forms[j]
template.FormList[j] = &protocol.Form{
formItem := &protocol.Form{
Id: form.Id,
Label: form.Label,
Value: "",
InputType: form.InputType,
SectionType: form.Section,
Required: form.Required,
Data: make([]*protocol.FormDataItem, 0),
ValueList: make([]*protocol.ValueListItem, 0),
}
if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio {
utils.JsonUnmarshal(form.ValueList, &formItem.ValueList)
}
template.FormList[j] = formItem
}
rsp.Templates = append(rsp.Templates, template)
}
... ... @@ -291,6 +297,7 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
forms []*models.AuditForm
chance *models.Chance
chanceDraft *models.ChanceDraft
formData []*protocol.Form
)
rsp = &protocol.TemplateResponse{}
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
... ... @@ -331,9 +338,11 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
if chanceDraft, err = models.GetChanceDraftById(request.ChanceId); err == nil {
var old []protocol.SelfCheck
utils.JsonUnmarshal(chanceDraft.SelfChecks, &old)
utils.JsonUnmarshal(chanceDraft.SourceContent, &formData)
template.Questions = GetNewestCheckQuestions(chanceDraft.AuditTemplateId, old)
}
} else { //正常机会
utils.JsonUnmarshal(chance.SourceContent, &formData)
if template.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId); err != nil {
log.Error(err)
return
... ... @@ -347,14 +356,33 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
}
for j := range forms {
form := forms[j]
template.FormList[j] = &protocol.Form{
formItem := &protocol.Form{
Id: form.Id,
Label: form.Label,
Value: "",
InputType: form.InputType,
SectionType: form.Section,
Required: form.Required,
Data: make([]*protocol.FormDataItem, 0),
ValueList: make([]*protocol.ValueListItem, 0),
}
if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio {
utils.JsonUnmarshal(form.ValueList, &formItem.ValueList)
}
//填充旧的表单数据
setOldForm := func() {
for i := range formData {
data := formData[i]
if data.Id == formItem.Id && strings.EqualFold(data.Label, data.Label) {
formItem.Value = data.Value
formItem.Data = data.Data
}
}
}
if request.ChanceId > 0 {
setOldForm()
}
template.FormList[j] = formItem
}
rsp.Template = template
return
... ... @@ -432,7 +460,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
err = protocol.NewErrWithMessage(5302)
return
}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover, SelfCheckNeed: template.SelfCheckNeed}
orm := orm.NewOrm()
orm.Begin()
//2.检查模板是否有权限
... ... @@ -648,7 +676,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
err = protocol.NewErrWithMessage(5301)
return
}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover, SelfCheckNeed: template.SelfCheckNeed}
CheckChanceDifferent(header, chance, request)
... ... @@ -791,11 +819,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
//检查机会更新
func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
var (
isSaveLog bool = false
chanceReviseLog *models.ChanceReviseLog
message string
)
defer func() {
if p := recover(); p != nil {
log.Error(p)
... ... @@ -804,52 +827,80 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
if header.UserId == chance.UserId {
return
}
//机会是审核通过的才有编辑记录!!
if chance.ReviewStatus != protocol.ReviewStatusPass {
return
}
var modifyLog = protocol.ChanceReviseLog{
var (
isSaveLog bool = false
modifyLog = protocol.ChanceReviseLog{
RemoveAllPhotoVideo: false,
RemoveAllSpeech: false,
}
checkIsSaveLog := func() {
)
funcCheckSave := func() {
if !isSaveLog {
isSaveLog = true
}
}
diffFormList := func(source string, dis []*protocol.Form) {
funcDiffForms := func(source string, src []*protocol.Form) {
var (
src []*protocol.Form
mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
dst []*protocol.Form
mapForm = make(map[string]*protocol.Form)
reviseContents []protocol.ReviseContent
)
jsonUnmarshal(source, &src)
keyFunc := func(form *protocol.Form) string {
utils.JsonUnmarshal(source, &dst)
funcKey := func(form *protocol.Form) string {
return fmt.Sprintf("%v_%v", form.Label, form.SectionType)
}
for i := range src {
mapForm[keyFunc(src[i])] = src[i]
for i := range dst {
mapForm[funcKey(dst[i])] = dst[i]
}
for i := range dis {
isDiff := false
srcValue := ""
if v, ok := mapForm[keyFunc(dis[i])]; ok {
for i := range src {
var (
isDiff = false
oldForm *protocol.Form
srcValue = ""
)
if v, ok := mapForm[funcKey(src[i])]; ok {
srcValue = v.Value
if dis[i].Value != v.Value {
if src[i].Value != v.Value {
isDiff = true
}
if len(src[i].Data) > 0 || len(v.Data) > 0 {
if !reflect.DeepEqual(src[i].Data, v.Data) {
isDiff = true
}
}
oldForm = v
} else {
isDiff = true
}
if isDiff {
reviseContents = append(reviseContents, protocol.ReviseContent{
Content: fmt.Sprintf("将“%v”由“%v”改为 “%v”", dis[i].Label, srcValue, dis[i].Value)})
checkIsSaveLog()
c := protocol.ReviseContent{
Content: fmt.Sprintf("将“%v”由“%v”改为“%v”", src[i].Label, srcValue, src[i].Value),
Label: src[i].Label,
InputType: src[i].InputType,
Data: src[i].Data,
}
//文件表单
if src[i].InputType == protocol.InputFiles {
if oldForm != nil && len(oldForm.Data) > 0 && len(src[i].Data) == 0 {
c.RemoveAllPhotoVideo = true
}
c.Content = fmt.Sprintf("将%v修改为:", src[i].Label)
}
reviseContents = append(reviseContents, c)
funcCheckSave()
}
}
modifyLog.DiffContents = reviseContents
}
diffChanceData := func() {
funcDiffChanceData := func() {
var (
speechs []protocol.Speech
pictures []protocol.Picture
... ... @@ -860,12 +911,12 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
jsonUnmarshal(chanceData.Images, &pictures)
jsonUnmarshal(chanceData.Videos, &videos)
if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
checkIsSaveLog()
funcCheckSave()
modifyLog.Videos = request.Videos
modifyLog.Pictures = request.Pictures
}
if !reflect.DeepEqual(request.Speechs, speechs) {
checkIsSaveLog()
funcCheckSave()
modifyLog.Speechs = request.Speechs
}
... ... @@ -882,16 +933,13 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
modifyLog.RemoveAllSpeech = true
}
} else {
checkIsSaveLog()
funcCheckSave()
modifyLog.Speechs = request.Speechs
modifyLog.Videos = request.Videos
modifyLog.Speechs = request.Speechs
}
}
diffFormList(chance.SourceContent, request.FormList)
diffChanceData()
checkModifyLog := func() {
funcFormatEmpty := func() {
if len(modifyLog.Speechs) == 0 {
modifyLog.Speechs = make([]protocol.Speech, 0)
}
... ... @@ -905,13 +953,26 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
modifyLog.DiffContents = make([]protocol.ReviseContent, 0)
}
}
checkModifyLog()
if isSaveLog { //&& changeCount > 0
funcDiffForms(chance.SourceContent, request.FormList) //比对表单
funcDiffChanceData() //比对机会数据
funcFormatEmpty() //格式化变更日志
if isSaveLog {
_ = SaveChanceReviseLog(header, chance, modifyLog)
}
}
//保存机会变更日志
func SaveChanceReviseLog(header *protocol.RequestHeader, chance *models.Chance, modifyLog protocol.ChanceReviseLog) (err error) {
var (
chanceReviseLog *models.ChanceReviseLog
message string
)
orm := orm.NewOrm()
orm.Begin()
var logId int64
var logId, id int64
//发送日志
if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
if id, err = agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
... ... @@ -932,22 +993,22 @@ func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance,
orm.Rollback()
return
}
if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
log.Error(err)
if chanceType, e := models.GetChanceTypeById(chance.ChanceTypeId); e != nil {
log.Error(e)
err = e
orm.Rollback()
return
} else {
message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name)
}
//发送修改机会消息
if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
if err = agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
}
return
}
//修改公开状态
... ... @@ -1590,7 +1651,9 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
provider *protocol.BaseUserInfo
flag int
)
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, models.NewChancePoolOption(request.ChanceTypeId, []int{}, request.Type, request.ReserveTypeId), request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
options := models.NewChancePoolOption(request.ChanceTypeId, []int{}, request.Type, request.ReserveTypeId)
options.SetKeyWord(request.KeyWord)
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, options, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1615,10 +1678,11 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
CreateTime: chance.CreateTime.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
item.Pictures, item.Videos = agg.CombineAllFiles(item.FormList, item.Pictures, item.Videos)
item.FormList = agg.FormFilter(item.FormList, agg.ClearEmptyForm, agg.ClearFilesForm)
commItem.Chance = item
//点赞评论数据
... ... @@ -1953,7 +2017,7 @@ func clearEmptyForm(inputFormList []*protocol.Form) (FormList []*protocol.Form)
}
for i := range inputFormList {
item := inputFormList[i]
if len(item.Value) > 0 {
if len(item.Value) > 0 || len(item.Data) > 0 {
FormList = append(FormList, item)
}
}
... ... @@ -2018,7 +2082,6 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
UpdateTime: chance.UpdateAt.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
//jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
item.SelfChecks = agg.GetChanceSelfChecks(chance)
item.FormList = clearEmptyForm(item.FormList)
item.RelatedDepartmentId = chance.DepartmentId
... ... @@ -2102,7 +2165,6 @@ func ChanceDraftDetail(header *protocol.RequestHeader, request *protocol.ChanceD
item.RelatedDepartmentInfo = agg.GetDepartment(int(chance.DepartmentId))
jsonUnmarshal(chance.SourceContent, &item.FormList)
jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
item.FormList = clearEmptyForm(item.FormList)
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
if len(chanceData.Videos) > 0 {
... ...