123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package Project
- import (
- "ERP_project/logs"
- "git.baozhida.cn/ERP_libs/lib"
- orm2 "github.com/beego/beego/v2/client/orm"
- "time"
- _ "github.com/astaxie/beego/cache/redis"
- "github.com/beego/beego/v2/adapter/orm"
- _ "github.com/go-sql-driver/mysql"
- )
- // 项目明细
- type ProjectDetail struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_project_id int `orm:"index;size(256);null"` // 项目ID
- T_function string `orm:"size(256);null"` // 功能与指标
- T_planned_time float32 `orm:"digits(12);decimals(2)"` // 计划时间(工作日)
- T_finish string `orm:"size(1024);null"` // 是否完成 0 未完成 1 已完成
- 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 *ProjectDetail) TableName() string {
- return "project_detail" // 数据库名称 // ************** 替换 FormulaList **************
- }
- type ProjectDetailDaoImpl struct {
- orm orm.Ormer
- }
- func NewProjectDetail(orm orm.Ormer) *ProjectDetailDaoImpl {
- return &ProjectDetailDaoImpl{orm: orm}
- }
- //func init() {
- // //注册模型
- // orm.RegisterModel(new(ProjectDetail))
- //}
- //type ProjectDetail_R struct {
- // T_project_id int // 项目ID
- // T_function string // 功能与指标
- // T_planned_time float32 // 计划时间(工作日)
- // T_finish string // 是否完成 0 未完成 1 已完成
- //}
- //func ProjectDetailToProjectDetail_R(t ProjectDetail) (r ProjectDetail_R) {
- // r.T_project_id = t.T_project_id
- // r.T_function = t.T_function
- // r.T_planned_time = t.T_planned_time
- // r.T_finish = t.T_finish
- //
- // return r
- //}
- // 添加
- func (dao *ProjectDetailDaoImpl) Add_ProjectDetail(r ProjectDetail) (id int64, err error) {
- id, err = dao.orm.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- return id, err
- }
- // 删除
- func (dao *ProjectDetailDaoImpl) Delete_ProjectDetail_ByT_project_id(T_project_id int) error {
- // 也可以直接使用 Model 结构体作为表名
- qs := dao.orm.QueryTable(new(ProjectDetail))
- var list []ProjectDetail
- _, err := qs.Filter("T_project_id", T_project_id).All(&list)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return err
- }
- if len(list) == 0 {
- return nil
- }
- for _, v := range list {
- _, err = dao.orm.Delete(&v)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return err
- }
- }
- return nil
- }
- // 获取列表
- func (dao *ProjectDetailDaoImpl) Read_ProjectDetail_List(T_project_id int) (r_ []ProjectDetail_R) {
- // 也可以直接使用 Model 结构体作为表名
- qs := dao.orm.QueryTable(new(ProjectDetail))
- // 过滤
- cond := orm.NewCondition()
- cond = cond.And("T_project_id", T_project_id)
- // 查询
- var r []ProjectDetail
- _, err := qs.SetCond((*orm2.Condition)(cond)).OrderBy("Id").All(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- //for _, v := range r {
- // r_ = append(r_, ProjectDetailToProjectDetail_R(v))
- //}
- return r_
- }
- func (dao *ProjectDetailDaoImpl) Read_ProjectDetail_T_State_List(T_number string) (lists orm2.ParamsList) {
- o := orm.NewOrm()
- var pl_lists orm2.ParamsList
- sql := "SELECT DISTINCT t__state FROM contract_product WHERE t_contract_number = " + T_number
- _, err := o.Raw(sql).ValuesFlat(&pl_lists)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return pl_lists
- }
|