| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- package base
- import (
- "context"
- "dashoo.cn/opms_libary/multipart"
- "dashoo.cn/opms_libary/myerrors"
- "fmt"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gconv"
- "github.com/gogf/gf/util/gvalid"
- "dashoo.cn/common_definition/comm_def"
- projModel "dashoo.cn/micro/app/model/proj"
- projSrv "dashoo.cn/micro/app/service/proj"
- )
- type BusinessHandler struct{}
- // Swagger:Business 项目 项目列表
- func (p *BusinessHandler) GetList(ctx context.Context, req *projModel.ProjBusinessSearchReq, rsp *comm_def.CommonMsg) error {
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- total, list, err := businessService.GetList(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // Swagger:Business 项目 项目详情
- func (p *BusinessHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if req.Id == 0 {
- return myerrors.ValidError("id参数有误!")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- rsp.Data, err = businessService.GetEntityById(req.Id)
- if err != nil {
- return myerrors.QueryError(err, "项目")
- }
- return nil
- }
- // Swagger:Business 项目 获取项目产品
- func (p *BusinessHandler) GetBusinessProduct(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if req.Id == 0 {
- return myerrors.ValidError("项目参数有误!")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- productList, err := businessService.GetBusinessProduct(req.Id)
- if err != nil {
- return err
- }
- rsp.Data = productList
- return nil
- }
- // Swagger:Business 项目 获取项目动态
- func (p *BusinessHandler) GetBusinessDynamics(ctx context.Context, req *projModel.BusinessReq, rsp *comm_def.CommonMsg) error {
- if req.BusId == 0 {
- return myerrors.ValidError("项目参数有误!")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- total, list, err := businessService.GetBusinessDynamics(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // Swagger:Business 项目 获取项目动态列表
- func (p *BusinessHandler) GetBusinessDynamicsList(ctx context.Context, req *projModel.BusinessDynamicsReq, rsp *comm_def.CommonMsg) error {
- if req.BusId == 0 {
- return myerrors.ValidError("项目参数有误!")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- total, list, err := businessService.GetBusinessDynamicsList(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // Swagger:Business 项目 创建项目
- func (p *BusinessHandler) Create(ctx context.Context, req *projModel.AddProjBusinessReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- // 校验产品数据
- for _, v := range req.Products {
- if err := gvalid.CheckStruct(ctx, v, nil); err != nil {
- return err
- }
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.Create(req)
- if err != nil {
- return myerrors.CreateError(err, "项目")
- }
- return nil
- }
- // Swagger:Business 项目 更新项目
- func (p *BusinessHandler) UpdateById(ctx context.Context, req *projModel.UpdateProjBusinessReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.UpdateById(req)
- if err != nil {
- return myerrors.UpdateError(err, "项目")
- }
- return nil
- }
- // Swagger:Business 项目 删除项目
- func (p *BusinessHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if len(req.Ids) == 0 {
- return myerrors.ValidError("id参数有误!")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.DeleteByIds(req.Ids)
- if err != nil {
- return myerrors.DeleteError(err, "项目")
- }
- return nil
- }
- // BusinessUpgrade 项目升级
- // Swagger:Business 项目 项目升级
- func (p *BusinessHandler) BusinessUpgrade(ctx context.Context, req *projModel.BusinessUpgradeReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- if req.NboType != projSrv.StatusC && req.NboBudget <= 0 {
- return myerrors.TipsError("项目预算不能小于0")
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.BusinessUpgrade(req, nil)
- if err != nil {
- return err
- }
- return nil
- }
- // BusinessUpgradeA 项目升级A类
- // Swagger:Business 项目 项目升级
- func (p *BusinessHandler) BusinessUpgradeA(ctx context.Context, args *multipart.MultipartFile, rsp *comm_def.CommonMsg) error {
- req := new(projModel.BusinessUpgradeReq)
- if err := gconv.Struct(args.Meta, req); err != nil {
- return err
- }
- if req.NboType != projSrv.StatusC && req.NboBudget <= 0 {
- return myerrors.TipsError("项目预算不能小于0")
- }
- if req.NboType == projSrv.StatusA && req.IsAdoptDashoo == "10" {
- if args.FileName == "" {
- return fmt.Errorf("文件名称不能为空")
- }
- if args.File == nil {
- return fmt.Errorf("文件不能为空")
- }
- if args.File.Name() == "" {
- return fmt.Errorf("文件路径不能为空")
- }
- }
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.BusinessUpgrade(req, args)
- if err != nil {
- return err
- }
- return nil
- }
- // BusinessDowngrade 项目降级
- // Swagger:Business 项目 项目降级
- func (p *BusinessHandler) BusinessDowngrade(ctx context.Context, req *projModel.BusinessDowngradeReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.BusinessDowngrade(req)
- if err != nil {
- return err
- }
- return nil
- }
- // BusinessTransfer 项目转移
- // Swagger:Business 项目 项目转移
- func (p *BusinessHandler) BusinessTransfer(ctx context.Context, req *projModel.BusinessTransferReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.BusinessTransfer(req)
- if err != nil {
- return err
- }
- return nil
- }
- // ConvertToReserve 转为储备项目
- // Swagger:Business 项目 转为储备项目
- func (p *BusinessHandler) ConvertToReserve(ctx context.Context, req *projModel.BusinessToReserveReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.ConvertToReserve(req)
- if err != nil {
- return err
- }
- return nil
- }
- // SetPrimacyContact 设置首要联系人
- // Swagger:Business 项目 设置首要联系人
- func (p *BusinessHandler) SetPrimacyContact(ctx context.Context, req *projModel.BusinessPrimacyContactReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.SetPrimacyContact(req)
- if err != nil {
- return err
- }
- return nil
- }
- // UpdateBusinessStatus 更新项目状态
- // Swagger:Business 项目 更新项目状态
- func (p *BusinessHandler) UpdateBusinessStatus(ctx context.Context, req *projModel.UpdateBusinessStatusReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- businessService, err := projSrv.NewBusinessService(ctx)
- if err != nil {
- return err
- }
- err = businessService.UpdateBusinessStatus(req)
- if err != nil {
- return err
- }
- return nil
- }
|