123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- package Project
- import (
- "ERP_project/logs"
- "ERP_project/models/Account"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- "gogs.baozhida.cn/zoie/ERP_libs/lib"
- "strconv"
- "strings"
- "time"
- )
- const (
- Delete = iota
- WaitAudit // 待审核
- HaveInHand // 进行中
- Completed // 已完成
- PayPerf // 已发绩效
- )
- // 项目管理
- type Project struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_uid string `orm:"index;size(32);null"` // 用户uuid
- T_dept int `orm:"index;size(8);null"` // 部门
- T_name string `orm:"size(256);null"` // 项目名称
- T_start_date string `orm:"size(256);null"` // 开始日期
- T_end_date string `orm:"size(256);null"` // 结束日期
- T_set_up_date string `orm:"size(256);null"` // 立项日期
- T_description string `orm:"type(text);null"` // 项目简介
- T_planning_cycle float32 `orm:"digits(12);decimals(2)"` // 计划完成周期
- T_reality_cycle float32 `orm:"digits(12);decimals(2)"` // 实际完成周期
- T_advance_day float32 `orm:"digits(12);decimals(2)"` // 提前完成天数
- T_bonus float32 `orm:"digits(12);decimals(2)"` // 奖励金额
- T_Perf float32 `orm:"digits(12);decimals(2)"` // 绩效总金额
- T_detail string `orm:"type(text);null"` // 明细
- T_remark string `orm:"type(text);null"` // 备注
- T_approver string `orm:"size(32);null"` // 审批人
- T_State int `orm:"size(2);default(2)"` // 0 删除 1 待审核 2 进行中 3 已完成 4 已发绩效
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
- }
- func (t *Project) TableName() string {
- return "project"
- }
- type ProjectDaoImpl struct {
- orm orm.Ormer
- }
- func NewProject(orm orm.Ormer) *ProjectDaoImpl {
- return &ProjectDaoImpl{orm: orm}
- }
- func init() {
- //注册模型
- orm2.Debug = true
- orm.RegisterModel(new(Project))
- }
- type Project_R struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 用户名称
- T_name string // 项目名称
- T_start_date string // 开始日期
- T_end_date string // 结束日期
- T_set_up_date string // 立项日期
- T_description string // 项目简介
- T_planning_cycle float32 // 计划完成周期
- T_reality_cycle float32 // 实际完成周期
- T_advance_day float32 // 提前完成天数
- T_bonus float32 // 奖励金额
- T_Perf float32 // 绩效总金额
- T_remark string // 备注
- T_approver string // 审批人
- T_approver_name string // 审批人
- T_State int
- }
- type ProjectDetail_R struct {
- T_function string // 功能与指标
- T_planned_time float32 // 计划时间(工作日)
- T_finish string // 是否完成
- }
- type Project_Detail struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 用户名称
- T_name string // 项目名称
- T_start_date string // 开始日期
- T_end_date string // 结束日期
- T_set_up_date string // 立项日期
- T_description string // 项目简介
- T_planning_cycle float32 // 计划完成周期
- T_reality_cycle float32 // 实际完成周期
- T_advance_day float32 // 提前完成天数
- T_bonus float32 // 奖励金额
- T_Perf float32 // 绩效总金额
- T_remark string // 备注
- T_approver string // 审批人
- T_approver_name string // 审批人
- T_State int
- T_Detail []ProjectDetail_R // 项目明细
- }
- type Project_S struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 用户名称
- T_name string // 项目名称
- T_planning_cycle float32 // 开始日期
- T_end_date string // 结束日期
- T_set_up_date string // 立项日期
- T_Perf float32 // 绩效总金额
- T_State int
- }
- // ---------------- 特殊方法 -------------------
- func ProjectToProject_R(t Project) (r Project_R) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_name = t.T_name
- r.T_start_date = t.T_start_date
- r.T_end_date = t.T_end_date
- r.T_set_up_date = t.T_set_up_date
- r.T_description = t.T_description
- r.T_planning_cycle = t.T_planning_cycle
- r.T_reality_cycle = t.T_reality_cycle
- r.T_advance_day = t.T_advance_day
- r.T_bonus = t.T_bonus
- r.T_Perf = t.T_Perf
- r.T_remark = t.T_remark
- r.T_approver = t.T_approver
- r.T_approver_name = Account.Read_User_T_name_Get(t.T_approver)
- r.T_State = t.T_State
- return r
- }
- func ProjectToProject_Detail(t Project) (r Project_Detail) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_name = t.T_name
- r.T_start_date = t.T_start_date
- r.T_end_date = t.T_end_date
- r.T_set_up_date = t.T_set_up_date
- r.T_description = t.T_description
- r.T_planning_cycle = t.T_planning_cycle
- r.T_reality_cycle = t.T_reality_cycle
- r.T_advance_day = t.T_advance_day
- r.T_bonus = t.T_bonus
- r.T_Perf = t.T_Perf
- r.T_remark = t.T_remark
- r.T_approver = t.T_approver
- r.T_approver_name = Account.Read_User_T_name_Get(t.T_approver)
- r.T_State = t.T_State
- r.T_Detail = ProjectToProjectDetail(t.T_detail)
- return r
- }
- func ProjectToProjectDetail(T_detail string) (r []ProjectDetail_R) {
- if len(T_detail) == 0 {
- return
- }
- detailList := strings.Split(strings.Trim(T_detail, "|"), "|")
- for _, detail := range detailList {
- T_function := strings.Split(detail, ",")[0]
- T_planned_time := strings.Split(detail, ",")[1]
- T_finish := strings.Split(detail, ",")[2]
- r = append(r, ProjectDetail_R{
- T_function: T_function,
- T_planned_time: float32(lib.StringToFloat64TwoDecimal(T_planned_time)),
- T_finish: T_finish,
- })
- }
- return r
- }
- func ProjectToProject_S(t Project) (r Project_S) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_name = t.T_name
- r.T_planning_cycle = t.T_planning_cycle
- r.T_end_date = t.T_end_date
- r.T_set_up_date = t.T_set_up_date
- r.T_Perf = t.T_Perf
- r.T_State = t.T_State
- return r
- }
- func (dao *ProjectDaoImpl) Read_Project_ById(id int) (r Project, err error) {
- o := orm.NewOrm()
- r = Project{Id: id}
- err = o.Read(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- return r, err
- }
- // 添加
- func (dao *ProjectDaoImpl) Add_Project(m Project) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(&m)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return
- }
- // 修改
- func (dao *ProjectDaoImpl) Update_Project(m Project, cols ...string) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Update(&m, cols...)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 删除
- func (dao *ProjectDaoImpl) Delete_Project(m Project) (id int64, err error) {
- o := orm.NewOrm()
- m.T_State = Delete
- id, err = o.Update(&m, "T_State")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 获取列表
- func (dao *ProjectDaoImpl) Read_Project_List(T_uid, T_approver string, page, page_z int) (r []Project_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Project
- qs := o.QueryTable(new(Project))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- cond = cond.And("T_State__gt", Delete)
- if len(T_uid) > 0 {
- cond = cond.And("T_uid", T_uid)
- }
- // 审批人
- if len(T_approver) > 0 {
- cond = cond.And("T_approver", T_approver)
- }
- var err error
- if page_z == 9999 {
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- } else {
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- }
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range map_r {
- r = append(r, ProjectToProject_R(v))
- }
- return r, cnt
- }
- // 获取列表
- func (dao *ProjectDaoImpl) Read_Project_Finance_List(T_uuid string, page, page_z int) (r []Project_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Project
- qs := o.QueryTable(new(Project))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- state := []int{Completed, PayPerf}
- cond = cond.And("T_uid", T_uuid).And("T_State__in", state)
- var err error
- if page_z == 9999 {
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- } else {
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- }
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range map_r {
- r = append(r, ProjectToProject_R(v))
- }
- return r, cnt
- }
- func (dao *ProjectDaoImpl) Read_T_uuid_List(T_approver string) (lists []string) {
- o := orm.NewOrm()
- var pl_lists orm2.ParamsList
- sql := "SELECT DISTINCT t_uid FROM project"
- if len(T_approver) > 0 {
- sql += " WHERE t_approver = '" + T_approver + "'"
- } else {
- sql += " WHERE t__state in ('" + strconv.Itoa(Completed) + "','" + strconv.Itoa(PayPerf) + "')"
- }
- sql += " LIMIT 0,1000"
- _, err := o.Raw(sql).ValuesFlat(&pl_lists)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range pl_lists {
- lists = append(lists, v.(string))
- }
- return lists
- }
|