初始
This commit is contained in:
239
internal/app/system/logic/qianqiNibianqi/qianqi_nibianqi.go
Normal file
239
internal/app/system/logic/qianqiNibianqi/qianqi_nibianqi.go
Normal file
@ -0,0 +1,239 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-31 09:40:17
|
||||
// 生成路径: internal/app/system/logic/qianqi_nibianqi.go
|
||||
// 生成人:gfast
|
||||
// desc:逆变器
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"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/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"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"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterQianqiNibianqi(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiNibianqi {
|
||||
return &sQianqiNibianqi{}
|
||||
}
|
||||
|
||||
type sQianqiNibianqi struct{}
|
||||
|
||||
func (s *sQianqiNibianqi) EditDetail(ctx context.Context, req *system.QianqiNibianqiEditDetailReq) (err error) {
|
||||
str := "update " + dao.QianqiNibianqi.Table() + " set detail= case "
|
||||
if len(req.List) > 0 {
|
||||
var wh []string
|
||||
for _, detail := range req.List {
|
||||
marshal, err := json.Marshal(detail.Detail)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
st := "when name='" + detail.Name + "' then '" + string(marshal) + "' "
|
||||
wh = append(wh, st)
|
||||
}
|
||||
str = str + strings.Join(wh, " ") + " end where project_id= " + req.ProjectId
|
||||
// dao.QianqiXiangbian.Ctx(ctx).Raw(str)
|
||||
_, err = g.DB().Exec(ctx, str)
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiNibianqi) List(ctx context.Context, req *system.QianqiNibianqiSearchReq) (listRes *system.QianqiNibianqiSearchRes, err error) {
|
||||
listRes = new(system.QianqiNibianqiSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiNibianqi.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiNibianqi.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.QianqiNibianqi.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.SourceId != "" {
|
||||
m = m.Where(dao.QianqiNibianqi.Columns().SourceId+" = ?", req.SourceId)
|
||||
}
|
||||
if req.ModelId != "" {
|
||||
m = m.Where(dao.QianqiNibianqi.Columns().ModelId+" = ?", req.ModelId)
|
||||
}
|
||||
if req.Xiangbianid != "" {
|
||||
m = m.Where(dao.QianqiNibianqi.Columns().Xiangbianid+" = ?", req.Xiangbianid)
|
||||
}
|
||||
// 创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
|
||||
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,id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.QianqiNibianqiInfoRes
|
||||
// err = m.Fields(system.QianqiNibianqiSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
if !req.NotInPlan {
|
||||
m = m.Fields(system.QianqiNibianqiSearchRes{}).Page(req.PageNum, req.PageSize)
|
||||
} else {
|
||||
m = m.Fields(system.QianqiNibianqiSearchRes{}).Where(dao.QianqiNibianqi.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=?)", req.ProjectId)
|
||||
}
|
||||
err = m.Order(order).Scan(&res)
|
||||
var mo []struct {
|
||||
Url string `json:"url"`
|
||||
ModelId string `json:"model_id"`
|
||||
}
|
||||
dao.ZmkgGisModelLib.Ctx(ctx).Fields("url", "model_id").Scan(&mo)
|
||||
mp := make(map[string]string)
|
||||
for _, s2 := range mo {
|
||||
mp[s2.ModelId] = coryCommon.GetWd + s2.Url
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiNibianqiListRes, len(res))
|
||||
for k, v := range res {
|
||||
u := mp[v.ModelId]
|
||||
|
||||
listRes.List[k] = &model.QianqiNibianqiListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
Name: v.Name,
|
||||
SourceId: v.SourceId,
|
||||
ModelId: v.ModelId,
|
||||
Detail: v.Detail,
|
||||
Xiangbianid: v.Xiangbianid,
|
||||
CreateAt: v.CreateAt,
|
||||
Url: u,
|
||||
SourceType: v.SourceType,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiNibianqi) GetById(ctx context.Context, id int) (res *model.QianqiNibianqiInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiNibianqi.Ctx(ctx).WithAll().Where(dao.QianqiNibianqi.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
// 获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.QianqiNibianqiInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiNibianqi) Add(ctx context.Context, req *system.QianqiNibianqiAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
FilePath := ""
|
||||
res, e := service.SysProject().GetByProjectId(ctx, req.ProjectId)
|
||||
if e != nil {
|
||||
liberr.ErrIsNil(ctx, e)
|
||||
return
|
||||
}
|
||||
if res == nil {
|
||||
liberr.ErrIsNil(ctx, errors.New("项目不存在"))
|
||||
return
|
||||
}
|
||||
file := req.File
|
||||
for i := range file {
|
||||
str, err := coryCommon.UploadFile(ctx, file[i], coryCommon.LargeFileShp)
|
||||
if err != nil {
|
||||
liberr.ErrIsNil(ctx, err, "上传失败!")
|
||||
}
|
||||
arr := strings.Split(str, ".")
|
||||
arr[len(arr)-1] = "shp"
|
||||
FilePath = strings.Join(arr, ".")
|
||||
// FilePath = strings.Join(split[:len(split)-1], "/") //strings.Replace(, "/resource/public", "/file", -1)
|
||||
// sourceId, _ = gmd5.EncryptString(FilePath)
|
||||
}
|
||||
// 需要读取方阵里面的信息
|
||||
err1, s2 := shp.ReadShp(FilePath)
|
||||
if err1 != nil {
|
||||
liberr.ErrIsNil(ctx, err1)
|
||||
}
|
||||
CreateBy := ct.New().GetLoginUser(ctx).Id
|
||||
var arr []do.QianqiNibianqi
|
||||
for _, p := range s2.Polylines {
|
||||
// 将方阵的名称 作为方阵的id
|
||||
// sourceId := gmd5.MustEncryptString(p.Name)
|
||||
nibianqi := do.QianqiNibianqi{}
|
||||
nibianqi.ProjectId = req.ProjectId
|
||||
nibianqi.SourceId = gmd5.MustEncryptString(req.ProjectId + p.Name)
|
||||
nibianqi.Name = p.Name
|
||||
nibianqi.ModelId = "41b366a9bae250098716da675d3ae26d"
|
||||
nibianqi.CreateBy = CreateBy
|
||||
detail := shp.Detail{Position: p.Positions[0]}
|
||||
marshal, err := json.Marshal(detail)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
nibianqi.Detail = string(marshal)
|
||||
|
||||
// time.Sleep(time.Millisecond)
|
||||
|
||||
// 判断是否已经存在了该方阵,存在了就不再添加
|
||||
count, _ := dao.QianqiNibianqi.Ctx(ctx).Where(dao.QianqiNibianqi.Columns().SourceId, nibianqi.SourceId).Count()
|
||||
if count == 0 {
|
||||
arr = append(arr, nibianqi)
|
||||
}
|
||||
}
|
||||
if len(arr) > 0 {
|
||||
_, err = dao.QianqiNibianqi.Ctx(ctx).Insert(&arr)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiNibianqi) Edit(ctx context.Context, req *system.QianqiNibianqiEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
// name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.QianqiNibianqi.Ctx(ctx).WherePri(req.Id).Update(do.QianqiNibianqi{
|
||||
// ProjectId: req.ProjectId,
|
||||
Name: req.Name,
|
||||
// SourceId: req.SourceId,
|
||||
// ModelId: req.ModelId,
|
||||
Detail: req.Detail,
|
||||
// Xiangbianid: req.Xiangbianid,
|
||||
UpdateBy: "1",
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiNibianqi) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiNibianqi.Ctx(ctx).Unscoped().Delete(dao.QianqiNibianqi.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user