初始
This commit is contained in:
186
internal/app/system/logic/sysProjectValue/sys_project_value.go
Normal file
186
internal/app/system/logic/sysProjectValue/sys_project_value.go
Normal file
@ -0,0 +1,186 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-03-27 12:55:26
|
||||
// 生成路径: internal/app/system/logic/sys_project_value.go
|
||||
// 生成人:xiaoyang
|
||||
// desc:projectValue
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterSysProjectValue(New())
|
||||
}
|
||||
|
||||
func New() *sSysProjectValue {
|
||||
return &sSysProjectValue{}
|
||||
}
|
||||
|
||||
type sSysProjectValue struct{}
|
||||
|
||||
func (s *sSysProjectValue) EveryList(ctx context.Context, req *system.EveryProjectValueSearchReq) (listRes *system.EveryProjectValueSearchRes, err error) {
|
||||
listRes = new(system.EveryProjectValueSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
var list []model.EveryProjectValue
|
||||
// 查询每一个项目的所有年产值/月产值
|
||||
m := dao.SysProjectValue.Ctx(ctx).As("spv")
|
||||
if req.ProId != "" {
|
||||
m = m.Where("spv.pro_id", req.ProId)
|
||||
}
|
||||
if req.Year != "" {
|
||||
m = m.Where("spv.year", req.Year).Fields("spv.year")
|
||||
}
|
||||
if req.Month != "" {
|
||||
m = m.Where("spv.month", req.Month).Fields("spv.month")
|
||||
}
|
||||
// 项目简称 short_name
|
||||
if err := m.Fields("sp.short_name As projectName,spv.id,spv.pro_id As proId,SUM(spv.pro_value) AS proValue").
|
||||
InnerJoin("sys_project sp ON sp.id = spv.pro_id").Where("sp.show_hidden !=", 2).
|
||||
Group("spv.pro_id").
|
||||
Order("sp.short_name asc").Scan(&list); err != nil {
|
||||
return
|
||||
}
|
||||
// 总数
|
||||
total := dao.SysProjectValue.Ctx(ctx).As("spv")
|
||||
if req.Year != "" {
|
||||
total = total.Where("spv.year", req.Year)
|
||||
}
|
||||
if req.Month != "" {
|
||||
total = total.Where("spv.month", req.Month)
|
||||
}
|
||||
totalvalue, err := total.Fields("SUM(spv.pro_value) AS totalValue").
|
||||
InnerJoin("sys_project sp ON sp.id = spv.pro_id").
|
||||
Value()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
totalvaluef := strconv.FormatFloat(gconv.Float64(totalvalue), 'f', 2, 64)
|
||||
|
||||
listRes.List = &model.TotalProjectValue{
|
||||
EveryProjectValue: list,
|
||||
TotalValue: gconv.String(totalvaluef),
|
||||
}
|
||||
|
||||
return
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysProjectValue) List(ctx context.Context, req *system.SysProjectValueSearchReq) (listRes *system.SysProjectValueSearchRes, err error) {
|
||||
listRes = new(system.SysProjectValueSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.SysProjectValue.Ctx(ctx).As("spv")
|
||||
if req.ProId != "" {
|
||||
m = m.Where("spv.pro_id = ?", gconv.Int64(req.ProId))
|
||||
}
|
||||
if req.Year != "" {
|
||||
m = m.Where(" spv.year= ?", req.Year)
|
||||
}
|
||||
if req.Month != "" {
|
||||
m = m.Where("spv.month = ?", req.Month)
|
||||
}
|
||||
if req.ProValue != "" {
|
||||
m = m.Where("spv.pro_Value = ?", req.ProValue)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("spv.createdAt >=? AND "+" spv.createdAt <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
if req.IsShow == "2" {
|
||||
m = m.Where("sp.show_hidden !=", req.IsShow)
|
||||
}
|
||||
// 连表删除
|
||||
var res []*model.SysProjectValueListRes
|
||||
err = m.Fields("sp.short_name AS shortName,spv.id,spv.pro_id As proId,spv.pro_value As proValue,spv.year,spv.month,spv.created_at AS createdAt").
|
||||
InnerJoin("sys_project sp ON sp.id = spv.pro_id").
|
||||
Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.SysProjectValueListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.SysProjectValueListRes{
|
||||
Id: v.Id,
|
||||
ProId: v.ProId,
|
||||
ShortName: v.ShortName,
|
||||
Year: v.Year,
|
||||
Month: v.Month,
|
||||
ProValue: v.ProValue,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysProjectValue) GetById(ctx context.Context, id int64) (res *model.SysProjectValueListRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// err = dao.SysProjectValue.Ctx(ctx).WithAll().Where(dao.SysProjectValue.Columns().Id, id).Scan(&res)
|
||||
err = dao.SysProjectValue.Ctx(ctx).As("spv").
|
||||
Fields("sp.short_name AS shortName,spv.id,spv.pro_id As proId,spv.pro_value As proValue,spv.year,spv.month,spv.created_at AS createdAt").
|
||||
InnerJoin("sys_project sp ON sp.id = spv.pro_id").
|
||||
Where("sp.show_hidden !=", 2).Where("spv.id = ?", id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysProjectValue) Add(ctx context.Context, req *system.SysProjectValueAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.SysProjectValue.Ctx(ctx).Insert(do.SysProjectValue{
|
||||
ProId: req.ProId,
|
||||
Year: req.Year,
|
||||
Month: req.Month,
|
||||
ProValue: req.ProValue,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysProjectValue) Edit(ctx context.Context, req *system.SysProjectValueEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.SysProjectValue.Ctx(ctx).WherePri(req.Id).Update(do.SysProjectValue{
|
||||
ProId: req.ProId,
|
||||
Year: req.Year,
|
||||
Month: req.Month,
|
||||
ProValue: req.ProValue,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysProjectValue) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.SysProjectValue.Ctx(ctx).Delete(dao.SysProjectValue.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user