variety.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. package supply_analysis
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_manage/request"
  8. "eta/eta_api/models/data_manage/response"
  9. "eta/eta_api/models/data_manage/supply_analysis"
  10. "eta/eta_api/services/data"
  11. supply_analysisServ "eta/eta_api/services/data/supply_analysis"
  12. "eta/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // VarietyController 期货指标分类
  20. type VarietyController struct {
  21. controllers.BaseAuthController
  22. }
  23. // List
  24. // @Title 存量装置图表分类列表
  25. // @Description 存量装置图表分类列表接口
  26. // @Param IsAnalyse query bool true "是否有权限的,true、false"
  27. // @Param Keyword query string true "关键字搜索"
  28. // @Success 200 {object} response.VarietyListResp
  29. // @router /variety/list [get]
  30. func (this *VarietyController) List() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. isAnalyse, _ := this.GetBool("IsAnalyse")
  37. keyword := this.GetString("Keyword")
  38. pageSize, _ := this.GetInt("PageSize")
  39. currentIndex, _ := this.GetInt("CurrentIndex")
  40. var startSize int
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. startSize = utils.StartIndex(currentIndex, pageSize)
  48. var condition string
  49. var pars []interface{}
  50. if keyword != `` {
  51. condition += ` AND (a.variety_name like ? OR c.edb_code like ? ) `
  52. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  53. }
  54. // 是否超管
  55. isSuperAdmin := supply_analysisServ.IsVarietySuperAdmin(this.SysUser)
  56. varietyObj := supply_analysis.Variety{}
  57. var total int
  58. var list []*supply_analysis.VarietyItem
  59. var err error
  60. if isSuperAdmin || !isAnalyse {
  61. total, list, err = varietyObj.GetListBySuperAdminPage(condition, pars, startSize, pageSize)
  62. } else {
  63. if isAnalyse {
  64. condition += ` AND b.sys_user_id = ? `
  65. pars = append(pars, this.SysUser.AdminId)
  66. }
  67. total, list, err = varietyObj.GetListByPage(condition, pars, startSize, pageSize)
  68. }
  69. if err != nil && err.Error() != utils.ErrNoRow() {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  72. return
  73. }
  74. for k, v := range list {
  75. button := supply_analysis.VarietyButton{}
  76. if isSuperAdmin {
  77. button.Edit = true
  78. button.Delete = true
  79. button.Analyse = true
  80. } else {
  81. if v.PermissionUserId != `` {
  82. tmpUserIdStrList := strings.Split(v.PermissionUserId, ",")
  83. if utils.InArrayByStr(tmpUserIdStrList, strconv.Itoa(this.SysUser.AdminId)) {
  84. button.Analyse = true
  85. }
  86. }
  87. }
  88. v.Button = button
  89. list[k] = v
  90. }
  91. resp := response.VarietyListResp{
  92. AddButton: isSuperAdmin,
  93. Paging: paging.GetPaging(currentIndex, pageSize, total),
  94. List: list,
  95. }
  96. br.Ret = 200
  97. br.Success = true
  98. br.Msg = "获取成功"
  99. br.Data = resp
  100. }
  101. // Add
  102. // @Title 新增品种
  103. // @Description 新增品种接口
  104. // @Param request body request.AddVarietyReq true "type json string"
  105. // @Success 200 Ret=200 添加成功
  106. // @router /variety/add [post]
  107. func (this *VarietyController) Add() {
  108. br := new(models.BaseResponse).Init()
  109. defer func() {
  110. this.Data["json"] = br
  111. this.ServeJSON()
  112. }()
  113. var req request.AddVarietyReq
  114. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  115. if err != nil {
  116. br.Msg = "参数解析异常!"
  117. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  118. return
  119. }
  120. isSuperAdmin := supply_analysisServ.IsVarietySuperAdmin(this.SysUser)
  121. if !isSuperAdmin {
  122. br.Msg = "无操作权限"
  123. br.IsSendEmail = false
  124. return
  125. }
  126. if req.VarietyName == "" {
  127. br.Msg = "请输入品种名称"
  128. br.IsSendEmail = false
  129. return
  130. }
  131. varietyName := utils.TrimStr(req.VarietyName)
  132. item, err := supply_analysis.GetVarietyByName(varietyName)
  133. if err != nil && err.Error() != utils.ErrNoRow() {
  134. br.Msg = "添加失败"
  135. br.ErrMsg = "添加失败,Err:" + err.Error()
  136. return
  137. }
  138. if item != nil {
  139. br.Msg = "添加失败,品种名称不能重复"
  140. br.IsSendEmail = false
  141. return
  142. }
  143. variety := &supply_analysis.Variety{
  144. VarietyId: 0,
  145. VarietyName: varietyName,
  146. LastUpdateSysUserId: this.SysUser.AdminId,
  147. LastUpdateSysUserRealName: this.SysUser.RealName,
  148. ProductionDay: 365,
  149. SysUserId: this.SysUser.AdminId,
  150. SysUserRealName: this.SysUser.RealName,
  151. ModifyTime: time.Now(),
  152. CreateTime: time.Now(),
  153. }
  154. err = supply_analysis.CreateVariety(variety, req.AdminIdList)
  155. if err != nil {
  156. br.Msg = "添加品种失败"
  157. br.ErrMsg = "添加品种失败,Err:" + err.Error()
  158. return
  159. }
  160. br.Ret = 200
  161. br.Msg = "添加成功"
  162. br.IsAddLog = true
  163. br.Success = true
  164. }
  165. // Edit
  166. // @Title 编辑品种接口
  167. // @Description 编辑品种接口
  168. // @Param request body request.EditVarietyReq true "type json string"
  169. // @Success 200 Ret=200 修改成功
  170. // @router /variety/edit [post]
  171. func (this *VarietyController) Edit() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. var req request.EditVarietyReq
  178. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  179. if err != nil {
  180. br.Msg = "参数解析异常!"
  181. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  182. return
  183. }
  184. isSuperAdmin := supply_analysisServ.IsVarietySuperAdmin(this.SysUser)
  185. if !isSuperAdmin {
  186. br.Msg = "无操作权限"
  187. br.IsSendEmail = false
  188. return
  189. }
  190. if req.VarietyId <= 0 {
  191. br.Msg = "请选择品种"
  192. br.IsSendEmail = false
  193. return
  194. }
  195. if req.VarietyName == "" {
  196. br.Msg = "请输入品种名称"
  197. br.IsSendEmail = false
  198. return
  199. }
  200. varietyName := utils.TrimStr(req.VarietyName)
  201. item, err := supply_analysis.GetVarietyByName(varietyName)
  202. if err != nil && err.Error() != utils.ErrNoRow() {
  203. br.Msg = "添加失败"
  204. br.ErrMsg = "添加失败,Err:" + err.Error()
  205. return
  206. }
  207. if item != nil && item.VarietyId != req.VarietyId {
  208. br.Msg = "添加失败,品种名称不能重复"
  209. br.IsSendEmail = false
  210. return
  211. }
  212. // 获取品种详情
  213. varietyInfo, err := supply_analysis.GetVarietyById(req.VarietyId)
  214. if err != nil {
  215. br.Msg = "查询品种失败"
  216. br.ErrMsg = "查询品种失败;ERR:" + err.Error()
  217. return
  218. }
  219. // 编辑
  220. varietyInfo.VarietyName = varietyName
  221. varietyInfo.LastUpdateSysUserId = this.SysUser.AdminId
  222. varietyInfo.LastUpdateSysUserRealName = this.SysUser.RealName
  223. varietyInfo.ModifyTime = time.Now()
  224. err = supply_analysis.EditVariety(varietyInfo, req.AdminIdList)
  225. if err != nil {
  226. br.Msg = "修改品种失败"
  227. br.ErrMsg = "修改品种失败,Err:" + err.Error()
  228. return
  229. }
  230. br.Ret = 200
  231. br.Msg = "修改成功"
  232. br.IsAddLog = true
  233. br.Success = true
  234. }
  235. // DeleteCheck
  236. // @Title 删除品种检测接口
  237. // @Description 删除品种检测接口
  238. // @Param request body request.DelVarietyReq true "type json string"
  239. // @Success 200 Ret=200 检测成功
  240. // @router /variety/delete/check [post]
  241. func (this *VarietyController) DeleteCheck() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. var req request.DelVarietyReq
  248. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  249. if err != nil {
  250. br.Msg = "参数解析异常!"
  251. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  252. return
  253. }
  254. if req.VarietyId <= 0 {
  255. br.Msg = "请选择品种"
  256. br.IsSendEmail = false
  257. return
  258. }
  259. var deleteStatus int
  260. var tipsMsg string
  261. //判断该品种是否生成指标
  262. count, err := supply_analysis.GetCountVarietyEdbInfoByVarietyId(req.VarietyId)
  263. if err != nil {
  264. br.Msg = "删除失败"
  265. br.ErrMsg = "查询品种下是否含有指标失败,Err:" + err.Error()
  266. return
  267. }
  268. // 是否超管
  269. isSuperAdmin := supply_analysisServ.IsVarietySuperAdmin(this.SysUser)
  270. if !isSuperAdmin {
  271. deleteStatus = 1
  272. tipsMsg = "无删除权限"
  273. } else {
  274. if count > 0 {
  275. deleteStatus = 1
  276. tipsMsg = "该品种已在指标库生成指标,不可删除"
  277. }
  278. }
  279. resp := response.VarietyDeleteCheckResp{
  280. DeleteStatus: deleteStatus,
  281. TipsMsg: tipsMsg,
  282. }
  283. br.Ret = 200
  284. br.Msg = "检测成功"
  285. br.Success = true
  286. br.Data = resp
  287. }
  288. // Delete
  289. // @Title 删除存量装置图表分类/图表
  290. // @Description 删除存量装置图表分类/图表接口
  291. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  292. // @Success 200 Ret=200 删除成功
  293. // @router /variety/delete [post]
  294. func (this *VarietyController) Delete() {
  295. br := new(models.BaseResponse).Init()
  296. defer func() {
  297. this.Data["json"] = br
  298. this.ServeJSON()
  299. }()
  300. var req request.DelVarietyReq
  301. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  302. if err != nil {
  303. br.Msg = "参数解析异常!"
  304. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  305. return
  306. }
  307. if req.VarietyId <= 0 {
  308. br.Msg = "请选择品种"
  309. br.IsSendEmail = false
  310. return
  311. }
  312. //判断该品种是否生成指标
  313. count, err := supply_analysis.GetCountVarietyEdbInfoByVarietyId(req.VarietyId)
  314. if err != nil {
  315. br.Msg = "删除失败"
  316. br.ErrMsg = "查询品种下是否含有指标失败,Err:" + err.Error()
  317. return
  318. }
  319. // 是否超管
  320. isSuperAdmin := supply_analysisServ.IsVarietySuperAdmin(this.SysUser)
  321. if !isSuperAdmin {
  322. br.Msg = `无删除权限`
  323. br.IsSendEmail = false
  324. return
  325. }
  326. if count > 0 {
  327. br.Msg = `该品种已在指标库生成指标,不可删除`
  328. br.IsSendEmail = false
  329. return
  330. }
  331. varietyInfo, err := supply_analysis.GetVarietyById(req.VarietyId)
  332. if err != nil {
  333. if err.Error() == utils.ErrNoRow() {
  334. br.Msg = "该品种不存在或已删除"
  335. br.IsSendEmail = false
  336. } else {
  337. br.Msg = "删除失败"
  338. br.ErrMsg = "查找品种失败,ERR:" + err.Error()
  339. }
  340. return
  341. }
  342. err = varietyInfo.Delete()
  343. if err != nil {
  344. br.Msg = "删除失败"
  345. br.ErrMsg = "查找品种失败,ERR:" + err.Error()
  346. return
  347. }
  348. br.Ret = 200
  349. br.Msg = "删除成功"
  350. br.Success = true
  351. br.IsAddLog = true
  352. }
  353. // Detail
  354. // @Title 存量装置图表分类列表
  355. // @Description 存量装置图表分类列表接口
  356. // @Param VarietyId query int true "品种id"
  357. // @Success 200 {object} response.VarietyListResp
  358. // @router /variety/detail [get]
  359. func (this *VarietyController) Detail() {
  360. br := new(models.BaseResponse).Init()
  361. defer func() {
  362. this.Data["json"] = br
  363. this.ServeJSON()
  364. }()
  365. varietyId, _ := this.GetInt("VarietyId")
  366. if varietyId < 0 {
  367. br.Msg = "不存在该品种或该品种已被删除"
  368. br.ErrMsg = "不存在该品种或该品种已被删除"
  369. br.IsSendEmail = false
  370. }
  371. // 获取品种详情
  372. varietyInfo, err := supply_analysis.GetVarietyById(varietyId)
  373. if err != nil {
  374. br.Msg = "查询品种失败"
  375. br.ErrMsg = "查询品种失败;ERR:" + err.Error()
  376. if err.Error() != utils.ErrNoRow() {
  377. br.Msg = "不存在该品种或该品种已被删除"
  378. br.ErrMsg = "不存在该品种或该品种已被删除"
  379. br.IsSendEmail = false
  380. }
  381. return
  382. }
  383. if varietyInfo == nil {
  384. br.Msg = "不存在该品种或该品种已被删除"
  385. br.ErrMsg = "不存在该品种或该品种已被删除"
  386. br.IsSendEmail = false
  387. return
  388. }
  389. resp := supply_analysis.VarietyItem{
  390. VarietyId: varietyInfo.VarietyId,
  391. VarietyName: varietyInfo.VarietyName,
  392. ProductionDay: varietyInfo.ProductionDay,
  393. LastUpdateSysUserId: varietyInfo.LastUpdateSysUserId,
  394. LastUpdateSysUserRealName: varietyInfo.LastUpdateSysUserRealName,
  395. PermissionUserId: ``,
  396. ModifyTime: varietyInfo.ModifyTime.Format(utils.FormatDateTime),
  397. CreateTime: varietyInfo.CreateTime.Format(utils.FormatDateTime),
  398. //Button: supply_analysis.VarietyButton{},
  399. }
  400. br.Ret = 200
  401. br.Success = true
  402. br.Msg = "获取成功"
  403. br.Data = resp
  404. }
  405. // Analysis
  406. // @Title 品种分析
  407. // @Description 品种分析接口
  408. // @Param request body request.AnalysisReq true "type json string"
  409. // @Success 200 Ret=200 检测成功
  410. // @router /variety/analysis [post]
  411. func (this *VarietyController) Analysis() {
  412. br := new(models.BaseResponse).Init()
  413. defer func() {
  414. this.Data["json"] = br
  415. this.ServeJSON()
  416. }()
  417. var req request.AnalysisReq
  418. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  419. if err != nil {
  420. br.Msg = "参数解析异常!"
  421. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  422. return
  423. }
  424. if req.VarietyId <= 0 {
  425. br.Msg = "请选择品种"
  426. br.IsSendEmail = false
  427. return
  428. }
  429. //加入缓存机制,避免创建同一时间,多人去分析 start
  430. redisKey := fmt.Sprint("supply_analysis:variety:", req.VarietyId)
  431. isExist := utils.Rc.IsExist(redisKey)
  432. if isExist {
  433. br.Msg = "品种正在分析中,请等待"
  434. br.IsSendEmail = false
  435. return
  436. } else {
  437. //设置3分钟缓存
  438. utils.Rc.SetNX(redisKey, 1, time.Second*300)
  439. defer func() {
  440. utils.Rc.Delete(redisKey)
  441. }()
  442. }
  443. //加入缓存机制,避免创建同一时间,多人去分析 end
  444. // 获取品种详情
  445. varietyInfo, err := supply_analysis.GetVarietyById(req.VarietyId)
  446. if err != nil {
  447. br.Msg = "查询品种失败"
  448. br.ErrMsg = "查询品种失败;ERR:" + err.Error()
  449. return
  450. }
  451. //判断该品种是否生成指标
  452. list, err := supply_analysis.GetVarietyEdbListByVarietyId(req.VarietyId)
  453. if err != nil {
  454. br.Msg = "分析失败"
  455. br.ErrMsg = "分析失败,Err:" + err.Error()
  456. return
  457. }
  458. // 如果没有生成过指标,那么就先生成指标
  459. if len(list) <= 0 {
  460. //randStr := utils.GetRandDigit(4)
  461. //prefixCode := "HZ_V"
  462. //suffixCode := time.Now().Format("060102") + randStr
  463. //`source` int(9) DEFAULT NULL COMMENT '来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动',
  464. list := []*supply_analysis.VarietyEdbInfo{
  465. {
  466. //VarietyEdbId: 0,
  467. VarietyId: req.VarietyId,
  468. EdbName: varietyInfo.VarietyName + "影响周度产量",
  469. Frequency: "日度",
  470. EdbInfoId: 0,
  471. //EdbCode: fmt.Sprint(prefixCode, 1, suffixCode),
  472. Source: 1,
  473. ModifyTime: time.Now(),
  474. CreateTime: time.Now(),
  475. },
  476. {
  477. //VarietyEdbId: 0,
  478. VarietyId: req.VarietyId,
  479. EdbName: varietyInfo.VarietyName + "周度产量变动",
  480. Frequency: "日度",
  481. EdbInfoId: 0,
  482. //EdbCode: fmt.Sprint(prefixCode, 2, suffixCode),
  483. Source: 2,
  484. ModifyTime: time.Now(),
  485. CreateTime: time.Now(),
  486. },
  487. {
  488. //VarietyEdbId: 0,
  489. VarietyId: req.VarietyId,
  490. EdbName: varietyInfo.VarietyName + "影响月度产量",
  491. Frequency: "月度",
  492. EdbInfoId: 0,
  493. //EdbCode: fmt.Sprint(prefixCode, 3, suffixCode),
  494. Source: 3,
  495. ModifyTime: time.Now(),
  496. CreateTime: time.Now(),
  497. },
  498. {
  499. //VarietyEdbId: 0,
  500. VarietyId: req.VarietyId,
  501. EdbName: varietyInfo.VarietyName + "月度产量变动",
  502. Frequency: "月度",
  503. EdbInfoId: 0,
  504. //EdbCode: fmt.Sprint(prefixCode, 4, suffixCode),
  505. Source: 4,
  506. ModifyTime: time.Now(),
  507. CreateTime: time.Now(),
  508. },
  509. }
  510. err = supply_analysis.BatchCreateVarietyEdbInfo(list)
  511. if err != nil {
  512. br.Msg = `分析失败`
  513. br.ErrMsg = `分析失败,生成指标失败,ERR:` + err.Error()
  514. return
  515. }
  516. }
  517. tmpMap := map[string]interface{}{
  518. "VarietyId": req.VarietyId,
  519. "AdminId": this.SysUser.AdminId,
  520. "AdminName": this.SysUser.RealName,
  521. }
  522. reqJson, err := json.Marshal(tmpMap)
  523. // 开始分析
  524. _, err = supply_analysisServ.Calculate(string(reqJson))
  525. if err != nil {
  526. br.Msg = `分析失败`
  527. br.ErrMsg = `分析失败,ERR:` + err.Error()
  528. return
  529. }
  530. // 更新ETA指标库信息
  531. {
  532. if len(list) > 0 {
  533. for _, v := range list {
  534. if v.EdbInfoId > 0 {
  535. edbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
  536. if err != nil {
  537. continue
  538. }
  539. // 刷新指标数据
  540. go data.RefreshEdbData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.EdbCode, edbInfo.StartDate)
  541. }
  542. }
  543. }
  544. }
  545. // 变更品种的更新时间
  546. {
  547. varietyInfo.ModifyTime = time.Now()
  548. varietyInfo.LastUpdateSysUserId = this.SysUser.AdminId
  549. varietyInfo.LastUpdateSysUserRealName = this.SysUser.RealName
  550. go varietyInfo.Update([]string{"ModifyTime", "LastUpdateSysUserId", "LastUpdateSysUserRealName"})
  551. }
  552. br.Ret = 200
  553. br.Msg = "分析成功"
  554. br.Success = true
  555. }
  556. // ModifyProductionDay
  557. // @Title 编辑品种的生产天数接口
  558. // @Description 编辑品种的生产天数接口
  559. // @Param request body request.ModifyProductionDayReq true "type json string"
  560. // @Success 200 Ret=200 修改成功
  561. // @router /variety/production_day/modify [post]
  562. func (this *VarietyController) ModifyProductionDay() {
  563. br := new(models.BaseResponse).Init()
  564. defer func() {
  565. this.Data["json"] = br
  566. this.ServeJSON()
  567. }()
  568. var req request.ModifyProductionDayReq
  569. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  570. if err != nil {
  571. br.Msg = "参数解析异常!"
  572. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  573. return
  574. }
  575. var hasPermission bool //是否有操作权限
  576. // 是否有装置的操作权限
  577. hasPermission, err = supply_analysisServ.HasVarietyPlantPermission(this.SysUser, req.VarietyId)
  578. if err != nil && err.Error() != utils.ErrNoRow() {
  579. br.Msg = "获取失败"
  580. br.ErrMsg = "查询是否有装置的操作权限失败;ERR:" + err.Error()
  581. return
  582. }
  583. if !hasPermission {
  584. br.Msg = "无操作权限"
  585. br.ErrMsg = "无操作权限"
  586. return
  587. }
  588. if req.VarietyId <= 0 {
  589. br.Msg = "请选择品种"
  590. br.IsSendEmail = false
  591. return
  592. }
  593. if req.Day <= 0 {
  594. br.Msg = "生产天数不能小于等于0"
  595. br.IsSendEmail = false
  596. return
  597. }
  598. // 获取品种详情
  599. varietyInfo, err := supply_analysis.GetVarietyById(req.VarietyId)
  600. if err != nil {
  601. br.Msg = "查询品种失败"
  602. br.ErrMsg = "查询品种失败;ERR:" + err.Error()
  603. return
  604. }
  605. // 编辑
  606. varietyInfo.ProductionDay = req.Day
  607. varietyInfo.LastUpdateSysUserId = this.SysUser.AdminId
  608. varietyInfo.LastUpdateSysUserRealName = this.SysUser.RealName
  609. varietyInfo.ModifyTime = time.Now()
  610. err = varietyInfo.Update([]string{"ProductionDay", "LastUpdateSysUserId", "LastUpdateSysUserRealName", "ModifyTime"})
  611. if err != nil {
  612. br.Msg = "修改生产天数失败"
  613. br.ErrMsg = "修改生产天数失败,Err:" + err.Error()
  614. return
  615. }
  616. br.Ret = 200
  617. br.Msg = "修改成功"
  618. br.IsAddLog = true
  619. br.Success = true
  620. }