初始
This commit is contained in:
264
internal/app/system/logic/plant/plant.go
Normal file
264
internal/app/system/logic/plant/plant.go
Normal file
@ -0,0 +1,264 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-04-12 10:38:43
|
||||
// 生成路径: internal/app/system/logic/plant.go
|
||||
// 生成人:gfast
|
||||
// desc:电站信息
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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.RegisterPlant(New())
|
||||
}
|
||||
|
||||
func New() *sPlant {
|
||||
return &sPlant{}
|
||||
}
|
||||
|
||||
type sPlant struct{}
|
||||
|
||||
func (s *sPlant) List(ctx context.Context, req *system.PlantSearchReq) (listRes *system.PlantSearchRes, err error) {
|
||||
listRes = new(system.PlantSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.Plant.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.Plant.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.Plant.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Address != "" {
|
||||
m = m.Where(dao.Plant.Columns().Address+" = ?", req.Address)
|
||||
}
|
||||
if req.City != "" {
|
||||
m = m.Where(dao.Plant.Columns().City+" = ?", req.City)
|
||||
}
|
||||
if req.District != "" {
|
||||
m = m.Where(dao.Plant.Columns().District+" = ?", req.District)
|
||||
}
|
||||
if req.Province != "" {
|
||||
m = m.Where(dao.Plant.Columns().Province+" = ?", req.Province)
|
||||
}
|
||||
if req.NetworkTime != "" {
|
||||
m = m.Where(dao.Plant.Columns().NetworkTime+" = ?", gconv.Time(req.NetworkTime))
|
||||
}
|
||||
if req.UpdateTime != "" {
|
||||
m = m.Where(dao.Plant.Columns().UpdateTime+" = ?", gconv.Time(req.UpdateTime))
|
||||
}
|
||||
if req.CompanyId != "" {
|
||||
m = m.Where(dao.Plant.Columns().CompanyId+" = ?", req.CompanyId)
|
||||
}
|
||||
if req.CompanyName != "" {
|
||||
m = m.Where(dao.Plant.Columns().CompanyName+" = ?", req.CompanyName)
|
||||
}
|
||||
if req.OwnerId != "" {
|
||||
m = m.Where(dao.Plant.Columns().OwnerId+" = ?", req.OwnerId)
|
||||
}
|
||||
if req.OwnerName != "" {
|
||||
m = m.Where(dao.Plant.Columns().OwnerName+" = ?", req.OwnerName)
|
||||
}
|
||||
if req.ServiceProviderName != "" {
|
||||
m = m.Where(dao.Plant.Columns().ServiceProviderName+" = ?", req.ServiceProviderName)
|
||||
}
|
||||
if req.ServiceProviderPhone != "" {
|
||||
m = m.Where(dao.Plant.Columns().ServiceProviderPhone+" = ?", req.ServiceProviderPhone)
|
||||
}
|
||||
if req.NetworkType != "" {
|
||||
m = m.Where(dao.Plant.Columns().NetworkType+" = ?", req.NetworkType)
|
||||
}
|
||||
if req.PowerPlantType != "" {
|
||||
m = m.Where(dao.Plant.Columns().PowerPlantType+" = ?", req.PowerPlantType)
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.Plant.Columns().Status+" = ?", gconv.Int(req.Status))
|
||||
}
|
||||
if req.PaymentType != "" {
|
||||
m = m.Where(dao.Plant.Columns().PaymentType+" = ?", req.PaymentType)
|
||||
}
|
||||
if req.PlantContact != "" {
|
||||
m = m.Where(dao.Plant.Columns().PlantContact+" = ?", req.PlantContact)
|
||||
}
|
||||
if req.PlantContactPhone != "" {
|
||||
m = m.Where(dao.Plant.Columns().PlantContactPhone+" = ?", req.PlantContactPhone)
|
||||
}
|
||||
if req.PlantImg != "" {
|
||||
m = m.Where(dao.Plant.Columns().PlantImg+" = ?", req.PlantImg)
|
||||
}
|
||||
if req.SubassemblyNumber != "" {
|
||||
m = m.Where(dao.Plant.Columns().SubassemblyNumber+" = ?", gconv.Int(req.SubassemblyNumber))
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.Plant.Columns().CreatedAt+" >=? AND "+dao.Plant.Columns().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 := "name asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.PlantInfoRes
|
||||
err = m.Fields(system.PlantSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.PlantListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.PlantListRes{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Address: v.Address,
|
||||
City: v.City,
|
||||
District: v.District,
|
||||
Province: v.Province,
|
||||
Latitude: v.Latitude,
|
||||
Longitude: v.Longitude,
|
||||
Kwp: v.Kwp,
|
||||
MonKwh: v.MonKwh,
|
||||
NowKw: v.NowKw,
|
||||
SumKwh: v.SumKwh,
|
||||
TodayKwh: v.TodayKwh,
|
||||
YearKwh: v.YearKwh,
|
||||
NetworkTime: v.NetworkTime,
|
||||
UpdateTime: v.UpdateTime,
|
||||
CompanyId: v.CompanyId,
|
||||
CompanyName: v.CompanyName,
|
||||
OwnerId: v.OwnerId,
|
||||
OwnerName: v.OwnerName,
|
||||
ServiceProviderName: v.ServiceProviderName,
|
||||
ServiceProviderPhone: v.ServiceProviderPhone,
|
||||
NetworkType: v.NetworkType,
|
||||
PowerPlantType: v.PowerPlantType,
|
||||
Status: v.Status,
|
||||
PaymentType: v.PaymentType,
|
||||
PlantContact: v.PlantContact,
|
||||
PlantContactPhone: v.PlantContactPhone,
|
||||
PlantImg: v.PlantImg,
|
||||
Remark: v.Remark,
|
||||
DipAngle: v.DipAngle,
|
||||
OrientationAngle: v.OrientationAngle,
|
||||
SubassemblyNumber: v.SubassemblyNumber,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlant) GetById(ctx context.Context, id string) (res *model.PlantInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.Plant.Ctx(ctx).WithAll().Where(dao.Plant.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlant) Add(ctx context.Context, req *system.PlantAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.Plant.Ctx(ctx).Insert(do.Plant{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Address: req.Address,
|
||||
City: req.City,
|
||||
District: req.District,
|
||||
Province: req.Province,
|
||||
Latitude: req.Latitude,
|
||||
Longitude: req.Longitude,
|
||||
Kwp: req.Kwp,
|
||||
MonKwh: req.MonKwh,
|
||||
NowKw: req.NowKw,
|
||||
SumKwh: req.SumKwh,
|
||||
TodayKwh: req.TodayKwh,
|
||||
YearKwh: req.YearKwh,
|
||||
NetworkTime: req.NetworkTime,
|
||||
UpdateTime: req.UpdateTime,
|
||||
CompanyId: req.CompanyId,
|
||||
CompanyName: req.CompanyName,
|
||||
OwnerId: req.OwnerId,
|
||||
OwnerName: req.OwnerName,
|
||||
ServiceProviderName: req.ServiceProviderName,
|
||||
ServiceProviderPhone: req.ServiceProviderPhone,
|
||||
NetworkType: req.NetworkType,
|
||||
PowerPlantType: req.PowerPlantType,
|
||||
Status: req.Status,
|
||||
PaymentType: req.PaymentType,
|
||||
PlantContact: req.PlantContact,
|
||||
PlantContactPhone: req.PlantContactPhone,
|
||||
PlantImg: req.PlantImg,
|
||||
Remark: req.Remark,
|
||||
DipAngle: req.DipAngle,
|
||||
OrientationAngle: req.OrientationAngle,
|
||||
SubassemblyNumber: req.SubassemblyNumber,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlant) Edit(ctx context.Context, req *system.PlantEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.Plant.Ctx(ctx).WherePri(req.Id).Update(do.Plant{
|
||||
Name: req.Name,
|
||||
Address: req.Address,
|
||||
City: req.City,
|
||||
District: req.District,
|
||||
Province: req.Province,
|
||||
Latitude: req.Latitude,
|
||||
Longitude: req.Longitude,
|
||||
Kwp: req.Kwp,
|
||||
MonKwh: req.MonKwh,
|
||||
NowKw: req.NowKw,
|
||||
SumKwh: req.SumKwh,
|
||||
TodayKwh: req.TodayKwh,
|
||||
YearKwh: req.YearKwh,
|
||||
NetworkTime: req.NetworkTime,
|
||||
UpdateTime: req.UpdateTime,
|
||||
CompanyId: req.CompanyId,
|
||||
CompanyName: req.CompanyName,
|
||||
OwnerId: req.OwnerId,
|
||||
OwnerName: req.OwnerName,
|
||||
ServiceProviderName: req.ServiceProviderName,
|
||||
ServiceProviderPhone: req.ServiceProviderPhone,
|
||||
NetworkType: req.NetworkType,
|
||||
PowerPlantType: req.PowerPlantType,
|
||||
Status: req.Status,
|
||||
PaymentType: req.PaymentType,
|
||||
PlantContact: req.PlantContact,
|
||||
PlantContactPhone: req.PlantContactPhone,
|
||||
PlantImg: req.PlantImg,
|
||||
Remark: req.Remark,
|
||||
DipAngle: req.DipAngle,
|
||||
OrientationAngle: req.OrientationAngle,
|
||||
SubassemblyNumber: req.SubassemblyNumber,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPlant) Delete(ctx context.Context, ids []string) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.Plant.Ctx(ctx).Delete(dao.Plant.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user