初始
This commit is contained in:
252
internal/app/system/logic/qianqiFangzhen/qianqi_fangzhen.go
Normal file
252
internal/app/system/logic/qianqiFangzhen/qianqi_fangzhen.go
Normal file
@ -0,0 +1,252 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-31 11:20:55
|
||||
// 生成路径: internal/app/system/logic/qianqi_fangzhen.go
|
||||
// 生成人:gfast
|
||||
// desc:方阵
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/shp"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
tool2 "github.com/tiger1103/gfast/v3/api/v1/common/tool"
|
||||
"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"
|
||||
create "github.com/tiger1103/gfast/v3/third/create"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterQianqiFangzhen(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiFangzhen {
|
||||
return &sQianqiFangzhen{}
|
||||
}
|
||||
|
||||
type sQianqiFangzhen struct{}
|
||||
|
||||
func (s *sQianqiFangzhen) EditDetail(ctx context.Context, req *system.QianqiFangzhenEditDetailReq) (err error) {
|
||||
g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
marshal, err := json.Marshal(req.Detail)
|
||||
if err != nil {
|
||||
fmt.Println("是否错误:", err)
|
||||
return
|
||||
}
|
||||
_, err = dao.QianqiFangzhen.Ctx(ctx).Where("source_id", req.SourceId).Update(g.Map{"detail": string(marshal)})
|
||||
return
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) List(ctx context.Context, req *system.QianqiFangzhenSearchReq) (listRes *system.QianqiFangzhenSearchRes, err error) {
|
||||
listRes = new(system.QianqiFangzhenSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiFangzhen.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiFangzhen.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.QianqiFangzhen.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
// 创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.QianqiFangzhen.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.QianqiFangzhen.Columns().CreatedAt+" >=? AND "+dao.QianqiFangzhen.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,id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.QianqiFangzhenInfoRes
|
||||
if !req.NotInPlan {
|
||||
m = m.Fields(system.QianqiFangzhenSearchRes{}).Page(req.PageNum, req.PageSize)
|
||||
} else {
|
||||
m = m.Fields(system.QianqiFangzhenSearchRes{}).Where(dao.QianqiFangzhen.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=?)", req.ProjectId)
|
||||
}
|
||||
err = m.Fields(system.QianqiFangzhenSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiFangzhenListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiFangzhenListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
Name: v.Name,
|
||||
SourceId: v.SourceId,
|
||||
SourcePath: v.SourcePath,
|
||||
XiangbianId: v.XiangbianId,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Detail: v.Detail,
|
||||
SourceType: v.SourceType,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) GetById(ctx context.Context, id int) (res *model.QianqiFangzhenInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiFangzhen.Ctx(ctx).WithAll().Where(dao.QianqiFangzhen.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
// 获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.QianqiFangzhenInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) Add(ctx context.Context, req *system.QianqiFangzhenAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
FilePath := ""
|
||||
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, ".")
|
||||
}
|
||||
// 需要读取方阵里面的信息
|
||||
err1, s2 := shp.ReadShp(FilePath)
|
||||
if err1 != nil {
|
||||
liberr.ErrIsNil(ctx, err1)
|
||||
}
|
||||
|
||||
////// 2024-12-18 原本代码为上面注释的代码 前端注释掉了文件上传,宝塔上面有shp文件
|
||||
////FilePath := "/resource/public/shp/2024-12-18/cs方阵.shp"
|
||||
////s2 := sshp.Adasda(FilePath)
|
||||
//FilePath := ""
|
||||
//file := req.File
|
||||
//fmt.Println("!!!!! ", len(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, ".")
|
||||
//}
|
||||
//if len(req.File) == 0 {
|
||||
// liberr.ErrIsNil(ctx, err, "没有获取相关文件!")
|
||||
//}
|
||||
//s2 := sshp.Adasda(FilePath)
|
||||
|
||||
var templateDataList []do.WorkStatus
|
||||
CreateBy := ct.New().GetLoginUser(ctx).Id
|
||||
for _, p := range s2.Polylines {
|
||||
// 将方阵的名称 作为方阵的id
|
||||
sourceId := tool2.GetUuid()
|
||||
// 判断是否已经存在了该方阵,存在了就不再添加
|
||||
count, _ := dao.QianqiFangzhen.Ctx(ctx).Where("source_id=? and project_id=?", sourceId, req.ProjectId).Count()
|
||||
if count != 0 {
|
||||
continue
|
||||
}
|
||||
marshal, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
nm := ""
|
||||
if p.Name != "" {
|
||||
nm = strings.Split(p.Name, " ")[0]
|
||||
} else {
|
||||
nm = p.Name
|
||||
}
|
||||
fangzhen, err := dao.QianqiFangzhen.Ctx(ctx).Insert(&do.QianqiFangzhen{
|
||||
ProjectId: req.ProjectId,
|
||||
Name: nm,
|
||||
SourceId: sourceId,
|
||||
SourcePath: FilePath,
|
||||
CreateBy: CreateBy,
|
||||
Detail: string(marshal),
|
||||
})
|
||||
templateID, err := fangzhen.LastInsertId()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
templateData, err := create.FetchTemplateData(ctx, templateID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
templateDataList = append(templateDataList, templateData...)
|
||||
}
|
||||
_, err := dao.WorkStatus.Ctx(ctx).Data(templateDataList).Batch(50).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func changeFileExtensionToShp(filePath string) string {
|
||||
fileParts := strings.Split(filePath, ".")
|
||||
fileParts[len(fileParts)-1] = "shp"
|
||||
return strings.Join(fileParts, ".")
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) Edit(ctx context.Context, req *system.QianqiFangzhenEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.QianqiFangzhen.Ctx(ctx).Where(dao.QianqiFangzhen.Columns().SourceId, req.SourceId).Update(do.QianqiFangzhen{
|
||||
Name: req.Name,
|
||||
Detail: req.Detail,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiFangzhen.Ctx(ctx).Unscoped().Delete(dao.QianqiFangzhen.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiFangzhen) UpdateViewName(ctx context.Context, req *system.QianqiFangzhenUpdateViewNameReq) error {
|
||||
err := g.Try(ctx, func(ctx context.Context) {
|
||||
_, err := dao.QianqiFangzhen.Ctx(ctx).Where(dao.QianqiFangzhen.Columns().Id, req.Id).
|
||||
Update(g.Map{dao.QianqiFangzhen.Columns().View: req.View})
|
||||
liberr.ErrIsNil(ctx, err, "更新失败")
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user