...
|
...
|
@@ -2,19 +2,16 @@ package audit |
|
|
|
|
|
import (
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
orm2 "github.com/astaxie/beego/orm"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/services/agg"
|
|
|
"oppmg/utils"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
//添加模板
|
|
|
func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) {
|
|
|
var (
|
|
|
auditForm *models.AuditForm
|
...
|
...
|
@@ -30,7 +27,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs |
|
|
//模板
|
|
|
{
|
|
|
template = &models.AuditTemplate{
|
|
|
ChanceTypeId: request.Template.ChanceTypeId,
|
|
|
CompanyId: int(companyId),
|
|
|
Name: request.Template.Name,
|
|
|
Doc: request.Template.Doc,
|
...
|
...
|
@@ -78,7 +74,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs |
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板更新
|
|
|
func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
...
|
...
|
@@ -181,158 +176,8 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input |
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板列表
|
|
|
func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) {
|
|
|
var (
|
|
|
chanceTypes []*models.ChanceType
|
|
|
templates []*models.AuditTemplate
|
|
|
)
|
|
|
if chanceTypes, err = models.GetChanceTypeByCompany(int(companyId)); err != nil {
|
|
|
log.Error("get:%v msg:%v", companyId, err.Error())
|
|
|
return
|
|
|
}
|
|
|
var ()
|
|
|
rsp = &protocol.TemplateListResponse{}
|
|
|
for i := 0; i < len(chanceTypes); i++ {
|
|
|
t := chanceTypes[i]
|
|
|
item := &protocol.TemplateList{
|
|
|
Id: t.Id,
|
|
|
Name: t.Name,
|
|
|
Icon: t.Icon,
|
|
|
}
|
|
|
rsp.List = append(rsp.List, item)
|
|
|
if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
continue
|
|
|
}
|
|
|
for j := range templates {
|
|
|
temp := templates[j]
|
|
|
var vObj []protocol.VisibleObject
|
|
|
//TODO:可见
|
|
|
//1.检查可见性
|
|
|
|
|
|
//2.可见对象 VisibleObject
|
|
|
if temp.VisibleType == models.VisibleTypeDepartment {
|
|
|
if vObj, err = agg.GetVisibleObject(temp.VisibleObject); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
tempItem := &protocol.TemplateItem{
|
|
|
Id: temp.Id,
|
|
|
Name: temp.Name,
|
|
|
Doc: temp.Doc,
|
|
|
Icon: temp.Icon,
|
|
|
EnableStatus: temp.EnableStatus,
|
|
|
Sort: temp.SortNum,
|
|
|
VisibleType: temp.VisibleType,
|
|
|
VisibleObject: vObj,
|
|
|
}
|
|
|
item.Templates = append(item.Templates, tempItem)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//编辑可见范围
|
|
|
func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVisibleRequest) (rsp *protocol.TemplateEditVisibleResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
data []byte
|
|
|
)
|
|
|
rsp = &protocol.TemplateEditVisibleResponse{}
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if template.CompanyId != int(companyId) {
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, template.CompanyId)
|
|
|
return
|
|
|
}
|
|
|
if data, err = json.Marshal(request.VisibleObject); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(template, map[string]interface{}{"VisibleObject": string(data)}); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//操作一级分类
|
|
|
func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) {
|
|
|
var (
|
|
|
chanceType *models.ChanceType
|
|
|
)
|
|
|
rsp = &protocol.TemplateOperateCategoryResponse{}
|
|
|
if request.Id > 0 { //编辑
|
|
|
if chanceType, err = models.GetChanceTypeById(request.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
if chanceType.CompanyId != int(companyId) {
|
|
|
err = protocol.NewErrWithMessage("10027")
|
|
|
log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId)
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "UpdateAt": time.Now()}); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
chanceType = &models.ChanceType{
|
|
|
Name: request.Name,
|
|
|
Icon: request.Icon,
|
|
|
CompanyId: int(companyId),
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
if _, err = models.AddChanceType(chanceType); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取模板详情
|
|
|
func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
auditForm []*models.AuditForm
|
|
|
)
|
|
|
rsp = &protocol.TemplateGetResponse{}
|
|
|
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
|
|
|
log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
{
|
|
|
rsp.Template = protocol.Template{
|
|
|
Id: template.Id,
|
|
|
ChanceTypeId: template.ChanceTypeId,
|
|
|
Name: template.Name,
|
|
|
Doc: template.Doc,
|
|
|
Icon: template.Icon,
|
|
|
}
|
|
|
rsp.Example = template.Example
|
|
|
|
|
|
if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil {
|
|
|
if err == sql.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
for i := range auditForm {
|
|
|
input := auditForm[i]
|
|
|
rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{
|
|
|
Id: input.Id,
|
|
|
Sort: input.SortNum,
|
|
|
Lable: input.InputType,
|
|
|
Required: int(input.Required),
|
|
|
SectionType: input.Section,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|