作者 tangxvhui

机会储备池

... ... @@ -242,3 +242,72 @@ func (c *AuditController) ChanceCheckResultPassOrNo() {
msg = protocol.NewReturnResponse(nil, err)
return
}
//GetChanceReserveTypeList 获取机会储备池分类类型
//@router /v1/chance/reserve_type/list
func (c *AuditController) ChanceReserveTypeList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
list := serveaudit.GetReserveTypeLsit(param.PageIndex, param.PageSize)
msg = protocol.NewReturnResponse(list, nil)
return
}
//EditReserveType 编辑机会储备池分类类型
//@router /v1/chance/reserve_type/edit
func (c *AuditController) EditReserveType() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int `json:"id"`
Name string `json:"name"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
var err error
if param.Id == 0 {
err = serveaudit.AddReserveType(param.Name)
} else {
err = serveaudit.EditReserveType(param.Id, param.Name)
}
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditReserveType 编辑机会储备池分类类型
//@router /v1/chance/reserve_type/delete
func (c *AuditController) DeleteReserveType() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
err := serveaudit.DeleteReserveType(param.Id)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type ChanceReserveType struct {
Id int `orm:"column(id);auto"`
Name string `orm:"column(name);size(50)" description:"储备类型名称"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
SortNum int `orm:"column(sort_num);null" description:"序号 "`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "`
}
func (t *ChanceReserveType) TableName() string {
return "chance_reserve_type"
}
func init() {
orm.RegisterModel(new(ChanceReserveType))
}
// AddChanceReserveType insert a new ChanceReserveType into database and returns
// last inserted Id on success.
func AddChanceReserveType(m *ChanceReserveType) (id int64, err error) {
m.CreateAt = time.Now()
m.UpdateAt = time.Now()
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
func UpdateChanceReserveType(m *ChanceReserveType, cols []string) (err error) {
m.UpdateAt = time.Now()
cols = append(cols, "UpdateAt")
o := orm.NewOrm()
_, err = o.Update(m, cols...)
return
}
func DeleteChanceReserveType(id int) (err error) {
o := orm.NewOrm()
m := &ChanceReserveType{Id: id}
_, err = o.Delete(m)
return err
}
... ...
... ... @@ -338,3 +338,15 @@ type RspCheckResultList struct {
CommentTotal string `json:"comment_total"`
CheckResultStatusName string `json:"check_result_status_name"` //自查内容筛选状态
}
//ResponseChanceReserveTypeList 机会储备池列表
type ResponseChanceReserveTypeList struct {
ResponsePageInfo
List []ChanceReserveTypeData `json:"lists"`
}
//ChanceReserveTypeData 机会储备池列表
type ChanceReserveTypeData struct {
Id int `json:"id"`
Name string `json:"name"`
}
... ...
package audit
import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"github.com/astaxie/beego/orm"
)
func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceReserveTypeList {
rsp := protocol.ResponseChanceReserveTypeList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0,
CurrentPage: pageIndex,
},
List: make([]protocol.ChanceReserveTypeData, 0),
}
var (
cnt int64
allData []models.ChanceReserveType
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&models.ChanceReserveType{}).Count()
if err != nil {
log.Error("获取chance_reserve_type记录数失败,err:%s", err)
return rsp
}
if cnt == 0 {
return rsp
}
first := (pageIndex - 1) * pageSize
_, err = o.QueryTable(&models.ChanceReserveType{}).
OrderBy("-create_at").
Limit(pageSize, first).
All(&allData)
if err != nil {
log.Error("获取chance_reserve_type数据失败,err:%s", err)
return rsp
}
for i := range allData {
d := protocol.ChanceReserveTypeData{
Id: allData[i].Id,
Name: allData[i].Name,
}
rsp.List = append(rsp.List, d)
}
rsp.TotalPage = int(cnt)
return rsp
}
func AddReserveType(name string) error {
m := &models.ChanceReserveType{
Name: name,
}
_, err := models.AddChanceReserveType(m)
if err != nil {
log.Error("添加储备池类似失败,err:%s", err)
}
return nil
}
func EditReserveType(id int, name string) error {
m := &models.ChanceReserveType{
Id: id,
Name: name,
}
err := models.UpdateChanceReserveType(m, []string{"Name"})
if err != nil {
log.Error("更新储备池类似失败,err:%s", err)
}
return nil
}
func DeleteReserveType(id int) error {
err := models.DeleteChanceReserveType(id)
if err != nil {
log.Error("删除储备池类似失败,err:%s", err)
}
return nil
}
... ...