spillage.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. package api
  2. import (
  3. "io/ioutil"
  4. "log"
  5. "net/http"
  6. "time"
  7. "../../pkg/app"
  8. "../../pkg/e"
  9. "../../pkg/logging"
  10. "../../pkg/setting"
  11. "../../routers/restful"
  12. "github.com/Anderson-Lu/gofasion/gofasion"
  13. "github.com/gin-gonic/gin"
  14. "github.com/xormplus/xorm"
  15. )
  16. type feedtemplet struct {
  17. Id int64 `xorm:"id"`
  18. Ccname string `xorm:"ccname"`
  19. Cname string `xorm:"tname"`
  20. }
  21. type tmrStruct struct {
  22. Id int64 `xorm:"id"`
  23. Tname string `xorm:"tname"`
  24. Maxstirfeed float64 `xorm:"maxstirfeed"`
  25. }
  26. type lpplanStruct struct {
  27. Id int64 `xorm:"id"`
  28. Tmrname string `xorm:"tmrname"`
  29. Tmrid int64 `xorm:"tmrid"`
  30. Sort int64 `xorm:"sort"`
  31. Sel int64 `xorm:"sel"`
  32. Times int64 `xorm:"times"`
  33. Ftname string `xorm:"ftname"`
  34. Ftid int64 `xorm:"ftid"`
  35. Maxweight float64 `xorm:"maxweight"`
  36. Sumweight float64 `xorm:"sumweight"`
  37. Sumcowcount int64 `xorm:"sumcowcount"`
  38. Pastureid string `xorm:"pastureid"`
  39. }
  40. type sysopt struct {
  41. Inforvalue int `xorm:"inforvalue"`
  42. }
  43. type lpplanQueryInfo struct {
  44. Pastureid int64 `xorm:"pastureid"`
  45. Lppid int64 `xorm:"id"`
  46. Maxweight float64 `xorm:"maxweight"`
  47. Lweight float64 `xorm:"lweight"`
  48. Lweighthis float64 `xorm:"lweighthis"`
  49. Barid int64 `xorm:"barid"`
  50. Barname string `xorm:"barname"`
  51. Sort int64 `xorm:"sort"`
  52. Tmrid int64 `xorm:"tmrid"`
  53. Tmrname string `xorm:"tmrname"`
  54. Cowcount int64 `xorm:"cowcount"`
  55. Ccountradio float64 `xorm:"ccountradio"`
  56. Background string `xorm:"background"`
  57. Times int64 `xorm:"times"`
  58. Ftid int64 `xorm:"ftid"`
  59. }
  60. type fpdetailQueryInfo struct {
  61. Fpdid int64 `xorm:"fpdid"`
  62. Ptsrate float64 `xorm:"ptsrate"`
  63. Ptsuse float64 `xorm:"ptsuse"`
  64. Ptuse float64 `xorm:"ptuse"`
  65. Weight float64 `xorm:"weight"`
  66. Barid int64 `xorm:"barid"`
  67. Barname string `xorm:"barname"`
  68. Cowcount int64 `xorm:"cowcount"`
  69. Ccountradio float64 `xorm:"ccountradio"`
  70. Fttypeid int64 `xorm:"fttypeid"`
  71. }
  72. type lpplandtl1 struct {
  73. Pastureid int64 `xorm:"pastureid"`
  74. Lppid int64 `xorm:"lppid"`
  75. Barid int64 `xorm:"barid"`
  76. Barname string `xorm:"barname"`
  77. Fpdid int64 `xorm:"fpdid"`
  78. Fttype int64 `xorm:"fttype"`
  79. Lweight float64 `xorm:"lweight"`
  80. Sort int64 `xorm:"sort"`
  81. Tmrid int64 `xorm:"tmrid"`
  82. Tmrname string `xorm:"tmrname"`
  83. Cowcount int64 `xorm:"cowcount"`
  84. Ccountradio float64 `xorm:"ccountradio"`
  85. Background string `xorm:"background"`
  86. Lweighthis float64 `xorm:"lweighthis"`
  87. }
  88. //撒料计划 自动生成
  89. func Autogeneration(c *gin.Context) {
  90. appG := app.Gin{C: c}
  91. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  92. fsion := gofasion.NewFasion(string(dataByte))
  93. pastureid := fsion.Get("pastureid").ValueStr()
  94. typeIN := fsion.Get("type").ValueInt64()
  95. tx := restful.Engine.NewSession()
  96. feedtempletlist, err := getfeedtemplet(pastureid, tx)
  97. if err != nil {
  98. appG.Response(http.StatusOK, e.ERROR, false)
  99. return
  100. }
  101. tmrlist, err := gettmr(pastureid, tx)
  102. if err != nil {
  103. appG.Response(http.StatusOK, e.ERROR, false)
  104. return
  105. }
  106. times, err := gettimes(pastureid, tx)
  107. if err != nil {
  108. appG.Response(http.StatusOK, e.ERROR, false)
  109. return
  110. }
  111. lpplanlist, err := getLpplanlist(pastureid, tx)
  112. if err != nil {
  113. appG.Response(http.StatusOK, e.ERROR, false)
  114. return
  115. }
  116. fpdetailWeightList, err := getFpdetail(pastureid, tx)
  117. if err != nil {
  118. appG.Response(http.StatusOK, e.ERROR, false)
  119. return
  120. }
  121. for _, tem := range feedtempletlist {
  122. count, err := getLpplanCount(tx)
  123. if err != nil {
  124. appG.Response(http.StatusOK, e.ERROR, false)
  125. return
  126. }
  127. for _, tmr := range tmrlist {
  128. for i := 1; i <= times; i++ {
  129. exist := false
  130. var lppLweight, maxweight float64
  131. for _, lpp := range lpplanlist {
  132. if lpp.Tmrid == tmr.Id && lpp.Times == int64(i) && lpp.Ftid == tem.Id {
  133. exist = true
  134. lppLweight += lpp.Lweight
  135. maxweight += lpp.Maxweight
  136. }
  137. }
  138. lppLweight = maxweight - lppLweight
  139. for _, fpd := range fpdetailWeightList {
  140. if (tem.Id == fpd.Ptid || tem.Id == fpd.Ptsid) && i == int(fpd.Times) {
  141. var ftid int64
  142. if fpd.Ptid != 0 {
  143. ftid = fpd.Ptid
  144. } else {
  145. ftid = fpd.Ptsid
  146. }
  147. if tmr.Maxstirfeed <= 0 {
  148. if !exist {
  149. count++
  150. ids, err := setting.SnowIds.NextId()
  151. if err != nil {
  152. ids = time.Now().UnixNano()
  153. logging.Info("create SnowIds err", err)
  154. }
  155. lpplan := &lpplanStruct{
  156. Id: ids,
  157. Tmrname: tmr.Tname,
  158. Tmrid: tmr.Id,
  159. Sort: count,
  160. Sel: 1,
  161. Times: int64(i),
  162. Ftname: tem.Cname,
  163. Ftid: ftid,
  164. Maxweight: tmr.Maxstirfeed,
  165. Sumweight: 0,
  166. Sumcowcount: 0,
  167. Pastureid: pastureid,
  168. }
  169. err = addLpplan(lpplan, tx)
  170. if err != nil {
  171. appG.Response(http.StatusOK, e.ERROR, false)
  172. return
  173. }
  174. }
  175. } else {
  176. var weight float64
  177. weight = fpd.Weight - lppLweight
  178. for weight > 0 {
  179. count++
  180. ids, err := setting.SnowIds.NextId()
  181. if err != nil {
  182. ids = time.Now().UnixNano()
  183. logging.Info("create SnowIds err", err)
  184. }
  185. lpplan := &lpplanStruct{
  186. Id: ids,
  187. Tmrname: tmr.Tname,
  188. Tmrid: tmr.Id,
  189. Sort: count,
  190. Sel: 1,
  191. Times: int64(i),
  192. Ftname: tem.Cname,
  193. Ftid: ftid,
  194. Maxweight: tmr.Maxstirfeed,
  195. Sumweight: 0,
  196. Sumcowcount: 0,
  197. Pastureid: pastureid,
  198. }
  199. err = addLpplan(lpplan, tx)
  200. if err != nil {
  201. appG.Response(http.StatusOK, e.ERROR, false)
  202. return
  203. }
  204. weight = weight - tmr.Maxstirfeed
  205. }
  206. }
  207. break
  208. }
  209. // }
  210. }
  211. }
  212. }
  213. // }(tem)
  214. }
  215. // go func(typeIN int64, pastureid string, tx *xorm.Session) {
  216. err = autogeneration(typeIN, pastureid, tx)
  217. if err != nil {
  218. appG.Response(http.StatusOK, e.ERROR, false)
  219. return
  220. }
  221. // }(typeIN, pastureid, tx)
  222. appG.Response(http.StatusOK, e.SUCCESS, true)
  223. }
  224. //查看配方模板
  225. func getfeedtemplet(pastureid string, tx *xorm.Session) ([]*feedtemplet, error) {
  226. data := make([]*feedtemplet, 0)
  227. err := tx.Table("feedtemplet").Select("id,ccname,tname").Where("pastureid = ? ", pastureid).Find(&data)
  228. if err != nil {
  229. log.Println("getfeedtemplet-error", err)
  230. return nil, err
  231. }
  232. return data, nil
  233. }
  234. //查看tmr设备
  235. func gettmr(pastureid string, tx *xorm.Session) ([]*tmrStruct, error) {
  236. data := make([]*tmrStruct, 0)
  237. session := tx.Table("tmr")
  238. session.Select("TRIM(id) id,tname,maxstirfeed")
  239. session.Where("pastureid = ? ", pastureid)
  240. session.Where("enable = 1")
  241. session.In("tclassid", "1,2,3")
  242. err := session.Find(&data)
  243. if err != nil {
  244. log.Println("gettmr-error", err)
  245. return nil, err
  246. }
  247. return data, nil
  248. }
  249. //判断计划种是否有该车次
  250. func getLpplanExist(tmrid, ftid int64, times int, pastureid string, tx *xorm.Session) (bool, error) {
  251. session := tx.Table("lpplan")
  252. session.Where("pastureid = ? ", pastureid)
  253. session.Where("times = ? ", times)
  254. session.Where("tmrid = ? ", tmrid)
  255. session.Where("ftid = ? ", ftid)
  256. exist, err := session.Exist()
  257. if err != nil {
  258. log.Println("getLpplanExist-error", err)
  259. return false, err
  260. }
  261. return exist, nil
  262. }
  263. type fpdetailWeight struct {
  264. Times int64 `xorm:"times"`
  265. Weight float64 `xorm:"weight"`
  266. Pastureid int64 `xorm:"pastureid"`
  267. Ptid int64 `xorm:"ptid"`
  268. Ptsid int64 `xorm:"ptsid"`
  269. Cowcount int64 `xorm:"cowcount"`
  270. }
  271. //获取料数量
  272. func getFpdetail(pastureid string, tx *xorm.Session) ([]*fpdetailWeight, error) {
  273. fpdetaillist := make([]*fpdetailWeight, 0)
  274. err := tx.SQL(`SELECT times,sum(ROUND(ptsrate*weight,2)-ptsuse) weight,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
  275. cowcount FROM fpdetail
  276. WHERE fpdetail.pastureid = ? AND ptsuse< ROUND(ptsrate*weight,2) and ptsid !=0
  277. group by ptid,times,ptsid
  278. UNION
  279. SELECT times,sum(ROUND((1-ptsrate)*weight,2)-ptuse)weight,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,cowcount FROM fpdetail
  280. WHERE fpdetail.pastureid = ? AND ptuse<ROUND((1-ptsrate)*weight,2) and ptid !=0
  281. group by ptid,times,ptsid
  282. `, pastureid, pastureid).Find(&fpdetaillist)
  283. if err != nil {
  284. log.Println("getFpdetail-error", err)
  285. tx.Rollback()
  286. return nil, err
  287. }
  288. return fpdetaillist, nil
  289. }
  290. type lpplanList struct {
  291. Tmrid int64 `xorm:"tmrid"`
  292. Times int64 `xorm:"times"`
  293. Ftid int64 `xorm:"ftid"`
  294. Maxweight float64 `xorm:"maxweight"`
  295. Lweight float64 `xorm:"lweight"`
  296. }
  297. func getLpplanlist(patsureid string, tx *xorm.Session) ([]*lpplanList, error) {
  298. session := tx.SQL(` select t1.times,t1.tmrid,t1.ftid,t1.maxweight ,ifnull(t2.lweight,0)as lweight from lpplan t1
  299. left join ( select ifnull(sum(lweight),0) as lweight,lppid from lpplandtl1 where pastureid =? GROUP BY lppid) t2 on t1.id = t2.lppid
  300. where t1.pastureid = ? `, patsureid, patsureid)
  301. data := make([]*lpplanList, 0)
  302. err := session.Find(&data)
  303. if err != nil {
  304. log.Println("getLpplanlist-error", err)
  305. return nil, err
  306. }
  307. return data, nil
  308. }
  309. // 添加车次计划
  310. func addLpplan(lpplan *lpplanStruct, tx *xorm.Session) error {
  311. _, err := tx.Table("lpplan").Insert(lpplan)
  312. if err != nil {
  313. log.Println("addLpplan-error", err)
  314. return err
  315. }
  316. return nil
  317. }
  318. //获取车次数量
  319. func getLpplanCount(tx *xorm.Session) (int64, error) {
  320. count, err := tx.Table("lpplan").Count()
  321. if err != nil {
  322. log.Println("getLpplanCount-error", err)
  323. return 0, err
  324. }
  325. return count, err
  326. }
  327. //获取班次信息
  328. func gettimes(pastureid string, tx *xorm.Session) (int, error) {
  329. session := tx.Table("sysopt")
  330. session.Where("pastureid = ? ", pastureid)
  331. session.Where("inforname = 'times' ")
  332. data := new(sysopt)
  333. _, err := session.Get(data)
  334. if err != nil {
  335. log.Println("gettimes-error", err)
  336. return 0, err
  337. }
  338. return data.Inforvalue, nil
  339. }
  340. func autogeneration(typeIN int64, pastureid string, tx *xorm.Session) error {
  341. tx.Begin()
  342. if typeIN == 1 {
  343. _, err := tx.SQL(`DELETE FROM lpplandtl1 WHERE pastureid = ?`, pastureid).Execute()
  344. if err != nil {
  345. log.Println("autogeneration-error-1", err)
  346. tx.Rollback()
  347. return err
  348. }
  349. _, err = tx.SQL(`update fpdetail
  350. set ptuse = 0,ptsuse=0
  351. WHERE pastureid = ?`, pastureid).Execute()
  352. if err != nil {
  353. log.Println("autogeneration-error-2", err)
  354. tx.Rollback()
  355. return err
  356. }
  357. }
  358. lpplansession := tx.SQL(`select
  359. t1.sort,t1.tmrid,t1.tmrname,t1.ftid,
  360. t1.pastureid,t1.id ,t1.maxweight,ifnull(t2.lweight,0) as lweight,t1.times from lpplan t1
  361. left join ( select ifnull(sum(lweight),0) as lweight,lppid from lpplandtl1 where pastureid =? GROUP BY lppid) t2 on t1.id = t2.lppid
  362. where t1.pastureid = ? and t1.maxweight > ifnull(t2.lweight,0) `, pastureid, pastureid)
  363. lpplanlist := make([]*lpplanQueryInfo, 0)
  364. err := lpplansession.Find(&lpplanlist)
  365. if err != nil {
  366. log.Println("autogeneration-error-3", err)
  367. tx.Rollback()
  368. return err
  369. }
  370. for _, lpplan := range lpplanlist {
  371. // fpdetailsession := tx.Table("fpdetail").Alias("fpd")
  372. // fpdetailsession.Select("fpd.barid,fpd.barname,fpd.id as fpdid ,fpd.weight as weight,ifnull(fpd.ptuse,0) as ptuse,ifnull(fpd.ptsuse,0) as ptsuse,fpd.barid,fpd.barname,fpd.cowcount,fpd.ccountradio,fpd.ptsrate as ptsrate")
  373. // fpdetailsession.Where(" fpd.ptid = ? ", lpplan.Ftid)
  374. // fpdetailsession.Where(" fpd.times = ? ", lpplan.Times)
  375. // fpdetailsession.Where("fpd.pastureid = ? ", pastureid)
  376. // fpdetailsession.GroupBy("fpd.id")
  377. fpdetaillist := make([]*fpdetailQueryInfo, 0)
  378. err = tx.SQL(`SELECT 0 as fttypeid,fpd.cowcount,fpd.ccountradio,fpd.id as fpdid,fpd.times,fpd.tratio,ROUND(fpd.ptsrate*fpd.weight,2)-fpd.ptsuse weight,
  379. TRIM(fpd.barid) barid,TRIM(fpd.pastureid) pastureid,TRIM(fpd.ptid) ptid,TRIM(fpd.ptsid ) ptsid ,
  380. (select bname from bar where pastureid =fpd.pastureid and id = fpd.barid ) barname,
  381. cowcount,ccountradio,1 isfill FROM fpdetail fpd
  382. join feedp fp on fp.ptsfid = fpd.ptsid and fp.pastureid = fpd.pastureid
  383. inner join feedtemplet ft on ft.id = fp.ftid and ft.pastureid = fpd.pastureid
  384. WHERE fpd.pastureid = ? AND ptuse<ROUND((1-fpd.ptsrate)*fpd.weight,2) and fpd.ptsid = ?
  385. and fpd.times = ?
  386. UNION
  387. SELECT ft.fttypeid,fpd.cowcount,fpd.ccountradio,fpd.id as fpdid,times,tratio,ROUND((1-fpd.ptsrate)*fpd.weight,2)-fpd.ptuse weight,TRIM(fpd.barid) barid,TRIM(fpd.pastureid) pastureid,TRIM(fpd.ptid) ptid,TRIM(fpd.ptsid ) ptsid ,
  388. (select bname from bar where pastureid =fpd.pastureid and id = fpd.barid ) barname,cowcount,ccountradio,0 isfill FROM fpdetail fpd
  389. join feedp fp on fp.ftid = fpd.ptid and fp.pastureid = fpd.pastureid
  390. inner join feedtemplet ft on ft.id = fp.ftid and ft.pastureid = fpd.pastureid
  391. WHERE fpd.pastureid = ? AND ptuse<ROUND((1-fpd.ptsrate)*fpd.weight,2) and fpd.ptid = ?
  392. and fpd.times = ?`, pastureid, lpplan.Ftid, lpplan.Times, pastureid, lpplan.Ftid, lpplan.Times).Find(&fpdetaillist)
  393. // err = fpdetailsession
  394. if err != nil {
  395. log.Println("autogeneration-error-4", err)
  396. tx.Rollback()
  397. return err
  398. }
  399. for _, fpdetail := range fpdetaillist {
  400. // //剩余料
  401. var weight float64
  402. weight = fpdetail.Weight
  403. if lpplan.Maxweight <= lpplan.Lweight || weight < 0 {
  404. continue
  405. }
  406. var insertlweight float64
  407. if lpplan.Maxweight-lpplan.Lweight > weight {
  408. insertlweight = weight
  409. } else {
  410. insertlweight = lpplan.Maxweight - lpplan.Lweight
  411. }
  412. lpplan.Lweight += insertlweight
  413. lpplan.Lweighthis = insertlweight
  414. // fpdetail.Ptsuse += insertlweight
  415. _, err = tx.SQL(` UPDATE fpdetail SET ptuse=IF(?=1,IF(ptuse+? <0,0,ptuse+?),ptuse),ptsuse=IF(?=0,IF(ptsuse+?<0,0,ptsuse+?),ptsuse)
  416. WHERE pastureid=? AND id=? `, fpdetail.Fttypeid, fpdetail.Weight, fpdetail.Weight, fpdetail.Fttypeid, fpdetail.Weight, fpdetail.Weight, pastureid, fpdetail.Fpdid).Execute()
  417. if err != nil {
  418. log.Println("autogeneration-error-5", err)
  419. tx.Rollback()
  420. return err
  421. }
  422. fpdetail.Weight = fpdetail.Weight - insertlweight
  423. lpplandtlExecute, err := tx.SQL(`select id from lpplandtl1 where pastureid= ?
  424. and lppid = ? and fpdid =? and fttype = ? `, pastureid, lpplan.Lppid, fpdetail.Fpdid, fpdetail.Fttypeid).Exist()
  425. if err != nil {
  426. log.Println("autogeneration-error-6", err)
  427. tx.Rollback()
  428. return err
  429. }
  430. if lpplandtlExecute {
  431. lpplandtl1query := new(lpplandtl1)
  432. query := tx.Table("lpplandtl1")
  433. query.Where("pastureid = ?", pastureid)
  434. query.Where("lppid = ?", lpplan.Lppid)
  435. query.Where("fpdid = ?", fpdetail.Fpdid)
  436. query.Where("fttype = 1")
  437. _, err = query.Get(lpplandtl1query)
  438. if err != nil {
  439. log.Println("autogeneration-error-7", err)
  440. tx.Rollback()
  441. return err
  442. }
  443. upLpplandtl1 := tx.Table("lpplandtl1")
  444. data := &lpplandtl1{
  445. Pastureid: lpplan.Pastureid,
  446. Lppid: lpplan.Lppid,
  447. Barid: fpdetail.Barid,
  448. Barname: fpdetail.Barname,
  449. Fpdid: fpdetail.Fpdid,
  450. Fttype: fpdetail.Fttypeid,
  451. Lweight: lpplandtl1query.Lweight + insertlweight,
  452. Sort: lpplan.Sort,
  453. Tmrid: lpplan.Tmrid,
  454. Tmrname: lpplan.Tmrname,
  455. Cowcount: fpdetail.Cowcount,
  456. Ccountradio: fpdetail.Ccountradio,
  457. // Background: lpplan.Background,
  458. Lweighthis: insertlweight,
  459. }
  460. upLpplandtl1.Where("pastureid = ?", pastureid)
  461. upLpplandtl1.Where("lppid = ?", lpplan.Lppid)
  462. upLpplandtl1.Where("fpdid = ?", fpdetail.Fpdid)
  463. upLpplandtl1.Where("fttype = 1")
  464. _, err = upLpplandtl1.Update(data)
  465. if err != nil {
  466. log.Println("autogeneration-error-8", err)
  467. tx.Rollback()
  468. return err
  469. }
  470. } else {
  471. data := &lpplandtl1{
  472. Pastureid: lpplan.Pastureid,
  473. Lppid: lpplan.Lppid,
  474. Barid: lpplan.Barid,
  475. Barname: lpplan.Barname,
  476. Fpdid: fpdetail.Fpdid,
  477. Fttype: fpdetail.Fttypeid,
  478. Lweight: insertlweight,
  479. Sort: lpplan.Sort,
  480. Tmrid: lpplan.Tmrid,
  481. Tmrname: lpplan.Tmrname,
  482. Cowcount: lpplan.Cowcount,
  483. Ccountradio: lpplan.Ccountradio,
  484. Background: lpplan.Background,
  485. Lweighthis: insertlweight,
  486. }
  487. addLpplandtl1 := tx.Table("lpplandtl1")
  488. _, err = addLpplandtl1.Insert(data)
  489. if err != nil {
  490. log.Println("autogeneration-error-9", err)
  491. tx.Rollback()
  492. return err
  493. }
  494. }
  495. }
  496. if typeIN == 1 {
  497. _, err = tx.SQL("update lpplan set sel = 1 where id = ?", lpplan.Lppid).Execute()
  498. if err != nil {
  499. log.Println("autogeneration-error-10", err)
  500. return err
  501. }
  502. }
  503. }
  504. err = tx.Commit()
  505. if err != nil {
  506. log.Println("autogeneration-error-11", err)
  507. return err
  508. }
  509. return nil
  510. }