初始
This commit is contained in:
224
internal/app/system/controller/pv_ module.go
Normal file
224
internal/app/system/controller/pv_ module.go
Normal file
@ -0,0 +1,224 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成controller操作代码。
|
||||
// 生成日期:2024-03-23 10:25:39
|
||||
// 生成路径: internal/app/system/controller/pv_ module.go
|
||||
// 生成人:gfast
|
||||
// desc:光伏组件
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"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/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
type pvModuleController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
var PvModule = new(pvModuleController)
|
||||
|
||||
// List 列表
|
||||
func (c *pvModuleController) List(ctx context.Context, req *system.PvModuleSearchReq) (res *system.PvModuleSearchRes, err error) {
|
||||
res, err = service.PvModule().List(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Get 获取光伏组件
|
||||
func (c *pvModuleController) Get(ctx context.Context, req *system.PvModuleGetReq) (res *system.PvModuleGetRes, err error) {
|
||||
res = new(system.PvModuleGetRes)
|
||||
res.PvModuleInfoRes, err = service.PvModule().GetById(ctx, req.Id)
|
||||
return
|
||||
}
|
||||
|
||||
// Add 添加光伏组件
|
||||
func (c *pvModuleController) Add(ctx context.Context, req *system.PvModuleAddReq) (res *system.PvModuleAddRes, err error) {
|
||||
err = service.PvModule().Add(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 修改光伏组件
|
||||
func (c *pvModuleController) Edit(ctx context.Context, req *system.PvModuleEditReq) (res *system.PvModuleEditRes, err error) {
|
||||
err = service.PvModule().Edit(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除光伏组件
|
||||
func (c *pvModuleController) Delete(ctx context.Context, req *system.PvModuleDeleteReq) (res *system.PvModuleDeleteRes, err error) {
|
||||
err = service.PvModule().Delete(ctx, req.Ids)
|
||||
return
|
||||
}
|
||||
|
||||
// Import 导入
|
||||
func (c *pvModuleController) Import(ctx context.Context, req *system.PvModuleImportReq) (res *system.PvModuleImportRes, err error) {
|
||||
err = service.PvModule().Import(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// 导入逆变器
|
||||
func (c *pvModuleController) ImportInverter(ctx context.Context, req *system.PvModuleImportInverterReq) (res *system.PvModuleImportRes, err error) {
|
||||
err = service.PvModule().ImportInverter(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// 导入光伏板
|
||||
func (c *pvModuleController) ImportPvBoard(ctx context.Context, req *system.PvModuleImportPvBoardReq) (res *system.PvModuleImportRes, err error) {
|
||||
err = service.PvModule().ImportPvBoard(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *pvModuleController) AddWorkSchedule(ctx context.Context, req *system.PvModuleAddDailyReq) (res *system.PvModuleAddDailyRes, err error) {
|
||||
err = service.PvModule().AddWorkSchedule(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取日报
|
||||
func (c *pvModuleController) GetWorkSchedule(ctx context.Context, req *system.PvModuleGetDailyReq) (res *system.PvModuleGetDailyRes, err error) {
|
||||
return service.PvModule().GetDaily(ctx, req)
|
||||
}
|
||||
|
||||
// 删除日报
|
||||
func (c *pvModuleController) DeleteWorkSchedule(ctx context.Context, req *system.PvModuleDeleteDailyReq) (res *system.PvModuleDeleteDailyRes, err error) {
|
||||
err = service.PvModule().DeleteDaily(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
type Zhuangdian struct {
|
||||
Position shp.Point `json:"position"`
|
||||
}
|
||||
|
||||
func ProcessFiles(ctx context.Context, files []*ghttp.UploadFile) (*shp.ShpObj, error) {
|
||||
var filePaths string
|
||||
|
||||
// 遍历请求中的所有文件
|
||||
for _, file := range files {
|
||||
// 保存文件后返回其路径
|
||||
uploadedFilePath, err := coryCommon.UploadFile(ctx, file, coryCommon.LargeFileShp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将文件路径按"."分割成切片
|
||||
filePathParts := strings.Split(uploadedFilePath, ".")
|
||||
// 如果切片长度大于1,将最后一个元素(文件扩展名)改为"shp"
|
||||
if len(filePathParts) > 1 {
|
||||
filePathParts[len(filePathParts)-1] = "shp"
|
||||
}
|
||||
// 将修改后的切片重新组合成文件路径,并将其添加到文件路径中
|
||||
updatedFilePath := strings.Join(filePathParts, ".")
|
||||
filePaths = updatedFilePath
|
||||
}
|
||||
|
||||
err, shp := shp.ReadShp(filePaths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return shp, nil
|
||||
}
|
||||
|
||||
// 上传 excel 为指定项目添加数据
|
||||
func (c *pvModuleController) AddExcel(ctx context.Context, req *system.PvModuleAddExcelReq) (res *system.PvModuleAddExcelRes, err error) {
|
||||
filePath, err := coryCommon.UploadFile(ctx, req.File, coryCommon.Temporary+"/")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filePath = coryCommon.ResourcePublicToFunc(filepath.ToSlash(filePath), 2)
|
||||
f, err := excelize.OpenFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func(f *excelize.File) {
|
||||
f.Close()
|
||||
}(f)
|
||||
|
||||
type group struct {
|
||||
Name string
|
||||
MatrixNumber string
|
||||
NominalTiltAngle string
|
||||
}
|
||||
|
||||
rows, err := f.GetRows("方阵统计分析")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groups := map[string][]group{}
|
||||
|
||||
for _, row := range rows[1:] {
|
||||
// 方阵编号
|
||||
matrixName := row[0]
|
||||
// 标称倾角
|
||||
nominalTiltAngle := row[2]
|
||||
// 标称方位角
|
||||
nominalAzimuthAngle := row[3]
|
||||
|
||||
if len(strings.Split(matrixName, ".")) != 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
transName := strings.ReplaceAll(strings.Split(matrixName, ".")[0], "G", "T")
|
||||
|
||||
groups[transName] = append(groups[transName], group{
|
||||
Name: matrixName,
|
||||
MatrixNumber: nominalTiltAngle,
|
||||
NominalTiltAngle: nominalAzimuthAngle,
|
||||
})
|
||||
}
|
||||
|
||||
// 根据子项目获取其所拥有的方阵
|
||||
fangzhenList := []entity.QianqiFangzhen{}
|
||||
if err := dao.QianqiFangzhen.Ctx(ctx).
|
||||
Where(dao.QianqiFangzhen.Columns().ProjectId, req.SubProjectID).
|
||||
Scan(&fangzhenList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: 统一更新具有相同标称倾角和标称方位角的名字
|
||||
for i := 0; i < len(fangzhenList); i++ {
|
||||
v := fangzhenList[i]
|
||||
// 遍历方阵
|
||||
for _, k := range groups[v.Name] {
|
||||
dao.PvModule.Ctx(ctx).Where(dao.PvModule.Columns().SubProjectid, v.ProjectId).
|
||||
Where(dao.PvModule.Columns().Name, k.Name).
|
||||
Data(
|
||||
g.Map{
|
||||
dao.PvModule.Columns().Tilt: k.MatrixNumber,
|
||||
dao.PvModule.Columns().Azimuth: k.NominalTiltAngle,
|
||||
},
|
||||
).Update()
|
||||
}
|
||||
}
|
||||
|
||||
return &system.PvModuleAddExcelRes{}, nil
|
||||
}
|
||||
|
||||
// 为逆变器绑定设备ID
|
||||
func (c *pvModuleController) BindInverterDeviceID(ctx context.Context, req *system.PvModuleBindDeviceIDReq) (*system.PvModuleBindDeviceIDRes, error) {
|
||||
err := g.Try(ctx, func(ctx context.Context) {
|
||||
_, err := dao.PvModule.Ctx(ctx).Where(dao.PvModule.Columns().Id, req.ID).
|
||||
Data(g.Map{
|
||||
dao.PvModule.Columns().DeviceId: req.DeviceID,
|
||||
}).Update()
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
|
||||
return &system.PvModuleBindDeviceIDRes{}, nil
|
||||
}
|
Reference in New Issue
Block a user