limscreatereport.go 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. package lims
  2. import (
  3. "dashoo.cn/backend/api/business/auditsetting"
  4. "dashoo.cn/backend/api/business/limscreatereport"
  5. "encoding/base64"
  6. "encoding/json"
  7. "fmt"
  8. "os"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "dashoo.cn/business2/organize"
  14. "dashoo.cn/business2/userRole"
  15. "dashoo.cn/backend/api/business/codecsequence"
  16. "dashoo.cn/backend/api/business/limsbalance"
  17. "dashoo.cn/backend/api/business/limsdataentry"
  18. "dashoo.cn/backend/api/business/limsdoctemplate"
  19. "dashoo.cn/backend/api/business/limsentrust"
  20. "dashoo.cn/backend/api/business/workflow"
  21. "github.com/360EntSecGroup-Skylar/excelize"
  22. . "github.com/linxGnu/goseaweedfs"
  23. "dashoo.cn/backend/api/business/Limsreportyyaqf"
  24. "dashoo.cn/backend/api/business/Limsreportzuhq"
  25. "dashoo.cn/backend/api/business/limsreportbeampumpingunits"
  26. "dashoo.cn/backend/api/business/limsreportelecground"
  27. "dashoo.cn/backend/api/business/limsreportequipotent"
  28. "dashoo.cn/backend/api/business/limsreporthuxf"
  29. "dashoo.cn/backend/api/business/limsreportkqpm"
  30. "dashoo.cn/backend/api/business/limsreportldbh"
  31. "dashoo.cn/backend/api/business/limsreportlp"
  32. "dashoo.cn/backend/api/business/limsreportnobeampumpingunits"
  33. . "dashoo.cn/backend/api/controllers"
  34. "dashoo.cn/utils"
  35. )
  36. type CreateReportController struct {
  37. BaseController
  38. }
  39. type RequestModel struct {
  40. ReportUrl string
  41. ReportAddress string
  42. ReportName string
  43. ReportId int
  44. }
  45. type ShenHeModel struct {
  46. ReportId int
  47. SuccessStatus int
  48. AuditorRemark string
  49. }
  50. type ReportCallback struct {
  51. Id string `json:"Id"`
  52. DocUrl string `json:"DocUrl"`
  53. }
  54. // @Title 获取报告分页列表
  55. // @Description 获取报告分页列表
  56. // @Success 200 {object} []createreport.LimsCreateReport
  57. // @router /list [get]
  58. func (this *CreateReportController) GetCreateReportList() {
  59. //获取分页信息
  60. page := this.GetPageInfoForm()
  61. orderby := "Id"
  62. asc := false
  63. Order := this.GetString("Order")
  64. Prop := this.GetString("Prop")
  65. if Order != "" && Prop != "" {
  66. orderby = Prop
  67. if Order == "asc" {
  68. asc = true
  69. }
  70. }
  71. ReportCode := this.GetString("ReportCode")
  72. ReportStatus := this.GetString("ReportStatus")
  73. CreateOn := this.GetString("CreateOn")
  74. TemplateName := this.GetString("TemplateName")
  75. ConUserBy := this.GetString("ConUserBy")
  76. where := " ReportStatus in (1,2,3,5) and CreateUserId = '" + this.User.Id + "'"
  77. if ReportCode != "" {
  78. where = where + " and ReportCode like '%" + ReportCode + "%'"
  79. }
  80. if ReportStatus != "" {
  81. where = where + " a nd ReportStatus = '" + ReportStatus + "'"
  82. }
  83. if TemplateName != "" {
  84. where = where + " and TemplateName like '%" + TemplateName + "%'"
  85. }
  86. if ConUserBy != "" {
  87. where = where + " and ConUserBy like '%" + ConUserBy + "%'"
  88. }
  89. if CreateOn != "" {
  90. dates := strings.Split(CreateOn, ",")
  91. if len(dates) == 2 {
  92. minDate := dates[0]
  93. maxDate := dates[1]
  94. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  95. }
  96. }
  97. var list []limscreatereport.LimsCreateReport
  98. svc := limscreatereport.GetCreateReportService(utils.DBE)
  99. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  100. var datainfo DataInfo
  101. datainfo.Items = list
  102. datainfo.CurrentItemCount = total
  103. this.Data["json"] = &datainfo
  104. this.ServeJSON()
  105. }
  106. // @Title 获取全部列表
  107. // @Description 获取全部列表
  108. // @Success 200 {object} []createreport.LimsCreateReport
  109. // @router /todolist [get]
  110. func (this *CreateReportController) GetCreateReportToDoList() {
  111. //获取分页信息
  112. page := this.GetPageInfoForm()
  113. orderby := "Id"
  114. asc := false
  115. Order := this.GetString("Order")
  116. Prop := this.GetString("Prop")
  117. if Order != "" && Prop != "" {
  118. orderby = Prop
  119. if Order == "asc" {
  120. asc = true
  121. }
  122. }
  123. ReportCode := this.GetString("ReportCode")
  124. ReportStatus := this.GetString("ReportStatus")
  125. CreateOn := this.GetString("CreateOn")
  126. TemplateName := this.GetString("TemplateName")
  127. ConUserBy := this.GetString("ConUserBy")
  128. //userSvc := userRole.GetUserService(utils.DBE)
  129. //organizeSvc := organize.GetOrganizeService(utils.DBE)
  130. //departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  131. //工作流获取代办事务
  132. svcActiviti := workflow.GetActivitiService(utils.DBE)
  133. var processInstanceId string
  134. var RoleSet auditsetting.Base_OilAuditSetting
  135. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  136. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTAUDIT, &RoleSet)
  137. processInstanceId = svcActiviti.GetMyTasks(RoleSet.WorkFlowCord, this.User.Id)
  138. //switch this.User.DepartmentId {
  139. //case "100000150":
  140. // processInstanceId = svcActiviti.GetMyTasks(workflow.TJZ_PROCESS_KEY, this.User.Id)
  141. //case "100000151":
  142. // processInstanceId = svcActiviti.GetMyTasks(workflow.YX_PROCESS_KEY, this.User.Id)
  143. //}
  144. ////取出当前部门及下级部门的所有用户列表
  145. //var subUserList []userRole.Base_User
  146. //whereUser := " 1=1 "
  147. //whereUser += " and Id in (" + processInstanceId + ")"
  148. //whereUser += " and DepartmentId in (" + departList + ")"
  149. //userSvc.GetEntities(&subUserList, whereUser)
  150. //var userIds string
  151. //
  152. //for _, tmpUser := range subUserList {
  153. // userIds += strconv.Itoa(tmpUser.Id) + ","
  154. //}
  155. //userIds = strings.Trim(userIds, ",")
  156. where := " 1=1 "
  157. where += " AND Id in (" + processInstanceId + ")"
  158. if ReportCode != "" {
  159. where = where + " and ReportCode like '%" + ReportCode + "%'"
  160. }
  161. if ReportStatus != "" {
  162. where = where + " and ReportStatus = '" + ReportStatus + "'"
  163. }
  164. if TemplateName != "" {
  165. where = where + " and TemplateName like '%" + TemplateName + "%'"
  166. }
  167. if ConUserBy != "" {
  168. where = where + " and ConUserBy like '%" + ConUserBy + "%'"
  169. }
  170. if CreateOn != "" {
  171. dates := strings.Split(CreateOn, ",")
  172. if len(dates) == 2 {
  173. minDate := dates[0]
  174. maxDate := dates[1]
  175. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  176. }
  177. }
  178. var list []limscreatereport.LimsCreateReport
  179. svc := limscreatereport.GetCreateReportService(utils.DBE)
  180. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  181. var datainfo DataInfo
  182. datainfo.Items = list
  183. datainfo.CurrentItemCount = total
  184. this.Data["json"] = &datainfo
  185. this.ServeJSON()
  186. }
  187. // @Title 获取全部列表
  188. // @Description 获取全部列表
  189. // @Success 200 {object} []createreport.LimsCreateReport
  190. // @router /alllist [get]
  191. func (this *CreateReportController) GetCreateReportAllList() {
  192. //获取分页信息
  193. page := this.GetPageInfoForm()
  194. orderby := "Id"
  195. asc := false
  196. Order := this.GetString("Order")
  197. Prop := this.GetString("Prop")
  198. if Order != "" && Prop != "" {
  199. orderby = Prop
  200. if Order == "asc" {
  201. asc = true
  202. }
  203. }
  204. ReportCode := this.GetString("ReportCode")
  205. ReportStatus := this.GetString("ReportStatus")
  206. CreateOn := this.GetString("CreateOn")
  207. TemplateName := this.GetString("TemplateName")
  208. ConUserBy := this.GetString("ConUserBy")
  209. userSvc := userRole.GetUserService(utils.DBE)
  210. organizeSvc := organize.GetOrganizeService(utils.DBE)
  211. departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  212. //取出当前部门及下级部门的所有用户列表
  213. var subUserList []userRole.Base_User
  214. whereUser := " 1=1 "
  215. whereUser += " and DepartmentId in (" + departList + ")"
  216. userSvc.GetEntities(&subUserList, whereUser)
  217. var userIds string
  218. for _, tmpUser := range subUserList {
  219. userIds += strconv.Itoa(tmpUser.Id) + ","
  220. }
  221. userIds = strings.Trim(userIds, ",")
  222. where := " 1=1 "
  223. where += " AND CreateUserId in (" + userIds + ")"
  224. if ReportCode != "" {
  225. where = where + " and ReportCode like '%" + ReportCode + "%'"
  226. }
  227. if ReportStatus != "" {
  228. where = where + " and ReportStatus = '" + ReportStatus + "'"
  229. }
  230. if TemplateName != "" {
  231. where = where + " and TemplateName like '%" + TemplateName + "%'"
  232. }
  233. if ConUserBy != "" {
  234. where = where + " and ConUserBy like '%" + ConUserBy + "%'"
  235. }
  236. if CreateOn != "" {
  237. dates := strings.Split(CreateOn, ",")
  238. if len(dates) == 2 {
  239. minDate := dates[0]
  240. maxDate := dates[1]
  241. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  242. }
  243. }
  244. var list []limscreatereport.LimsCreateReport
  245. svc := limscreatereport.GetCreateReportService(utils.DBE)
  246. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  247. var datainfo DataInfo
  248. datainfo.Items = list
  249. datainfo.CurrentItemCount = total
  250. this.Data["json"] = &datainfo
  251. this.ServeJSON()
  252. }
  253. // @Title 获取报告数量
  254. // @Description 获取报告数量
  255. // @Success 200 {object} []createreport.LimsCreateReport
  256. // @router /getreporttotal/:id [get]
  257. func (this *CreateReportController) GetReportTotal() {
  258. Id := this.Ctx.Input.Param(":id")
  259. where := "EId = '" + Id + "'"
  260. svc := limscreatereport.GetCreateReportService(utils.DBE)
  261. total := svc.GetReportCount(this.User.AccCode+LimsCreateReportName, where)
  262. var errinfo ErrorInfo
  263. errinfo.Code = total
  264. this.Data["json"] = &errinfo
  265. this.ServeJSON()
  266. }
  267. // @Title 获取报告Url
  268. // @Description 获取报告Url
  269. // @Success 200 {object} []createreport.LimsCreateReport
  270. // @router /getreporturl/:id [get]
  271. func (this *CreateReportController) GetReportUrl() {
  272. var reportlist []limscreatereport.ReportModel
  273. var reportrequest RequestModel
  274. var ReportUrl string
  275. Id := this.Ctx.Input.Param(":id")
  276. where := "a.Id = '" + Id + "'"
  277. order := " b.CreateOn desc"
  278. svc := limscreatereport.GetCreateReportService(utils.DBE)
  279. reportlist = svc.GetReportUrl(this.User.AccCode+LimsCreateReportName, this.User.AccCode+LimsReportHistoryName, order, where)
  280. if reportlist[0].UnHGReportUrl == "" {
  281. ReportUrl = reportlist[0].ReportUrl
  282. } else {
  283. ReportUrl = reportlist[0].UnHGReportUrl
  284. }
  285. reportrequest.ReportAddress = "http://" + ReportUrl
  286. reportrequest.ReportId = reportlist[0].Id
  287. reportrequest.ReportUrl = base64.RawURLEncoding.EncodeToString(quickStringByte(ReportUrl))
  288. reportname := strconv.Itoa(reportlist[0].Id) + "_" + reportlist[0].TemplateName + ".xlsx"
  289. reportrequest.ReportName = base64.RawURLEncoding.EncodeToString(quickStringByte(reportname))
  290. var errinfo ErrorDataInfo
  291. errinfo.Item = reportrequest
  292. this.Data["json"] = &errinfo
  293. this.ServeJSON()
  294. }
  295. // @Title 获取新增报告列表
  296. // @Description 获取新增报告列表
  297. // @Success 200 {object} []createreport.LimsCreateReport
  298. // @router /repoertentrustlist/ [get]
  299. func (this *CreateReportController) GetReportEntrustList() {
  300. //获取分页信息
  301. page := this.GetPageInfoForm()
  302. entrustno := this.GetString("entrustno")
  303. EntrustTypeId := this.GetString("EntrustTypeId")
  304. CustomerId := this.GetString("CustomerId")
  305. detectsampleId := this.GetString("DetectSampleId")
  306. EntrustStatus := this.GetString("EntrustStatus")
  307. EntrustTime := this.GetString("EntrustTime")
  308. ProjectTypeId := this.GetString("ProjectTypeId")
  309. orderby := "a.Id desc"
  310. userSvc := userRole.GetUserService(utils.DBE)
  311. organizeSvc := organize.GetOrganizeService(utils.DBE)
  312. departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  313. //取出当前部门及下级部门的所有用户列表
  314. var subUserList []userRole.Base_User
  315. whereUser := " 1=1 "
  316. whereUser += " and DepartmentId in (" + departList + ")"
  317. userSvc.GetEntities(&subUserList, whereUser)
  318. var userIds string
  319. for _, tmpUser := range subUserList {
  320. userIds += strconv.Itoa(tmpUser.Id) + ","
  321. }
  322. userIds = strings.Trim(userIds, ",")
  323. where := " 1=1 "
  324. where += " and a.CreateUserId in (" + userIds + ")"
  325. where += " AND c.CheckStatus = 4 and (a.ReportStatus = 0 or a.ReportStatus is NULL) and c.CreateReportStatus = 0 "
  326. if entrustno != "" {
  327. where = where + " and a.EntrustNo like '%" + entrustno + "%'"
  328. }
  329. if EntrustTypeId != "" {
  330. where = where + " and a.EntrustTypeId = '" + EntrustTypeId + "'"
  331. }
  332. if ProjectTypeId != "" {
  333. where = where + " and a.ProjectTypeId = '" + ProjectTypeId + "'"
  334. }
  335. if CustomerId != "" {
  336. where = where + " and a.CustomerId = '" + CustomerId + "'"
  337. }
  338. if detectsampleId != "" {
  339. where = where + " and a.DetectSampleId = '" + detectsampleId + "'"
  340. }
  341. if EntrustStatus != "" {
  342. where = where + " and a.EntrustStatus = '" + EntrustStatus + "'"
  343. }
  344. if EntrustTime != "" {
  345. dates := strings.Split(EntrustTime, ",")
  346. if len(dates) == 2 {
  347. minDate := dates[0]
  348. maxDate := dates[1]
  349. where = where + " and a.EntrustTime>='" + minDate + "' and a.EntrustTime<='" + maxDate + "'"
  350. }
  351. }
  352. var list []limscreatereport.DataEntryEntrustModel
  353. svc := limscreatereport.GetCreateReportService(utils.DBE)
  354. total, list := svc.GetDataEntryEntrust(this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsTaskBalanceName, this.User.AccCode+LimsEntrustMainName, page.CurrentPage, page.Size, orderby, where)
  355. var datainfo DataInfo
  356. datainfo.Items = list
  357. datainfo.CurrentItemCount = total
  358. this.Data["json"] = &datainfo
  359. this.ServeJSON()
  360. }
  361. // @Title 获取委托表详情
  362. // @Description 获取委托单详情
  363. // @Success 200 {object} []createreport.CreateReport
  364. // @router /dictlist/ [get]
  365. func (this *CreateReportController) GetDictOptions() {
  366. svc := limscreatereport.GetCreateReportService(utils.DBE)
  367. tableNameList := make(map[string]string)
  368. tableNameList["CustomerName"] = CustomerName
  369. tableNameList["TestPackageTypesName"] = TestPackageTypesName
  370. dictList := svc.GetDictList(this.User.AccCode, tableNameList)
  371. var datainfo DataInfo
  372. datainfo.Items = dictList
  373. this.Data["json"] = &datainfo
  374. this.ServeJSON()
  375. }
  376. // @Title 数据录入时生成报告
  377. // @Description 生成报告
  378. // @Success 200 {object} controllers.Request
  379. // @router /datatoexcelreport/ [post]
  380. func (this *CreateReportController) DataToExcelReport() {
  381. var jsonblob = this.Ctx.Input.RequestBody
  382. var reportlist limsdataentry.LimsDateEntryModel
  383. var datalist limscreatereport.DataEntryEntrustModel
  384. json.Unmarshal(jsonblob, &reportlist)
  385. datalist.Id = reportlist.EId
  386. datalist.EId = reportlist.EId
  387. datalist.DataEntryId = reportlist.Id
  388. datalist.TaskId = reportlist.TaskId
  389. datareportlist := []limscreatereport.DataEntryEntrustModel{
  390. datalist,
  391. }
  392. this.CreateReportN(datareportlist, 1)
  393. }
  394. // @Title 复检
  395. // @Description 报告复检生成数据录入
  396. // @Success 200 {object} controllers.Request
  397. // @router /recheck/[post]
  398. func (this *CreateReportController) Recheck() {
  399. ReCheckUser := this.GetString("ReCheckUser")
  400. RecheckUserId := this.GetString("ReCheckUserId")
  401. var jsonblob = this.Ctx.Input.RequestBody
  402. var errinfo ErrorDataInfo
  403. svcEntrust := limsentrust.GetLimsEnturstService(utils.DBE)
  404. var reportmodel limscreatereport.LimsCreateReport
  405. json.Unmarshal(jsonblob, &reportmodel)
  406. //获取模板的URL
  407. var docTemplate limsdataentry.LimsDocTemplate
  408. docTemplateList := svcEntrust.GetReportTemplateUrl(
  409. this.User.AccCode+LimsEntrustMainName,
  410. this.User.AccCode+TestPackageTypesName,
  411. this.User.AccCode+LimsDocTemplateName,
  412. strconv.Itoa(reportmodel.EId))
  413. if !reflect.ValueOf(docTemplateList).IsNil() && len(docTemplateList) > 0 {
  414. docTemplate = docTemplateList[0]
  415. } else {
  416. errinfo.Message = "报告模板不存在!"
  417. errinfo.Code = -1
  418. this.Data["json"] = &errinfo
  419. this.ServeJSON()
  420. return
  421. }
  422. svc := limscreatereport.GetCreateReportService(utils.DBE)
  423. var dataentrylist []limsdataentry.LimsDateEntry
  424. svc.GetEntitysByWhere(this.User.AccCode+LimsDateEntryName, "EId = '"+utils.ToStr(reportmodel.EId)+"'", &dataentrylist)
  425. dataentryId,TaskId:=svc.CreateDataentry(this.User.DepartmentId, this.User.AccCode, this.User.AccCode+LimsTaskBalanceName, this.User.AccCode+LimsEntrustMainName, this.User.AccCode+LimsDateEntryName,this.User.AccCode+LimsDocTemplateName,this.User.AccCode+LimsDocTemplateDetailName, reportmodel, dataentrylist[0].DataEntryCode, this.User.DepartmentId,RecheckUserId,ReCheckUser)
  426. //新增数据录入记录 开始工作流
  427. //更新报告状态
  428. var emptyEntity limscreatereport.LimsCreateReport
  429. emptyEntity.ReportStatus = 5
  430. svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, reportmodel.Id, &emptyEntity, []string{"ReportStatus"})
  431. //不合格的录入数据写入新生成的数据录入
  432. switch docTemplate.TemplateCode {
  433. //防雷装置报告
  434. case limsdoctemplate.DAYT_LIGHTPROTECT_REPORT:
  435. var lplist []limsreportlp.LimsReportLightProtect
  436. lpwhere := "EId = '" + utils.ToStr(reportmodel.EId) + "' and CheckResult = '×'"
  437. svc.GetEntitysByWhere(this.User.AccCode+LimsReportLightProtectName, lpwhere, &lplist)
  438. if len(lplist) == 0 {
  439. var errinfo ErrorDataInfo
  440. errinfo.Message = "数据为空"
  441. errinfo.Code = -1
  442. this.Data["json"] = &errinfo
  443. this.ServeJSON()
  444. return
  445. } else {
  446. for i := 0; i < len(lplist); i++ {
  447. var entity limsreportlp.LimsReportLightProtect
  448. entity = lplist[i]
  449. entity.CheckResult = ""
  450. entity.CreateOn = time.Now()
  451. entity.CreateBy = this.User.Realname
  452. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  453. entity.EId, _ = utils.StrTo(reportmodel.EId).Int()
  454. entity.DataEntryId, _ = utils.StrTo(dataentryId).Int()
  455. entity.TaskBalanceId, _ = utils.StrTo(TaskId).Int()
  456. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportLightProtectName, &entity)
  457. var errinfo ErrorDataInfo
  458. if err == nil {
  459. errinfo.Item = dataentryId
  460. errinfo.Message = "操作成功!"
  461. errinfo.Code = 0
  462. this.Data["json"] = &errinfo
  463. this.ServeJSON()
  464. } else {
  465. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  466. errinfo.Code = -1
  467. this.Data["json"] = &errinfo
  468. this.ServeJSON()
  469. }
  470. }
  471. }
  472. //防雷装置(等电位)报告
  473. case limsdoctemplate.DAYT_EQUIPOTENT_REPORT:
  474. var eqlist []limsreportequipotent.LimsReportEquipotent
  475. eqwhere := "EId = '" + utils.ToStr(reportmodel.EId) + "' and CheckResult = '×'"
  476. svc.GetEntitysByWhere(this.User.AccCode+LimsReportEquipotentName, eqwhere, &eqlist)
  477. if len(eqlist) == 0 {
  478. var errinfo ErrorDataInfo
  479. errinfo.Message = "数据为空"
  480. errinfo.Code = -1
  481. this.Data["json"] = &errinfo
  482. this.ServeJSON()
  483. return
  484. } else {
  485. for i := 0; i < len(eqlist); i++ {
  486. var entity limsreportequipotent.LimsReportEquipotent
  487. entity = eqlist[i]
  488. entity.CheckResult = ""
  489. entity.CreateOn = time.Now()
  490. entity.CreateBy = this.User.Realname
  491. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  492. entity.EId, _ = utils.StrTo(reportmodel.EId).Int()
  493. entity.DataEntryId, _ = utils.StrTo(dataentryId).Int()
  494. entity.TaskBalanceId, _ = utils.StrTo(TaskId).Int()
  495. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportEquipotentName, &entity)
  496. var errinfo ErrorDataInfo
  497. if err == nil {
  498. errinfo.Item = dataentryId
  499. errinfo.Message = "操作成功!"
  500. errinfo.Code = 0
  501. this.Data["json"] = &errinfo
  502. this.ServeJSON()
  503. } else {
  504. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  505. errinfo.Code = -1
  506. this.Data["json"] = &errinfo
  507. this.ServeJSON()
  508. }
  509. }
  510. }
  511. //电气接地装置报告
  512. case limsdoctemplate.DAYT_ELECGROUND_REPORT:
  513. var eglist []limsreportelecground.LimsReportElecGround
  514. egwhere := "EId = '" + utils.ToStr(reportmodel.EId) + "' and CheckResult = '×'"
  515. svc.GetEntitysByWhere( this.User.AccCode+LimsReportElecGroundName, egwhere, &eglist)
  516. if len(eglist) == 0 {
  517. var errinfo ErrorDataInfo
  518. errinfo.Message = "数据为空"
  519. errinfo.Code = -1
  520. this.Data["json"] = &errinfo
  521. this.ServeJSON()
  522. return
  523. } else {
  524. for i := 0; i < len(eglist); i++ {
  525. var entity limsreportelecground.LimsReportElecGround
  526. entity = eglist[i]
  527. entity.CheckResult = ""
  528. entity.CreateOn = time.Now()
  529. entity.CreateBy = this.User.Realname
  530. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  531. entity.EId, _ = utils.StrTo(reportmodel.EId).Int()
  532. entity.DataEntryId, _ = utils.StrTo(dataentryId).Int()
  533. entity.TaskBalanceId, _ = utils.StrTo(TaskId).Int()
  534. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportElecGroundName, &entity)
  535. var errinfo ErrorDataInfo
  536. if err == nil {
  537. errinfo.Item = dataentryId
  538. errinfo.Message = "操作成功!"
  539. errinfo.Code = 0
  540. this.Data["json"] = &errinfo
  541. this.ServeJSON()
  542. } else {
  543. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  544. errinfo.Code = -1
  545. this.Data["json"] = &errinfo
  546. this.ServeJSON()
  547. }
  548. }
  549. }
  550. //漏电保护检测报告
  551. case limsdoctemplate.DAYT_LEAKPROTECT_REPORT:
  552. var ldbhlist []limsreportldbh.LimsReportLeakProtect
  553. ldbhwhere := "EId = '" + utils.ToStr(reportmodel.EId) + "' and CheckResult = '×'"
  554. svc.GetEntitysByWhere(this.User.AccCode+LimsReportLeakProtectName, ldbhwhere, &ldbhlist)
  555. if len(ldbhlist) == 0 {
  556. var errinfo ErrorDataInfo
  557. errinfo.Message = "数据为空"
  558. errinfo.Code = -1
  559. this.Data["json"] = &errinfo
  560. this.ServeJSON()
  561. return
  562. } else {
  563. for i := 0; i < len(ldbhlist); i++ {
  564. var entity limsreportldbh.LimsReportLeakProtect
  565. entity = ldbhlist[i]
  566. entity.CheckResult = ""
  567. entity.CreateOn = time.Now()
  568. entity.CreateBy = this.User.Realname
  569. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  570. entity.EId, _ = utils.StrTo(reportmodel.EId).Int()
  571. entity.DataEntryId, _ = utils.StrTo(dataentryId).Int()
  572. entity.TaskBalanceId, _ = utils.StrTo(TaskId).Int()
  573. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportLeakProtectName, &entity)
  574. var errinfo ErrorDataInfo
  575. if err == nil {
  576. errinfo.Item = dataentryId
  577. errinfo.Message = "操作成功!"
  578. errinfo.Code = 0
  579. this.Data["json"] = &errinfo
  580. this.ServeJSON()
  581. } else {
  582. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  583. errinfo.Code = -1
  584. this.Data["json"] = &errinfo
  585. this.ServeJSON()
  586. }
  587. }
  588. }
  589. }
  590. }
  591. // @Title 生成报告
  592. // @Description 选中多条记录生成报告
  593. // @Success 200 {object} controllers.Request
  594. // @router /datatoexcelreportn/ [post]
  595. func (this *CreateReportController) DataToExcelReportN() {
  596. var jsonblob = this.Ctx.Input.RequestBody
  597. var datalist []limscreatereport.DataEntryEntrustModel
  598. json.Unmarshal(jsonblob, &datalist)
  599. var errinfo ErrorInfo
  600. taskid := datalist[0].TaskId
  601. if len(datalist) > 1 {
  602. for i := 1; i < len(datalist); i++ {
  603. if datalist[i].TaskId != taskid {
  604. errinfo.Message = "请选择相同的检测任务生成报告!"
  605. errinfo.Code = -1
  606. this.Data["json"] = &errinfo
  607. this.ServeJSON()
  608. return
  609. } else {
  610. this.CreateReportN(datalist, 0)
  611. break
  612. }
  613. }
  614. } else {
  615. this.CreateReportN(datalist, 0)
  616. }
  617. }
  618. /**
  619. * 选择多条记录生成报告
  620. */
  621. func (this *CreateReportController) CreateReportN(datalist []limscreatereport.DataEntryEntrustModel, datareportshow int) {
  622. var reportId int64
  623. var errinfo ErrorDataInfo
  624. var reportUrl string
  625. var UnHGReportUrl string
  626. var err error
  627. svcReport := limscreatereport.GetCreateReportService(utils.DBE)
  628. svcEntrust := limsentrust.GetLimsEnturstService(utils.DBE)
  629. //生成dataentryidlist
  630. var dataentryIds string
  631. for _, tmpUser := range datalist {
  632. dataentryIds += strconv.Itoa(tmpUser.DataEntryId) + ","
  633. }
  634. dataentryIds = strings.Trim(dataentryIds, ",")
  635. //获取模板的URL
  636. var docTemplate limsdataentry.LimsDocTemplate
  637. docTemplateList := svcEntrust.GetReportTemplateUrl(
  638. this.User.AccCode+LimsEntrustMainName,
  639. this.User.AccCode+TestPackageTypesName,
  640. this.User.AccCode+LimsDocTemplateName,
  641. strconv.Itoa(datalist[0].Id))
  642. if !reflect.ValueOf(docTemplateList).IsNil() && len(docTemplateList) > 0 {
  643. docTemplate = docTemplateList[0]
  644. } else {
  645. errinfo.Message = "报告模板不存在!"
  646. errinfo.Code = -1
  647. errinfo.Item = reportId
  648. this.Data["json"] = &errinfo
  649. this.ServeJSON()
  650. return
  651. }
  652. //判断是否有可生成的数据
  653. for _, listdata := range datalist {
  654. if listdata.CreateReportStatus == 1 {
  655. errinfo.Message = "此数据已生成报告,不能再生成!"
  656. errinfo.Code = -1
  657. errinfo.Item = reportId
  658. this.Data["json"] = &errinfo
  659. this.ServeJSON()
  660. return
  661. }
  662. }
  663. //获取任务委托实体
  664. var entrustMains []limsentrust.LimsEntrustMain
  665. var model limscreatereport.ReportTemplateModel
  666. whereStr := "id='" + strconv.Itoa(datalist[0].Id) + "'"
  667. svcEntrust.GetEntitysByWhere(this.User.AccCode+LimsEntrustMainName, whereStr, &entrustMains)
  668. wheretem := "a.id='" + strconv.Itoa(datalist[0].Id) + "'"
  669. model = svcReport.GetTemplate(this.User.AccCode+LimsEntrustMainName, this.User.AccCode+TestPackageTypesName, wheretem)
  670. //生成报告文档,返回URL地址
  671. reportUrl, UnHGReportUrl, err = this.generateExcelReportN(entrustMains[0], docTemplate, strconv.Itoa(datalist[0].Id), dataentryIds)
  672. fmt.Println(UnHGReportUrl)
  673. if len(reportUrl) > 0 && err == nil {
  674. this.ReportCreateThen(reportUrl, "", datalist, entrustMains, model, datareportshow, reportId, err)
  675. }
  676. if len(UnHGReportUrl) > 0 && err == nil {
  677. this.ReportCreateThen("", UnHGReportUrl, datalist, entrustMains, model, datareportshow, reportId, err)
  678. }
  679. }
  680. /**
  681. * 生成报告处理
  682. */
  683. func (this *CreateReportController) ReportCreateThen(reportUrl string, UnHGReportUrl string, datalist []limscreatereport.DataEntryEntrustModel, entrustMains []limsentrust.LimsEntrustMain, model limscreatereport.ReportTemplateModel, datareportshow int, reportId int64, err error) {
  684. var errinfo ErrorDataInfo
  685. svcReport := limscreatereport.GetCreateReportService(utils.DBE)
  686. //生成报告数据
  687. var reportEntity limscreatereport.LimsCreateReport
  688. reportEntity.ReportUrl = reportUrl
  689. reportEntity.UnHGReportUrl = UnHGReportUrl
  690. reportEntity.DocName = datalist[0].DocName
  691. reportEntity.EId, _ = utils.StrTo(strconv.Itoa(datalist[0].Id)).Int()
  692. reportEntity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  693. reportEntity.CreateBy = this.User.Realname
  694. reportEntity.CreateOn = time.Now()
  695. //reportEntity.ConUserOn = new(time.Time)
  696. //reportEntity.SignUserOn =new()
  697. reportEntity.TemplateId = model.TemplateId
  698. reportEntity.TestDetail = model.FullName
  699. reportEntity.CustomerId = model.CustomerId
  700. reportEntity.EntrustNo = model.EntrustNo
  701. reportEntity.CustomerName = model.CustomerName
  702. reportEntity.ReportCode = entrustMains[0].EntrustNo
  703. var emptyEntity limscreatereport.LimsCreateReport
  704. svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
  705. var users []userRole.Base_RoleList
  706. if datareportshow == 0 {
  707. reportId, err = svcReport.InsertEntityBytbl(this.User.AccCode+LimsCreateReportName, &reportEntity)
  708. //启动数据录入工作流
  709. svcActiviti := workflow.GetActivitiService(utils.DBE)
  710. var processInstanceId string
  711. var receiveVal string
  712. users = svc.GetUserByRole("10000184", this.User.AccCode)
  713. var userIds string
  714. for _, tmpUser := range users {
  715. userIds += strconv.FormatInt(tmpUser.Id, 10) + ","
  716. }
  717. userIds = strings.Trim(userIds, ",")
  718. var RoleSet auditsetting.Base_OilAuditSetting
  719. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  720. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTAUDIT, &RoleSet)
  721. processInstanceId = svcActiviti.StartProcess(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), this.User.Id)
  722. emptyEntity.FlowKey = processInstanceId
  723. err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, reportEntity.Id, &emptyEntity, []string{"FlowKey"})
  724. if UnHGReportUrl == "" {
  725. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), userIds, this.User.Id, "1", "合格报告审核")
  726. } else {
  727. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), userIds, this.User.Id, "1", "不合格报告审核")
  728. }
  729. if receiveVal == "true" {
  730. //报告生成将标志位变1
  731. for _, listdata := range datalist {
  732. listdata.CreateReportStatus = 1
  733. err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsDateEntryName, listdata.DataEntryId, &listdata, []string{"CreateReportStatus"})
  734. }
  735. if err == nil {
  736. errinfo.Message = "报告生成成功"
  737. errinfo.Code = 0
  738. errinfo.Item = reportEntity
  739. this.Data["json"] = &errinfo
  740. this.ServeJSON()
  741. } else {
  742. errinfo.Message = "报告生成发生错误!"
  743. errinfo.Code = -1
  744. this.Data["json"] = &errinfo
  745. this.ServeJSON()
  746. }
  747. } else {
  748. errinfo.Message = "工作流异常,请联系管理员!"
  749. errinfo.Code = -1
  750. this.Data["json"] = &errinfo
  751. this.ServeJSON()
  752. return
  753. }
  754. //switch this.User.DepartmentId {
  755. //case "100000150":
  756. // users = svc.GetUserByRole("10000184", this.User.AccCode)
  757. // var userIds string
  758. // for _, tmpUser := range users {
  759. // userIds += strconv.FormatInt(tmpUser.Id, 10) + ","
  760. // }
  761. // userIds = strings.Trim(userIds, ",")
  762. //
  763. // var RoleSet auditsetting.Base_OilAuditSetting
  764. // rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  765. // rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTAUDIT, &RoleSet)
  766. //
  767. // processInstanceId = svcActiviti.StartProcess(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), this.User.Id)
  768. // emptyEntity.FlowKey = processInstanceId
  769. // err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, reportEntity.Id, &emptyEntity, []string{"FlowKey"})
  770. // if UnHGReportUrl == "" {
  771. // receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), userIds, this.User.Id, "1", "特检合格报告审核")
  772. // } else {
  773. // receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(reportEntity.Id), userIds, this.User.Id, "1", "特检不合格报告审核")
  774. // }
  775. // if receiveVal == "true" {
  776. // //报告生成将标志位变1
  777. // for _, listdata := range datalist {
  778. // listdata.CreateReportStatus = 1
  779. // err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsDateEntryName, listdata.DataEntryId, &listdata, []string{"CreateReportStatus"})
  780. // }
  781. // if err == nil {
  782. // errinfo.Message = "报告生成成功"
  783. // errinfo.Code = 0
  784. // errinfo.Item = reportEntity
  785. // this.Data["json"] = &errinfo
  786. // this.ServeJSON()
  787. // } else {
  788. // errinfo.Message = "报告生成发生错误!"
  789. // errinfo.Code = -1
  790. // this.Data["json"] = &errinfo
  791. // this.ServeJSON()
  792. // }
  793. // } else {
  794. // errinfo.Message = "工作流异常,请联系管理员!"
  795. // errinfo.Code = -1
  796. // this.Data["json"] = &errinfo
  797. // this.ServeJSON()
  798. // return
  799. // }
  800. //case "100000151":
  801. // users = svc.GetUserByRole("10000182", this.User.AccCode)
  802. // var userIds string
  803. // for _, tmpUser := range users {
  804. // userIds += strconv.FormatInt(tmpUser.Id, 10) + ","
  805. // }
  806. // userIds = strings.Trim(userIds, ",")
  807. // processInstanceId = svcActiviti.StartProcess(workflow.YX_PROCESS_KEY, strconv.Itoa(reportEntity.Id), this.User.Id)
  808. // var emptyEntity limscreatereport.LimsCreateReport
  809. // emptyEntity.FlowKey = processInstanceId
  810. // err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, reportEntity.Id, &emptyEntity, []string{"FlowKey"})
  811. // receiveVal = svcActiviti.TaskComplete(workflow.YX_PROCESS_KEY, strconv.Itoa(reportEntity.Id), userIds, this.User.Id, "1", "宇信报告审核")
  812. // if receiveVal == "true" {
  813. // //报告生成将标志位变1
  814. // for _, listdata := range datalist {
  815. // listdata.CreateReportStatus = 1
  816. // err = svcReport.UpdateEntityBytbl(this.User.AccCode+LimsDateEntryName, listdata.DataEntryId, &listdata, []string{"CreateReportStatus"})
  817. // }
  818. // if err == nil {
  819. // errinfo.Message = "报告生成成功"
  820. // errinfo.Code = 0
  821. // errinfo.Item = reportEntity
  822. // this.Data["json"] = &errinfo
  823. // this.ServeJSON()
  824. // } else {
  825. // errinfo.Message = "报告生成发生错误!"
  826. // errinfo.Code = -1
  827. // this.Data["json"] = &errinfo
  828. // this.ServeJSON()
  829. // }
  830. // } else {
  831. // errinfo.Message = "工作流异常,请联系管理员!"
  832. // errinfo.Code = -1
  833. // this.Data["json"] = &errinfo
  834. // this.ServeJSON()
  835. // return
  836. // }
  837. //}
  838. } else {
  839. if err == nil {
  840. errinfo.Message = "报告生成成功"
  841. errinfo.Code = 0
  842. errinfo.Item = reportEntity
  843. this.Data["json"] = &errinfo
  844. this.ServeJSON()
  845. } else {
  846. errinfo.Message = "报告生成发生错误!"
  847. errinfo.Code = -1
  848. this.Data["json"] = &errinfo
  849. this.ServeJSON()
  850. }
  851. }
  852. }
  853. /**
  854. * 新加的报告模板在这个方法添加(选择多条生成报告)
  855. */
  856. func (this *CreateReportController) generateExcelReportN(entrustMain limsentrust.LimsEntrustMain,
  857. docTemplate limsdataentry.LimsDocTemplate, entrustId string, dataentryIds string) (reportUrl string, UnHGReportUrl string, err error) {
  858. switch docTemplate.TemplateCode {
  859. //呼吸阀检测报告
  860. case limsdoctemplate.DAYT_ATMOSVALVE_REPORT:
  861. //获取序列号
  862. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  863. seqStr := codecSvc.GetReportHuxfSequence(this.User.AccCode)
  864. svc := limsreporthuxf.GetLimsReportHuxfService(utils.DBE)
  865. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportHuxfName, this.User.AccCode+LimsSpecifyStandardName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  866. //阻火器报告
  867. case limsdoctemplate.DAYT_BACKFIRE_REPORT:
  868. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  869. seqStr := codecSvc.GetReportZuhqSequence(this.User.AccCode)
  870. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  871. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportZuhqName, this.User.AccCode+LimsPressureLeakName, this.User.AccCode+LimsSpecifyStandardName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  872. //空气泡沫产生器
  873. case limsdoctemplate.DAYT_AIRFOAMGENERATOR_REPORT:
  874. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  875. seqStr := codecSvc.GetReportKqpmSequence(this.User.AccCode)
  876. svc := limsreportkqpm.GetLimsReportkqpmService(utils.DBE)
  877. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportKqpmName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  878. //液压安全阀报告
  879. case limsdoctemplate.DAYT_HYDRAULICSAFE_REPORT:
  880. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  881. seqStr := codecSvc.GetReportYyaqfSequence(this.User.AccCode)
  882. svc := limsreportyyaqf.GetLimsReportYyaqfService(utils.DBE)
  883. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportYeyaqfName, this.User.AccCode+LimsSpecifyStandardName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  884. //游梁式抽油机检测报告
  885. case limsdoctemplate.DAYT_BEAMPUMPINGUNIT_REPORT:
  886. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  887. seqStr := codecSvc.GetDetailBeamPumpingUnitsSequence(this.User.AccCode)
  888. svc := limsreportbeampumpingunits.GetLimsReportBeamPumpingUnitsService(utils.DBE)
  889. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportBeamPumpingUnitName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  890. //无游梁式抽油机检测报告
  891. case limsdoctemplate.DAYT_NOBEAMPUMPINGUNIT_REPORT:
  892. codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  893. seqStr := codecSvc.GetDetailNoBeamPumpingUnitsSequence(this.User.AccCode)
  894. svc := limsreportnobeampumpingunits.GetLimsReportNoBeamPumpingUnitsService(utils.DBE)
  895. reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportNoBeamPumpingUnitName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  896. //防雷装置报告
  897. case limsdoctemplate.DAYT_LIGHTPROTECT_REPORT:
  898. seqStr := entrustMain.EntrustNo
  899. svc := limsreportlp.GetLimsReportLpService(utils.DBE)
  900. //数据写入excel 报告生成合格不合格两种
  901. reportUrl, err = svc.DataToExcelReport("○", entrustMain, this.User.AccCode+LimsReportLightProtectName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  902. UnHGReportUrl, err = svc.DataToExcelReport("×", entrustMain, this.User.AccCode+LimsReportLightProtectName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  903. //防雷装置(等电位)报告
  904. case limsdoctemplate.DAYT_EQUIPOTENT_REPORT:
  905. seqStr := entrustMain.EntrustNo
  906. svc := limsreportequipotent.GetLimsReportEquipotentService(utils.DBE)
  907. reportUrl, err = svc.DataToExcelReport("○",entrustMain, this.User.AccCode+LimsReportEquipotentName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  908. UnHGReportUrl, err = svc.DataToExcelReport("×",entrustMain, this.User.AccCode+LimsReportEquipotentName, this.User.AccCode+LimsDateEntryName,this.User.AccCode+LimsCreateReportName,BaseUserName,seqStr, docTemplate.FileURL, entrustId, this.User.Description,dataentryIds)
  909. //电气接地装置报告
  910. case limsdoctemplate.DAYT_ELECGROUND_REPORT:
  911. seqStr := entrustMain.EntrustNo
  912. svc := limsreportelecground.GetLimsReportElecGroundService(utils.DBE)
  913. reportUrl, err = svc.DataToExcelReport("○",entrustMain, this.User.AccCode+LimsReportElecGroundName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  914. UnHGReportUrl, err = svc.DataToExcelReport("×",entrustMain, this.User.AccCode+LimsReportElecGroundName,this.User.AccCode+LimsDateEntryName,this.User.AccCode+LimsCreateReportName,BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description,dataentryIds)
  915. //漏电保护检测报告
  916. case limsdoctemplate.DAYT_LEAKPROTECT_REPORT:
  917. seqStr := entrustMain.EntrustNo
  918. svc := limsreportldbh.GetLimsReportldbhService(utils.DBE)
  919. reportUrl, err = svc.DataToExcelReport("○",entrustMain, this.User.AccCode+LimsReportLeakProtectName, this.User.AccCode+LimsDateEntryName, this.User.AccCode+LimsCreateReportName, BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description, dataentryIds)
  920. UnHGReportUrl, err = svc.DataToExcelReport("×",entrustMain, this.User.AccCode+LimsReportLeakProtectName,this.User.AccCode+LimsDateEntryName,this.User.AccCode+LimsCreateReportName,BaseUserName, seqStr, docTemplate.FileURL, entrustId, this.User.Description,dataentryIds)
  921. }
  922. return reportUrl, UnHGReportUrl, err
  923. }
  924. // @Title 生成报告
  925. // @Description 判断是否已经生成了报告
  926. // @Success 200 {object} controllers.Request
  927. // @router /datatoexcelreport/:id [post]
  928. //func (this *CreateReportController) DataToExcelReport() {
  929. // entrustId := this.Ctx.Input.Param(":id")
  930. // svcReport := limscreatereport.GetCreateReportService(utils.DBE)
  931. // //判断同一个委托单是否已生成报告
  932. // where := "EId = '" + entrustId + "'"
  933. // total := svcReport.GetReportCount(this.User.AccCode+LimsCreateReportName, where)
  934. // if total == 0 {
  935. // //生成报告
  936. // this.CreateReport(entrustId)
  937. // } else {
  938. // err := svcReport.DeleteEntityBytbl(this.User.AccCode+LimsCreateReportName, where)
  939. // if err == nil {
  940. // //生成报告
  941. // this.CreateReport(entrustId)
  942. // } else {
  943. // fmt.Println("报告删除失败")
  944. // }
  945. // }
  946. //}
  947. // @Title 审核数字签名
  948. // @Description 审核数字签名
  949. // @Success 200 {object} controllers.Request
  950. // @router /signature [put]
  951. func (this *CreateReportController) Signature() {
  952. var reportmodel limscreatereport.LimsCreateReport
  953. var jsonblob = this.Ctx.Input.RequestBody
  954. var dataother limscreatereport.ShenheModel
  955. json.Unmarshal(jsonblob, &dataother)
  956. //审核成功
  957. if dataother.SuccessStatus == 1 {
  958. //循环选中的审核列表
  959. for i := 0; i < len(dataother.ApplyList); i++ {
  960. //通过模板Id查模板表
  961. svc := limscreatereport.GetCreateReportService(utils.DBE)
  962. var templateentity limsdoctemplate.LimsDocTemplate
  963. svc.GetEntityByIdBytbl(this.User.AccCode+LimsDocTemplateName, dataother.ApplyList[i].TemplateId, &templateentity)
  964. _dir := "./static/limsdoc/dataentry/doc/Report_" + strconv.Itoa(dataother.ApplyList[i].Id)
  965. //从文件服务器下载文件到_dir
  966. utils.DownloadFile("http://"+dataother.ApplyList[i].ReportUrl, strconv.Itoa(dataother.ApplyList[i].Id)+".xlsx", _dir)
  967. xlsx, err := excelize.OpenFile(_dir + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  968. if err != nil {
  969. fmt.Println(err)
  970. }
  971. //根据不同的模板进行不同的签名操作
  972. switch templateentity.TemplateCode {
  973. //呼吸阀检测报告
  974. case limsdoctemplate.DAYT_ATMOSVALVE_REPORT:
  975. //插入审核人签名
  976. pictureerr := xlsx.AddPicture("sheet3", "D22", "./"+this.User.Description, "")
  977. if pictureerr != nil {
  978. fmt.Println(pictureerr)
  979. }
  980. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  981. direrr := dexist(savedir)
  982. if direrr == nil {
  983. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  984. }
  985. //阻火器报告
  986. case limsdoctemplate.DAYT_BACKFIRE_REPORT:
  987. //插入审核人签名
  988. pictureerr := xlsx.AddPicture("sheet3", "E36", "./"+this.User.Description, "")
  989. if pictureerr != nil {
  990. fmt.Println(pictureerr)
  991. }
  992. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  993. direrr := dexist(savedir)
  994. if direrr == nil {
  995. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  996. }
  997. //防雷装置报告
  998. case limsdoctemplate.DAYT_LIGHTPROTECT_REPORT:
  999. //插入审核人签名
  1000. pictureerr := xlsx.AddPicture("sheet5", "E30", "./"+this.User.Description, "")
  1001. if pictureerr != nil {
  1002. fmt.Println(pictureerr)
  1003. }
  1004. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1005. direrr := dexist(savedir)
  1006. if direrr == nil {
  1007. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1008. }
  1009. //防雷装置(等电位)报告
  1010. case limsdoctemplate.DAYT_EQUIPOTENT_REPORT:
  1011. //插入审核人签名
  1012. pictureerr := xlsx.AddPicture("sheet5", "E26", "./"+this.User.Description, "")
  1013. if pictureerr != nil {
  1014. fmt.Println(pictureerr)
  1015. }
  1016. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1017. direrr := dexist(savedir)
  1018. if direrr == nil {
  1019. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1020. }
  1021. //电气接地装置报告
  1022. case limsdoctemplate.DAYT_ELECGROUND_REPORT:
  1023. //插入审核人签名
  1024. pictureerr := xlsx.AddPicture("sheet5", "E28", "./"+this.User.Description, "")
  1025. if pictureerr != nil {
  1026. fmt.Println(pictureerr)
  1027. }
  1028. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1029. direrr := dexist(savedir)
  1030. if direrr == nil {
  1031. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1032. }
  1033. //电流表检测报告
  1034. case limsdoctemplate.DAYT_AMMETER_REPORT:
  1035. //插入审核人签名
  1036. pictureerr := xlsx.AddPicture("sheet6", "F37", "./"+this.User.Description, "")
  1037. if pictureerr != nil {
  1038. fmt.Println(pictureerr)
  1039. }
  1040. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1041. direrr := dexist(savedir)
  1042. if direrr == nil {
  1043. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1044. }
  1045. //空气泡沫产生器
  1046. case limsdoctemplate.DAYT_AIRFOAMGENERATOR_REPORT:
  1047. //插入审核人签名
  1048. pictureerr := xlsx.AddPicture("sheet2", "D35", "./"+this.User.Description, "")
  1049. if pictureerr != nil {
  1050. fmt.Println(pictureerr)
  1051. }
  1052. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1053. direrr := dexist(savedir)
  1054. if direrr == nil {
  1055. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1056. }
  1057. //液压安全阀报告
  1058. case limsdoctemplate.DAYT_HYDRAULICSAFE_REPORT:
  1059. //插入审核人签名
  1060. pictureerr := xlsx.AddPicture("sheet2", "E35", "./"+this.User.Description, "")
  1061. if pictureerr != nil {
  1062. fmt.Println(pictureerr)
  1063. }
  1064. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1065. direrr := dexist(savedir)
  1066. if direrr == nil {
  1067. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1068. }
  1069. //游梁式抽油机检测报告
  1070. case limsdoctemplate.DAYT_NOBEAMPUMPINGUNIT_REPORT:
  1071. //插入审核人签名
  1072. pictureerr := xlsx.AddPicture("sheet2", "E35", "./"+this.User.Description, "")
  1073. if pictureerr != nil {
  1074. fmt.Println(pictureerr)
  1075. }
  1076. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1077. direrr := dexist(savedir)
  1078. if direrr == nil {
  1079. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1080. }
  1081. //漏电保护检测报告
  1082. case limsdoctemplate.DAYT_LEAKPROTECT_REPORT:
  1083. //插入审核人签名
  1084. pictureerr := xlsx.AddPicture("sheet5", "F37", "./"+this.User.Description, "")
  1085. if pictureerr != nil {
  1086. fmt.Println(pictureerr)
  1087. }
  1088. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id)
  1089. direrr := dexist(savedir)
  1090. if direrr == nil {
  1091. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx")
  1092. }
  1093. }
  1094. DocFilePath := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList[i].Id) + "/" + strconv.Itoa(dataother.ApplyList[i].Id) + ".xlsx"
  1095. //文件保存上传文件到服务器
  1096. var sw *Seaweed
  1097. var filer []string
  1098. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  1099. filer = []string{_filer}
  1100. }
  1101. sw = NewSeaweed("http", "weed1.labsop.cn:9333", filer, 2*1024*1024, 5*time.Minute)
  1102. _, _, fID, err := sw.UploadFile(DocFilePath, "", "")
  1103. if err != nil {
  1104. fmt.Println(err)
  1105. } else {
  1106. fmt.Println("-------Fid------", fID)
  1107. }
  1108. var entrustmodel limsentrust.LimsEntrustMain
  1109. //Daddress := "http://" + utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  1110. var entrustcols []string = []string{"ReportStatus"}
  1111. var cols []string = []string{"ReportStatus", "ConUserId", "ConUserBy", "ConUserOn"}
  1112. reportmodel.ReportStatus = dataother.SuccessStatus
  1113. reportmodel.ConUserId, _ = utils.StrTo(this.User.Id).Int()
  1114. reportmodel.ConUserBy = this.User.Realname
  1115. reportmodel.ConUserOn = time.Now()
  1116. entrustmodel.ReportStatus = dataother.SuccessStatus
  1117. svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, dataother.ApplyList[i].Id, reportmodel, cols)
  1118. where := "Id= '" + strconv.Itoa(dataother.ApplyList[i].EId) + "'"
  1119. svc.UpdateEntityBywheretbl(this.User.AccCode+LimsEntrustMainName, &entrustmodel, entrustcols, where)
  1120. var errinfo ErrorInfo
  1121. if err == nil {
  1122. errinfo.Message = "审核成功!"
  1123. errinfo.Code = 0
  1124. this.Data["json"] = &errinfo
  1125. this.ServeJSON()
  1126. } else {
  1127. errinfo.Message = "审核错误!"
  1128. errinfo.Code = -1
  1129. this.Data["json"] = &errinfo
  1130. this.ServeJSON()
  1131. }
  1132. }
  1133. }
  1134. }
  1135. /**
  1136. * 报告生成
  1137. */
  1138. //func (this *CreateReportController) CreateReport(entrustId string) {
  1139. // var reportId int64
  1140. // var errinfo ErrorDataInfo
  1141. // var reportUrl string
  1142. // var seqStr string
  1143. // var err error
  1144. // svcReport := limscreatereport.GetCreateReportService(utils.DBE)
  1145. // svcEntrust := limsentrust.GetLimsEnturstService(utils.DBE)
  1146. // //获取模板的URL
  1147. // var docTemplate limsdataentry.LimsDocTemplate
  1148. // docTemplateList := svcEntrust.GetReportTemplateUrl(
  1149. // this.User.AccCode+LimsEntrustMainName,
  1150. // this.User.AccCode+TestPackageTypesName,
  1151. // this.User.AccCode+LimsDocTemplateName,
  1152. // entrustId)
  1153. // if !reflect.ValueOf(docTemplateList).IsNil() && len(docTemplateList) > 0 {
  1154. // docTemplate = docTemplateList[0]
  1155. // } else {
  1156. // errinfo.Message = "报告模板不存在!"
  1157. // errinfo.Code = -1
  1158. // errinfo.Item = reportId
  1159. // this.Data["json"] = &errinfo
  1160. // this.ServeJSON()
  1161. // return
  1162. // }
  1163. // //获取任务委托实体
  1164. // var entrustMains []limsentrust.LimsEntrustMain
  1165. // var model limscreatereport.ReportTemplateModel
  1166. // whereStr := "id='" + entrustId + "'"
  1167. // svcEntrust.GetEntitysByWhere(this.User.AccCode+LimsEntrustMainName, whereStr, &entrustMains)
  1168. // wheretem := "a.id='" + entrustId + "'"
  1169. // model = svcReport.GetTemplate(this.User.AccCode+LimsEntrustMainName, this.User.AccCode+TestPackageTypesName, wheretem)
  1170. // //生成报告文档,返回URL地址
  1171. // reportUrl, seqStr, err = this.generateExcelReport(entrustMains[0], docTemplate, entrustId)
  1172. // if len(reportUrl) > 0 && err == nil {
  1173. // //生成报告数据
  1174. // var reportEntity limscreatereport.LimsCreateReport
  1175. // reportEntity.ReportUrl = reportUrl
  1176. // reportEntity.EId, _ = utils.StrTo(entrustId).Int()
  1177. // reportEntity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1178. // reportEntity.CreateBy = this.User.Realname
  1179. // reportEntity.CreateOn = time.Now()
  1180. // //reportEntity.ConUserOn = new(time.Time)
  1181. // //reportEntity.SignUserOn =new()
  1182. // reportEntity.TemplateId = model.TemplateId
  1183. // reportEntity.TemplateName = model.FullName
  1184. // reportEntity.CustomerId = model.CustomerId
  1185. // reportEntity.EntrustNo = model.EntrustNo
  1186. // reportEntity.CustomerName = model.CustomerName
  1187. // reportEntity.ReportCode = seqStr
  1188. // reportId, err = svcReport.InsertEntityBytbl(this.User.AccCode+LimsCreateReportName, &reportEntity)
  1189. // if err == nil {
  1190. // errinfo.Message = "报告生成成功"
  1191. // errinfo.Code = 0
  1192. // errinfo.Item = reportEntity
  1193. // this.Data["json"] = &errinfo
  1194. // this.ServeJSON()
  1195. // }
  1196. // //生成工作流事件
  1197. // /*svc := workflow.GetWorkflowService(utils.DBE)
  1198. // userSvc := baseUser.GetBaseUserService(utils.DBE)
  1199. // var userEntity userRole.Base_User
  1200. // userSvc.GetEntityById(this.User.Id, &userEntity)
  1201. // _, eventList, docID := svc.ReportDocumentCreate(
  1202. // userEntity.Email,
  1203. // reportEntity.TemplateName,
  1204. // strconv.Itoa(reportEntity.Id) )
  1205. // wfsvc := wfdocuemntevents.GetWfdocuemnteventsService(utils.DBE)
  1206. // var wfdocuemntevents wfdocuemntevents.WFDocuemntEvents
  1207. // wfdocuemntevents.BusType = "大港油田:报告审批"
  1208. // wfdocuemntevents.BusId = int(reportEntity.Id)
  1209. // wfdocuemntevents.DocumentId = int(docID)
  1210. // wfdocuemntevents.DoceventList = eventList
  1211. // wfdocuemntevents.CreateBy = this.User.Realname
  1212. // wfdocuemntevents.CreateUserId = this.User.Id
  1213. // wfdocuemntevents.CreateOn = time.Now()
  1214. // wfsvc.InsertEntity(wfdocuemntevents)*/
  1215. // }
  1216. // if err != nil {
  1217. // errinfo.Message = "报告生成失败!"
  1218. // errinfo.Code = -1
  1219. // this.Data["json"] = &errinfo
  1220. // this.ServeJSON()
  1221. // }
  1222. //}
  1223. /**
  1224. * 新加的报告模板在这个方法添加
  1225. */
  1226. //func (this *CreateReportController) generateExcelReport(entrustMain limsentrust.LimsEntrustMain,
  1227. // docTemplate limsdataentry.LimsDocTemplate, entrustId string) (reportUrl string, seqStr string, err error) {
  1228. //
  1229. // codecSvc := codecsequence.GetCodecSequenceService(utils.DBE)
  1230. // fmt.Println("-----code---", docTemplate.TemplateCode)
  1231. // switch docTemplate.TemplateCode {
  1232. // //呼吸阀检测报告
  1233. // case limsdoctemplate.DAYT_ATMOSVALVE_REPORT:
  1234. // //获取序列号
  1235. // seqStr = codecSvc.GetReportHuxfSequence(this.User.AccCode)
  1236. // svc := limsreporthuxf.GetLimsReportHuxfService(utils.DBE)
  1237. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportHuxfName,this.User.AccCode+LimsSpecifyStandardName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1238. // //阻火器报告
  1239. // case limsdoctemplate.DAYT_BACKFIRE_REPORT:
  1240. // seqStr = codecSvc.GetReportZuhqSequence(this.User.AccCode)
  1241. // svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  1242. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportZuhqName, this.User.AccCode+LimsPressureLeakName,this.User.AccCode+LimsSpecifyStandardName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1243. // //防雷装置报告
  1244. // //case limsdoctemplate.DAYT_LIGHTPROTECT_REPORT:
  1245. // // seqStr = codecSvc.GetReportLightProtectSequence(this.User.AccCode)
  1246. // // svc := limsreportlp.GetLimsReportLpService(utils.DBE)
  1247. // // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportLightProtectName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1248. //
  1249. // //防雷装置(等电位)报告
  1250. // case limsdoctemplate.DAYT_EQUIPOTENT_REPORT:
  1251. // seqStr = codecSvc.GetReportEquipotentSequence(this.User.AccCode)
  1252. // svc := limsreportequipotent.GetLimsReportEquipotentService(utils.DBE)
  1253. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportEquipotentName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1254. //
  1255. // //电气接地装置报告
  1256. // case limsdoctemplate.DAYT_ELECGROUND_REPORT:
  1257. // seqStr = codecSvc.GetReportElecGroundSequence(this.User.AccCode)
  1258. // svc := limsreportelecground.GetLimsReportElecGroundService(utils.DBE)
  1259. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportElecGroundName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1260. //
  1261. // //电流表检测报告
  1262. // case limsdoctemplate.DAYT_AMMETER_REPORT:
  1263. // seqStr = codecSvc.GetReportAmmeterSequence(this.User.AccCode)
  1264. // svc := limsreportammeter.GetLimsReportAmmeterService(utils.DBE)
  1265. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportAmmeterName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1266. //
  1267. // //空气泡沫产生器
  1268. // case limsdoctemplate.DAYT_AIRFOAMGENERATOR_REPORT:
  1269. // seqStr = codecSvc.GetReportKqpmSequence(this.User.AccCode)
  1270. // svc := limsreportkqpm.GetLimsReportkqpmService(utils.DBE)
  1271. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportKqpmName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1272. // //液压安全阀报告
  1273. // case limsdoctemplate.DAYT_HYDRAULICSAFE_REPORT:
  1274. // seqStr = codecSvc.GetReportYyaqfSequence(this.User.AccCode)
  1275. // svc := limsreportyyaqf.GetLimsReportYyaqfService(utils.DBE)
  1276. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportYeyaqfName,this.User.AccCode+LimsSpecifyStandardName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1277. // //游梁式抽油机检测报告
  1278. // case limsdoctemplate.DAYT_BEAMPUMPINGUNIT_REPORT:
  1279. // seqStr = codecSvc.GetReportBeamPumpingUnitsSequence(this.User.AccCode)
  1280. // svc := limsreportbeampumpingunits.GetLimsReportBeamPumpingUnitsService(utils.DBE)
  1281. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportBeamPumpingUnitName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1282. //
  1283. // //漏电保护检测报告
  1284. // case limsdoctemplate.DAYT_LEAKPROTECT_REPORT:
  1285. // seqStr = codecSvc.GetReportLeakProtectSequence(this.User.AccCode)
  1286. // svc := limsreportldbh.GetLimsReportldbhService(utils.DBE)
  1287. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportLeakProtectName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1288. //
  1289. // //无游梁式抽油机检测报告
  1290. // case limsdoctemplate.DAYT_NOBEAMPUMPINGUNIT_REPORT:
  1291. // seqStr = codecSvc.GetReportNoBeamPumpingUnitsSequence(this.User.AccCode)
  1292. // svc := limsreportnobeampumpingunits.GetLimsReportNoBeamPumpingUnitsService(utils.DBE)
  1293. // reportUrl, err = svc.DataToExcelReport(entrustMain, this.User.AccCode+LimsReportNoBeamPumpingUnitName, seqStr, docTemplate.FileURL, entrustId, this.User.Description)
  1294. // }
  1295. // return reportUrl, seqStr, err
  1296. //}
  1297. //文件是否存在判断
  1298. func dexist(_dir string) error {
  1299. //判断是否已经有文件路径
  1300. exist, patherr := utils.PathExists(_dir)
  1301. if patherr != nil {
  1302. fmt.Println(patherr)
  1303. }
  1304. var dirErr error
  1305. if !exist {
  1306. // 创建文件夹
  1307. dirErr = os.Mkdir(_dir, os.ModePerm)
  1308. }
  1309. return dirErr
  1310. }
  1311. // @Title 签发数字签名
  1312. // @Description 签发数字签名
  1313. // @Success 200 {object} controllers.Request
  1314. // @router /signtrans [put]
  1315. func (this *CreateReportController) SignTrans() {
  1316. var reportmodel limscreatereport.LimsCreateReport
  1317. var jsonblob = this.Ctx.Input.RequestBody
  1318. var dataother limscreatereport.QianfaModel
  1319. json.Unmarshal(jsonblob, &dataother)
  1320. //审核成功
  1321. if dataother.SuccessStatus == 2 {
  1322. //通过模板Id查模板表
  1323. svc := limscreatereport.GetCreateReportService(utils.DBE)
  1324. var templateentity limsdoctemplate.LimsDocTemplate
  1325. svc.GetEntityByIdBytbl(this.User.AccCode+LimsDocTemplateName, dataother.ApplyList.TemplateId, &templateentity)
  1326. _dir := "./static/limsdoc/dataentry/doc/Report_" + strconv.Itoa(dataother.ApplyList.Id)
  1327. //从文件服务器下载文件到_dir
  1328. utils.DownloadFile("http://"+dataother.ApplyList.ReportUrl, strconv.Itoa(dataother.ApplyList.Id)+".xlsx", _dir)
  1329. xlsx, err := excelize.OpenFile(_dir + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1330. if err != nil {
  1331. fmt.Println(err)
  1332. }
  1333. //根据不同的模板进行不同的签名操作
  1334. switch templateentity.TemplateCode {
  1335. //呼吸阀检测报告
  1336. case limsdoctemplate.DAYT_ATMOSVALVE_REPORT:
  1337. //插入审核人签名
  1338. pictureerr := xlsx.AddPicture("sheet3", "D22", "./"+this.User.Description, "")
  1339. if pictureerr != nil {
  1340. fmt.Println(pictureerr)
  1341. }
  1342. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1343. direrr := dexist(savedir)
  1344. if direrr == nil {
  1345. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1346. }
  1347. //阻火器报告
  1348. case limsdoctemplate.DAYT_BACKFIRE_REPORT:
  1349. //插入批准人签名
  1350. pictureerr := xlsx.AddPicture("sheet3", "E36", "./"+this.User.Description, "")
  1351. if pictureerr != nil {
  1352. fmt.Println(pictureerr)
  1353. }
  1354. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1355. direrr := dexist(savedir)
  1356. if direrr == nil {
  1357. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1358. }
  1359. //防雷装置报告
  1360. case limsdoctemplate.DAYT_LIGHTPROTECT_REPORT:
  1361. //插入批准人签名
  1362. pictureerr := xlsx.AddPicture("sheet5", "E30", "./"+this.User.Description, "")
  1363. if pictureerr != nil {
  1364. fmt.Println(pictureerr)
  1365. }
  1366. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1367. direrr := dexist(savedir)
  1368. if direrr == nil {
  1369. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1370. }
  1371. //防雷装置(等电位)报告
  1372. case limsdoctemplate.DAYT_EQUIPOTENT_REPORT:
  1373. //插入批准人签名
  1374. pictureerr := xlsx.AddPicture("sheet5", "E26", "./"+this.User.Description, "")
  1375. if pictureerr != nil {
  1376. fmt.Println(pictureerr)
  1377. }
  1378. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1379. direrr := dexist(savedir)
  1380. if direrr == nil {
  1381. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1382. }
  1383. //电气接地装置报告
  1384. case limsdoctemplate.DAYT_ELECGROUND_REPORT:
  1385. //插入批准人签名
  1386. pictureerr := xlsx.AddPicture("sheet5", "E28", "./"+this.User.Description, "")
  1387. if pictureerr != nil {
  1388. fmt.Println(pictureerr)
  1389. }
  1390. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1391. direrr := dexist(savedir)
  1392. if direrr == nil {
  1393. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1394. }
  1395. //电流表检测报告
  1396. case limsdoctemplate.DAYT_AMMETER_REPORT:
  1397. //插入批准人签名
  1398. pictureerr := xlsx.AddPicture("sheet6", "F37", "./"+this.User.Description, "")
  1399. if pictureerr != nil {
  1400. fmt.Println(pictureerr)
  1401. }
  1402. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1403. direrr := dexist(savedir)
  1404. if direrr == nil {
  1405. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1406. }
  1407. //空气泡沫产生器
  1408. case limsdoctemplate.DAYT_AIRFOAMGENERATOR_REPORT:
  1409. //插入批准人签名
  1410. pictureerr := xlsx.AddPicture("sheet2", "D35", "./"+this.User.Description, "")
  1411. if pictureerr != nil {
  1412. fmt.Println(pictureerr)
  1413. }
  1414. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1415. direrr := dexist(savedir)
  1416. if direrr == nil {
  1417. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1418. }
  1419. //液压安全阀报告
  1420. case limsdoctemplate.DAYT_HYDRAULICSAFE_REPORT:
  1421. //插入批准人签名
  1422. pictureerr := xlsx.AddPicture("sheet2", "E35", "./"+this.User.Description, "")
  1423. if pictureerr != nil {
  1424. fmt.Println(pictureerr)
  1425. }
  1426. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1427. direrr := dexist(savedir)
  1428. if direrr == nil {
  1429. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1430. }
  1431. //游梁式抽油机检测报告
  1432. case limsdoctemplate.DAYT_NOBEAMPUMPINGUNIT_REPORT:
  1433. //插入批准人签名
  1434. pictureerr := xlsx.AddPicture("sheet2", "E35", "./"+this.User.Description, "")
  1435. if pictureerr != nil {
  1436. fmt.Println(pictureerr)
  1437. }
  1438. savedir := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1439. direrr := dexist(savedir)
  1440. if direrr == nil {
  1441. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1442. }
  1443. //漏电保护检测报告
  1444. case limsdoctemplate.DAYT_LEAKPROTECT_REPORT:
  1445. //插入批准人签名
  1446. pictureerr := xlsx.AddPicture("sheet5", "C37", "./"+this.User.Description, "")
  1447. if pictureerr != nil {
  1448. fmt.Println(pictureerr)
  1449. }
  1450. savedir := "./static/limsdoc/dataentry/doc/SignReport_" + strconv.Itoa(dataother.ApplyList.Id)
  1451. direrr := dexist(savedir)
  1452. if direrr == nil {
  1453. xlsx.SaveAs("./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx")
  1454. }
  1455. }
  1456. DocFilePath := "./static/limsdoc/dataentry/doc/LastReport_" + strconv.Itoa(dataother.ApplyList.Id) + "/" + strconv.Itoa(dataother.ApplyList.Id) + ".xlsx"
  1457. //文件保存上传文件到服务器
  1458. var sw *Seaweed
  1459. var filer []string
  1460. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  1461. filer = []string{_filer}
  1462. }
  1463. sw = NewSeaweed("http", "weed1.labsop.cn:9333", filer, 2*1024*1024, 5*time.Minute)
  1464. _, _, fID, err := sw.UploadFile(DocFilePath, "", "")
  1465. if err != nil {
  1466. fmt.Println(err)
  1467. } else {
  1468. fmt.Println("-------Fid------", fID)
  1469. }
  1470. var entrustmodel limsentrust.LimsEntrustMain
  1471. var signmodel limscreatereport.LimsReportSign
  1472. Daddress := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  1473. var entrustcols []string = []string{"ReportStatus"}
  1474. var cols []string = []string{"ReportStatus", "ReportUrl", "SignUserId", "SignUserBy", "SignUserOn"}
  1475. reportmodel.ReportStatus = dataother.SuccessStatus
  1476. reportmodel.ReportUrl = Daddress
  1477. reportmodel.SignUserId, _ = utils.StrTo(this.User.Id).Int()
  1478. reportmodel.SignUserBy = this.User.Realname
  1479. reportmodel.SignUserOn = time.Now()
  1480. entrustmodel.ReportStatus = dataother.SuccessStatus
  1481. signmodel.ReportStatus = dataother.SuccessStatus
  1482. signmodel.ReportId = dataother.ApplyList.Id
  1483. signmodel.ReportName = dataother.ApplyList.ReportName
  1484. signmodel.SignTrans = dataother.ApplyList.SignTrans
  1485. signmodel.ReceiveBy = dataother.ApplyList.ReceiveBy
  1486. signmodel.Remark = dataother.AuditorRemark
  1487. signmodel.TransTime = dataother.ApplyList.TransTime
  1488. signmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1489. signmodel.CreateBy = this.User.Realname
  1490. signmodel.CreateOn = time.Now()
  1491. svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, dataother.ApplyList.Id, reportmodel, cols)
  1492. where := "Id= '" + strconv.Itoa(dataother.ApplyList.EId) + "'"
  1493. svc.UpdateEntityBywheretbl(this.User.AccCode+LimsEntrustMainName, &entrustmodel, entrustcols, where)
  1494. _, err = svc.InsertEntityBytbl(this.User.AccCode+LimsReportSignName, &signmodel)
  1495. var errinfo ErrorInfo
  1496. if err == nil {
  1497. errinfo.Message = "发送成功!"
  1498. errinfo.Code = 0
  1499. this.Data["json"] = &errinfo
  1500. this.ServeJSON()
  1501. } else {
  1502. errinfo.Message = "发送错误!"
  1503. errinfo.Code = -1
  1504. this.Data["json"] = &errinfo
  1505. this.ServeJSON()
  1506. }
  1507. }
  1508. }
  1509. // @Title 审核
  1510. // @Description 审核
  1511. // @Success 200 {object} controllers.Request
  1512. // @router /reportnumcheck/ [put]
  1513. func (this *CreateReportController) ShenHeReportCheck() {
  1514. svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
  1515. var jsonblob= this.Ctx.Input.RequestBody
  1516. var dataother ShenHeModel
  1517. var errinfo ErrorInfo
  1518. json.Unmarshal(jsonblob, &dataother)
  1519. var list []limscreatereport.LimsCreateReport
  1520. where := " Id = '" + strconv.Itoa(dataother.ReportId) + "'"
  1521. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1522. var reportlistall []limscreatereport.LimsCreateReport
  1523. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName," EId=" + utils.ToStr(list[0].EId) + "",&reportlistall)
  1524. if len(reportlistall)>1{
  1525. errinfo.Message = "确认报告审核不通过?"
  1526. errinfo.Code = 0
  1527. this.Data["json"] = &errinfo
  1528. this.ServeJSON()
  1529. }
  1530. }
  1531. // @Title 审核
  1532. // @Description 审核
  1533. // @Success 200 {object} controllers.Request
  1534. // @router /shenhereport/ [put]
  1535. func (this *CreateReportController) ShenHeReport() {
  1536. svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
  1537. var jsonblob = this.Ctx.Input.RequestBody
  1538. var dataother ShenHeModel
  1539. json.Unmarshal(jsonblob, &dataother)
  1540. var list []limscreatereport.LimsCreateReport
  1541. var users []userRole.Base_RoleList
  1542. //审核状态判断进行的操作
  1543. if dataother.SuccessStatus == 1 {
  1544. where := " Id = '" + strconv.Itoa(dataother.ReportId) + "'"
  1545. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1546. var entityempty limscreatereport.LimsCreateReport
  1547. var errinfo ErrorInfo
  1548. var cols []string = []string{"ReportStatus", "ConUserOn", "ConUserId", "ConUserBy", "CheckRemark"}
  1549. entityempty.ReportStatus = dataother.SuccessStatus
  1550. entityempty.ConUserOn = time.Now()
  1551. entityempty.ConUserId, _ = utils.StrTo(this.User.Id).Int()
  1552. entityempty.ConUserBy = this.User.Realname
  1553. entityempty.CheckRemark = dataother.AuditorRemark
  1554. //提交审核工作流
  1555. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1556. var receiveVal string
  1557. var RoleSet auditsetting.Base_OilAuditSetting
  1558. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  1559. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTISSUE, &RoleSet)
  1560. users = svc.GetUserByRole(strconv.Itoa(RoleSet.RoleId), this.User.AccCode)
  1561. var userIds string
  1562. for _, tmpUser := range users {
  1563. userIds += strconv.FormatInt(tmpUser.Id, 10) + ","
  1564. }
  1565. userIds = strings.Trim(userIds, ",")
  1566. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(dataother.ReportId), userIds, this.User.Id, "1", dataother.AuditorRemark)
  1567. if receiveVal == "true" {
  1568. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, list[0].Id, entityempty, cols)
  1569. if err == nil {
  1570. errinfo.Message = "通过审核!"
  1571. errinfo.Code = 0
  1572. this.Data["json"] = &errinfo
  1573. this.ServeJSON()
  1574. } else {
  1575. errinfo.Message = "审核错误!"
  1576. errinfo.Code = -1
  1577. this.Data["json"] = &errinfo
  1578. this.ServeJSON()
  1579. }
  1580. } else {
  1581. errinfo.Message = "工作流异常,请联系管理员!"
  1582. errinfo.Code = -1
  1583. this.Data["json"] = &errinfo
  1584. this.ServeJSON()
  1585. return
  1586. }
  1587. } else {
  1588. var errinfo ErrorInfo
  1589. where := " Id = '" + strconv.Itoa(dataother.ReportId) + "'"
  1590. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1591. var reportlistall []limscreatereport.LimsCreateReport
  1592. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName," EId=" + utils.ToStr(list[0].EId) + "",&reportlistall)
  1593. var entityempty limscreatereport.LimsCreateReport
  1594. entityempty.ReportStatus = dataother.SuccessStatus
  1595. entityempty.ConUserOn = time.Now()
  1596. entityempty.ConUserId, _ = utils.StrTo(this.User.Id).Int()
  1597. entityempty.ConUserBy = this.User.Realname
  1598. entityempty.CheckRemark = dataother.AuditorRemark
  1599. var cols []string = []string{"ReportStatus", "ConUserOn", "ConUserId", "ConUserBy", "CheckRemark"}
  1600. //提交审核工作流
  1601. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1602. var receiveVal string
  1603. var RoleSet auditsetting.Base_OilAuditSetting
  1604. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  1605. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTISSUE, &RoleSet)
  1606. for j:=0;j<len(reportlistall);j++{
  1607. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(reportlistall[j].Id), strconv.Itoa(reportlistall[j].CreateUserId), this.User.Id, "0", dataother.AuditorRemark)
  1608. if receiveVal == "true" {
  1609. for i:=0;i<len(reportlistall);i++{
  1610. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, reportlistall[i].Id, entityempty, cols)
  1611. if err == nil {
  1612. errinfo.Message = "未通过审核!"
  1613. errinfo.Code = 0
  1614. this.Data["json"] = &errinfo
  1615. this.ServeJSON()
  1616. } else {
  1617. errinfo.Message = "审核错误!"
  1618. errinfo.Code = -1
  1619. this.Data["json"] = &errinfo
  1620. this.ServeJSON()
  1621. }
  1622. }
  1623. } else {
  1624. errinfo.Message = "工作流异常,请联系管理员!"
  1625. errinfo.Code = -1
  1626. this.Data["json"] = &errinfo
  1627. this.ServeJSON()
  1628. return
  1629. }
  1630. }
  1631. var balanceentity limsbalance.LimsTaskBalance
  1632. var dataentryentity []limsdataentry.LimsDateEntry
  1633. var balanceentityempty limsbalance.LimsTaskBalance
  1634. var dataentryentityempty limsdataentry.LimsDateEntry
  1635. svc.GetEntityByWhere(this.User.AccCode+LimsTaskBalanceName," EId=" + utils.ToStr(list[0].EId) + "",&balanceentity)
  1636. var balancecols []string = []string{"DataEntryStatus"}
  1637. balanceentityempty.DataEntryStatus = 0
  1638. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsTaskBalanceName, balanceentity.Id, balanceentityempty, balancecols)
  1639. fmt.Println(err)
  1640. svc.GetEntitysByWhere(this.User.AccCode+LimsDateEntryName," EId=" + utils.ToStr(list[0].EId) + "",&dataentryentity)
  1641. for i:=0; i<len(dataentryentity) ;i++ {
  1642. var dataentrycols []string = []string{"CheckStatus","DocKey"}
  1643. dataentryentityempty.CheckStatus = 0
  1644. dataentryentityempty.CreateOn=time.Now()
  1645. //启动数据录入工作流
  1646. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1647. var processInstanceId string
  1648. processInstanceId=svcActiviti.StartProcess(RoleSet.WorkFlowCord, strconv.Itoa(dataentryentity[i].Id), strconv.Itoa(dataentryentity[i].CheckUserId))
  1649. dataentryentityempty.DocKey=processInstanceId
  1650. svc.UpdateEntityBytbl(this.User.AccCode+LimsDateEntryName, dataentryentity[i].Id, dataentryentityempty, dataentrycols)
  1651. }
  1652. }
  1653. }
  1654. // @Title 签发
  1655. // @Description 签发
  1656. // @Success 200 {object} controllers.Request
  1657. // @router /qianfareport/ [put]
  1658. func (this *CreateReportController) QianfaReport() {
  1659. svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
  1660. var jsonblob = this.Ctx.Input.RequestBody
  1661. var dataother ShenHeModel
  1662. json.Unmarshal(jsonblob, &dataother)
  1663. var list []limscreatereport.LimsCreateReport
  1664. var RoleSet auditsetting.Base_OilAuditSetting
  1665. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  1666. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTISSUE, &RoleSet)
  1667. //审核状态判断进行的操作
  1668. if dataother.SuccessStatus == 3 {
  1669. where := " Id = '" + strconv.Itoa(dataother.ReportId) + "'"
  1670. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1671. var entityempty limscreatereport.LimsCreateReport
  1672. var errinfo ErrorInfo
  1673. var cols []string = []string{"ReportStatus", "SignUserOn", "SignUserId", "SignUserBy", "SignRemark"}
  1674. entityempty.ReportStatus = dataother.SuccessStatus
  1675. entityempty.SignUserOn = time.Now()
  1676. entityempty.SignUserId, _ = utils.StrTo(this.User.Id).Int()
  1677. entityempty.SignUserBy = this.User.Realname
  1678. entityempty.SignRemark = dataother.AuditorRemark
  1679. //提交审核工作流
  1680. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1681. var receiveVal string
  1682. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(dataother.ReportId), "", this.User.Id, "1", dataother.AuditorRemark)
  1683. if receiveVal == "true" {
  1684. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, list[0].Id, entityempty, cols)
  1685. if err == nil {
  1686. errinfo.Message = "签发成功!"
  1687. errinfo.Code = 0
  1688. this.Data["json"] = &errinfo
  1689. this.ServeJSON()
  1690. } else {
  1691. errinfo.Message = "签发错误!"
  1692. errinfo.Code = -1
  1693. this.Data["json"] = &errinfo
  1694. this.ServeJSON()
  1695. }
  1696. } else {
  1697. errinfo.Message = "工作流异常,请联系管理员!"
  1698. errinfo.Code = -1
  1699. this.Data["json"] = &errinfo
  1700. this.ServeJSON()
  1701. return
  1702. }
  1703. } else {
  1704. where := " Id = '" + strconv.Itoa(dataother.ReportId) + "'"
  1705. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1706. var entityempty limscreatereport.LimsCreateReport
  1707. var errinfo ErrorInfo
  1708. entityempty.ReportStatus = dataother.SuccessStatus
  1709. entityempty.SignUserOn = time.Now()
  1710. entityempty.SignUserId, _ = utils.StrTo(this.User.Id).Int()
  1711. entityempty.SignUserBy = this.User.Realname
  1712. entityempty.SignRemark = dataother.AuditorRemark
  1713. var cols []string = []string{"ReportStatus", "SignUserOn", "SignUserId", "SignUserBy", "SignRemark"}
  1714. //提交审核工作流
  1715. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1716. var receiveVal string
  1717. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, strconv.Itoa(dataother.ReportId), strconv.Itoa(list[0].CreateUserId), this.User.Id, "0", dataother.AuditorRemark)
  1718. if receiveVal == "true" {
  1719. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCreateReportName, list[0].Id, entityempty, cols)
  1720. if err == nil {
  1721. errinfo.Message = "签发未通过!"
  1722. errinfo.Code = 0
  1723. this.Data["json"] = &errinfo
  1724. this.ServeJSON()
  1725. } else {
  1726. errinfo.Message = "签发错误!"
  1727. errinfo.Code = -1
  1728. this.Data["json"] = &errinfo
  1729. this.ServeJSON()
  1730. }
  1731. } else {
  1732. errinfo.Message = "工作流异常,请联系管理员!"
  1733. errinfo.Code = -1
  1734. this.Data["json"] = &errinfo
  1735. this.ServeJSON()
  1736. return
  1737. }
  1738. }
  1739. }
  1740. // @Title 报告修改回调
  1741. // @Description 报告修改回调
  1742. // @Success 200 {object} controllers.Request
  1743. // @router /reporteditcallback [post]
  1744. func (this *CreateReportController) ReportEditCallback() {
  1745. var callback ReportCallback
  1746. var jsonblob = this.Ctx.Input.RequestBody
  1747. json.Unmarshal(jsonblob, &callback)
  1748. fmt.Println("------reportcallback---", callback)
  1749. currentTime := time.Now().Format("060102150405") //当前时间
  1750. svc := limscreatereport.GetCreateReportService(utils.DBE)
  1751. var list []limscreatereport.LimsCreateReport
  1752. //dataentryid, _ := utils.StrTo(callback.Id).Int()
  1753. where := "Id= '" + callback.Id + "'"
  1754. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &list)
  1755. //生成文档历史表
  1756. var historylist []limscreatereport.LimsReportHistory
  1757. where2 := "ParentId= '" + callback.Id + "'"
  1758. svc.GetEntitysByOrderbyWhere(this.User.AccCode+LimsReportHistoryName, where2, " SaveTime asc ", &historylist)
  1759. var historyentity limscreatereport.LimsReportHistory
  1760. historyentity.ParentId, _ = utils.StrTo(callback.Id).Int()
  1761. historyentity.SaveTime = time.Now()
  1762. historyentity.CreateOn = time.Now()
  1763. historyentity.Version = "v" + currentTime
  1764. historyentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1765. historyentity.CreateBy = this.User.Realname
  1766. historyentity.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1767. historyentity.ModifiedBy = this.User.Realname
  1768. historyentity.Address = "http://" + callback.DocUrl
  1769. if len(historylist) >= 4 {
  1770. //删除历史数据
  1771. where3 := " Version = '" + historylist[0].Version + "'"
  1772. delerr := svc.DeleteEntityBytbl(this.User.AccCode+LimsReportHistoryName, where3)
  1773. if delerr != nil {
  1774. fmt.Println(delerr)
  1775. }
  1776. deldoc := os.Remove("././static/limsdoc/dataentry/doc" + historylist[0].Address)
  1777. if deldoc != nil {
  1778. fmt.Println(deldoc)
  1779. }
  1780. svc.InsertEntityBytbl(this.User.AccCode+LimsReportHistoryName, &historyentity)
  1781. } else {
  1782. svc.InsertEntityBytbl(this.User.AccCode+LimsReportHistoryName, &historyentity)
  1783. }
  1784. }
  1785. // @Title 报告删除回到数据录入初始状态
  1786. // @Description
  1787. // @Success 200 {object} ErrorInfo
  1788. // @Failure 403 :id 为空
  1789. // @router /reportdelect/:Id [delete]
  1790. func (this *CreateReportController) DelReport() {
  1791. Id := this.Ctx.Input.Param(":Id")
  1792. var errinfo ErrorInfo
  1793. svc := limscreatereport.GetCreateReportService(utils.DBE)
  1794. if Id == "" {
  1795. errinfo.Message = "操作失败!请求信息不完整"
  1796. errinfo.Code = -2
  1797. this.Data["json"] = &errinfo
  1798. this.ServeJSON()
  1799. return
  1800. }
  1801. var reportlist []limscreatereport.LimsCreateReport
  1802. where := " Id= " + Id
  1803. svc.GetEntitysByWhere(this.User.AccCode+LimsCreateReportName, where, &reportlist)
  1804. //修改数据录入状态
  1805. for i := 0; i < len(reportlist); i++ {
  1806. var dataentrymodel limsdataentry.LimsDateEntry
  1807. dataentrymodel.CreateReportStatus = 0
  1808. dataentrymodel.CheckStatus = 0
  1809. dawhere := " EId = '" + utils.ToStr(reportlist[i].EId) + "'"
  1810. svc.UpdateEntityBywheretbl(this.User.AccCode+LimsDateEntryName, &dataentrymodel, []string{"CreateReportStatus", "CheckStatus"}, dawhere)
  1811. }
  1812. //修改balance表
  1813. var balancemodel limsbalance.LimsTaskBalance
  1814. balancemodel.DataEntryStatus = 0
  1815. bawhere := " EId = '" + utils.ToStr(reportlist[0].EId) + "'"
  1816. svc.UpdateEntityBywheretbl(this.User.AccCode+LimsTaskBalanceName, &balancemodel, []string{"DataEntryStatus"}, bawhere)
  1817. //删除报告表数据
  1818. err := svc.DeleteEntityBytbl(this.User.AccCode+LimsCreateReportName, where)
  1819. if err == nil {
  1820. //提交审核工作流
  1821. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1822. var receiveVal string
  1823. var RoleSet auditsetting.Base_OilAuditSetting
  1824. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  1825. rsvc.GetAuditStepRoleEntity(OilAuditSettingName,this.User.DepartmentId,workflow.REPORTISSUE, &RoleSet)
  1826. receiveVal = svcActiviti.TaskComplete(RoleSet.WorkFlowCord, Id, "", this.User.Id, "0", "特检删除报告")
  1827. if receiveVal == "true" {
  1828. errinfo.Message = "删除成功"
  1829. errinfo.Code = 0
  1830. this.Data["json"] = &errinfo
  1831. this.ServeJSON()
  1832. } else {
  1833. errinfo.Message = "工作流异常,请联系管理员!"
  1834. errinfo.Code = -1
  1835. this.Data["json"] = &errinfo
  1836. this.ServeJSON()
  1837. return
  1838. }
  1839. } else {
  1840. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  1841. errinfo.Code = -1
  1842. this.Data["json"] = &errinfo
  1843. this.ServeJSON()
  1844. }
  1845. }