初始
This commit is contained in:
		
							
								
								
									
										178
									
								
								internal/app/system/logic/qianqiBubantu/qianqi_bubantu.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								internal/app/system/logic/qianqiBubantu/qianqi_bubantu.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,178 @@ | ||||
| // ========================================================================== | ||||
| // GFast自动生成logic操作代码。 | ||||
| // 生成日期:2023-07-31 11:44:41 | ||||
| // 生成路径: internal/app/system/logic/qianqi_bubantu.go | ||||
| // 生成人:gfast | ||||
| // desc:布板图 | ||||
| // company:云南奇讯科技有限公司 | ||||
| // ========================================================================== | ||||
|  | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"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/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" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	service.RegisterQianqiBubantu(New()) | ||||
| } | ||||
|  | ||||
| func New() *sQianqiBubantu { | ||||
| 	return &sQianqiBubantu{} | ||||
| } | ||||
|  | ||||
| type sQianqiBubantu struct{} | ||||
|  | ||||
| func (s *sQianqiBubantu) List(ctx context.Context, req *system.QianqiBubantuSearchReq) (listRes *system.QianqiBubantuSearchRes, err error) { | ||||
| 	listRes = new(system.QianqiBubantuSearchRes) | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		m := dao.QianqiBubantu.Ctx(ctx).WithAll() | ||||
| 		if req.ProjectId != "" { | ||||
| 			m = m.Where(dao.QianqiBubantu.Columns().ProjectId+" = ?", req.ProjectId) | ||||
| 		} | ||||
| 		if req.Name != "" { | ||||
| 			m = m.Where(dao.QianqiBubantu.Columns().Name+" like ?", "%"+req.Name+"%") | ||||
| 		} | ||||
|  | ||||
| 		//创建时间模糊查询 | ||||
| 		if req.CreatedAt != "" { | ||||
| 			date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt)) | ||||
| 			m = m.Where(dao.QianqiBubantu.Columns().CreatedAt+" like ?", "%"+date+"%") | ||||
| 		} | ||||
| 		if len(req.DateRange) != 0 { | ||||
| 			m = m.Where(dao.QianqiBubantu.Columns().CreatedAt+" >=? AND "+dao.QianqiBubantu.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.QianqiBubantuInfoRes | ||||
|  | ||||
| 		if !req.NotInPlan { | ||||
| 			m = m.Fields(system.QianqiBubantuSearchRes{}).Page(req.PageNum, req.PageSize) | ||||
| 		} else { | ||||
| 			m = m.Fields(system.QianqiBubantuSearchRes{}).Where(dao.QianqiBubantu.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=?)", req.ProjectId) | ||||
| 		} | ||||
| 		err = m.Order(order).Scan(&res) | ||||
|  | ||||
| 		liberr.ErrIsNil(ctx, err, "获取数据失败") | ||||
| 		listRes.List = make([]*model.QianqiBubantuListRes, len(res)) | ||||
| 		for k, v := range res { | ||||
| 			listRes.List[k] = &model.QianqiBubantuListRes{ | ||||
| 				Id:           v.Id, | ||||
| 				ProjectId:    v.ProjectId, | ||||
| 				Name:         v.Name, | ||||
| 				SourceId:     v.SourceId, | ||||
| 				SourcePath:   v.SourcePath, | ||||
| 				CreatedAt:    v.CreatedAt, | ||||
| 				SourceType:   v.SourceType, | ||||
| 				GuangfubanId: v.GuangfubanId, | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiBubantu) GetById(ctx context.Context, id int) (res *model.QianqiBubantuInfoRes, err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		err = dao.QianqiBubantu.Ctx(ctx).WithAll().Where(dao.QianqiBubantu.Columns().Id, id).Scan(&res) | ||||
| 		liberr.ErrIsNil(ctx, err, "获取信息失败") | ||||
| 		//获取创建人 更新人 | ||||
| 		by := coryCommon.New().CreateByOrUpdateBy(ctx, res) | ||||
| 		infoRes := by.(model.QianqiBubantuInfoRes) | ||||
| 		res = &infoRes | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiBubantu) Add(ctx context.Context, req *system.QianqiBubantuAddReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		var fileName = "" | ||||
| 		var FilePath = "" | ||||
| 		var sourceId = "" | ||||
| 		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, "上传失败!") | ||||
| 			} | ||||
| 			//fmt.Println(file[i].Filename) | ||||
| 			fileName = file[i].Filename | ||||
| 			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) | ||||
| 		} | ||||
| 		count, _ := dao.QianqiBubantu.Ctx(ctx).Where(dao.QianqiBubantu.Columns().SourceId, sourceId).Count() | ||||
| 		if count == 0 { | ||||
| 			_, err = dao.QianqiBubantu.Ctx(ctx).Insert(&do.QianqiBubantu{ | ||||
| 				ProjectId:    req.ProjectId, | ||||
| 				GuangfubanId: req.GuangfubanId, | ||||
| 				Name:         strings.Split(fileName, ".")[0], | ||||
| 				SourceId:     sourceId, | ||||
| 				SourcePath:   FilePath, | ||||
| 				CreateBy:     ct.New().GetLoginUser(ctx).Id, | ||||
| 			}) | ||||
| 			liberr.ErrIsNil(ctx, err, "添加失败") | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiBubantu) Edit(ctx context.Context, req *system.QianqiBubantuEditReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		name := ct.New().GetLoginUser(ctx).Id | ||||
| 		//name := "1" | ||||
| 		_, err = dao.QianqiBubantu.Ctx(ctx).WherePri(req.Id).Update(do.QianqiBubantu{ | ||||
| 			//ProjectId:  req.ProjectId, | ||||
| 			Name: req.Name, | ||||
| 			//SourceId:   req.SourceId, | ||||
| 			//SourcePath: req.SourcePath, | ||||
| 			UpdateBy: name, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "修改失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiBubantu) Delete(ctx context.Context, ids []int) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.QianqiBubantu.Ctx(ctx).Unscoped().Delete(dao.QianqiBubantu.Columns().Id+" in (?)", ids) | ||||
| 		liberr.ErrIsNil(ctx, err, "删除失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
		Reference in New Issue
	
	Block a user