business.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. package proj
  2. import (
  3. "context"
  4. contractDao "dashoo.cn/micro/app/dao/contract"
  5. custDao "dashoo.cn/micro/app/dao/cust"
  6. projDao "dashoo.cn/micro/app/dao/proj"
  7. model "dashoo.cn/micro/app/model/proj"
  8. workflowModel "dashoo.cn/micro/app/model/workflow"
  9. "dashoo.cn/micro/app/service"
  10. workflowService "dashoo.cn/micro/app/service/workflow"
  11. "dashoo.cn/opms_libary/myerrors"
  12. "dashoo.cn/opms_libary/plugin/dingtalk/message"
  13. "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
  14. "dashoo.cn/opms_libary/utils"
  15. "fmt"
  16. "github.com/gogf/gf/database/gdb"
  17. "github.com/gogf/gf/frame/g"
  18. "github.com/gogf/gf/os/gtime"
  19. "github.com/gogf/gf/util/gconv"
  20. "github.com/shopspring/decimal"
  21. "strconv"
  22. "strings"
  23. )
  24. type businessService struct {
  25. *service.ContextService
  26. Dao *projDao.ProjBusinessDao
  27. }
  28. func NewBusinessService(ctx context.Context) (svc *businessService, err error) {
  29. svc = new(businessService)
  30. if svc.ContextService, err = svc.Init(ctx); err != nil {
  31. return nil, err
  32. }
  33. svc.Dao = projDao.NewProjBusinessDao(svc.Tenant)
  34. return svc, nil
  35. }
  36. func (p *businessService) GetList(req *model.ProjBusinessSearchReq) (total int, businessList []*model.ProjBusinessRes, err error) {
  37. db := p.Dao.As("proj").DataScope(p.Ctx, "sale_id")
  38. if req.NboName != "" {
  39. db = db.WhereLike("proj."+p.Dao.C.NboName, "%"+req.NboName+"%")
  40. }
  41. if req.CustName != "" {
  42. db = db.WhereLike("proj."+p.Dao.C.CustName, "%"+req.CustName+"%")
  43. }
  44. if req.SaleName != "" {
  45. db = db.WhereLike("proj."+p.Dao.C.SaleName, "%"+req.SaleName+"%")
  46. }
  47. if req.NboType != "" {
  48. db = db.Where("proj."+p.Dao.C.NboType, req.NboType)
  49. }
  50. if req.ProductLine != "" {
  51. db = db.Where("proj."+p.Dao.C.ProductLine, req.ProductLine)
  52. }
  53. if req.NboSource != "" {
  54. db = db.Where("proj."+p.Dao.C.NboSource, req.NboSource)
  55. }
  56. if req.DistributorName != "" {
  57. db = db.Where("proj."+p.Dao.C.DistributorName, "%"+req.DistributorName+"%")
  58. }
  59. if req.BeginTime != "" {
  60. db = db.WhereGTE("proj."+p.Dao.C.FilingTime, req.BeginTime)
  61. }
  62. if req.EndTime != "" {
  63. db = db.WhereLTE("proj."+p.Dao.C.FilingTime, req.EndTime)
  64. }
  65. total, err = db.Count()
  66. if err != nil {
  67. err = myerrors.DbError("获取总行数失败。")
  68. return
  69. }
  70. if req.NboType == StatusDeal {
  71. db = db.Unscoped().WhereNull(`proj.deleted_time`).
  72. LeftJoin(contractDao.CtrContract.Table, "contract", "`proj`.id=`contract`.nbo_id AND `contract`.`deleted_time` IS NULL ").
  73. Fields("`proj`.cust_city_id as cust_city_id,`contract`.contract_amount, `contract`.created_time as proj_closing_time")
  74. }
  75. db = db.Fields("`proj`.*")
  76. err = db.Page(req.PageNum, req.PageSize).OrderDesc("id").Scan(&businessList)
  77. return
  78. }
  79. func (p *businessService) GetEntityById(id int64) (business *model.ProjBusiness, err error) {
  80. err = p.Dao.Where(projDao.ProjBusiness.C.Id, id).Scan(&business)
  81. return
  82. }
  83. func (p *businessService) GetBusinessProduct(id int64) (productList []*model.ProjBusinessProduct, err error) {
  84. productDao := projDao.NewProjBusinessProductDao(p.Tenant)
  85. err = productDao.Where(productDao.ProjBusinessProductDao.C.BusId, id).Scan(&productList)
  86. return
  87. }
  88. func (p *businessService) GetBusinessDynamics(req *model.BusinessReq) (total int, result g.MapStrAny, err error) {
  89. result = make(g.MapStrAny, 0)
  90. dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).ProjBusinessDynamicsDao.Where(projDao.ProjBusinessDynamics.C.BusId, req.BusId)
  91. total, err = dynamicsDao.Count()
  92. if err != nil {
  93. g.Log().Error(err)
  94. return
  95. }
  96. dynamicsList, err := dynamicsDao.Page(req.GetPage()).Order("created_time desc").All()
  97. if err != nil || dynamicsList == nil {
  98. return
  99. }
  100. // 数据树格式转换
  101. opnDateFlag := gtime.New(dynamicsList[0].OpnDate).Format("Y-m-d")
  102. for k, v := range dynamicsList {
  103. opnDate := gtime.New(v.OpnDate).Format("Y-m-d")
  104. if opnDateFlag == opnDate && k != 0 {
  105. result[opnDate] = append(result[opnDate].(g.ListStrAny), g.Map{
  106. "opnPeople": v.OpnPeople,
  107. "opnDate": v.OpnDate,
  108. "opnType": v.OpnType,
  109. "remark": v.Remark,
  110. "opnContent": gconv.Map(v.OpnContent),
  111. })
  112. } else {
  113. temp := make(g.ListStrAny, 0)
  114. temp = append(temp, g.Map{
  115. "opnPeople": v.OpnPeople,
  116. "opnDate": v.OpnDate,
  117. "opnType": v.OpnType,
  118. "remark": v.Remark,
  119. "opnContent": gconv.Map(v.OpnContent),
  120. })
  121. result[opnDate] = temp
  122. }
  123. }
  124. return
  125. }
  126. func (p *businessService) GetBusinessDynamicsList(req *model.BusinessDynamicsReq) (total int, list []map[string]interface{}, err error) {
  127. dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).Where(projDao.ProjBusinessDynamics.C.BusId, req.BusId)
  128. if req.OpnType != "" {
  129. dynamicsDao = dynamicsDao.Where(projDao.ProjBusinessDynamics.C.OpnType+" = ?", req.OpnType)
  130. }
  131. total, err = dynamicsDao.Count()
  132. if err != nil {
  133. g.Log().Error(err)
  134. return
  135. }
  136. dynamicsList, err := dynamicsDao.Page(req.GetPage()).Order("created_time desc").All()
  137. for _, v := range dynamicsList {
  138. val := gconv.Map(v)
  139. val["opnContent"] = gconv.Map(v.OpnContent)
  140. list = append(list, val)
  141. }
  142. return
  143. }
  144. // 获取项目编号
  145. func (s *businessService) getNboCode(customerCode string) (string, error) {
  146. sequence, err := service.Sequence(s.Dao.DB, "nbo_code")
  147. if err != nil {
  148. return "", err
  149. }
  150. return customerCode + sequence, nil
  151. }
  152. func (p *businessService) Create(req *model.AddProjBusinessReq) (err error) {
  153. // 获取客户信息
  154. customer, err := custDao.NewCustCustomerDao(p.Tenant).WherePri(req.CustId).One()
  155. if err != nil {
  156. return err
  157. }
  158. if customer == nil {
  159. return myerrors.TipsError("客户不存在")
  160. }
  161. // 设置默认联系人
  162. contact := g.Map{
  163. projDao.ProjBusinessContact.C.ContactId: req.ContactId,
  164. }
  165. service.SetCreatedInfo(contact, p.GetCxtUserId(), p.GetCxtUserName())
  166. // 设置产品信息
  167. totalPrice, products, err := p.setProductInfo(0, req.Products)
  168. if err != nil {
  169. return err
  170. }
  171. // 获取项目编号
  172. nboCode, err := p.getNboCode(customer.CustCode)
  173. if err != nil {
  174. return err
  175. }
  176. // 初始化项目信息
  177. businessData := new(model.ProjBusiness)
  178. if err = gconv.Struct(req, businessData); err != nil {
  179. return
  180. }
  181. businessData.NboCode = nboCode
  182. //businessData.NboStatus = StatusOK
  183. businessData.NboType = StatusC
  184. businessData.ApproStatus = ApprovalNotSubmit
  185. businessData.EstTransPrice = totalPrice
  186. businessData.CustProvinceId = customer.CustProvinceId
  187. businessData.CustProvince = customer.CustProvince
  188. businessData.CustCityId = customer.CustCityId
  189. businessData.CustCity = customer.CustCity
  190. businessData.CustRegionId = customer.CustRegionId
  191. businessData.CustRegion = customer.CustRegion
  192. businessData.DeptId = p.GetCxtUserDeptId()
  193. service.SetCreatedInfo(businessData, p.GetCxtUserId(), p.GetCxtUserName())
  194. businessData.FilingTime = businessData.CreatedTime
  195. // 事务
  196. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  197. // 添加项目
  198. lastId, err := p.Dao.TX(tx).InsertAndGetId(businessData)
  199. if err != nil {
  200. return err
  201. }
  202. // 创建了联系人
  203. contact[projDao.ProjBusinessContact.C.BusId] = lastId
  204. _, err = projDao.NewProjBusinessContactDao(p.Tenant).TX(tx).Insert(contact)
  205. if err != nil {
  206. return err
  207. }
  208. // 处理项目产品信息
  209. for _, v := range products {
  210. v.BusId = int(lastId)
  211. }
  212. // 添加项目产品
  213. _, err = projDao.NewProjBusinessProductDao(p.Tenant).TX(tx).Insert(products)
  214. if err != nil {
  215. return err
  216. }
  217. // 添加项目动态
  218. dynamics := model.ProjBusinessDynamics{
  219. BusId: int(lastId),
  220. OpnType: OpnCreate,
  221. Remark: businessData.Remark,
  222. }
  223. err = p.CreateProjBusinessDynamics(tx, dynamics, businessData)
  224. return err
  225. })
  226. return
  227. }
  228. // setProductInfo 设置产品信息
  229. func (p *businessService) setProductInfo(busId int, productInfo []model.BusinessProduct) (total float64, products []*model.ProjBusinessProduct, err error) {
  230. products = make([]*model.ProjBusinessProduct, len(productInfo))
  231. if err = gconv.Structs(productInfo, &products); err != nil {
  232. return 0, nil, err
  233. }
  234. var totalPrice decimal.Decimal
  235. for _, v := range products {
  236. v.Id = 0
  237. v.BusId = busId
  238. v.TotalPrice = decimal.NewFromFloat(v.ProdPrice).Mul(decimal.NewFromInt(int64(v.ProdNum))).InexactFloat64()
  239. totalPrice = totalPrice.Add(decimal.NewFromFloat(v.TotalPrice))
  240. service.SetCreatedInfo(v, p.GetCxtUserId(), p.GetCxtUserName())
  241. }
  242. return totalPrice.InexactFloat64(), products, nil
  243. }
  244. func (p *businessService) UpdateById(req *model.UpdateProjBusinessReq) error {
  245. record, err := p.Dao.WherePri(req.Id).Count()
  246. if err != nil {
  247. return err
  248. }
  249. if record == 0 {
  250. return myerrors.TipsError("项目不存在。")
  251. }
  252. // 设置产品信息
  253. totalPrice, products, err := p.setProductInfo(req.Id, req.Products)
  254. if err != nil {
  255. return err
  256. }
  257. // 设置默认联系人
  258. contact := g.Map{
  259. projDao.ProjBusinessContact.C.BusId: req.Id,
  260. projDao.ProjBusinessContact.C.ContactId: req.ContactId,
  261. }
  262. contactFlag, err := projDao.NewProjBusinessContactDao(p.Tenant).Where(contact).Count()
  263. if err != nil {
  264. return err
  265. }
  266. if contactFlag == 0 {
  267. service.SetCreatedInfo(contact, p.GetCxtUserId(), p.GetCxtUserName())
  268. }
  269. // 设置项目信息
  270. req.EstTransPrice = totalPrice
  271. businessData := gconv.Map(req)
  272. service.SetUpdatedInfo(businessData, p.GetCxtUserId(), p.GetCxtUserName())
  273. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  274. // 更新项目
  275. _, err = p.Dao.TX(tx).FieldsEx(service.UpdateFieldEx...).WherePri(projDao.ProjBusiness.C.Id, req.Id).Update(businessData)
  276. if err != nil {
  277. return err
  278. }
  279. // 删除项目产品
  280. _, err = projDao.NewProjBusinessProductDao(p.Tenant).TX(tx).Where(projDao.ProjBusinessProduct.C.BusId, req.Id).Delete()
  281. if err != nil {
  282. return err
  283. }
  284. // 添加项目产品
  285. _, err = projDao.NewProjBusinessProductDao(p.Tenant).TX(tx).Insert(products)
  286. if err != nil {
  287. return err
  288. }
  289. // 关联联系人
  290. if contactFlag == 0 {
  291. _, err = projDao.NewProjBusinessContactDao(p.Tenant).TX(tx).Insert(contact)
  292. if err != nil {
  293. return err
  294. }
  295. }
  296. // 添加项目动态
  297. dynamics := model.ProjBusinessDynamics{
  298. BusId: req.Id,
  299. OpnType: OpnUpdate,
  300. Remark: req.Remark,
  301. }
  302. err = p.CreateProjBusinessDynamics(tx, dynamics, req)
  303. return err
  304. })
  305. return err
  306. }
  307. func (p *businessService) DeleteByIds(ids []int64) (err error) {
  308. _, err = p.Dao.WhereIn(projDao.ProjBusiness.C.Id, ids).Delete()
  309. return
  310. }
  311. // BusinessTransfer 项目转移
  312. func (p *businessService) BusinessTransfer(req *model.BusinessTransferReq) error {
  313. business, err := p.Dao.WherePri(req.Id).WhereNot(p.Dao.C.ApproStatus, ApprovalWaiting).One()
  314. if err != nil {
  315. return err
  316. }
  317. if business == nil {
  318. return myerrors.TipsError("项目已提交审批任务,无法重复提交。")
  319. }
  320. businessMap := g.Map{
  321. p.Dao.C.ApproStatus: ApprovalWaiting,
  322. }
  323. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  324. opnContent := businessMap
  325. opnContent["origSaleId"] = business.SaleId
  326. opnContent["origSaleName"] = business.SaleName
  327. opnContent["saleId"] = req.UserId
  328. opnContent["saleName"] = req.UserName
  329. opnContent["remark"] = req.Remark
  330. // 审批流
  331. workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
  332. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  333. // 更新项目
  334. _, err = p.Dao.TX(tx).WherePri(projDao.ProjBusiness.C.Id, req.Id).Data(businessMap).Update()
  335. if err != nil {
  336. return err
  337. }
  338. // 添加项目动态
  339. dynamics := model.ProjBusinessDynamics{
  340. BusId: req.Id,
  341. OpnType: OpnTransfer,
  342. Remark: req.Remark,
  343. }
  344. err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
  345. if err != nil {
  346. g.Log().Error(err)
  347. return err
  348. }
  349. // OMS项目转移 审批
  350. bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
  351. _, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectTransfer, "", &workflow.StartProcessInstanceRequest{
  352. ProcessCode: &BusinessTransferRequestProcessCode,
  353. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  354. {
  355. Id: utils.String("TextField-K2AD4O5B"),
  356. Name: utils.String("项目编码"),
  357. Value: utils.String(business.NboCode),
  358. },
  359. {
  360. Id: utils.String("TextField_7EFHRQ9DDF80"),
  361. Name: utils.String("项目名称"),
  362. Value: utils.String(business.NboName),
  363. },
  364. {
  365. Id: utils.String("TextField_1T3DEY5FWV7K0"),
  366. Name: utils.String("客户名称"),
  367. Value: utils.String(business.CustName),
  368. },
  369. {
  370. Id: utils.String("TextField_QDU06LXYKK00"),
  371. Name: utils.String("所在省"),
  372. Value: utils.String(business.CustProvince),
  373. },
  374. {
  375. Id: utils.String("TextField_MVSOO6EG6YO0"),
  376. Name: utils.String("所在市"),
  377. Value: utils.String(business.CustCity),
  378. },
  379. {
  380. Id: utils.String("TextField_1E1WOYGKRTDS0"),
  381. Name: utils.String("项目级别"),
  382. Value: utils.String(nboType[business.NboType]),
  383. },
  384. {
  385. Id: utils.String("TextField_NRQXWLJ17HC0"),
  386. Name: utils.String("申请人"),
  387. Value: utils.String(p.GetCxtUserName()),
  388. },
  389. {
  390. Id: utils.String("TextField_GHSQYDGD13K0"),
  391. Name: utils.String("转移原因"),
  392. Value: utils.String(req.Remark),
  393. },
  394. {
  395. Id: utils.String("TextField_76P8FPHH0UC0"),
  396. Name: utils.String("接收人"),
  397. Value: utils.String(req.UserName),
  398. },
  399. },
  400. })
  401. if err != nil {
  402. g.Log().Error(err)
  403. return err
  404. }
  405. return nil
  406. })
  407. return err
  408. }
  409. // BusinessTransferNotify 项目转移 审批结果通知
  410. func (p *businessService) BusinessTransferNotify(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
  411. business, err := p.checkDingTalkNotify(flow, msg)
  412. if err != nil {
  413. return err
  414. }
  415. var data = g.Map{}
  416. if msg.ProcessType == "terminate" {
  417. data[p.Dao.C.ApproStatus] = ApprovalReturn
  418. }
  419. if msg.ProcessType == "finish" && msg.Result != "refuse" {
  420. data[p.Dao.C.ApproStatus] = ApprovalRejection
  421. }
  422. if msg.ProcessType == "finish" && msg.Result == "agree" {
  423. // 从项目动态内获取变更信息
  424. var transferDynamics model.ProjBusinessDynamics
  425. dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).Where(projDao.ProjBusinessDynamics.C.BusId, business.Id)
  426. err = dynamicsDao.Where(projDao.ProjBusinessDynamics.C.OpnType, OpnTransfer).OrderDesc("created_time").Scan(&transferDynamics)
  427. if err != nil {
  428. return err
  429. }
  430. changeData := gconv.Map(transferDynamics.OpnContent)
  431. data[p.Dao.C.SaleId] = changeData["saleId"]
  432. data[p.Dao.C.SaleName] = changeData["saleName"]
  433. data[p.Dao.C.Remark] = changeData["remark"]
  434. data[p.Dao.C.ApproStatus] = ApprovalOK
  435. }
  436. // 项目修改
  437. _, err = p.Dao.WherePri(business.Id).FieldsEx(service.UpdateFieldEx...).Data(data).Update()
  438. if err != nil {
  439. return err
  440. }
  441. // 添加项目动态
  442. dynamics := model.ProjBusinessDynamics{
  443. BusId: business.Id,
  444. OpnType: OpnTransferApproval,
  445. }
  446. err = p.CreateProjBusinessDynamics(nil, dynamics, data)
  447. if err != nil {
  448. return err
  449. }
  450. return err
  451. }
  452. // BusinessGradation 项目调级
  453. func (p *businessService) BusinessGradation(busId int, nboType, busType string) (*model.ProjBusiness, error) {
  454. business, err := p.Dao.WherePri(busId).WhereNot(p.Dao.C.ApproStatus, ApprovalWaiting).One()
  455. if err != nil {
  456. return nil, err
  457. }
  458. if business == nil {
  459. return nil, myerrors.TipsError("项目已提交审批任务,无法重复提交。")
  460. }
  461. if business.NboType == nboType {
  462. return nil, myerrors.TipsError("同级别无法进行调级。")
  463. }
  464. if business.NboType == StatusDeal {
  465. return nil, myerrors.TipsError("成交项目无法进行调级。")
  466. }
  467. if business.NboType == StatusReserve && nboType == StatusDeal {
  468. return nil, myerrors.TipsError("储备项目无法直接转为成交项目。")
  469. }
  470. if busType == "up" && gconv.Int(business.NboType) < gconv.Int(nboType) {
  471. return nil, myerrors.TipsError("项目级别错误。")
  472. }
  473. if busType == "down" && gconv.Int(business.NboType) > gconv.Int(nboType) {
  474. return nil, myerrors.TipsError("项目级别错误。")
  475. }
  476. return business, err
  477. }
  478. // BusinessUpgrade 项目升级
  479. func (p *businessService) BusinessUpgrade(req *model.BusinessUpgradeReq) error {
  480. business, err := p.BusinessGradation(req.Id, req.NboType, "up")
  481. if err != nil {
  482. return err
  483. }
  484. businessMap := g.Map{
  485. p.Dao.C.ApproStatus: ApprovalWaiting,
  486. }
  487. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  488. opnContent := gconv.Map(req)
  489. opnContent["origNboType"] = business.NboType
  490. opnContent["approStatus"] = ApprovalWaiting
  491. service.SetUpdatedInfo(opnContent, p.GetCxtUserId(), p.GetCxtUserName())
  492. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  493. // 更新项目调级
  494. _, err = p.Dao.TX(tx).WherePri(req.Id).Data(businessMap).Update()
  495. if err != nil {
  496. return err
  497. }
  498. // 添加项目动态
  499. dynamics := model.ProjBusinessDynamics{
  500. BusId: business.Id,
  501. OpnType: OpnUpgrade,
  502. Remark: req.Remark,
  503. }
  504. err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
  505. if err != nil {
  506. return err
  507. }
  508. err = p.BusUpgradeDingEvent(business, req)
  509. return err
  510. })
  511. return err
  512. }
  513. // 获取项目的钉钉审批的升级类型
  514. func (p *businessService) getBusDingUpgradeType(dbNboType, reqNboType string) string {
  515. var upgradeType string
  516. switch true {
  517. case dbNboType == StatusReserve && reqNboType == StatusC: // 储备转C
  518. upgradeType = "option_0"
  519. case dbNboType == StatusReserve && reqNboType == StatusB: // 储备转B
  520. upgradeType = "option_1"
  521. case dbNboType == StatusReserve && reqNboType == StatusA: // 储备转A
  522. upgradeType = "option_KTAX3Y9K5340"
  523. case dbNboType == StatusC && reqNboType == StatusB: // C转B
  524. upgradeType = "option_0"
  525. case dbNboType == StatusC && reqNboType == StatusA: // C转A
  526. upgradeType = "option_0"
  527. case dbNboType == StatusB && reqNboType == StatusA: // B转A
  528. upgradeType = "option_1"
  529. default:
  530. }
  531. return upgradeType
  532. }
  533. // BusUpgradeDingEvent 项目升级钉钉审批流调用
  534. func (p *businessService) BusUpgradeDingEvent(business *model.ProjBusiness, req *model.BusinessUpgradeReq) error {
  535. upgradeType := p.getBusDingUpgradeType(business.NboType, req.NboType)
  536. if upgradeType == "" {
  537. return myerrors.TipsError("错误的升级类型")
  538. }
  539. // 审批流
  540. workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
  541. // OMS项目升级 审批
  542. var err error
  543. var dingReq *workflow.StartProcessInstanceRequest
  544. bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
  545. switch req.NboType {
  546. case StatusC:
  547. dingReq = &workflow.StartProcessInstanceRequest{
  548. ProcessCode: &BusinessUpgradeCRequestProcessCode,
  549. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  550. {
  551. Id: utils.String("TextField-K2AD4O5B"),
  552. Name: utils.String("项目编码"),
  553. Value: utils.String(business.NboCode),
  554. },
  555. {
  556. Id: utils.String("TextField_BDLSECETVSG0"),
  557. Name: utils.String("项目名称"),
  558. Value: utils.String(business.NboName),
  559. },
  560. {
  561. Id: utils.String("DDSelectField_VSA3U380ZK00"),
  562. Name: utils.String("升级类型"),
  563. Value: utils.String(upgradeType),
  564. },
  565. {
  566. Id: utils.String("TextField_1J9BJMOZ18F40"),
  567. Name: utils.String("客户名称"),
  568. Value: utils.String(business.CustName),
  569. },
  570. {
  571. Id: utils.String("TextField_AEUWH63LJ0O0"),
  572. Name: utils.String("销售工程师"),
  573. Value: utils.String(business.SaleName),
  574. },
  575. {
  576. Id: utils.String("TextareaField_1LO81IKHH91C0"),
  577. Name: utils.String("转化原因"),
  578. Value: utils.String(req.Remark),
  579. },
  580. },
  581. }
  582. case StatusB, StatusA: // 目前转B、A表单提交参数一致,仅A比B多几个必填-----2023.02.27
  583. processCode := &BusinessUpgradeBRequestProcessCode
  584. if req.NboType == StatusA {
  585. processCode = &BusinessUpgradeARequestProcessCode
  586. }
  587. dingReq = &workflow.StartProcessInstanceRequest{
  588. ProcessCode: processCode,
  589. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  590. {
  591. Id: utils.String("TextField-K2AD4O5B"),
  592. Name: utils.String("项目编码"),
  593. Value: utils.String(business.NboCode),
  594. },
  595. {
  596. Id: utils.String("TextField_BDLSECETVSG0"),
  597. Name: utils.String("项目名称"),
  598. Value: utils.String(business.NboName),
  599. },
  600. {
  601. Id: utils.String("DDSelectField_VSA3U380ZK00"),
  602. Name: utils.String("升级类型"),
  603. Value: utils.String(upgradeType),
  604. },
  605. {
  606. Id: utils.String("TextField_1J9BJMOZ18F40"),
  607. Name: utils.String("客户名称"),
  608. Value: utils.String(business.CustName),
  609. },
  610. {
  611. Id: utils.String("NumberField_1F88MCD0W8KG0"),
  612. Name: utils.String("项目预算"),
  613. Value: utils.String(gconv.String(req.NboBudget)),
  614. },
  615. {
  616. Id: utils.String("TextField_1PWK6WHMGITC0"),
  617. Name: utils.String("经销商/代理商"),
  618. Value: utils.String(req.DistributorName),
  619. },
  620. {
  621. Id: utils.String("TextField_X4D3QGARU7K0"),
  622. Name: utils.String("支持内容"),
  623. Value: utils.String(req.TechnicalSupportContent),
  624. },
  625. {
  626. Id: utils.String("TextField_AEUWH63LJ0O0"),
  627. Name: utils.String("销售工程师"),
  628. Value: utils.String(business.SaleName),
  629. },
  630. {
  631. Id: utils.String("DDDateField_1FW1QZQYBZVK0"),
  632. Name: utils.String("采购时间"),
  633. Value: utils.String(gconv.String(req.PurchasingTime.Format("Y-m-d"))),
  634. },
  635. {
  636. Id: utils.String("DDSelectField_21ASEWDIB3MO0"),
  637. Name: utils.String("采购方式"),
  638. Value: utils.String(gconv.String(purchasingWayType[req.PurchasingWay])),
  639. },
  640. {
  641. Id: utils.String("DDSelectField_5R11VVM6GI00"),
  642. Name: utils.String("是否我司参数"),
  643. Value: utils.String(gconv.String(yesOrNoType[req.IsAdoptDashoo])),
  644. },
  645. {
  646. Id: utils.String("TextareaField_1GEL8JJL3H5S0"),
  647. Name: utils.String("备注"),
  648. Value: utils.String(req.Remark),
  649. },
  650. },
  651. }
  652. default:
  653. return nil
  654. }
  655. _, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectUpGrade, "", dingReq)
  656. if err != nil {
  657. g.Log().Error(err)
  658. return err
  659. }
  660. return nil
  661. }
  662. // BusinessUpgradeNotify 项目升级 审批结果通知
  663. func (p *businessService) BusinessUpgradeNotify(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
  664. business, err := p.checkDingTalkNotify(flow, msg)
  665. if err != nil {
  666. return err
  667. }
  668. var data = g.Map{}
  669. if msg.ProcessType == "terminate" {
  670. data[p.Dao.C.ApproStatus] = ApprovalReturn
  671. }
  672. if msg.ProcessType == "finish" && msg.Result != "refuse" {
  673. data[p.Dao.C.ApproStatus] = ApprovalRejection
  674. }
  675. if msg.ProcessType == "finish" && msg.Result == "agree" {
  676. // 从项目动态内获取变更信息
  677. dynamics := new(model.ProjBusinessDynamics)
  678. dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).Where(projDao.ProjBusinessDynamics.C.BusId, business.Id)
  679. err = dynamicsDao.Where(projDao.ProjBusinessDynamics.C.OpnType, OpnUpgrade).OrderDesc("created_time").Scan(dynamics)
  680. if err != nil {
  681. return err
  682. }
  683. updateData := new(model.BusinessUpgradeReq)
  684. gconv.Struct(dynamics.OpnContent, updateData)
  685. data = gconv.Map(updateData)
  686. data[p.Dao.C.ApproStatus] = ApprovalOK
  687. }
  688. // 项目修改
  689. _, err = p.Dao.WherePri(business.Id).FieldsEx(service.UpdateFieldEx...).Data(data).Update()
  690. if err != nil {
  691. return err
  692. }
  693. // 添加项目动态
  694. dynamics := model.ProjBusinessDynamics{
  695. BusId: business.Id,
  696. OpnType: OpnUpgradeApproval,
  697. }
  698. err = p.CreateProjBusinessDynamics(nil, dynamics, data)
  699. if err != nil {
  700. return err
  701. }
  702. return nil
  703. }
  704. // 获取项目的钉钉审批的降级类型
  705. func (p *businessService) getBusDingDowngradeType(dbNboType, reqNboType string) string {
  706. var downgradeType string
  707. switch true {
  708. case dbNboType == StatusB && reqNboType == StatusC:
  709. downgradeType = "option_0"
  710. case dbNboType == StatusA && reqNboType == StatusB:
  711. downgradeType = "option_1"
  712. case dbNboType == StatusA && reqNboType == StatusC:
  713. downgradeType = "option_2"
  714. case dbNboType == StatusA && reqNboType == StatusReserve:
  715. downgradeType = "option_YZMFJYQQK6O0"
  716. case dbNboType == StatusB && reqNboType == StatusReserve:
  717. downgradeType = "option_232GR5NMFCSG0"
  718. case dbNboType == StatusC && reqNboType == StatusReserve:
  719. downgradeType = "option_1ZV2GJLDKQOW0"
  720. default:
  721. }
  722. return downgradeType
  723. }
  724. // BusinessDowngrade 项目降级
  725. func (p *businessService) BusinessDowngrade(req *model.BusinessDowngradeReq) error {
  726. business, err := p.BusinessGradation(req.Id, req.NboType, "down")
  727. if err != nil {
  728. return err
  729. }
  730. downgradeType := p.getBusDingDowngradeType(business.NboType, req.NboType)
  731. if downgradeType == "" {
  732. return myerrors.TipsError("错误的降级类型")
  733. }
  734. businessMap := g.Map{
  735. p.Dao.C.ApproStatus: ApprovalWaiting,
  736. }
  737. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  738. opnContent := gconv.Map(req)
  739. opnContent["origNboType"] = business.NboType
  740. opnContent["approStatus"] = ApprovalWaiting
  741. service.SetUpdatedInfo(opnContent, p.GetCxtUserId(), p.GetCxtUserName())
  742. // 审批流
  743. workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
  744. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  745. // 更新项目调级
  746. _, err = p.Dao.TX(tx).WherePri(req.Id).Data(businessMap).Update()
  747. if err != nil {
  748. return err
  749. }
  750. // 添加项目动态
  751. dynamics := model.ProjBusinessDynamics{
  752. BusId: business.Id,
  753. OpnType: OpnDowngrade,
  754. Remark: req.Remark,
  755. }
  756. err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
  757. if err != nil {
  758. return err
  759. }
  760. // OMS项目降级 审批
  761. bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
  762. _, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectDownGrade, "", &workflow.StartProcessInstanceRequest{
  763. ProcessCode: &BusinessDowngradeRequestProcessCode,
  764. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  765. {
  766. Id: utils.String("TextField-K2AD4O5B"),
  767. Name: utils.String("项目编码"),
  768. Value: utils.String(business.NboCode),
  769. },
  770. {
  771. Id: utils.String("TextField_BDLSECETVSG0"),
  772. Name: utils.String("项目名称"),
  773. Value: utils.String(business.NboName),
  774. },
  775. {
  776. Id: utils.String("TextField_1J9BJMOZ18F40"),
  777. Name: utils.String("客户名称"),
  778. Value: utils.String(business.CustName),
  779. },
  780. {
  781. Id: utils.String("TextField_GL7MQUB723K0"),
  782. Name: utils.String("所在省"),
  783. Value: utils.String(business.CustProvince),
  784. },
  785. {
  786. Id: utils.String("TextField_CFA88QQQUUO0"),
  787. Name: utils.String("所在市"),
  788. Value: utils.String(business.CustCity),
  789. },
  790. {
  791. Id: utils.String("DDSelectField_VSA3U380ZK00"),
  792. Name: utils.String("降级类型"),
  793. Value: utils.String(downgradeType),
  794. },
  795. {
  796. Id: utils.String("TextField_X4D3QGARU7K0"),
  797. Name: utils.String("支持内容"),
  798. Value: utils.String(req.TechnicalSupportContent),
  799. },
  800. {
  801. Id: utils.String("TextField_AEUWH63LJ0O0"),
  802. Name: utils.String("销售工程师"),
  803. Value: utils.String(business.SaleName),
  804. },
  805. {
  806. Id: utils.String("TextareaField_PTGJOKD3J7K0"),
  807. Name: utils.String("降级原因"),
  808. Value: utils.String(req.Remark),
  809. },
  810. },
  811. })
  812. if err != nil {
  813. g.Log().Error(err)
  814. return err
  815. }
  816. return nil
  817. })
  818. return err
  819. }
  820. // BusinessDowngradeNotify 项目降级 审批结果通知
  821. func (p *businessService) BusinessDowngradeNotify(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
  822. business, err := p.checkDingTalkNotify(flow, msg)
  823. if err != nil {
  824. return err
  825. }
  826. var data = g.Map{}
  827. if msg.ProcessType == "terminate" {
  828. data[p.Dao.C.ApproStatus] = ApprovalReturn
  829. }
  830. if msg.ProcessType == "finish" && msg.Result != "refuse" {
  831. data[p.Dao.C.ApproStatus] = ApprovalRejection
  832. }
  833. if msg.ProcessType == "finish" && msg.Result == "agree" {
  834. // 从项目动态内获取变更信息
  835. dynamics := new(model.ProjBusinessDynamics)
  836. dynamicsDao := projDao.NewProjBusinessDynamicsDao(p.Tenant).Where(projDao.ProjBusinessDynamics.C.BusId, business.Id)
  837. err = dynamicsDao.Where(projDao.ProjBusinessDynamics.C.OpnType, OpnDowngrade).OrderDesc("created_time").Scan(dynamics)
  838. if err != nil {
  839. return err
  840. }
  841. updateData := new(model.BusinessDowngradeReq)
  842. gconv.Struct(dynamics.OpnContent, updateData)
  843. data = gconv.Map(updateData)
  844. data[p.Dao.C.ApproStatus] = ApprovalOK
  845. }
  846. // 项目修改
  847. _, err = p.Dao.WherePri(business.Id).FieldsEx(service.UpdateFieldEx...).Data(data).Update()
  848. if err != nil {
  849. return err
  850. }
  851. // 添加项目动态
  852. dynamics := model.ProjBusinessDynamics{
  853. BusId: business.Id,
  854. OpnType: OpnDowngradeApproval,
  855. }
  856. err = p.CreateProjBusinessDynamics(nil, dynamics, data)
  857. if err != nil {
  858. return err
  859. }
  860. return nil
  861. }
  862. // SetPrimacyContact 项目设置首要联系人
  863. func (p *businessService) SetPrimacyContact(req *model.BusinessPrimacyContactReq) (err error) {
  864. business, err := p.Dao.Where(projDao.ProjBusiness.C.Id, req.Id).One()
  865. if err != nil {
  866. return err
  867. }
  868. if business == nil {
  869. return myerrors.TipsError("项目不存在。")
  870. }
  871. businessMap := g.Map{
  872. p.Dao.C.ContactId: req.ContactId,
  873. p.Dao.C.ContactName: req.ContactName,
  874. p.Dao.C.ContactPostion: req.ContactPostion,
  875. p.Dao.C.ContactTelephone: req.ContactTelephone,
  876. }
  877. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  878. opnContent := businessMap
  879. opnContent["origContactId"] = business.ContactId
  880. opnContent["origContactName"] = business.ContactName
  881. opnContent["origContactPostion"] = business.ContactPostion
  882. opnContent["origContactTelephone"] = business.ContactTelephone
  883. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  884. // 更新项目
  885. _, err = p.Dao.TX(tx).WherePri(projDao.ProjBusiness.C.Id, req.Id).Data(businessMap).Update()
  886. if err != nil {
  887. return err
  888. }
  889. // 添加项目动态
  890. dynamics := model.ProjBusinessDynamics{
  891. BusId: req.Id,
  892. OpnType: OpnPrimacyContact,
  893. Remark: req.Remark,
  894. }
  895. err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
  896. return err
  897. })
  898. return err
  899. }
  900. // UpdateBusinessStatus 更新项目状态
  901. func (p *businessService) UpdateBusinessStatus(req *model.UpdateBusinessStatusReq) error {
  902. business, err := p.Dao.WherePri(req.Id).One()
  903. if err != nil {
  904. return err
  905. }
  906. if business == nil {
  907. return myerrors.TipsError("项目不存在。")
  908. }
  909. businessMap := g.Map{
  910. p.Dao.C.NboStatus: req.NboStatus,
  911. p.Dao.C.Remark: req.Remark,
  912. }
  913. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  914. opnContent := businessMap
  915. opnContent["origNboStatus"] = business.NboStatus
  916. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  917. // 更新项目
  918. _, err = p.Dao.TX(tx).WherePri(projDao.ProjBusiness.C.Id, req.Id).Data(businessMap).Update()
  919. if err != nil {
  920. return err
  921. }
  922. // 添加项目动态
  923. dynamics := model.ProjBusinessDynamics{
  924. BusId: req.Id,
  925. OpnType: OpnStatus,
  926. Remark: req.Remark,
  927. }
  928. err = p.CreateProjBusinessDynamics(tx, dynamics, opnContent)
  929. return err
  930. })
  931. return err
  932. }
  933. // CreateProjBusinessDynamics 创建项目动态
  934. func (p *businessService) CreateProjBusinessDynamics(tx *gdb.TX, dynamics model.ProjBusinessDynamics, opnContent interface{}) error {
  935. if v, ok := opnContent.(g.Map); ok {
  936. opnContent = utils.MapKeySnakeCamelCase(v)
  937. }
  938. // 添加项目动态
  939. dynamics.OpnPeopleId = p.GetCxtUserId()
  940. dynamics.OpnPeople = p.GetCxtUserName()
  941. dynamics.OpnDate = gtime.Now()
  942. dynamics.OpnContent = gconv.String(opnContent)
  943. service.SetCreatedInfo(&dynamics, p.GetCxtUserId(), p.GetCxtUserName())
  944. dao := projDao.NewProjBusinessDynamicsDao(p.Tenant).M
  945. if tx != nil {
  946. dao = dao.TX(tx)
  947. }
  948. _, err := dao.Insert(&dynamics)
  949. return err
  950. }
  951. // ConvertToReserve 转为储备项目
  952. func (p *businessService) ConvertToReserve(req *model.BusinessToReserveReq) error {
  953. business, err := p.Dao.WherePri(req.Id).WhereNot(p.Dao.C.ApproStatus, ApprovalWaiting).One()
  954. if err != nil {
  955. return err
  956. }
  957. if business == nil {
  958. return myerrors.TipsError("项目已提交审批任务,无法重复提交。")
  959. }
  960. // 审批流
  961. workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
  962. err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  963. // 更新项目
  964. businessMap := g.Map{
  965. p.Dao.C.ApproStatus: ApprovalWaiting,
  966. p.Dao.C.ProjConversionTime: gtime.Now(),
  967. p.Dao.C.ProjConversionReason: req.ProjConversionReason,
  968. }
  969. service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
  970. _, err = p.Dao.TX(tx).WherePri(business.Id).Data(businessMap).Update()
  971. if err != nil {
  972. return err
  973. }
  974. // 添加项目动态
  975. dynamics := model.ProjBusinessDynamics{
  976. BusId: business.Id,
  977. OpnType: OpnToReserve,
  978. Remark: req.ProjConversionReason,
  979. }
  980. err = p.CreateProjBusinessDynamics(tx, dynamics, businessMap)
  981. if err != nil {
  982. return err
  983. }
  984. // OMS项目转储备 审批
  985. bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
  986. _, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectToReserve, "", &workflow.StartProcessInstanceRequest{
  987. ProcessCode: &ConvertToReserveRequestProcessCode,
  988. FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
  989. {
  990. Id: utils.String("TextField-K2AD4O5B"),
  991. Name: utils.String("项目编码"),
  992. Value: utils.String(business.NboCode),
  993. },
  994. {
  995. Id: utils.String("TextField_CMH6TBXYR5S0"),
  996. Name: utils.String("项目名称"),
  997. Value: utils.String(business.NboName),
  998. },
  999. {
  1000. Id: utils.String("TextField_YQBGGYHQPS00"),
  1001. Name: utils.String("客户名称"),
  1002. Value: utils.String(business.CustName),
  1003. },
  1004. {
  1005. Id: utils.String("TextField_57000M1HBVO0"),
  1006. Name: utils.String("项目级别"),
  1007. Value: utils.String(nboType[business.NboType]),
  1008. },
  1009. {
  1010. Id: utils.String("TextField_1NDD3TY8KJB40"),
  1011. Name: utils.String("销售工程师"),
  1012. Value: utils.String(business.SaleName),
  1013. },
  1014. {
  1015. Id: utils.String("TextareaField_15KZFM4YHQ8W0"),
  1016. Name: utils.String("转化原因"),
  1017. Value: utils.String(req.ProjConversionReason),
  1018. },
  1019. },
  1020. })
  1021. if err != nil {
  1022. g.Log().Error(err)
  1023. return err
  1024. }
  1025. return nil
  1026. })
  1027. return err
  1028. }
  1029. // ConvertToReserveNotify 转为储备项目 审批结果通知
  1030. func (p *businessService) ConvertToReserveNotify(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
  1031. business, err := p.checkDingTalkNotify(flow, msg)
  1032. if err != nil {
  1033. return err
  1034. }
  1035. var data = g.Map{}
  1036. if msg.ProcessType == "terminate" {
  1037. data[p.Dao.C.ApproStatus] = ApprovalReturn
  1038. }
  1039. if msg.ProcessType == "finish" && msg.Result != "refuse" {
  1040. data[p.Dao.C.ApproStatus] = ApprovalRejection
  1041. }
  1042. if msg.ProcessType == "finish" && msg.Result == "agree" {
  1043. data[p.Dao.C.NboType] = StatusReserve
  1044. data[p.Dao.C.ApproStatus] = ApprovalOK
  1045. }
  1046. // 项目修改
  1047. _, err = p.Dao.WherePri(business.Id).FieldsEx(service.UpdateFieldEx...).Data(data).Update()
  1048. if err != nil {
  1049. return err
  1050. }
  1051. // 添加项目动态
  1052. dynamics := model.ProjBusinessDynamics{
  1053. BusId: business.Id,
  1054. OpnType: OpnToReserveApproval,
  1055. }
  1056. err = p.CreateProjBusinessDynamics(nil, dynamics, data)
  1057. if err != nil {
  1058. return err
  1059. }
  1060. return err
  1061. }
  1062. // 钉钉审批通知检查
  1063. func (p *businessService) checkDingTalkNotify(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) (*model.ProjBusiness, error) {
  1064. bizCode := strings.Split(flow.BizCode, ":")
  1065. if len(bizCode) != 2 {
  1066. return nil, fmt.Errorf("项目转储备审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
  1067. }
  1068. nboCode := bizCode[0]
  1069. busId, err := strconv.Atoi(bizCode[1])
  1070. if err != nil {
  1071. return nil, fmt.Errorf("项目转储备审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
  1072. }
  1073. if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
  1074. return nil, fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
  1075. }
  1076. if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
  1077. return nil, fmt.Errorf("无法识别的 Result :%s", msg.Result)
  1078. }
  1079. fmt.Println(msg)
  1080. business, err := p.Dao.WherePri(busId).Where(p.Dao.C.NboCode, nboCode).One()
  1081. if err != nil {
  1082. return nil, err
  1083. }
  1084. if business == nil {
  1085. return nil, fmt.Errorf("项目不存在:%s Id: %d", flow.BizCode, flow.Id)
  1086. }
  1087. return business, nil
  1088. }