goodsaptitude.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. package oilsupplier
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "log"
  7. "os"
  8. "reflect"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitudeclass"
  13. "dashoo.cn/backend/api/business/items"
  14. "dashoo.cn/backend/api/business/baseUser"
  15. "dashoo.cn/backend/api/business/oilsupplier/goodsaptitude"
  16. . "dashoo.cn/backend/api/controllers"
  17. "dashoo.cn/business2/userRole"
  18. "dashoo.cn/utils"
  19. . "github.com/linxGnu/goseaweedfs"
  20. )
  21. type OilGoodsAptitudeController struct {
  22. BaseController
  23. }
  24. // @Title 获取列表
  25. // @Description get user by token
  26. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  27. // @router /list [get]
  28. func (this *OilGoodsAptitudeController) GetEntityList() {
  29. //获取分页信息
  30. page := this.GetPageInfoForm()
  31. where := " 1=1 "
  32. orderby := "Code"
  33. asc := true
  34. Order := this.GetString("Order")
  35. Prop := this.GetString("Prop")
  36. if Order != "" && Prop != "" {
  37. orderby = Prop
  38. if Order == "asc" {
  39. asc = true
  40. } else {
  41. asc = false
  42. }
  43. }
  44. Edition := this.GetString("Edition")
  45. CreateOn := this.GetString("CreateOn")
  46. Code := this.GetString("Code")
  47. Name := this.GetString("Name")
  48. BigClassName := this.GetString("BigClassName")
  49. BigClassCode := this.GetString("BigClassCode")
  50. MiddleClassName := this.GetString("MiddleClassName")
  51. SmallClassName := this.GetString("SmallClassName")
  52. GoodsName := this.GetString("GoodsName")
  53. GoodsLevel := this.GetString("GoodsLevel")
  54. GoodsDesc := this.GetString("GoodsDesc")
  55. Standard := this.GetString("Standard")
  56. CompanyType := this.GetString("CompanyType")
  57. if Edition != "" {
  58. where = where + " and Edition = '" + Edition + "'"
  59. }
  60. if Code != "" {
  61. where = where + " and Code like '%" + Code + "%'"
  62. }
  63. if Name != "" {
  64. where = where + " and Name like '%" + Name + "%'"
  65. }
  66. if BigClassName != "" {
  67. where = where + " and Name1 like '%" + BigClassName + "%'"
  68. }
  69. if BigClassCode != "" {
  70. where = where + " and Code1 like '%" + BigClassCode + "%'"
  71. }
  72. if MiddleClassName != "" {
  73. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  74. }
  75. if SmallClassName != "" {
  76. where = where + " and Name3 like '%" + SmallClassName + "%'"
  77. }
  78. if GoodsName != "" {
  79. where = where + " and Name4 like '%" + GoodsName + "%'"
  80. }
  81. if GoodsLevel != "" {
  82. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  83. }
  84. if GoodsDesc != "" {
  85. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  86. }
  87. if Standard != "" {
  88. where = where + " and Standard '%" + Standard + "%'"
  89. }
  90. if CompanyType != "" {
  91. where = where + " and CompanyType '%" + CompanyType + "%'"
  92. }
  93. if CreateOn != "" {
  94. dates := strings.Split(CreateOn, ",")
  95. if len(dates) == 2 {
  96. minDate := dates[0]
  97. maxDate := dates[1]
  98. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  99. }
  100. }
  101. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  102. var list []goodsaptitude.OilGoodsAptitudeView
  103. total := svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  104. var datainfo DataInfo
  105. datainfo.Items = list
  106. datainfo.CurrentItemCount = total
  107. datainfo.PageIndex = page.CurrentPage
  108. datainfo.ItemsPerPage = page.Size
  109. this.Data["json"] = &datainfo
  110. this.ServeJSON()
  111. }
  112. // @Title 获取列表新导入的列表
  113. // @Description get user by token
  114. // @Success 200 {object} []goodsaptitude.OilGoodsAptitude
  115. // @router /importlist [get]
  116. func (this *OilGoodsAptitudeController) GetImportEntityList() {
  117. //获取分页信息
  118. page := this.GetPageInfoForm()
  119. where := " 1=1 "
  120. orderby := "Code"
  121. asc := true
  122. Order := this.GetString("Order")
  123. Prop := this.GetString("Prop")
  124. if Order != "" && Prop != "" {
  125. orderby = Prop
  126. if Order == "asc" {
  127. asc = true
  128. } else {
  129. asc = false
  130. }
  131. }
  132. Edition := this.GetString("Edition")
  133. CreateOn := this.GetString("CreateOn")
  134. Code := this.GetString("Code")
  135. Name := this.GetString("Name")
  136. BigClassName := this.GetString("BigClassName")
  137. BigClassCode := this.GetString("BigClassCode")
  138. MiddleClassName := this.GetString("MiddleClassName")
  139. SmallClassName := this.GetString("SmallClassName")
  140. GoodsName := this.GetString("GoodsName")
  141. GoodsLevel := this.GetString("GoodsLevel")
  142. GoodsDesc := this.GetString("GoodsDesc")
  143. Standard := this.GetString("Standard")
  144. CompanyType := this.GetString("CompanyType")
  145. if Edition != "" {
  146. where = where + " and Edition = '" + Edition + "'"
  147. }
  148. if Code != "" {
  149. where = where + " and Code like '%" + Code + "%'"
  150. }
  151. if Name != "" {
  152. where = where + " and Name like '%" + Name + "%'"
  153. }
  154. if BigClassName != "" {
  155. where = where + " and Name1 like '%" + BigClassName + "%'"
  156. }
  157. if BigClassCode != "" {
  158. where = where + " and Code1 like '%" + BigClassCode + "%'"
  159. }
  160. if MiddleClassName != "" {
  161. where = where + " and Name2 like '%" + MiddleClassName + "%'"
  162. }
  163. if SmallClassName != "" {
  164. where = where + " and Name3 like '%" + SmallClassName + "%'"
  165. }
  166. if GoodsName != "" {
  167. where = where + " and Name4 like '%" + GoodsName + "%'"
  168. }
  169. if GoodsLevel != "" {
  170. where = where + " and GoodsLevel like '%" + GoodsLevel + "%'"
  171. }
  172. if GoodsDesc != "" {
  173. where = where + " and GoodsDesc like '%" + GoodsDesc + "%'"
  174. }
  175. if Standard != "" {
  176. where = where + " and Standard '%" + Standard + "%'"
  177. }
  178. if CompanyType != "" {
  179. where = where + " and CompanyType '%" + CompanyType + "%'"
  180. }
  181. if CreateOn != "" {
  182. dates := strings.Split(CreateOn, ",")
  183. if len(dates) == 2 {
  184. minDate := dates[0]
  185. maxDate := dates[1]
  186. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  187. }
  188. }
  189. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  190. var list []goodsaptitude.OilGoodsAptitudeView
  191. total := svc.GetMyPagingEntitiesWithOrderBytbl(ImportOilGoodsAptDetailViewName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  192. var datainfo DataInfo
  193. datainfo.Items = list
  194. datainfo.CurrentItemCount = total
  195. datainfo.PageIndex = page.CurrentPage
  196. datainfo.ItemsPerPage = page.Size
  197. this.Data["json"] = &datainfo
  198. this.ServeJSON()
  199. }
  200. // @Title 获取列表2019版本
  201. // @Description
  202. // @Success 200 {object}
  203. // @router /list_2019 [get]
  204. func (this *OilGoodsAptitudeController) GetEntityList_2019() {
  205. //获取分页信息
  206. page := this.GetPageInfoForm()
  207. where := " 1=1 "
  208. orderby := "Code"
  209. asc := true
  210. Order := this.GetString("Order")
  211. Prop := this.GetString("Prop")
  212. if Order != "" && Prop != "" {
  213. orderby = Prop
  214. if Order == "asc" {
  215. asc = true
  216. } else {
  217. asc = false
  218. }
  219. }
  220. Edition := this.GetString("Edition")
  221. Code := this.GetString("Code")
  222. Name := this.GetString("Name")
  223. if Edition != "" {
  224. where = where + " and a.Edition = '" + Edition + "'"
  225. }
  226. if Code != "" {
  227. where = where + " and b.Code like '%" + Code + "%'"
  228. }
  229. if Name != "" {
  230. where = where + " and b.Name like '%" + Name + "%'"
  231. }
  232. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  233. var list []goodsaptitude.OilGoodsAptitude_2
  234. total := svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  235. var datainfo DataInfo
  236. datainfo.Items = list
  237. datainfo.CurrentItemCount = total
  238. datainfo.PageIndex = page.CurrentPage
  239. datainfo.ItemsPerPage = page.Size
  240. this.Data["json"] = &datainfo
  241. this.ServeJSON()
  242. }
  243. // @Title 获取字典列表
  244. // @Description get user by token
  245. // @Success 200 {object} map[string]interface{}
  246. // @router /dictlist [get]
  247. func (this *OilGoodsAptitudeController) GetDictList() {
  248. dictList := make(map[string]interface{})
  249. dictSvc := items.GetItemsService(utils.DBE)
  250. userSvc := baseUser.GetBaseUserService(utils.DBE)
  251. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  252. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  253. var userEntity userRole.Base_User
  254. userSvc.GetEntityById(this.User.Id, &userEntity)
  255. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  256. dictList["AuditStep"] = dictSvc.GetKeyValueItems("AuditStep", this.User.AccCode)
  257. //var dictCustomer []svccustomer.Customer
  258. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  259. //dictList["EntrustCorp"] = &dictCustomer
  260. var datainfo DataInfo
  261. datainfo.Items = dictList
  262. this.Data["json"] = &datainfo
  263. this.ServeJSON()
  264. }
  265. // @Title 获取实体
  266. // @Description 获取实体
  267. // @Success 200 {object} goodsaptitude.OilGoodsAptitude
  268. // @router /get/:id [get]
  269. func (this *OilGoodsAptitudeController) GetEntity() {
  270. Id := this.Ctx.Input.Param(":id")
  271. var model goodsaptitude.OilGoodsAptitudeView
  272. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  273. //svc.GetEntityByIdBytbl(""+OilGoodsAptitudeName, Id, &model)
  274. where := " Id =" + Id
  275. svc.GetEntityByWhere(OilGoodsAptDetailViewName, where, &model)
  276. this.Data["json"] = &model
  277. this.ServeJSON()
  278. }
  279. // @Title 获取实体
  280. // @Description 获取实体
  281. // @Success 200 {object}
  282. // @router /get_2019/:id [get]
  283. func (this *OilGoodsAptitudeController) GetEntity_2019() {
  284. Id := this.Ctx.Input.Param(":id")
  285. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  286. var tempMap []map[string]string
  287. sql := `select a.Id,a.ClassId,a.F01,a.F02,a.F03,a.F04,a.F05,a.F06,a.F07,a.F08,a.F09,a.F10,
  288. a.F11,a.F12,a.F13,a.F14,a.F15,a.F16,a.F17,a.F18,a.F19,a.F20,
  289. a.F21,a.F22,a.F23,a.F24,a.F25,a.F26,a.F27,a.F28,a.F29,a.F30,
  290. a.F31,a.F32,a.F33,a.F34,a.F35,a.F36,a.F37,a.F38,a.F39,a.F40,
  291. a.F41,a.F42,a.F43,a.F44,a.F45,a.F46,b.Code, b.Name `
  292. sql += ` from ` + OilGoodsAptitudeName + ` a `
  293. sql += ` left join ` + OilGoodsAptitudeClassName + " b on b.Id = a.ClassId"
  294. sql += ` where a.Id='` + Id + `'`
  295. tempMap, _ = svc.DBE.QueryString(sql)
  296. this.Data["json"] = &tempMap
  297. this.ServeJSON()
  298. }
  299. // @Title 添加
  300. // @Description 新增
  301. // @Success 200 {object} controllers.Request
  302. // @router /add/:id [post]
  303. func (this *OilGoodsAptitudeController) AddEntity() {
  304. classId := this.Ctx.Input.Param(":id")
  305. var model goodsaptitude.OilGoodsAptitude
  306. var jsonBlob = this.Ctx.Input.RequestBody
  307. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  308. json.Unmarshal(jsonBlob, &model)
  309. model.CreateOn = time.Now()
  310. model.CreateBy = this.User.Realname
  311. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  312. model.ClassId, _ = strconv.Atoi(classId)
  313. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  314. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model)
  315. var errinfo ErrorDataInfo
  316. if err == nil {
  317. //新增
  318. errinfo.Message = "添加成功!"
  319. errinfo.Code = 0
  320. errinfo.Item = model.Id
  321. this.Data["json"] = &errinfo
  322. this.ServeJSON()
  323. } else {
  324. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  325. errinfo.Code = -1
  326. this.Data["json"] = &errinfo
  327. this.ServeJSON()
  328. }
  329. }
  330. // @Title 添加
  331. // @Description 新增
  332. // @Success 200 {object} controllers.Request
  333. // @router /add_2019 [post]
  334. func (this *OilGoodsAptitudeController) AddEntity_2019() {
  335. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  336. var model goodsaptitudeclass.OilGoodsAptitudeClass
  337. var jsonBlob = this.Ctx.Input.RequestBody
  338. json.Unmarshal(jsonBlob, &model)
  339. model.ParentId = -1
  340. model.Edition = "2"
  341. model.CreateOn = time.Now()
  342. model.CreateBy = this.User.Realname
  343. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  344. _, err := svc.InsertEntityBytbl(""+OilGoodsAptitudeClassName, &model)
  345. var model2 goodsaptitude.OilGoodsAptitude
  346. json.Unmarshal(jsonBlob, &model2)
  347. model2.ClassId = model.Id
  348. model2.Edition = "2"
  349. model2.CreateOn = time.Now()
  350. model2.CreateBy = this.User.Realname
  351. model2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  352. _, err = svc.InsertEntityBytbl(""+OilGoodsAptitudeName, &model2)
  353. var errinfo ErrorDataInfo
  354. if err == nil {
  355. //新增
  356. errinfo.Message = "添加成功!"
  357. errinfo.Code = 0
  358. errinfo.Item = model2.Id
  359. this.Data["json"] = &errinfo
  360. this.ServeJSON()
  361. } else {
  362. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  363. errinfo.Code = -1
  364. this.Data["json"] = &errinfo
  365. this.ServeJSON()
  366. }
  367. }
  368. // @Title 修改实体
  369. // @Description 修改实体
  370. // @Success 200 {object} controllers.Request
  371. // @router /update/:id [post]
  372. func (this *OilGoodsAptitudeController) UpdateEntity() {
  373. id := this.Ctx.Input.Param(":id")
  374. var errinfo ErrorInfo
  375. if id == "" {
  376. errinfo.Message = "操作失败!请求信息不完整"
  377. errinfo.Code = -2
  378. this.Data["json"] = &errinfo
  379. this.ServeJSON()
  380. return
  381. }
  382. var model goodsaptitude.OilGoodsAptitude
  383. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  384. var jsonBlob = this.Ctx.Input.RequestBody
  385. json.Unmarshal(jsonBlob, &model)
  386. model.ModifiedOn = time.Now()
  387. model.ModifiedBy = this.User.Realname
  388. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  389. cols := []string{
  390. "Id",
  391. "Code",
  392. "Name",
  393. "BigClassName",
  394. "MiddleClassName",
  395. "SmallClassName",
  396. "GoodsName",
  397. "GoodsLevel",
  398. "GoodsDesc",
  399. "Standard",
  400. "CompanyType",
  401. "F01",
  402. "F02",
  403. "F03",
  404. "F04",
  405. "F05",
  406. "F06",
  407. "F07",
  408. "F08",
  409. "F09",
  410. "F10",
  411. "F11",
  412. "F12",
  413. "F13",
  414. "F14",
  415. "F15",
  416. "F16",
  417. "F17",
  418. "F18",
  419. "F19",
  420. "F20",
  421. "F21",
  422. "F22",
  423. "F23",
  424. "F24",
  425. "F25",
  426. "F26",
  427. "F27",
  428. "F28",
  429. "F29",
  430. "F30",
  431. "F31",
  432. "F32",
  433. "F33",
  434. "F34",
  435. "F35",
  436. "F36",
  437. "F37",
  438. "F38",
  439. "F39",
  440. "F40",
  441. "F41",
  442. "F42",
  443. "F43",
  444. "F44",
  445. "F45",
  446. "F46",
  447. "Remark",
  448. "DeletionStateCode",
  449. "CreateOn",
  450. "CreateUserId",
  451. "CreateBy",
  452. "ModifiedOn",
  453. "ModifiedUserId",
  454. "ModifiedBy",
  455. }
  456. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  457. if err == nil {
  458. errinfo.Message = "修改成功!"
  459. errinfo.Code = 0
  460. this.Data["json"] = &errinfo
  461. this.ServeJSON()
  462. } else {
  463. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  464. errinfo.Code = -1
  465. this.Data["json"] = &errinfo
  466. this.ServeJSON()
  467. }
  468. }
  469. // @Title 修改实体
  470. // @Description 修改实体
  471. // @Success 200 {object} controllers.Request
  472. // @router /update_2019/:id [post]
  473. func (this *OilGoodsAptitudeController) UpdateEntity_2019() {
  474. id := this.Ctx.Input.Param(":id")
  475. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  476. var errinfo ErrorInfo
  477. if id == "" {
  478. errinfo.Message = "操作失败!请求信息不完整"
  479. errinfo.Code = -2
  480. this.Data["json"] = &errinfo
  481. this.ServeJSON()
  482. return
  483. }
  484. var model goodsaptitude.OilGoodsAptitude
  485. var jsonBlob = this.Ctx.Input.RequestBody
  486. json.Unmarshal(jsonBlob, &model)
  487. model.ModifiedOn = time.Now()
  488. model.ModifiedBy = this.User.Realname
  489. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  490. cols := []string{
  491. "F01",
  492. "F02",
  493. "F03",
  494. "F04",
  495. "F05",
  496. "F06",
  497. "F07",
  498. "F08",
  499. "F09",
  500. "F10",
  501. "F11",
  502. "F12",
  503. "F13",
  504. "F14",
  505. "F15",
  506. "F16",
  507. "F17",
  508. "F18",
  509. "F19",
  510. "F20",
  511. "F21",
  512. "F22",
  513. "F23",
  514. "F24",
  515. "F25",
  516. "F26",
  517. "F27",
  518. "F28",
  519. "F29",
  520. "F30",
  521. "F31",
  522. "F32",
  523. "F33",
  524. "F34",
  525. "F35",
  526. "F36",
  527. "F37",
  528. "F38",
  529. "F39",
  530. "F40",
  531. "F41",
  532. "F42",
  533. "F43",
  534. "F44",
  535. "F45",
  536. "F46",
  537. "ModifiedOn",
  538. "ModifiedUserId",
  539. "ModifiedBy",
  540. }
  541. err := svc.UpdateEntityBytbl(""+OilGoodsAptitudeName, id, &model, cols)
  542. var model2 goodsaptitudeclass.OilGoodsAptitudeClass
  543. json.Unmarshal(jsonBlob, &model2)
  544. model2.ModifiedOn = time.Now()
  545. model2.ModifiedBy = this.User.Realname
  546. model2.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  547. cols2 := []string{
  548. "Code",
  549. "Name",
  550. "ModifiedOn",
  551. "ModifiedUserId",
  552. "ModifiedBy",
  553. }
  554. err = svc.UpdateEntityBytbl(""+OilGoodsAptitudeClassName, model.ClassId, &model2, cols2)
  555. if err == nil {
  556. errinfo.Message = "修改成功!"
  557. errinfo.Code = 0
  558. this.Data["json"] = &errinfo
  559. this.ServeJSON()
  560. } else {
  561. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  562. errinfo.Code = -1
  563. this.Data["json"] = &errinfo
  564. this.ServeJSON()
  565. }
  566. }
  567. // @Title 修改实体
  568. // @Description 修改实体
  569. // @Success 200 {object} controllers.Request
  570. // @router /updatecode/:id [post]
  571. func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
  572. var errinfo ErrorInfo
  573. var err error
  574. id := this.Ctx.Input.Param(":id")
  575. if id == "" {
  576. errinfo.Message = "操作失败!请求信息不完整"
  577. errinfo.Code = -2
  578. this.Data["json"] = &errinfo
  579. this.ServeJSON()
  580. return
  581. }
  582. var classall goodsaptitude.OilGoodsAptitudeClassView
  583. var model goodsaptitudeclass.OilGoodsAptitudeClass
  584. var classmodel []goodsaptitudeclass.OilGoodsAptitudeClass
  585. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  586. var jsonBlob = this.Ctx.Input.RequestBody
  587. json.Unmarshal(jsonBlob, &classall)
  588. model.ModifiedOn = time.Now()
  589. model.ModifiedBy = this.User.Realname
  590. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  591. colsName := []string{"Name"}
  592. colsCode := []string{"Code"}
  593. //svc.GetEntityById(id, &model)
  594. if classall.Name1 != "" {
  595. where := " Name = '" + classall.Name1 + "' and Id <> " + utils.ToStr(classall.Id1)
  596. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  597. if len(classmodel) > 0 {
  598. errinfo.Message = "大类名称已存在,请重新添加!"
  599. errinfo.Code = -1
  600. this.Data["json"] = &errinfo
  601. this.ServeJSON()
  602. return
  603. } else {
  604. model.Name = classall.Name1
  605. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsName)
  606. }
  607. }
  608. if classall.Name2 != "" {
  609. where := " Name = '" + classall.Name2 + "' and Id <> " + utils.ToStr(classall.Id2)
  610. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  611. if len(classmodel) > 0 {
  612. errinfo.Message = "中类名称已存在,请重新添加!"
  613. errinfo.Code = -1
  614. this.Data["json"] = &errinfo
  615. this.ServeJSON()
  616. return
  617. } else {
  618. model.Name = classall.Name2
  619. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsName)
  620. }
  621. }
  622. if classall.Name3 != "" {
  623. where := " Name = '" + classall.Name3 + "' and Id <> " + utils.ToStr(classall.Id3)
  624. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  625. if len(classmodel) > 0 {
  626. errinfo.Message = "小类名称已存在,请重新添加!"
  627. errinfo.Code = -1
  628. this.Data["json"] = &errinfo
  629. this.ServeJSON()
  630. return
  631. } else {
  632. model.Name = classall.Name3
  633. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsName)
  634. }
  635. }
  636. if classall.Name4 != "" {
  637. where := " Name = '" + classall.Name4 + "' and Id <> " + utils.ToStr(classall.Id4)
  638. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  639. if len(classmodel) > 0 {
  640. errinfo.Message = "品名已存在,请重新添加!"
  641. errinfo.Code = -1
  642. this.Data["json"] = &errinfo
  643. this.ServeJSON()
  644. return
  645. } else {
  646. model.Name = classall.Name4
  647. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsName)
  648. }
  649. }
  650. if classall.Code1 != "" {
  651. where := " Code = " + classall.Code1 + " and Id <> " + utils.ToStr(classall.Id1)
  652. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  653. if len(classmodel) > 0 {
  654. errinfo.Message = "大类编码已存在,请重新添加!"
  655. errinfo.Code = -1
  656. this.Data["json"] = &errinfo
  657. this.ServeJSON()
  658. return
  659. } else {
  660. model.Code = classall.Code1
  661. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id1, &model, colsCode)
  662. }
  663. }
  664. if classall.Code2 != "" {
  665. where := " Code = " + classall.Code2 + " and Id <> " + utils.ToStr(classall.Id2)
  666. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  667. if len(classmodel) > 0 {
  668. errinfo.Message = "中类编码已存在,请重新添加!"
  669. errinfo.Code = -1
  670. this.Data["json"] = &errinfo
  671. this.ServeJSON()
  672. return
  673. } else {
  674. model.Code = classall.Code2
  675. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id2, &model, colsCode)
  676. }
  677. }
  678. if classall.Code3 != "" {
  679. where := " Code = " + classall.Code3 + " and Id <> " + utils.ToStr(classall.Id3)
  680. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  681. if len(classmodel) > 0 {
  682. errinfo.Message = "小类编码已存在,请重新添加!"
  683. errinfo.Code = -1
  684. this.Data["json"] = &errinfo
  685. this.ServeJSON()
  686. return
  687. } else {
  688. model.Code = classall.Code3
  689. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id3, &model, colsCode)
  690. }
  691. }
  692. if classall.Code4 != "" {
  693. where := " Code = " + classall.Code4 + " and Id <> " + utils.ToStr(classall.Id4)
  694. svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &classmodel)
  695. if len(classmodel) > 0 {
  696. errinfo.Message = "品名编码已存在,请重新添加!"
  697. errinfo.Code = -1
  698. this.Data["json"] = &errinfo
  699. this.ServeJSON()
  700. return
  701. } else {
  702. model.Code = classall.Code4
  703. err = svc.UpdateEntityBytbl(OilGoodsAptitudeClassName, classall.Id4, &model, colsCode)
  704. }
  705. }
  706. if err == nil {
  707. errinfo.Message = "修改成功!"
  708. errinfo.Code = 0
  709. this.Data["json"] = &errinfo
  710. this.ServeJSON()
  711. } else {
  712. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  713. errinfo.Code = -1
  714. this.Data["json"] = &errinfo
  715. this.ServeJSON()
  716. }
  717. }
  718. // @Title 删除单条信息
  719. // @Description
  720. // @Success 200 {object} ErrorInfo
  721. // @Failure 403 :id 为空
  722. // @router /delete/:Id [delete]
  723. func (this *OilGoodsAptitudeController) DeleteEntity() {
  724. Id := this.Ctx.Input.Param(":Id")
  725. var errinfo ErrorInfo
  726. if Id == "" {
  727. errinfo.Message = "操作失败!请求信息不完整"
  728. errinfo.Code = -2
  729. this.Data["json"] = &errinfo
  730. this.ServeJSON()
  731. return
  732. }
  733. var model goodsaptitude.OilGoodsAptitude
  734. var entityempty goodsaptitude.OilGoodsAptitude
  735. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  736. opdesc := "删除-" + Id
  737. err := svc.DeleteOperationAndWriteLogBytbl(""+OilGoodsAptitudeName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  738. if err == nil {
  739. errinfo.Message = "删除成功"
  740. errinfo.Code = 0
  741. this.Data["json"] = &errinfo
  742. this.ServeJSON()
  743. } else {
  744. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  745. errinfo.Code = -1
  746. this.Data["json"] = &errinfo
  747. this.ServeJSON()
  748. }
  749. }
  750. // @Title get 查询
  751. // @Description get SampleType by token
  752. // @Success 200 {object} sampletype.SampleType
  753. // @router /goodsparentlist/:name [get]
  754. func (this *OilGoodsAptitudeController) GoodsParentList() {
  755. Name := this.Ctx.Input.Param(":name")
  756. if Name != "" {
  757. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  758. where1 := "1=1"
  759. where1 += " AND Name LIKE '%" + Name + "%' OR Code LIKE '" + Name + "%' "
  760. sqlStr := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  761. "WHERE " + where1 + " AND Edition='1' AND DeletionStateCode = 0 ORDER BY Code"
  762. list, _ := svc.DBE.QueryString(sqlStr)
  763. /*
  764. sql := "SELECT Id, Code, Name, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass " +
  765. "WHERE DeletionStateCode = 0 AND " + where1 + " OR Id = (" + sqlStr + ")" +" ORDER BY Code"
  766. list, _ := svc.DBE.QueryString(sql)*/
  767. var datainfo DataInfo
  768. datainfo.Items = list
  769. this.Data["json"] = &datainfo
  770. this.ServeJSON()
  771. }
  772. }
  773. // @Title get 获取子类
  774. // @Description get SampleType by token
  775. // @Success 200 {object} sampletype.SampleType
  776. // @router /goodschildlist/:id [get]
  777. func (this *OilGoodsAptitudeController) GoodsChildList() {
  778. ParentId := this.Ctx.Input.Param(":id")
  779. sqlStr := "SELECT Id, `Code`, `Name`, concat(Code, ' ', Name) as CodeName, ParentId FROM OilGoodsAptitudeClass WHERE FIND_IN_SET(ParentId, fun_getOilGoodsAptitudeClasschildlist(" + ParentId + ")) AND DeletionStateCode = 0 order by Code"
  780. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  781. list, _ := svc.DBE.QueryString(sqlStr)
  782. var datainfo DataInfo
  783. datainfo.Items = list
  784. this.Data["json"] = &datainfo
  785. this.ServeJSON()
  786. }
  787. // @Title get 获取子类
  788. // @Description get SampleType by token
  789. // @Success 200 {object} sampletype.SampleType
  790. // @router /goodschildlistbypid/:parentid [get]
  791. func (this *OilGoodsAptitudeController) GoodsChildLisByParentId() {
  792. ParentId := this.Ctx.Input.Param(":parentid")
  793. sqlStr := "SELECT o.Id, o.`Code`, o.`Name`, concat(o.Code, ' ', o.Name) as CodeName, o.ParentId, g.GoodsLevel," +
  794. " (CASE WHEN length(Code)>=8 THEN '1' ELSE '0' END) as Leaf FROM OilGoodsAptitudeClass o " +
  795. " LEFT JOIN `OilGoodsAptitude` g ON (g.ClassId = o.Id)" +
  796. " WHERE o.ParentId = '" + ParentId + "' AND o.Edition='1' AND o.DeletionStateCode = 0 order by o.Code"
  797. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  798. list, _ := svc.DBE.QueryString(sqlStr)
  799. var datainfo DataInfo
  800. datainfo.Items = list
  801. this.Data["json"] = &datainfo
  802. this.ServeJSON()
  803. }
  804. // @Title get 导出ex
  805. // @Description get SampleType by token
  806. // @Success 200 {object} sampletype.SampleType
  807. // @router /exportexcelall [get]
  808. func (this *OilGoodsAptitudeController) ExportExcelAll() {
  809. //获取分页信息
  810. //page := this.GetPageInfoForm()
  811. where := " 1=1 "
  812. orderby := "Code"
  813. asc := true
  814. Order := this.GetString("Order")
  815. Prop := this.GetString("Prop")
  816. if Order != "" && Prop != "" {
  817. orderby = Prop
  818. if Order == "asc" {
  819. asc = true
  820. } else {
  821. asc = false
  822. }
  823. }
  824. Edition := this.GetString("Edition")
  825. if Edition != "" {
  826. where = where + " and Edition = '" + Edition + "'"
  827. }
  828. t := time.Now()
  829. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  830. var list []goodsaptitude.OilGoodsAptitudeView
  831. svc.GetMyPagingEntitiesWithOrderBytbl(OilGoodsAptDetailViewName, 0, 0, orderby, asc, &list, where)
  832. var title []string
  833. filetitle := "物资类"
  834. //自定义显示列
  835. showcolumnarr := this.GetString("showcolumnarr")
  836. showcolumnnamearr := this.GetString("showcolumnnamearr")
  837. titlestring := showcolumnnamearr
  838. title = strings.Split(titlestring, ",")
  839. f := xlsx.NewFile()
  840. sheet, _ := f.AddSheet(filetitle)
  841. //rowhead := sheet.AddRow()
  842. //rowhead.WriteSlice(&title, -1)
  843. cellname := strings.Split(showcolumnarr, ",")
  844. row := sheet.AddRow()
  845. row.WriteSlice(&cellname, -1)
  846. for _, item := range list {
  847. var enumModel goodsaptitude.OilGoodsAptitudeView
  848. tmpModel := &item
  849. enumModel = *tmpModel
  850. immumodel := reflect.ValueOf(&enumModel)
  851. elem := immumodel.Elem()
  852. row := sheet.AddRow()
  853. for _, name := range title {
  854. cell := row.AddCell()
  855. if strings.HasPrefix(name, "F") {
  856. var val = elem.FieldByName(name).String()
  857. if val == "1" {
  858. cell.Value = "是"
  859. } else {
  860. cell.Value = ""
  861. }
  862. } else {
  863. cell.Value = elem.FieldByName(name).String()
  864. }
  865. }
  866. }
  867. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  868. sheet.Cols[c].Width = 20
  869. }
  870. //this.SaveSampleXlsx(filetitle, title, showcolumnarr, list, f)
  871. dir := "static/file/excel/report/" + this.GetAccode()
  872. SaveDirectory(dir)
  873. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  874. f.Save(path)
  875. var sw *Seaweed
  876. var filer []string
  877. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  878. filer = []string{_filer}
  879. }
  880. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  881. _, _, fID, _ := sw.UploadFile(path, "", "")
  882. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  883. os.Remove(path)
  884. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  885. this.Data["json"] = retDocUrl
  886. this.ServeJSON()
  887. elapsed := time.Since(t)
  888. fmt.Println(elapsed)
  889. }
  890. // @Title get 导出ex
  891. // @Description get SampleType by token
  892. // @Success 200 {object} sampletype.SampleType
  893. // @router /exportexcelall2019 [get]
  894. func (this *OilGoodsAptitudeController) ExportExcelAll2019() {
  895. //获取分页信息
  896. //page := this.GetPageInfoForm()
  897. where := " 1=1 "
  898. orderby := "Code"
  899. asc := true
  900. Order := this.GetString("Order")
  901. Prop := this.GetString("Prop")
  902. if Order != "" && Prop != "" {
  903. orderby = Prop
  904. if Order == "asc" {
  905. asc = true
  906. } else {
  907. asc = false
  908. }
  909. }
  910. Edition := this.GetString("Edition")
  911. if Edition != "" {
  912. where = where + " and a.Edition = '" + Edition + "'"
  913. }
  914. t := time.Now()
  915. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  916. var list []goodsaptitude.OilGoodsAptitude_2
  917. svc.GetList_2019(OilGoodsAptitudeName, OilGoodsAptitudeClassName, 0, 0, orderby, asc, &list, where)
  918. var title []string
  919. filetitle := "物资类(顶级)"
  920. //自定义显示列
  921. showcolumnarr := this.GetString("showcolumnarr")
  922. showcolumnnamearr := this.GetString("showcolumnnamearr")
  923. titlestring := showcolumnnamearr
  924. title = strings.Split(titlestring, ",")
  925. f := xlsx.NewFile()
  926. sheet, _ := f.AddSheet(filetitle)
  927. cellname := strings.Split(showcolumnarr, ",")
  928. row := sheet.AddRow()
  929. row.WriteSlice(&cellname, -1)
  930. for _, item := range list {
  931. var enumModel goodsaptitude.OilGoodsAptitude_2
  932. tmpModel := &item
  933. enumModel = *tmpModel
  934. immumodel := reflect.ValueOf(&enumModel)
  935. elem := immumodel.Elem()
  936. row := sheet.AddRow()
  937. for _, name := range title {
  938. cell := row.AddCell()
  939. if strings.HasPrefix(name, "F") {
  940. var val = elem.FieldByName(name).String()
  941. if val == "1" {
  942. cell.Value = "是"
  943. } else {
  944. cell.Value = ""
  945. }
  946. } else {
  947. cell.Value = elem.FieldByName(name).String()
  948. }
  949. }
  950. }
  951. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  952. sheet.Cols[c].Width = 20
  953. }
  954. dir := "static/file/excel/report/" + this.GetAccode()
  955. SaveDirectory(dir)
  956. path := dir + "/" + utils.TimeFormat(time.Now(), "200612") + filetitle + ".xlsx"
  957. f.Save(path)
  958. var sw *Seaweed
  959. var filer []string
  960. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  961. filer = []string{_filer}
  962. }
  963. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  964. _, _, fID, _ := sw.UploadFile(path, "", "")
  965. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  966. os.Remove(path)
  967. fmt.Println("==retDocWatermarkUrl==", retDocUrl)
  968. this.Data["json"] = retDocUrl
  969. this.ServeJSON()
  970. elapsed := time.Since(t)
  971. fmt.Println(elapsed)
  972. }
  973. // @Title get 导入excel
  974. // @Description get SampleType by token
  975. // @Success 200 {object} sampletype.SampleType
  976. // @router /importexcel [get]
  977. func (this *OilGoodsAptitudeController) ImportExcel() {
  978. url := this.GetString("ExcelUrl")
  979. var errorinfo ErrorInfo
  980. if url == "" {
  981. errorinfo.Code = -2
  982. errorinfo.Message = "导入失败!"
  983. this.Data["json"] = &errorinfo
  984. this.ServeJSON()
  985. }
  986. session := utils.DBE.NewSession()
  987. err := session.Begin()
  988. sessionsvc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  989. defer func() {
  990. session.Close()
  991. }()
  992. err = sessionsvc.TruncateTable(Tmp_OilGoodsAptitudeName)
  993. if err != nil {
  994. session.Rollback()
  995. errorinfo.Code = -2
  996. errorinfo.Message = "导入失败!"
  997. this.Data["json"] = &errorinfo
  998. this.ServeJSON()
  999. }
  1000. err = sessionsvc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
  1001. if err != nil {
  1002. session.Rollback()
  1003. errorinfo.Code = -2
  1004. errorinfo.Message = "导入失败!"
  1005. this.Data["json"] = &errorinfo
  1006. this.ServeJSON()
  1007. }
  1008. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
  1009. utils.DownloadFile(url, "temp.xlsx", _dir)
  1010. t := time.Now()
  1011. filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/temp.xlsx"
  1012. xlFile, err := xlsx.OpenFile(filePath)
  1013. //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
  1014. if err != nil {
  1015. fmt.Printf("open failed: %s\n", err)
  1016. }
  1017. var sheet = xlFile.Sheets[0]
  1018. svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
  1019. Fstrs := svc.GetFCode()
  1020. Fstrs = "GoodsLevel,GoodsDesc,Standard,CompanyType," + Fstrs
  1021. columnArr := strings.Split(Fstrs, ",")
  1022. errLineNum := ""
  1023. codemap := make(map[string]int)
  1024. for i := 3; i < len(sheet.Rows); i++ {
  1025. cellsArr := sheet.Rows[i].Cells
  1026. parentId := 0
  1027. classId := 0
  1028. cellsArrLen := len(cellsArr)
  1029. cellD := strings.TrimSpace(cellsArr[3].String())
  1030. var valstr = ""
  1031. for idx, cell := range cellsArr {
  1032. if idx < 4 {
  1033. cellstr := cell.String()
  1034. //fmt.Printf("%s\n", cellstr)
  1035. if strings.TrimSpace(cellstr) == "" {
  1036. break
  1037. }
  1038. cellArr := strings.Fields(cellstr)
  1039. //id := sessionsvc.SelectGoodsAptitudeClassCode(cellArr[0])
  1040. var entity goodsaptitudeclass.Tmp_OilGoodsAptitudeClass
  1041. _, has := codemap[cellArr[0]]
  1042. if !has {
  1043. if idx != 0 {
  1044. upcellstr := cellsArr[idx -1].String()
  1045. upcellArr := strings.Fields(upcellstr)
  1046. parentId = codemap[upcellArr[0]]
  1047. }
  1048. entity.Code = cellArr[0]
  1049. entity.Name = cellArr[1]
  1050. entity.Edition = "1"
  1051. entity.ParentId = parentId
  1052. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1053. entity.CreateBy = this.User.Realname
  1054. entity.CreateOn = time.Now()
  1055. _, err := sessionsvc.InsertEntityBytbl(Tmp_OilGoodsAptitudeClassName, &entity)
  1056. if err != nil {
  1057. errLineNum += strconv.Itoa(i + 1) + ","
  1058. log.Println("Rollback1")
  1059. elapsed := time.Since(t)
  1060. fmt.Println(elapsed)
  1061. break
  1062. }
  1063. classId = entity.Id
  1064. if idx != 3 {
  1065. codemap[cellArr[0]] = entity.Id
  1066. }
  1067. }
  1068. }
  1069. if idx >= 4 {
  1070. valstr += "'" + cellsArr[idx].String() + "',"
  1071. }
  1072. }
  1073. if cellD != "" {
  1074. valstr = strings.Trim(valstr, ",")
  1075. valstr = strings.Replace(valstr, "是", "1", -1)
  1076. log.Println(cellsArr[3].String() + "==" + valstr)
  1077. var columnstr = ""
  1078. for l := 0; l < cellsArrLen - 4; l++ {
  1079. columnstr += columnArr[l] + ","
  1080. }
  1081. columnstr = strings.Trim(columnstr, ",")
  1082. err = sessionsvc.InsertTmpGoodsAptitude(strconv.Itoa(classId), columnstr, valstr)
  1083. if err != nil {
  1084. errLineNum += strconv.Itoa(i + 1) + ","
  1085. log.Println("Rollback2")
  1086. elapsed := time.Since(t)
  1087. fmt.Println(elapsed)
  1088. break
  1089. }
  1090. }
  1091. }
  1092. os.Remove(filePath)
  1093. if errLineNum != "" {
  1094. session.Rollback()
  1095. errorinfo.Code = -1
  1096. errorinfo.Message = "导入失败!错误行号:" + errLineNum
  1097. this.Data["json"] = &errorinfo
  1098. this.ServeJSON()
  1099. }
  1100. session.Commit()
  1101. elapsed := time.Since(t)
  1102. log.Println(elapsed)
  1103. errorinfo.Code = 0
  1104. errorinfo.Message = "导入成功!"
  1105. this.Data["json"] = &errorinfo
  1106. this.ServeJSON()
  1107. }
  1108. // @Title get 清空导入的信息
  1109. // @Description get SampleType by token
  1110. // @Success 200 {object} sampletype.SampleType
  1111. // @router /truncateimport [get]
  1112. func (this *OilGoodsAptitudeController) TruncateImport() {
  1113. session := utils.DBE.NewSession()
  1114. err := session.Begin()
  1115. defer session.Close()
  1116. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  1117. err = svc.TruncateTable(Tmp_OilGoodsAptitudeName)
  1118. var errorinfo ErrorInfo
  1119. if err != nil{
  1120. session.Rollback()
  1121. errorinfo.Code = -1
  1122. errorinfo.Message = "删除失败!"
  1123. this.Data["json"] = &errorinfo
  1124. this.ServeJSON()
  1125. }
  1126. err = svc.TruncateTable(Tmp_OilGoodsAptitudeClassName)
  1127. if err != nil{
  1128. session.Rollback()
  1129. errorinfo.Code = -1
  1130. errorinfo.Message = "删除失败!"
  1131. this.Data["json"] = &errorinfo
  1132. this.ServeJSON()
  1133. }
  1134. session.Commit()
  1135. errorinfo.Code = 0
  1136. errorinfo.Message = "删除成功!"
  1137. this.Data["json"] = &errorinfo
  1138. this.ServeJSON()
  1139. }
  1140. // @Title 将导入的数据 导入到正式表
  1141. // @Description get SampleType by token
  1142. // @Success 200 {object} sampletype.SampleType
  1143. // @router /insertgoodsaptitude [get]
  1144. func (this *OilGoodsAptitudeController) InsertGoodsAptitude() {
  1145. session := utils.DBE.NewSession()
  1146. err := session.Begin()
  1147. defer session.Close()
  1148. svc := goodsaptitude.GetOilGoodsAptitudeSession(session)
  1149. err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeName, OilGoodsAptitudeName)
  1150. var errinfo ErrorInfo
  1151. if err != nil {
  1152. session.Rollback()
  1153. errinfo.Code = -1
  1154. errinfo.Message = "跟新失败!"
  1155. this.Data["josn"] = &errinfo
  1156. this.ServeJSON()
  1157. }
  1158. err = svc.InsertGoodsAptitude(Tmp_OilGoodsAptitudeClassName, OilGoodsAptitudeClassName)
  1159. if err != nil {
  1160. session.Rollback()
  1161. errinfo.Code = -1
  1162. errinfo.Message = "跟新失败!"
  1163. this.Data["json"] = &errinfo
  1164. this.ServeJSON()
  1165. }
  1166. session.Commit()
  1167. errinfo.Code = 0
  1168. errinfo.Message = "跟新成功!"
  1169. this.Data["json"] = &errinfo
  1170. this.ServeJSON()
  1171. }