初始
This commit is contained in:
@ -0,0 +1,261 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-05 12:10:40
|
||||
// 生成路径: internal/app/system/logic/qianqi_guangfuban_ids_lizhu.go
|
||||
// 生成人:gfast
|
||||
// desc:光伏板立柱
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/shp"
|
||||
"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.RegisterQianqiGuangfubanIdsLizhu(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiGuangfubanIdsLizhu {
|
||||
return &sQianqiGuangfubanIdsLizhu{}
|
||||
}
|
||||
|
||||
type sQianqiGuangfubanIdsLizhu struct{}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) GisListFunc(ctx context.Context, req *system.GisListLizhuReq, num string) (listRes *system.GisListLizhuRes, err error) {
|
||||
listRes = new(system.GisListLizhuRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).WithAll()
|
||||
if num == "1" {
|
||||
m = m.Fields("id,name,source_type,source_id,project_id,detail")
|
||||
}
|
||||
if num == "2" {
|
||||
m = m.Fields("id,name,source_type,source_id,project_id")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().CreatedAt+" >=? AND "+dao.QianqiGuangfubanIdsLizhu.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
|
||||
if req.FangZhenID != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsZhuangdian.Columns().FangzhenId+" = ?", req.FangZhenID)
|
||||
}
|
||||
|
||||
order := "name asc,id asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.QianqiGuangfubanIdsLizhuInfoRes
|
||||
array, err := m.Array()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
listRes.Total = len(array)
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
if num == "1" {
|
||||
if strings.EqualFold(req.IsPaging, "YES") {
|
||||
m = m.Fields(system.QianqiGuangfubanIdsLizhuSearchRes{}).Page(req.PageNum, req.PageSize)
|
||||
}
|
||||
} else {
|
||||
if !req.NotInPlan {
|
||||
m = m.Page(req.PageNum, req.PageSize)
|
||||
} else {
|
||||
m = m.Fields(system.QianqiGuangfubanIdsLizhuSearchRes{}).
|
||||
Where(dao.QianqiGuangfubanIdsLizhu.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=? and source_type='lizhu')", req.ProjectId)
|
||||
}
|
||||
}
|
||||
err = m.Order(order).Scan(&res)
|
||||
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiGuangfubanIdsLizhuListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiGuangfubanIdsLizhuListRes{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
SourceType: v.SourceType,
|
||||
SourceId: v.SourceId,
|
||||
ProjectId: v.ProjectId,
|
||||
Detail: v.Detail,
|
||||
}
|
||||
}
|
||||
sort.Slice(listRes.List, func(i, j int) bool {
|
||||
return listRes.List[i].Name < listRes.List[j].Name
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
type booleanvalueEntity struct {
|
||||
Position *shp.Point `json:"position"`
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) BooleanValueFunc(ctx context.Context, req *system.BooleanValueEditReq) (err error) {
|
||||
//err = g.Try(ctx, func(ctx context.Context) {
|
||||
// var lz []*model.QianqiGuangfubanIdsLizhuInfoRes
|
||||
// err = dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).Where("project_id").Fields("id,detail").Scan(&lz)
|
||||
// for _, data := range lz {
|
||||
// var bl *booleanvalueEntity
|
||||
// err = json.Unmarshal([]byte(data.Detail), &bl)
|
||||
// if err != nil {
|
||||
// liberr.ErrIsNil(ctx, err, "立柱预计值更新失败!")
|
||||
// return
|
||||
// } else {
|
||||
// if (bl.Position.Height - bl.Position.Alt) > 0.7 {
|
||||
// bl.Position.Flag = true
|
||||
// } else {
|
||||
// bl.Position.Flag = false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// dao.qianqi
|
||||
// liberr.ErrIsNil(ctx, err, "立柱预计值更新失败!")
|
||||
//})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) List(ctx context.Context, req *system.QianqiGuangfubanIdsLizhuSearchReq) (listRes *system.QianqiGuangfubanIdsLizhuSearchRes, err error) {
|
||||
listRes = new(system.QianqiGuangfubanIdsLizhuSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.CreateBy != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().CreateBy+" = ?", req.CreateBy)
|
||||
}
|
||||
if req.UpdateBy != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().UpdateBy+" = ?", req.UpdateBy)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().CreatedAt+" >=? AND "+dao.QianqiGuangfubanIdsLizhu.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
if req.SourceType != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().SourceType+" = ?", req.SourceType)
|
||||
}
|
||||
if req.SourceId != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().SourceId+" = ?", req.SourceId)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.QianqiGuangfubanIdsLizhu.Columns().Status+" = ?", gconv.Int(req.Status))
|
||||
}
|
||||
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "name asc,id asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.QianqiGuangfubanIdsLizhuInfoRes
|
||||
|
||||
if !req.NotInPlan {
|
||||
m = m.Fields(system.QianqiGuangfubanIdsLizhuSearchRes{})
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
m = m.Page(req.PageNum, req.PageSize)
|
||||
} else {
|
||||
m = m.Fields(system.QianqiGuangfubanIdsLizhuSearchRes{}).
|
||||
Where(dao.QianqiGuangfubanIdsLizhu.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=? and source_type='lizhu')", req.ProjectId)
|
||||
}
|
||||
err = m.Order(order).Scan(&res)
|
||||
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiGuangfubanIdsLizhuListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiGuangfubanIdsLizhuListRes{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreatedAt: v.CreatedAt,
|
||||
SourceType: v.SourceType,
|
||||
SourceId: v.SourceId,
|
||||
ProjectId: v.ProjectId,
|
||||
Status: v.Status,
|
||||
Detail: v.Detail,
|
||||
}
|
||||
}
|
||||
sort.Slice(listRes.List, func(i, j int) bool {
|
||||
return listRes.List[i].Name < listRes.List[j].Name
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) GetById(ctx context.Context, id int) (res *model.QianqiGuangfubanIdsLizhuInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).WithAll().Where(dao.QianqiGuangfubanIdsLizhu.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) Add(ctx context.Context, req *system.QianqiGuangfubanIdsLizhuAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).Insert(do.QianqiGuangfubanIdsLizhu{
|
||||
Name: req.Name,
|
||||
CreateBy: req.CreateBy,
|
||||
UpdateBy: req.UpdateBy,
|
||||
SourceType: req.SourceType,
|
||||
SourceId: req.SourceId,
|
||||
ProjectId: req.ProjectId,
|
||||
Status: req.Status,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) Edit(ctx context.Context, req *system.QianqiGuangfubanIdsLizhuEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).WherePri(req.Id).Update(do.QianqiGuangfubanIdsLizhu{
|
||||
Name: req.Name,
|
||||
CreateBy: req.CreateBy,
|
||||
UpdateBy: req.UpdateBy,
|
||||
SourceType: req.SourceType,
|
||||
SourceId: req.SourceId,
|
||||
ProjectId: req.ProjectId,
|
||||
Status: req.Status,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiGuangfubanIdsLizhu) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiGuangfubanIdsLizhu.Ctx(ctx).Delete(dao.QianqiGuangfubanIdsLizhu.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user