business.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package base
  2. import (
  3. "context"
  4. "dashoo.cn/opms_libary/multipart"
  5. "dashoo.cn/opms_libary/myerrors"
  6. "fmt"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/util/gconv"
  9. "github.com/gogf/gf/util/gvalid"
  10. "dashoo.cn/common_definition/comm_def"
  11. projModel "dashoo.cn/micro/app/model/proj"
  12. projSrv "dashoo.cn/micro/app/service/proj"
  13. )
  14. type BusinessHandler struct{}
  15. // Swagger:Business 项目 项目列表
  16. func (p *BusinessHandler) GetList(ctx context.Context, req *projModel.ProjBusinessSearchReq, rsp *comm_def.CommonMsg) error {
  17. businessService, err := projSrv.NewBusinessService(ctx)
  18. if err != nil {
  19. return err
  20. }
  21. total, list, err := businessService.GetList(req)
  22. if err != nil {
  23. return err
  24. }
  25. rsp.Data = g.Map{"list": list, "total": total}
  26. return nil
  27. }
  28. // Swagger:Business 项目 项目详情
  29. func (p *BusinessHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  30. // 参数校验
  31. if req.Id == 0 {
  32. return myerrors.ValidError("id参数有误!")
  33. }
  34. businessService, err := projSrv.NewBusinessService(ctx)
  35. if err != nil {
  36. return err
  37. }
  38. rsp.Data, err = businessService.GetEntityById(req.Id)
  39. if err != nil {
  40. return myerrors.QueryError(err, "项目")
  41. }
  42. return nil
  43. }
  44. // Swagger:Business 项目 获取项目产品
  45. func (p *BusinessHandler) GetBusinessProduct(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  46. // 参数校验
  47. if req.Id == 0 {
  48. return myerrors.ValidError("项目参数有误!")
  49. }
  50. businessService, err := projSrv.NewBusinessService(ctx)
  51. if err != nil {
  52. return err
  53. }
  54. productList, err := businessService.GetBusinessProduct(req.Id)
  55. if err != nil {
  56. return err
  57. }
  58. rsp.Data = productList
  59. return nil
  60. }
  61. // Swagger:Business 项目 获取项目动态
  62. func (p *BusinessHandler) GetBusinessDynamics(ctx context.Context, req *projModel.BusinessReq, rsp *comm_def.CommonMsg) error {
  63. if req.BusId == 0 {
  64. return myerrors.ValidError("项目参数有误!")
  65. }
  66. businessService, err := projSrv.NewBusinessService(ctx)
  67. if err != nil {
  68. return err
  69. }
  70. total, list, err := businessService.GetBusinessDynamics(req)
  71. if err != nil {
  72. return err
  73. }
  74. rsp.Data = g.Map{"list": list, "total": total}
  75. return nil
  76. }
  77. // Swagger:Business 项目 获取项目动态列表
  78. func (p *BusinessHandler) GetBusinessDynamicsList(ctx context.Context, req *projModel.BusinessDynamicsReq, rsp *comm_def.CommonMsg) error {
  79. if req.BusId == 0 {
  80. return myerrors.ValidError("项目参数有误!")
  81. }
  82. businessService, err := projSrv.NewBusinessService(ctx)
  83. if err != nil {
  84. return err
  85. }
  86. total, list, err := businessService.GetBusinessDynamicsList(req)
  87. if err != nil {
  88. return err
  89. }
  90. rsp.Data = g.Map{"list": list, "total": total}
  91. return nil
  92. }
  93. // Swagger:Business 项目 创建项目
  94. func (p *BusinessHandler) Create(ctx context.Context, req *projModel.AddProjBusinessReq, rsp *comm_def.CommonMsg) error {
  95. // 参数校验
  96. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  97. return err
  98. }
  99. // 校验产品数据
  100. for _, v := range req.Products {
  101. if err := gvalid.CheckStruct(ctx, v, nil); err != nil {
  102. return err
  103. }
  104. }
  105. businessService, err := projSrv.NewBusinessService(ctx)
  106. if err != nil {
  107. return err
  108. }
  109. err = businessService.Create(req)
  110. if err != nil {
  111. return myerrors.CreateError(err, "项目")
  112. }
  113. return nil
  114. }
  115. // Swagger:Business 项目 更新项目
  116. func (p *BusinessHandler) UpdateById(ctx context.Context, req *projModel.UpdateProjBusinessReq, rsp *comm_def.CommonMsg) error {
  117. // 参数校验
  118. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  119. return err
  120. }
  121. businessService, err := projSrv.NewBusinessService(ctx)
  122. if err != nil {
  123. return err
  124. }
  125. err = businessService.UpdateById(req)
  126. if err != nil {
  127. return myerrors.UpdateError(err, "项目")
  128. }
  129. return nil
  130. }
  131. // Swagger:Business 项目 删除项目
  132. func (p *BusinessHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
  133. // 参数校验
  134. if len(req.Ids) == 0 {
  135. return myerrors.ValidError("id参数有误!")
  136. }
  137. businessService, err := projSrv.NewBusinessService(ctx)
  138. if err != nil {
  139. return err
  140. }
  141. err = businessService.DeleteByIds(req.Ids)
  142. if err != nil {
  143. return myerrors.DeleteError(err, "项目")
  144. }
  145. return nil
  146. }
  147. // BusinessUpgrade 项目升级
  148. // Swagger:Business 项目 项目升级
  149. func (p *BusinessHandler) BusinessUpgrade(ctx context.Context, req *projModel.BusinessUpgradeReq, rsp *comm_def.CommonMsg) error {
  150. // 参数校验
  151. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  152. return err
  153. }
  154. if req.NboType != projSrv.StatusC && req.NboBudget <= 0 {
  155. return myerrors.TipsError("项目预算不能小于0")
  156. }
  157. businessService, err := projSrv.NewBusinessService(ctx)
  158. if err != nil {
  159. return err
  160. }
  161. err = businessService.BusinessUpgrade(req, nil)
  162. if err != nil {
  163. return err
  164. }
  165. return nil
  166. }
  167. // BusinessUpgradeA 项目升级A类
  168. // Swagger:Business 项目 项目升级
  169. func (p *BusinessHandler) BusinessUpgradeA(ctx context.Context, args *multipart.MultipartFile, rsp *comm_def.CommonMsg) error {
  170. req := new(projModel.BusinessUpgradeReq)
  171. if err := gconv.Struct(args.Meta, req); err != nil {
  172. return err
  173. }
  174. if req.NboType != projSrv.StatusC && req.NboBudget <= 0 {
  175. return myerrors.TipsError("项目预算不能小于0")
  176. }
  177. if req.NboType == projSrv.StatusA && req.IsAdoptDashoo == "10" {
  178. if args.FileName == "" {
  179. return fmt.Errorf("文件名称不能为空")
  180. }
  181. if args.File == nil {
  182. return fmt.Errorf("文件不能为空")
  183. }
  184. if args.File.Name() == "" {
  185. return fmt.Errorf("文件路径不能为空")
  186. }
  187. }
  188. // 参数校验
  189. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  190. return err
  191. }
  192. businessService, err := projSrv.NewBusinessService(ctx)
  193. if err != nil {
  194. return err
  195. }
  196. err = businessService.BusinessUpgrade(req, args)
  197. if err != nil {
  198. return err
  199. }
  200. return nil
  201. }
  202. // BusinessDowngrade 项目降级
  203. // Swagger:Business 项目 项目降级
  204. func (p *BusinessHandler) BusinessDowngrade(ctx context.Context, req *projModel.BusinessDowngradeReq, rsp *comm_def.CommonMsg) error {
  205. // 参数校验
  206. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  207. return err
  208. }
  209. businessService, err := projSrv.NewBusinessService(ctx)
  210. if err != nil {
  211. return err
  212. }
  213. err = businessService.BusinessDowngrade(req)
  214. if err != nil {
  215. return err
  216. }
  217. return nil
  218. }
  219. // BusinessTransfer 项目转移
  220. // Swagger:Business 项目 项目转移
  221. func (p *BusinessHandler) BusinessTransfer(ctx context.Context, req *projModel.BusinessTransferReq, rsp *comm_def.CommonMsg) error {
  222. // 参数校验
  223. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  224. return err
  225. }
  226. businessService, err := projSrv.NewBusinessService(ctx)
  227. if err != nil {
  228. return err
  229. }
  230. err = businessService.BusinessTransfer(req)
  231. if err != nil {
  232. return err
  233. }
  234. return nil
  235. }
  236. // ConvertToReserve 转为储备项目
  237. // Swagger:Business 项目 转为储备项目
  238. func (p *BusinessHandler) ConvertToReserve(ctx context.Context, req *projModel.BusinessToReserveReq, rsp *comm_def.CommonMsg) error {
  239. // 参数校验
  240. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  241. return err
  242. }
  243. businessService, err := projSrv.NewBusinessService(ctx)
  244. if err != nil {
  245. return err
  246. }
  247. err = businessService.ConvertToReserve(req)
  248. if err != nil {
  249. return err
  250. }
  251. return nil
  252. }
  253. // SetPrimacyContact 设置首要联系人
  254. // Swagger:Business 项目 设置首要联系人
  255. func (p *BusinessHandler) SetPrimacyContact(ctx context.Context, req *projModel.BusinessPrimacyContactReq, rsp *comm_def.CommonMsg) error {
  256. // 参数校验
  257. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  258. return err
  259. }
  260. businessService, err := projSrv.NewBusinessService(ctx)
  261. if err != nil {
  262. return err
  263. }
  264. err = businessService.SetPrimacyContact(req)
  265. if err != nil {
  266. return err
  267. }
  268. return nil
  269. }
  270. // UpdateBusinessStatus 更新项目状态
  271. // Swagger:Business 项目 更新项目状态
  272. func (p *BusinessHandler) UpdateBusinessStatus(ctx context.Context, req *projModel.UpdateBusinessStatusReq, rsp *comm_def.CommonMsg) error {
  273. // 参数校验
  274. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  275. return err
  276. }
  277. businessService, err := projSrv.NewBusinessService(ctx)
  278. if err != nil {
  279. return err
  280. }
  281. err = businessService.UpdateBusinessStatus(req)
  282. if err != nil {
  283. return err
  284. }
  285. return nil
  286. }