初始
This commit is contained in:
		| @ -0,0 +1,224 @@ | ||||
| // ========================================================================== | ||||
| // GFast自动生成logic操作代码。 | ||||
| // 生成日期:2023-08-05 16:00:23 | ||||
| // 生成路径: internal/app/system/logic/qianqi_guangfuban_ids.go | ||||
| // 生成人:gfast | ||||
| // desc:光伏板模型的id | ||||
| // company:云南奇讯科技有限公司 | ||||
| // ========================================================================== | ||||
|  | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"github.com/gogf/gf/v2/frame/g" | ||||
| 	"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" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	service.RegisterQianqiGuangfubanIds(New()) | ||||
| } | ||||
|  | ||||
| func New() *sQianqiGuangfubanIds { | ||||
| 	return &sQianqiGuangfubanIds{} | ||||
| } | ||||
|  | ||||
| type sQianqiGuangfubanIds struct{} | ||||
|  | ||||
| func (s *sQianqiGuangfubanIds) List(ctx context.Context, req *system.QianqiGuangfubanIdsSearchReq) (listRes *system.QianqiGuangfubanIdsSearchRes, err error) { | ||||
| 	listRes = new(system.QianqiGuangfubanIdsSearchRes) | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		m := dao.QianqiGuangfubanIds.Ctx(ctx).WithAll() | ||||
| 		if req.Name != "" { | ||||
| 			m = m.Where(dao.QianqiGuangfubanIds.Columns().Name+" like ?", "%"+req.Name+"%") | ||||
| 		} | ||||
| 		if req.ProjectId != "" { | ||||
| 			m = m.Where(dao.QianqiGuangfubanIds.Columns().ProjectId+" = ?", req.ProjectId) | ||||
| 		} | ||||
| 		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 asc" | ||||
| 		if req.OrderBy != "" { | ||||
| 			order = req.OrderBy | ||||
| 		} | ||||
| 		var res []*model.QianqiGuangfubanIdsInfoRes | ||||
| 		m = m.Fields(system.QianqiGuangfubanIdsSearchRes{}).Page(req.PageNum, req.PageSize) | ||||
| 		if req.NotInPlan { | ||||
| 			m = m.Where(dao.QianqiGuangfubanIds.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 = []*model.Nibianqi{} | ||||
|  | ||||
| 		nibianqi_map := make(map[string]*model.Nibianqi) | ||||
| 		for _, v := range res { | ||||
| 			q := &model.QianqiGuangfubanIdsListRes{ | ||||
| 				Id:         v.Id, | ||||
| 				Name:       v.Name, | ||||
| 				DevId:      v.DevId, | ||||
| 				DevType:    v.DevType, | ||||
| 				CreateBy:   v.CreateBy, | ||||
| 				UpdateBy:   v.UpdateBy, | ||||
| 				CreatedAt:  v.CreatedAt, | ||||
| 				SourceType: v.SourceType, | ||||
| 				SourceId:   v.SourceId, | ||||
| 				ProjectId:  v.ProjectId, | ||||
| 				Range:      v.Range, | ||||
| 				Sphere:     v.Sphere, | ||||
| 			} | ||||
| 			names := strings.Split(v.Name, ".") | ||||
| 			nibianqiName := strings.Join(names[:2], ".") | ||||
|  | ||||
| 			if v2, ok := nibianqi_map[nibianqiName]; ok { | ||||
| 				v2.List = append(v2.List, q) | ||||
| 				nibianqi_map[nibianqiName] = v2 | ||||
| 			} else { | ||||
| 				nibianqi := model.Nibianqi{} | ||||
| 				nibianqi.NibianqiName = nibianqiName | ||||
| 				nibianqi.List = append(nibianqi.List, q) | ||||
| 				nibianqi_map[nibianqiName] = &nibianqi | ||||
| 			} | ||||
| 			/*listRes.List[k] = &model.QianqiGuangfubanIdsListRes{ | ||||
| 				Id:         v.Id, | ||||
| 				Name:       v.Name, | ||||
| 				DevId:      v.DevId, | ||||
| 				DevType:    v.DevType, | ||||
| 				CreateBy:   v.CreateBy, | ||||
| 				UpdateBy:   v.UpdateBy, | ||||
| 				CreatedAt:  v.CreatedAt, | ||||
| 				SourceType: v.SourceType, | ||||
| 				SourceId:   v.SourceId, | ||||
| 				ProjectId:  v.ProjectId, | ||||
| 			}*/ | ||||
| 		} | ||||
| 		for _, nibianqi := range nibianqi_map { | ||||
| 			listRes.List = append(listRes.List, nibianqi) | ||||
| 		} | ||||
| 		listRes.Total = len(listRes.List) | ||||
|  | ||||
| 		sort.Slice(listRes.List, func(i, j int) bool { | ||||
| 			return listRes.List[i].NibianqiName < listRes.List[j].NibianqiName | ||||
| 		}) | ||||
| 		for n, _ := range listRes.List { | ||||
| 			sort.Slice(listRes.List[n].List, func(i, j int) bool { | ||||
| 				return listRes.List[n].List[i].Name < listRes.List[n].List[j].Name | ||||
| 			}) | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiGuangfubanIds) GetById(ctx context.Context, req *system.QianqiGuangfubanIdsGetReq) (listRes *system.QianqiGuangfubanIdsGetRes, err error) { | ||||
| 	//err = g.Try(ctx, func(ctx context.Context) { | ||||
| 	//	err = dao.QianqiGuangfubanIds.Ctx(ctx).WithAll().Where(dao.QianqiGuangfubanIds.Columns().DevId, id).Scan(&res) | ||||
| 	//	liberr.ErrIsNil(ctx, err, "获取信息失败") | ||||
| 	//}) | ||||
|  | ||||
| 	listRes = new(system.QianqiGuangfubanIdsGetRes) | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		m := dao.QianqiGuangfubanIds.Ctx(ctx).WithAll() | ||||
| 		if req.Id != "" { | ||||
| 			m = m.Where(dao.QianqiGuangfubanIds.Columns().DevId+" = ?", req.Id) | ||||
| 		} | ||||
| 		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 := "id asc" | ||||
| 		if req.OrderBy != "" { | ||||
| 			order = req.OrderBy | ||||
| 		} | ||||
| 		var res []*model.QianqiGuangfubanIdsInfoRes | ||||
| 		m = m.Fields(system.QianqiGuangfubanIdsSearchRes{}) | ||||
| 		if !req.Total { | ||||
| 			m = m.Page(req.PageNum, req.PageSize) | ||||
| 		} | ||||
| 		//if !req.NotInPlan { | ||||
|  | ||||
| 		//} else { | ||||
| 		//	m = m.Fields(system.QianqiGuangfubanIdsSearchRes{}).Where(dao.QianqiGuangfubanIds.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.QianqiGuangfubanIdsInfoRes, len(res)) | ||||
| 		for k, v := range res { | ||||
| 			listRes.List[k] = &model.QianqiGuangfubanIdsInfoRes{ | ||||
| 				Id:         v.Id, | ||||
| 				Name:       v.Name, | ||||
| 				DevId:      v.DevId, | ||||
| 				DevType:    v.DevType, | ||||
| 				CreateBy:   v.CreateBy, | ||||
| 				UpdateBy:   v.UpdateBy, | ||||
| 				CreatedAt:  v.CreatedAt, | ||||
| 				SourceType: v.SourceType, | ||||
| 				SourceId:   v.SourceId, | ||||
| 				ProjectId:  v.ProjectId, | ||||
| 				Range:      v.Range, | ||||
| 				Sphere:     v.Sphere, | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiGuangfubanIds) Add(ctx context.Context, req *system.QianqiGuangfubanIdsAddReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.QianqiGuangfubanIds.Ctx(ctx).Insert(do.QianqiGuangfubanIds{ | ||||
| 			Name:       req.Name, | ||||
| 			DevId:      req.DevId, | ||||
| 			DevType:    req.DevType, | ||||
| 			CreateBy:   req.CreateBy, | ||||
| 			UpdateBy:   req.UpdateBy, | ||||
| 			SourceType: req.SourceType, | ||||
| 			SourceId:   req.SourceId, | ||||
| 			ProjectId:  req.ProjectId, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "添加失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiGuangfubanIds) Edit(ctx context.Context, req *system.QianqiGuangfubanIdsEditReq) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.QianqiGuangfubanIds.Ctx(ctx).Where(dao.QianqiGuangfubanIds.Columns().SourceId, req.SourceId).Update(do.QianqiGuangfubanIds{ | ||||
| 			//Name:       req.Name, | ||||
| 			//DevId:      req.DevId, | ||||
| 			//DevType:    req.DevType, | ||||
| 			//CreateBy:   req.CreateBy, | ||||
| 			//UpdateBy:   req.UpdateBy, | ||||
| 			//SourceType: req.SourceType, | ||||
| 			Range: req.Range, | ||||
| 		}) | ||||
| 		liberr.ErrIsNil(ctx, err, "修改失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *sQianqiGuangfubanIds) Delete(ctx context.Context, ids []int) (err error) { | ||||
| 	err = g.Try(ctx, func(ctx context.Context) { | ||||
| 		_, err = dao.QianqiGuangfubanIds.Ctx(ctx).Unscoped().Delete(dao.QianqiGuangfubanIds.Columns().Id+" in (?)", ids) | ||||
| 		liberr.ErrIsNil(ctx, err, "删除失败") | ||||
| 	}) | ||||
| 	return | ||||
| } | ||||
		Reference in New Issue
	
	Block a user