4
0

samplessource.go 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. // @Title 新增样本来源基本信息
  2. package biobank
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "github.com/tealeg/xlsx"
  10. "dashoo.cn/backend/api/business/codecsequence"
  11. "dashoo.cn/backend/api/business/donorsinfo"
  12. "dashoo.cn/backend/api/business/equipment"
  13. "dashoo.cn/backend/api/business/samplesfileinfo"
  14. "dashoo.cn/backend/api/business/samplesinfo"
  15. "dashoo.cn/backend/api/business/samplessource"
  16. "dashoo.cn/backend/api/business/sampletest"
  17. //"dashoo.cn/backend/api/business/authcode"
  18. . "dashoo.cn/backend/api/controllers"
  19. "dashoo.cn/utils"
  20. )
  21. type SamplesSourceController struct {
  22. BaseController
  23. }
  24. // @Title 获取样本来源列表
  25. // @Description get user by token
  26. // @Success 200 {object} models.Userblood
  27. // @router /samplessourcelist [get]
  28. func (this *SamplesSourceController) SamplesSourceList() {
  29. page := this.GetPageInfoForm()
  30. idcard := this.GetString("idcard")
  31. name := this.GetString("name")
  32. telephone := this.GetString("telephone")
  33. innerno := this.GetString("innerno")
  34. starttimeint, _ := this.GetInt64("starttimeint")
  35. endtimeint, _ := this.GetInt64("endtimeint")
  36. var list []samplessource.DonorsInfo
  37. svc := samplessource.GetSamplesSourceService(utils.DBE)
  38. where := " 1=1"
  39. orderby := "CreateOn"
  40. asc := false
  41. Order := this.GetString("Order")
  42. Prop := this.GetString("Prop")
  43. if Order != "" && Prop != "" {
  44. orderby = Prop
  45. if Order == "asc" {
  46. asc = true
  47. }
  48. }
  49. if idcard != "" {
  50. where = where + " and IDCard = '" + idcard + "'"
  51. }
  52. if name != "" {
  53. where = where + " and Name like '%" + name + "%'"
  54. }
  55. if telephone != "" {
  56. where = where + " and Telephone = '" + telephone + "'"
  57. }
  58. if innerno != "" {
  59. where = where + " and InnerNo = '" + innerno + "'"
  60. }
  61. if starttimeint > 0 {
  62. where = where + " and CreateOn >'" + time.Unix(starttimeint/1000, 0).Format("2006-01-02") + "'"
  63. }
  64. if endtimeint > 0 {
  65. where = where + " and CreateOn <'" + time.Unix(endtimeint/1000, 0).Format("2006-01-02") + " 23:59:59'"
  66. }
  67. // CreateBy := this.GetString("CreateBy")
  68. // if CreateBy != "" {
  69. // where = where + " and CreateBy like '%" + CreateBy + "%'"
  70. // }
  71. // CreateUserId := this.GetString("CreateUserId")
  72. // if CreateUserId != "" {
  73. // where = where + " and CreateUserId =" + CreateUserId + " "
  74. // }
  75. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  76. var datainfo DataInfo
  77. datainfo.Items = list
  78. datainfo.CurrentItemCount = total
  79. this.Data["json"] = &datainfo
  80. this.ServeJSON()
  81. }
  82. // @Title 删除样本来源信息
  83. // @Description
  84. // @Success 200 {object} ErrorInfo
  85. // @Failure 403 :id 为空
  86. // @router /deldonors/:id [delete]
  87. func (this *SamplesSourceController) DelDonors() {
  88. id := this.Ctx.Input.Param(":id")
  89. idcard := this.GetString("idcard")
  90. var errinfo ErrorInfo
  91. if id == "" {
  92. errinfo.Message = "操作失败!请求信息不完整"
  93. errinfo.Code = -2
  94. this.Data["json"] = &errinfo
  95. this.ServeJSON()
  96. return
  97. }
  98. var entity samplessource.DonorsInfo
  99. var entityempty samplessource.DonorsInfo
  100. opdesc := "删除样本来源-" + idcard
  101. svc := samplessource.GetSamplesSourceService(utils.DBE)
  102. err := svc.DeleteDonorAndWriteLogBytbl(this.User.AccCode+DonorstbName, this.User.AccCode+DonorslogtbName, id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, entity.Name)
  103. if err == nil {
  104. errinfo.Message = "删除成功"
  105. errinfo.Code = 0
  106. this.Data["json"] = &errinfo
  107. this.ServeJSON()
  108. } else {
  109. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  110. errinfo.Code = -1
  111. this.Data["json"] = &errinfo
  112. this.ServeJSON()
  113. }
  114. }
  115. // @Title 获取客户基本信息
  116. // @Description get user by token
  117. // @Success 200 {object} models.Userblood
  118. // @router /getbasicinfo [get]
  119. func (this *SamplesSourceController) GetBasicDetail() {
  120. Id := this.GetString("Id")
  121. var entity samplessource.DonorsInfo
  122. svc := samplessource.GetSamplesSourceService(utils.DBE)
  123. where := " Id ='" + Id + "'"
  124. svc.GetEntityByWhere(this.User.AccCode+DonorstbName, where, &entity)
  125. var datainfo DataInfo
  126. datainfo.Items = entity
  127. this.Data["json"] = &datainfo
  128. this.ServeJSON()
  129. }
  130. // @Title 新增样本来源基本信息
  131. // @Success 200 {object}
  132. // @router /savebasic [post]
  133. func (this *SamplesSourceController) AddBasic() {
  134. var model donorsinfo.DonorsInfo
  135. var jsonblob = this.Ctx.Input.RequestBody
  136. json.Unmarshal(jsonblob, &model)
  137. model.AccCode = this.User.AccCode
  138. model.CreateBy = this.User.Realname
  139. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  140. svc := samplessource.GetSamplesSourceService(utils.DBE)
  141. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorstbName, &model)
  142. var errinfo ErrorDataInfo
  143. if err == nil {
  144. errinfo.Message = "操作成功!"
  145. errinfo.Code = 0
  146. errinfo.Item = model.Id
  147. this.Data["json"] = &errinfo
  148. this.ServeJSON()
  149. } else {
  150. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  151. errinfo.Code = -1
  152. this.Data["json"] = &errinfo
  153. this.ServeJSON()
  154. }
  155. }
  156. // @Title 更新客户基本信息
  157. // @Description 更新客户基本信息
  158. // @Param id path string true "需要修改的试管信息"
  159. // @Success 200 {object} controllers.Request
  160. // @router /editbasic/:id [put]
  161. func (this *SamplesSourceController) EditBasic() {
  162. id := this.Ctx.Input.Param(":id")
  163. var errinfo ErrorInfo
  164. if id == "" {
  165. errinfo.Message = "操作失败!请求信息不完整"
  166. errinfo.Code = -2
  167. this.Data["json"] = &errinfo
  168. this.ServeJSON()
  169. return
  170. }
  171. var model donorsinfo.DonorsInfo
  172. var jsonblob = this.Ctx.Input.RequestBody
  173. json.Unmarshal(jsonblob, &model)
  174. var entity donorsinfo.DonorsInfo
  175. model.ModifiedBy = this.User.Realname
  176. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  177. svc := samplessource.GetSamplesSourceService(utils.DBE)
  178. var cols []string = []string{"IdCard", "InnerNo", "Name", "CompanyName", "Sex", "Duty", "Birthday",
  179. "Age", "Telephone", "Email", "Nation", "HomeAddress", "MaritalStatus", "PathologicalNum",
  180. "IllnessName", "Remark", "ModifiedBy", "ModifiedUserId"}
  181. // sva := donorsinfo.GetDonorsInfoService(utils.DBE)
  182. zback := svc.QueryZBackList(this.User.AccCode)
  183. for i := 0; i < (len(zback)); i++ {
  184. cols = append(cols, zback[i].Id)
  185. }
  186. opdesc := "修改样本来源-" + model.Name
  187. err := svc.UpdateDonorAndWriteLogBytbl(this.User.AccCode+DonorstbName, this.User.AccCode+DonorslogtbName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, model.Name)
  188. if err == nil {
  189. var list []samplesinfo.SamplesMain
  190. where_list := "SourceId = '" + strconv.Itoa(model.Id) + "'"
  191. svc.GetEntitysByWhere(this.User.AccCode+SamplesMaintbName, where_list, &list)
  192. if len(list) > 0 {
  193. for i := 0; i < len(list); i++ {
  194. var SamEntity samplesinfo.SamplesMain
  195. where_sam := "MId = '" + strconv.Itoa(list[i].MId) + "'"
  196. SamEntity.SourceName = model.Name
  197. SamEntity.MCreateBy = this.User.Username
  198. SamEntity.MCreateUserId, _ = utils.StrTo(this.User.Id).Int()
  199. var cols_sam []string = []string{"SourceName", "ModifiedBy", "ModifiedUserId"}
  200. svc.UpdateEntityBywheretbl(this.User.AccCode+SamplesMaintbName, &SamEntity, cols_sam, where_sam)
  201. }
  202. }
  203. }
  204. if err == nil {
  205. errinfo.Message = "操作成功!"
  206. errinfo.Code = 0
  207. this.Data["json"] = &errinfo
  208. this.ServeJSON()
  209. } else {
  210. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  211. errinfo.Code = -1
  212. this.Data["json"] = &errinfo
  213. this.ServeJSON()
  214. }
  215. }
  216. // @Title 获取检测信息
  217. // @Description get user by token
  218. // @Success 200 {object} models.Userblood
  219. // @router /getsampletestlist/:id [get]
  220. func (this *SamplesSourceController) Getsampletestlist() {
  221. id := this.Ctx.Input.Param(":id")
  222. var entity []sampletest.SampleTestMain
  223. svc := samplessource.GetSamplesSourceService(utils.DBE)
  224. where := " SourceId ='" + id + "'"
  225. svc.GetEntitysByWhere(this.User.AccCode+SampleTestMainName, where, &entity)
  226. var datainfo DataInfo
  227. datainfo.Items = entity
  228. this.Data["json"] = &datainfo
  229. this.ServeJSON()
  230. }
  231. // @Title 获取检测详情
  232. // @Description get user by token
  233. // @Success 200 {object} models.Userblood
  234. // @router /getsampletestdetaillist/:InspectionNum [get]
  235. func (this *SamplesSourceController) Getsampletestdetaillist() {
  236. InspectionNum := this.Ctx.Input.Param(":InspectionNum")
  237. var entity []sampletest.SampleTestDetail
  238. svc := samplessource.GetSamplesSourceService(utils.DBE)
  239. where := " InspectionNum ='" + InspectionNum + "'"
  240. svc.GetEntitysByWhere(this.User.AccCode+SampleTestDetailName, where, &entity)
  241. var datainfo DataInfo
  242. datainfo.Items = entity
  243. this.Data["json"] = &datainfo
  244. this.ServeJSON()
  245. }
  246. // @Title 获取病理检测信息
  247. // @Description get user by token
  248. // @Success 200 {object} models.Userblood
  249. // @router /pathologylist/:id [get]
  250. func (this *SamplesSourceController) GetPathologyList() {
  251. id := this.Ctx.Input.Param(":id")
  252. var entity []donorsinfo.DonorsDetail
  253. svc := samplessource.GetSamplesSourceService(utils.DBE)
  254. where := " ParentId ='" + id + "' and Type = 3"
  255. svc.GetEntitysByWhere(this.User.AccCode+DonorsDetailName, where, &entity)
  256. var datainfo DataInfo
  257. datainfo.Items = entity
  258. this.Data["json"] = &datainfo
  259. this.ServeJSON()
  260. }
  261. // @Title 添加病理信息
  262. // @Success 200 {object} controllers.Request
  263. // @router /addpathology [post]
  264. func (this *SamplesSourceController) AddPathology() {
  265. ParentId, _ := this.GetInt("ParentId")
  266. IdCard := this.GetString("IdCard")
  267. var model donorsinfo.DonorsDetail
  268. var jsonblob = this.Ctx.Input.RequestBody
  269. json.Unmarshal(jsonblob, &model)
  270. model.ParentId = ParentId
  271. model.IdCard = IdCard
  272. model.CreateBy = this.User.Realname
  273. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  274. svc := samplessource.GetSamplesSourceService(utils.DBE)
  275. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorsDetailName, &model)
  276. var errinfo ErrorDataInfo
  277. if err == nil {
  278. errinfo.Message = "操作成功!"
  279. errinfo.Code = 0
  280. errinfo.Item = model.Id
  281. this.Data["json"] = &errinfo
  282. this.ServeJSON()
  283. } else {
  284. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  285. errinfo.Code = -1
  286. this.Data["json"] = &errinfo
  287. this.ServeJSON()
  288. }
  289. }
  290. // @Title 添加病理信息关联HIS
  291. // @Success 200 {object} controllers.Request
  292. // @router /pathologyadd [post]
  293. func (this *SamplesSourceController) PathologyAdd() {
  294. Name := this.GetString("Name")
  295. Sex, _ := this.GetInt("Sex")
  296. Age, _ := this.GetInt("Age")
  297. var model donorsinfo.DonorsPathology
  298. var jsonblob = this.Ctx.Input.RequestBody
  299. json.Unmarshal(jsonblob, &model)
  300. var entity donorsinfo.DonorsInfo
  301. entity.Name = Name
  302. entity.Sex = Sex
  303. entity.Age = Age
  304. entity.CreateBy = this.User.Realname
  305. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  306. svc := samplessource.GetSamplesSourceService(utils.DBE)
  307. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorstbName, &entity)
  308. if err == nil {
  309. var entitydetail donorsinfo.DonorsDetail
  310. entitydetail.ParentId = entity.Id
  311. entitydetail.PathologicalNum = model.PathologicalNum
  312. entitydetail.DiagnosticTime = model.DiagnosticTime
  313. entitydetail.AdmissionNumber = model.AdmissionNumber
  314. entitydetail.CheckNum = model.CheckNum
  315. entitydetail.Department = model.Department
  316. entitydetail.IllnessName = model.IllnessName
  317. entitydetail.Type = model.Type
  318. entitydetail.CreateBy = this.User.Realname
  319. entitydetail.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  320. svc.InsertEntityBytbl(this.User.AccCode+DonorsDetailName, &entitydetail)
  321. }
  322. var errinfo ErrorDataInfo
  323. if err == nil {
  324. errinfo.Message = "操作成功!"
  325. errinfo.Code = 0
  326. errinfo.Item = entity.Id
  327. this.Data["json"] = &errinfo
  328. this.ServeJSON()
  329. } else {
  330. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  331. errinfo.Code = -1
  332. this.Data["json"] = &errinfo
  333. this.ServeJSON()
  334. }
  335. }
  336. // @Title 更新病理信息信息
  337. // @Description 更新病理信息信息
  338. // @Param id path string true
  339. // @Success 200 {object} controllers.Request
  340. // @router /editpathology/:id [put]
  341. func (this *SamplesSourceController) EditPathology() {
  342. id := this.Ctx.Input.Param(":id")
  343. var errinfo ErrorInfo
  344. if id == "" {
  345. errinfo.Message = "操作失败!请求信息不完整"
  346. errinfo.Code = -2
  347. this.Data["json"] = &errinfo
  348. this.ServeJSON()
  349. return
  350. }
  351. var model donorsinfo.DonorsDetail
  352. var jsonblob = this.Ctx.Input.RequestBody
  353. json.Unmarshal(jsonblob, &model)
  354. model.ModifiedBy = this.User.Realname
  355. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  356. svc := samplessource.GetSamplesSourceService(utils.DBE)
  357. where := " Id ='" + id + "'"
  358. var cols []string = []string{"PathologicalNum", "CheckPoint", "DiagnosticTime", "Department", "AdmissionNumber", "BedNum", "CheckNum", "ClinicalDiagnosis", "IllnessName", "ModifiedBy", "ModifiedUserId"}
  359. err := svc.UpdateEntityBywheretbl(this.User.AccCode+DonorsDetailName, &model, cols, where)
  360. if err == nil {
  361. errinfo.Message = "操作成功!"
  362. errinfo.Code = 0
  363. this.Data["json"] = &errinfo
  364. this.ServeJSON()
  365. } else {
  366. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  367. errinfo.Code = -1
  368. this.Data["json"] = &errinfo
  369. this.ServeJSON()
  370. }
  371. }
  372. // @Title 获取手术信息列表
  373. // @Description get user by token
  374. // @Success 200 {object} models.Userblood
  375. // @router /operationlist/:id [get]
  376. func (this *SamplesSourceController) GetOperationList() {
  377. id := this.Ctx.Input.Param(":id")
  378. var entity []donorsinfo.DonorsDetail
  379. svc := samplessource.GetSamplesSourceService(utils.DBE)
  380. where := " ParentId ='" + id + "' and Type = 1"
  381. svc.GetEntitysByWhere(this.User.AccCode+DonorsDetailName, where, &entity)
  382. var datainfo DataInfo
  383. datainfo.Items = entity
  384. this.Data["json"] = &datainfo
  385. this.ServeJSON()
  386. }
  387. // @Title 添加手术记录
  388. // @Success 200 {object} controllers.Request
  389. // @router /addoperation [post]
  390. func (this *SamplesSourceController) AddOperation() {
  391. ParentId, _ := this.GetInt("ParentId")
  392. IdCard := this.GetString("IdCard")
  393. var model donorsinfo.DonorsDetail
  394. var jsonblob = this.Ctx.Input.RequestBody
  395. json.Unmarshal(jsonblob, &model)
  396. model.ParentId = ParentId
  397. model.IdCard = IdCard
  398. model.CreateBy = this.User.Realname
  399. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  400. svc := samplessource.GetSamplesSourceService(utils.DBE)
  401. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorsDetailName, &model)
  402. var errinfo ErrorDataInfo
  403. if err == nil {
  404. errinfo.Message = "操作成功!"
  405. errinfo.Code = 0
  406. errinfo.Item = model.Id
  407. this.Data["json"] = &errinfo
  408. this.ServeJSON()
  409. } else {
  410. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  411. errinfo.Code = -1
  412. this.Data["json"] = &errinfo
  413. this.ServeJSON()
  414. }
  415. }
  416. // @Title 更新手术信息
  417. // @Description 更新手术信息
  418. // @Param id path string true
  419. // @Success 200 {object} controllers.Request
  420. // @router /editoperation/:id [put]
  421. func (this *SamplesSourceController) EditOperation() {
  422. id := this.Ctx.Input.Param(":id")
  423. var errinfo ErrorInfo
  424. if id == "" {
  425. errinfo.Message = "操作失败!请求信息不完整"
  426. errinfo.Code = -2
  427. this.Data["json"] = &errinfo
  428. this.ServeJSON()
  429. return
  430. }
  431. var model donorsinfo.DonorsDetail
  432. var jsonblob = this.Ctx.Input.RequestBody
  433. json.Unmarshal(jsonblob, &model)
  434. model.ModifiedBy = this.User.Realname
  435. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  436. svc := samplessource.GetSamplesSourceService(utils.DBE)
  437. where := " Id ='" + id + "'"
  438. var cols []string = []string{"OperationName", "OperativeSite", "Diagnosis", "OperationTime", "Leader", "Operator", "Hospital", "Department", "ModifiedBy", "BedNum", "Detail", "ModifiedUserId"}
  439. err := svc.UpdateEntityBywheretbl(this.User.AccCode+DonorsDetailName, &model, cols, where)
  440. if err == nil {
  441. errinfo.Message = "操作成功!"
  442. errinfo.Code = 0
  443. this.Data["json"] = &errinfo
  444. this.ServeJSON()
  445. } else {
  446. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  447. errinfo.Code = -1
  448. this.Data["json"] = &errinfo
  449. this.ServeJSON()
  450. }
  451. }
  452. // @Title 获取筛查信息列表
  453. // @Description get user by token
  454. // @Success 200 {object} models.Userblood
  455. // @router /screeninglist/:id [get]
  456. func (this *SamplesSourceController) GetScreeningList() {
  457. id := this.Ctx.Input.Param(":id")
  458. var entity []donorsinfo.DonorsDetail
  459. svc := samplessource.GetSamplesSourceService(utils.DBE)
  460. where := " ParentId ='" + id + "' and Type = 2"
  461. svc.GetEntitysByWhere(this.User.AccCode+DonorsDetailName, where, &entity)
  462. var datainfo DataInfo
  463. datainfo.Items = entity
  464. this.Data["json"] = &datainfo
  465. this.ServeJSON()
  466. }
  467. // @Title 添加筛查记录
  468. // @Success 200 {object} controllers.Request
  469. // @router /addscreening [post]
  470. func (this *SamplesSourceController) AddScreening() {
  471. ParentId, _ := this.GetInt("ParentId")
  472. IdCard := this.GetString("IdCard")
  473. var model donorsinfo.DonorsDetail
  474. var jsonblob = this.Ctx.Input.RequestBody
  475. json.Unmarshal(jsonblob, &model)
  476. model.ParentId = ParentId
  477. model.IdCard = IdCard
  478. model.CreateBy = this.User.Realname
  479. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  480. svc := samplessource.GetSamplesSourceService(utils.DBE)
  481. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorsDetailName, &model)
  482. var errinfo ErrorDataInfo
  483. if err == nil {
  484. errinfo.Message = "操作成功!"
  485. errinfo.Code = 0
  486. errinfo.Item = model.Id
  487. this.Data["json"] = &errinfo
  488. this.ServeJSON()
  489. } else {
  490. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  491. errinfo.Code = -1
  492. this.Data["json"] = &errinfo
  493. this.ServeJSON()
  494. }
  495. }
  496. // @Title 更新筛查信息
  497. // @Description 更新筛查信息
  498. // @Param id path string true
  499. // @Success 200 {object} controllers.Request
  500. // @router /editscreening/:id [put]
  501. func (this *SamplesSourceController) EditScreening() {
  502. id := this.Ctx.Input.Param(":id")
  503. var errinfo ErrorInfo
  504. if id == "" {
  505. errinfo.Message = "操作失败!请求信息不完整"
  506. errinfo.Code = -2
  507. this.Data["json"] = &errinfo
  508. this.ServeJSON()
  509. return
  510. }
  511. var model donorsinfo.DonorsDetail
  512. var jsonblob = this.Ctx.Input.RequestBody
  513. json.Unmarshal(jsonblob, &model)
  514. model.ModifiedBy = this.User.Realname
  515. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  516. svc := samplessource.GetSamplesSourceService(utils.DBE)
  517. where := " Id ='" + id + "'"
  518. var cols []string = []string{"ScreeningSite", "ScreeningType", "ScreeningTime", "Instrument", "Ultrasonic", "Ultrasound", "Record", "Description", "ModifiedBy", "BedNum", "Detail", "ModifiedUserId"}
  519. err := svc.UpdateEntityBywheretbl(this.User.AccCode+DonorsDetailName, &model, cols, where)
  520. if err == nil {
  521. errinfo.Message = "操作成功!"
  522. errinfo.Code = 0
  523. this.Data["json"] = &errinfo
  524. this.ServeJSON()
  525. } else {
  526. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  527. errinfo.Code = -1
  528. this.Data["json"] = &errinfo
  529. this.ServeJSON()
  530. }
  531. }
  532. // @Title 删除手术信息及筛查信息
  533. // @Description
  534. // @Success 200 {object} ErrorInfo
  535. // @Failure 403 :id 为空
  536. // @router /delopescr/:Id [delete]
  537. func (this *SamplesSourceController) DelOpeScr() {
  538. Id := this.Ctx.Input.Param(":Id")
  539. var errinfo ErrorInfo
  540. if Id == "" {
  541. errinfo.Message = "操作失败!请求信息不完整"
  542. errinfo.Code = -2
  543. this.Data["json"] = &errinfo
  544. this.ServeJSON()
  545. return
  546. }
  547. where := " Id= " + Id
  548. svc := samplessource.GetSamplesSourceService(utils.DBE)
  549. err := svc.DeleteEntityBytbl(this.User.AccCode+DonorsDetailName, where)
  550. if err == nil {
  551. errinfo.Message = "删除成功"
  552. errinfo.Code = 0
  553. this.Data["json"] = &errinfo
  554. this.ServeJSON()
  555. } else {
  556. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  557. errinfo.Code = -1
  558. this.Data["json"] = &errinfo
  559. this.ServeJSON()
  560. }
  561. }
  562. // @Title 获取影像信息列表
  563. // @Description get user by token
  564. // @Success 200 {object} models.Userblood
  565. // @router /imagelist/:id [get]
  566. func (this *SamplesSourceController) GetImageList() {
  567. id := this.Ctx.Input.Param(":id")
  568. var entity []donorsinfo.DonorsDetail
  569. svc := samplessource.GetSamplesSourceService(utils.DBE)
  570. where := " ParentId ='" + id + "' and Type = 0"
  571. svc.GetEntitysByWhere(this.User.AccCode+DonorsDetailName, where, &entity)
  572. var datainfo DataInfo
  573. datainfo.Items = entity
  574. this.Data["json"] = &datainfo
  575. this.ServeJSON()
  576. }
  577. // @Title 添加影像信息
  578. // @Success 200 {object}
  579. // @router /addimage [post]
  580. func (this *SamplesSourceController) AddImage() {
  581. ParentId, _ := this.GetInt("ParentId")
  582. IdCard := this.GetString("IdCard")
  583. var model donorsinfo.DonorsDetail
  584. var jsonblob = this.Ctx.Input.RequestBody
  585. json.Unmarshal(jsonblob, &model)
  586. model.ParentId = ParentId
  587. model.IdCard = IdCard
  588. model.CreateBy = this.User.Realname
  589. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  590. svc := samplessource.GetSamplesSourceService(utils.DBE)
  591. _, err := svc.InsertEntityBytbl(this.User.AccCode+DonorsDetailName, &model)
  592. var errinfo ErrorDataInfo
  593. if err == nil {
  594. errinfo.Message = "操作成功!"
  595. errinfo.Code = 0
  596. errinfo.Item = model.Id
  597. this.Data["json"] = &errinfo
  598. this.ServeJSON()
  599. } else {
  600. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  601. errinfo.Code = -1
  602. this.Data["json"] = &errinfo
  603. this.ServeJSON()
  604. }
  605. }
  606. // @Title 更新影像信息
  607. // @Description 更新筛查信息
  608. // @Param id path string true
  609. // @Success 200 {object} controllers.Request
  610. // @router /editimage/:id [put]
  611. func (this *SamplesSourceController) EditImage() {
  612. id := this.Ctx.Input.Param(":id")
  613. var errinfo ErrorInfo
  614. if id == "" {
  615. errinfo.Message = "操作失败!请求信息不完整"
  616. errinfo.Code = -2
  617. this.Data["json"] = &errinfo
  618. this.ServeJSON()
  619. return
  620. }
  621. var model donorsinfo.DonorsDetail
  622. var jsonblob = this.Ctx.Input.RequestBody
  623. json.Unmarshal(jsonblob, &model)
  624. model.ModifiedBy = this.User.Realname
  625. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  626. svc := samplessource.GetSamplesSourceService(utils.DBE)
  627. where := " Id ='" + id + "'"
  628. var cols []string = []string{"ImageSite", "ImageType", "Office", "ImageTime", "ImageDes", "FileUrl", "ModifiedBy", "ModifiedUserId"}
  629. err := svc.UpdateEntityBywheretbl(this.User.AccCode+DonorsDetailName, &model, cols, where)
  630. if err == nil {
  631. errinfo.Message = "操作成功!"
  632. errinfo.Code = 0
  633. this.Data["json"] = &errinfo
  634. this.ServeJSON()
  635. } else {
  636. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  637. errinfo.Code = -1
  638. this.Data["json"] = &errinfo
  639. this.ServeJSON()
  640. }
  641. }
  642. // @Title 获取动物样本来源列表
  643. // @Description get user by token
  644. // @Success 200 {object} models.Userblood
  645. // @router /animallist [get]
  646. func (this *SamplesSourceController) AnimalList() {
  647. page := this.GetPageInfoForm()
  648. var list []samplessource.AnimalInfo
  649. genus := this.GetString("Genus")
  650. name := this.GetString("Name")
  651. innerno := this.GetString("InnerNo")
  652. SurveyDate := this.GetString("SurveyDate")
  653. CreateOn := this.GetString("CreateOn")
  654. SourceType := this.GetString("SourceType")
  655. ProjectName := this.GetString("ProjectName")
  656. Address := this.GetString("Address")
  657. AuditorStatus := this.GetString("AuditorStatus")
  658. AuditorName := this.GetString("AuditorName")
  659. svc := samplessource.GetSamplesSourceService(utils.DBE)
  660. where := " 1=1"
  661. orderby := " CreateOn "
  662. asc := false
  663. Order := this.GetString("Order")
  664. Prop := this.GetString("Prop")
  665. if Order != "" && Prop != "" {
  666. orderby = Prop
  667. if Order == "asc" {
  668. asc = true
  669. }
  670. }
  671. if genus != "" {
  672. where = where + " and Genus = '" + genus + "'"
  673. }
  674. if name != "" {
  675. where = where + " and Name like '%" + name + "%'"
  676. }
  677. if innerno != "" {
  678. where = where + " and InnerNo like '%" + innerno + "%'"
  679. }
  680. if SurveyDate != "" {
  681. dates := strings.Split(SurveyDate, ",")
  682. if len(dates) == 2 {
  683. minDate := dates[0]
  684. maxDate := dates[1]
  685. where = where + " and SurveyDate>='" + minDate + "' and SurveyDate<='" + maxDate + "'"
  686. }
  687. }
  688. if CreateOn != "" {
  689. dates := strings.Split(CreateOn, ",")
  690. if len(dates) == 2 {
  691. minDate := dates[0]
  692. maxDate := dates[1]
  693. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  694. }
  695. }
  696. if SourceType != "" {
  697. where = where + " and SourceType = '" + SourceType + "'"
  698. }
  699. if ProjectName != "" {
  700. where = where + " and ProjectName = '" + ProjectName + "'"
  701. }
  702. if Address != "" {
  703. where = where + " and ( ProvinceName like '%" + Address + "% or CityName like '%" + Address + "% or StreetName like '%" + Address + "% or Address like '%" + Address + "%)'"
  704. }
  705. if AuditorStatus != "" {
  706. where = where + " and AuditorStatus = '" + AuditorStatus + "'"
  707. }
  708. if AuditorName != "" {
  709. where = where + " and AuditorName = '" + AuditorName + "'"
  710. }
  711. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  712. var datainfo DataInfo
  713. datainfo.Items = list
  714. datainfo.CurrentItemCount = total
  715. this.Data["json"] = &datainfo
  716. this.ServeJSON()
  717. }
  718. // @Title 判断内部编码存在
  719. // @Description get user by token
  720. // @Success 200 {object} models.Userblood
  721. // @router /innernomakesure [get]
  722. func (this *SamplesSourceController) InnerNoMakeSure() {
  723. InnerNo := this.GetString("InnerNo")
  724. svc := samplessource.GetSamplesSourceService(utils.DBE)
  725. where := " InnerNo= '" + InnerNo + "'"
  726. total := svc.GetInnerNo(this.User.AccCode+AnimaltbName, where)
  727. var datainfo DataInfo
  728. datainfo.Items = total
  729. this.Data["json"] = &datainfo
  730. this.ServeJSON()
  731. }
  732. // @Title 新增蜜蜂所来源基本信息
  733. // @Success 200 {object}
  734. // @router /savebee [post]
  735. func (this *SamplesSourceController) SaveBee() {
  736. var model samplessource.AnimalInfo
  737. var jsonblob = this.Ctx.Input.RequestBody
  738. json.Unmarshal(jsonblob, &model)
  739. model.AccCode = this.User.AccCode
  740. model.CreateBy = this.User.Realname
  741. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  742. svc := samplessource.GetSamplesSourceService(utils.DBE)
  743. svc.InsertEntityBytbl(this.User.AccCode+AnimaltbName, &model)
  744. var list []codecsequence.CodecSequence
  745. where_seq := "AccCode = '" + this.User.AccCode + "'"
  746. where_seq += " and AreaCode = '" + model.AreaCode + "'"
  747. svc.GetEntitysByWhere(CodecSequenceName, where_seq, &list)
  748. var entity codecsequence.CodecSequence
  749. if len(list) == 0 {
  750. entity.AccCode = this.User.AccCode
  751. entity.SeqName = strconv.Itoa(model.Id)
  752. entity.AreaCode = model.AreaCode
  753. entity.MinValue = 1
  754. entity.MaxValue = model.Amount
  755. entity.CurrentVal = 1
  756. entity.IncrementVal = 1
  757. entity.CreateBy = this.User.Realname
  758. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  759. svc.InsertEntity(&entity)
  760. } else {
  761. entity.AccCode = this.User.AccCode
  762. entity.SeqName = strconv.Itoa(model.Id)
  763. entity.AreaCode = model.AreaCode
  764. entity.MinValue = list[len(list)-1].MaxValue + 1
  765. entity.MaxValue = list[len(list)-1].MaxValue + model.Amount
  766. entity.CurrentVal = list[len(list)-1].MaxValue + 1
  767. entity.IncrementVal = 1
  768. entity.CreateBy = this.User.Realname
  769. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  770. svc.InsertEntity(&entity)
  771. }
  772. var sourceModel samplessource.AnimalInfo
  773. sourceModel.InnerNo = model.AreaCode + "-" + fmt.Sprintf("%04s", strconv.Itoa(entity.MinValue)) + "——" + model.AreaCode + "-" + fmt.Sprintf("%04s", strconv.Itoa(entity.MaxValue))
  774. where_innor := "Id = '" + strconv.Itoa(model.Id) + "'"
  775. var cols []string = []string{"InnerNo"}
  776. err := svc.UpdateEntityBywheretbl(this.User.AccCode+AnimaltbName, &sourceModel, cols, where_innor)
  777. var errinfo ErrorDataInfo
  778. if err == nil {
  779. errinfo.Message = "操作成功!"
  780. errinfo.Code = 0
  781. errinfo.Item = model.Id
  782. this.Data["json"] = &errinfo
  783. this.ServeJSON()
  784. } else {
  785. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  786. errinfo.Code = -1
  787. this.Data["json"] = &errinfo
  788. this.ServeJSON()
  789. }
  790. }
  791. // @Title 更新动物基本信息
  792. // @Description 更新动物基本信息
  793. // @Param id path string true "需要修改的试管信息"
  794. // @Success 200 {object} controllers.Request
  795. // @router /editbee/:id [put]
  796. func (this *SamplesSourceController) EditBee() {
  797. id := this.Ctx.Input.Param(":id")
  798. var errinfo ErrorInfo
  799. if id == "" {
  800. errinfo.Message = "操作失败!请求信息不完整"
  801. errinfo.Code = -2
  802. this.Data["json"] = &errinfo
  803. this.ServeJSON()
  804. return
  805. }
  806. var model samplessource.AnimalInfo
  807. var jsonblob = this.Ctx.Input.RequestBody
  808. json.Unmarshal(jsonblob, &model)
  809. var entity samplessource.AnimalInfo
  810. model.ModifiedBy = this.User.Username
  811. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  812. svc := samplessource.GetSamplesSourceService(utils.DBE)
  813. var cols []string = []string{"Genus", "InnerNo", "Name", "Amount", "Unit", "SourceType", "Weight", "Province", "ProvinceName", "City", "CityName", "Street", "StreetName", "Address", "AreaCode", "Longitude", "Latitude", "Altitude", "SurveyDate", "ProjectId", "ProjectName", "Remark", "ModifiedBy", "ModifiedUserId"}
  814. zback := svc.QueryZBackList(this.User.AccCode)
  815. for i := 0; i < (len(zback)); i++ {
  816. cols = append(cols, zback[i].Id)
  817. }
  818. opdesc := "修改样本来源-" + model.Name
  819. err := svc.UpdateDonorAndWriteLogBytbl(this.User.AccCode+AnimaltbName, this.User.AccCode+DonorslogtbName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, model.Name)
  820. if err == nil {
  821. var codemodel codecsequence.CodecSequence
  822. where_seq := "AccCode = '" + this.User.AccCode + "'"
  823. where_seq += " and SeqName = '" + strconv.Itoa(model.Id) + "'"
  824. svc.GetEntityByWhereBytbl(CodecSequenceName, where_seq, &codemodel)
  825. codemodel.MaxValue = codemodel.MinValue + model.Amount - 1
  826. codemodel.ModifiedBy = this.User.Username
  827. codemodel.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  828. var code_cols []string = []string{"MaxValue", "ModifiedBy", "ModifiedUserId"}
  829. svc.UpdateEntityBywheretbl(CodecSequenceName, &codemodel, code_cols, where_seq)
  830. var sourceModel samplessource.AnimalInfo
  831. sourceModel.InnerNo = model.AreaCode + "-" + fmt.Sprintf("%04s", strconv.Itoa(codemodel.MinValue)) + "——" + model.AreaCode + "-" + fmt.Sprintf("%04s", strconv.Itoa(codemodel.MaxValue))
  832. where_innor := "Id = '" + strconv.Itoa(model.Id) + "'"
  833. var cols_source []string = []string{"InnerNo"}
  834. svc.UpdateEntityBywheretbl(this.User.AccCode+AnimaltbName, &sourceModel, cols_source, where_innor)
  835. }
  836. if err == nil {
  837. var list []samplesinfo.SamplesMain
  838. where_list := "SourceId = '" + strconv.Itoa(model.Id) + "'"
  839. svc.GetEntitysByWhere(this.User.AccCode+SamplesMaintbName, where_list, &list)
  840. if len(list) > 0 {
  841. for i := 0; i < len(list); i++ {
  842. var SamEntity samplesinfo.SamplesMain
  843. where_sam := "MId = '" + strconv.Itoa(list[i].MId) + "'"
  844. SamEntity.SourceName = model.Name
  845. SamEntity.MCreateBy = this.User.Username
  846. SamEntity.MCreateUserId, _ = utils.StrTo(this.User.Id).Int()
  847. var cols_sam []string = []string{"SourceName", "ModifiedBy", "ModifiedUserId"}
  848. svc.UpdateEntityBywheretbl(this.User.AccCode+SamplesMaintbName, &SamEntity, cols_sam, where_sam)
  849. }
  850. }
  851. }
  852. if err == nil {
  853. errinfo.Message = "操作成功!"
  854. errinfo.Code = 0
  855. this.Data["json"] = &errinfo
  856. this.ServeJSON()
  857. } else {
  858. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  859. errinfo.Code = -1
  860. this.Data["json"] = &errinfo
  861. this.ServeJSON()
  862. }
  863. }
  864. // @Title 新增动物来源基本信息
  865. // @Success 200 {object}
  866. // @router /saveanimal [post]
  867. func (this *SamplesSourceController) SaveAnimal() {
  868. var model samplessource.AnimalInfo
  869. var jsonblob = this.Ctx.Input.RequestBody
  870. json.Unmarshal(jsonblob, &model)
  871. model.AccCode = this.User.AccCode
  872. model.CreateBy = this.User.Realname
  873. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  874. svc := samplessource.GetSamplesSourceService(utils.DBE)
  875. _, err := svc.InsertEntityBytbl(this.User.AccCode+AnimaltbName, &model)
  876. var errinfo ErrorDataInfo
  877. if err == nil {
  878. errinfo.Message = "操作成功!"
  879. errinfo.Code = 0
  880. errinfo.Item = model.Id
  881. this.Data["json"] = &errinfo
  882. this.ServeJSON()
  883. } else {
  884. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  885. errinfo.Code = -1
  886. this.Data["json"] = &errinfo
  887. this.ServeJSON()
  888. }
  889. }
  890. // @Title 获取动物样本源基本信息
  891. // @Description get user by token
  892. // @Success 200 {object} models.Userblood
  893. // @router /getanimalinfo [get]
  894. func (this *SamplesSourceController) GetAnimalDetail() {
  895. Id := this.GetString("Id")
  896. var entity samplessource.AnimalInfo
  897. svc := samplessource.GetSamplesSourceService(utils.DBE)
  898. where := " Id ='" + Id + "'"
  899. svc.GetEntityByWhere(this.User.AccCode+AnimaltbName, where, &entity)
  900. var datainfo DataInfo
  901. datainfo.Items = entity
  902. this.Data["json"] = &datainfo
  903. this.ServeJSON()
  904. }
  905. // @Title 更新动物基本信息
  906. // @Description 更新动物基本信息
  907. // @Param id path string true "需要修改的试管信息"
  908. // @Success 200 {object} controllers.Request
  909. // @router /editanimal/:id [put]
  910. func (this *SamplesSourceController) EditAnimal() {
  911. id := this.Ctx.Input.Param(":id")
  912. var errinfo ErrorInfo
  913. if id == "" {
  914. errinfo.Message = "操作失败!请求信息不完整"
  915. errinfo.Code = -2
  916. this.Data["json"] = &errinfo
  917. this.ServeJSON()
  918. return
  919. }
  920. var model samplessource.AnimalInfo
  921. var jsonblob = this.Ctx.Input.RequestBody
  922. json.Unmarshal(jsonblob, &model)
  923. var entity samplessource.AnimalInfo
  924. model.ModifiedBy = this.User.Username
  925. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  926. svc := samplessource.GetSamplesSourceService(utils.DBE)
  927. var cols []string = []string{"Genus", "GenusName", "InnerNo", "Name", "Amount", "Unit", "SourceType", "Weight", "Province", "ProvinceName", "City", "CityName", "Street", "StreetName", "Address", "AreaCode", "Longitude", "Latitude", "Altitude", "SurveyDate", "ProjectId", "ProjectName", "Remark", "ModifiedBy", "ModifiedUserId"}
  928. zback := svc.QueryZBackList(this.User.AccCode)
  929. for i := 0; i < (len(zback)); i++ {
  930. cols = append(cols, zback[i].Id)
  931. }
  932. opdesc := "修改样本来源-" + model.Name
  933. err := svc.UpdateDonorAndWriteLogBytbl(this.User.AccCode+AnimaltbName, this.User.AccCode+DonorslogtbName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, model.Name)
  934. if err == nil {
  935. var list []samplesinfo.SamplesMain
  936. where_list := "SourceId = '" + strconv.Itoa(model.Id) + "'"
  937. svc.GetEntitysByWhere(this.User.AccCode+SamplesMaintbName, where_list, &list)
  938. if len(list) > 0 {
  939. for i := 0; i < len(list); i++ {
  940. var SamEntity samplesinfo.SamplesMain
  941. where_sam := "MId = '" + strconv.Itoa(list[i].MId) + "'"
  942. SamEntity.SourceName = model.Name
  943. SamEntity.MCreateBy = this.User.Username
  944. SamEntity.MCreateUserId, _ = utils.StrTo(this.User.Id).Int()
  945. var cols_sam []string = []string{"SourceName", "ModifiedBy", "ModifiedUserId"}
  946. svc.UpdateEntityBywheretbl(this.User.AccCode+SamplesMaintbName, &SamEntity, cols_sam, where_sam)
  947. }
  948. }
  949. }
  950. if err == nil {
  951. errinfo.Message = "操作成功!"
  952. errinfo.Code = 0
  953. this.Data["json"] = &errinfo
  954. this.ServeJSON()
  955. } else {
  956. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  957. errinfo.Code = -1
  958. this.Data["json"] = &errinfo
  959. this.ServeJSON()
  960. }
  961. }
  962. // @Title 删除生物样本来源信息
  963. // @Description
  964. // @Success 200 {object} ErrorInfo
  965. // @Failure 403 :id 为空
  966. // @router /delbioinfo/:id [delete]
  967. func (this *SamplesSourceController) DelBioInfo() {
  968. id := this.Ctx.Input.Param(":id")
  969. var errinfo ErrorInfo
  970. if id == "" {
  971. errinfo.Message = "操作失败!请求信息不完整"
  972. errinfo.Code = -2
  973. this.Data["json"] = &errinfo
  974. this.ServeJSON()
  975. return
  976. }
  977. var entity samplessource.AnimalInfo
  978. var entityempty samplessource.AnimalInfo
  979. opdesc := "删除样本来源-" + entity.Name
  980. svc := samplessource.GetSamplesSourceService(utils.DBE)
  981. err := svc.DeleteDonorAndWriteLogBytbl(this.User.AccCode+AnimaltbName, this.User.AccCode+DonorslogtbName, id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, entity.Name)
  982. if err == nil {
  983. where_code := "SeqName = '" + id + "'"
  984. svc.DeleteEntityBytbl(CodecSequenceName, where_code)
  985. }
  986. if err == nil {
  987. errinfo.Message = "删除成功"
  988. errinfo.Code = 0
  989. this.Data["json"] = &errinfo
  990. this.ServeJSON()
  991. } else {
  992. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  993. errinfo.Code = -1
  994. this.Data["json"] = &errinfo
  995. this.ServeJSON()
  996. }
  997. }
  998. // @Title 审核生物样本来源信息
  999. // @Description 审核生物样本来源信息
  1000. // @Param id path string true
  1001. // @Success 200 {object}
  1002. // @router /auditoranimal/:id [put]
  1003. func (this *SamplesSourceController) AuditorAnimal() {
  1004. //进行部分修改
  1005. id := this.Ctx.Input.Param(":id")
  1006. var errinfo ErrorInfo
  1007. if id == "" {
  1008. errinfo.Message = "操作失败!请求信息不完整"
  1009. errinfo.Code = -2
  1010. this.Data["json"] = &errinfo
  1011. this.ServeJSON()
  1012. return
  1013. }
  1014. var model samplessource.AnimalInfo
  1015. var jsonblob = this.Ctx.Input.RequestBody
  1016. json.Unmarshal(jsonblob, &model)
  1017. var entity samplessource.AnimalInfo
  1018. model.AuditorName = this.User.Realname
  1019. model.AuditorId, _ = utils.StrTo(this.User.Id).Int()
  1020. model.ModifiedBy = this.User.Realname
  1021. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1022. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1023. opdesc := "审核样本来源-" + model.Name
  1024. var cols []string = []string{"AuditorStatus", "AuditorId", "AuditorName", "AuditorRemark", "ModifiedBy", "ModifiedUserId"}
  1025. err := svc.UpdateDonorAndWriteLogBytbl(this.User.AccCode+AnimaltbName, this.User.AccCode+DonorslogtbName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "样本采集")
  1026. if err == nil {
  1027. errinfo.Message = "操作成功!"
  1028. errinfo.Code = 0
  1029. this.Data["json"] = &errinfo
  1030. this.ServeJSON()
  1031. } else {
  1032. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  1033. errinfo.Code = -1
  1034. this.Data["json"] = &errinfo
  1035. this.ServeJSON()
  1036. }
  1037. }
  1038. // @Title 获取微生物样本来源列表
  1039. // @Description get user by token
  1040. // @Success 200 {object} models.Userblood
  1041. // @router /microbiallist [get]
  1042. func (this *SamplesSourceController) MicrobialList() {
  1043. page := this.GetPageInfoForm()
  1044. var list []samplessource.MicrobialInfo
  1045. genus := this.GetString("genus")
  1046. name := this.GetString("name")
  1047. tive := this.GetString("tive")
  1048. innerno := this.GetString("innerno")
  1049. weight := this.GetString("weight")
  1050. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1051. where := " 1=1"
  1052. orderby := "CreateOn"
  1053. asc := false
  1054. Order := this.GetString("Order")
  1055. Prop := this.GetString("Prop")
  1056. if Order != "" && Prop != "" {
  1057. orderby = Prop
  1058. if Order == "asc" {
  1059. asc = true
  1060. }
  1061. }
  1062. if genus != "" {
  1063. where = where + " and Genus = '" + genus + "'"
  1064. }
  1065. if name != "" {
  1066. where = where + " and Name like '%" + name + "%'"
  1067. }
  1068. if tive != "" {
  1069. where = where + " and Tive =" + tive + " "
  1070. }
  1071. if innerno != "" {
  1072. where = where + " and InnerNo = '" + innerno + "'"
  1073. }
  1074. if weight != "" {
  1075. where = where + " and Weight = '" + weight + "'"
  1076. }
  1077. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  1078. var datainfo DataInfo
  1079. datainfo.Items = list
  1080. datainfo.CurrentItemCount = total
  1081. this.Data["json"] = &datainfo
  1082. this.ServeJSON()
  1083. }
  1084. // @Title 新增微生物来源基本信息
  1085. // @Success 200 {object}
  1086. // @router /savemicro [post]
  1087. func (this *SamplesSourceController) SaveMicro() {
  1088. var model samplessource.MicrobialInfo
  1089. var jsonblob = this.Ctx.Input.RequestBody
  1090. json.Unmarshal(jsonblob, &model)
  1091. model.AccCode = this.User.AccCode
  1092. model.CreateBy = this.User.Realname
  1093. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1094. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1095. _, err := svc.InsertEntityBytbl(this.User.AccCode+MicrobialtbName, &model)
  1096. var errinfo ErrorDataInfo
  1097. if err == nil {
  1098. errinfo.Message = "操作成功!"
  1099. errinfo.Code = 0
  1100. errinfo.Item = model.Id
  1101. this.Data["json"] = &errinfo
  1102. this.ServeJSON()
  1103. } else {
  1104. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  1105. errinfo.Code = -1
  1106. this.Data["json"] = &errinfo
  1107. this.ServeJSON()
  1108. }
  1109. }
  1110. // @Title 获取微生物样本源基本信息
  1111. // @Description get user by token
  1112. // @Success 200 {object} models.Userblood
  1113. // @router /getmicrobialinfo [get]
  1114. func (this *SamplesSourceController) GetMicrobialDetail() {
  1115. Id := this.GetString("Id")
  1116. var entity samplessource.MicrobialInfo
  1117. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1118. where := " Id ='" + Id + "'"
  1119. svc.GetEntityByWhere(this.User.AccCode+MicrobialtbName, where, &entity)
  1120. var datainfo DataInfo
  1121. datainfo.Items = entity
  1122. this.Data["json"] = &datainfo
  1123. this.ServeJSON()
  1124. }
  1125. // @Title 根据样本来源获取群号区间 ----蜜蜂所
  1126. // @Description get sequence by seqName
  1127. // @Success 200 {int} sequence
  1128. // @router /getgroupcode [get]
  1129. func (this *SamplesSourceController) GetGroupCode() {
  1130. SourceId := this.GetString("SourceId")
  1131. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1132. var entity codecsequence.CodecSequence
  1133. where := " 1 = 1 "
  1134. if SourceId != "" {
  1135. where += " and SeqName = '" + SourceId + "'"
  1136. }
  1137. svc.GetEntityByWhere(CodecSequenceName, where, &entity)
  1138. var datainfo DataInfo
  1139. datainfo.Items = &entity
  1140. this.Data["json"] = &datainfo
  1141. this.ServeJSON()
  1142. }
  1143. // @Title 更新微生物基本信息
  1144. // @Description 更新微生物基本信息
  1145. // @Param id path string true "需要修改的试管信息"
  1146. // @Success 200 {object} controllers.Request
  1147. // @router /editmicro/:id [put]
  1148. func (this *SamplesSourceController) EditMicro() {
  1149. id := this.Ctx.Input.Param(":id")
  1150. var errinfo ErrorInfo
  1151. if id == "" {
  1152. errinfo.Message = "操作失败!请求信息不完整"
  1153. errinfo.Code = -2
  1154. this.Data["json"] = &errinfo
  1155. this.ServeJSON()
  1156. return
  1157. }
  1158. var model samplessource.MicrobialInfo
  1159. var jsonblob = this.Ctx.Input.RequestBody
  1160. json.Unmarshal(jsonblob, &model)
  1161. var entity samplessource.MicrobialInfo
  1162. model.ModifiedBy = this.User.Realname
  1163. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1164. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1165. var cols []string = []string{"Genus", "InnerNo", "Name", "Amount", "Unit", "SourceType", "Weight", "Remark", "ModifiedBy", "ModifiedUserId"}
  1166. zback := svc.QueryZBackList(this.User.AccCode)
  1167. for i := 0; i < (len(zback)); i++ {
  1168. cols = append(cols, zback[i].Id)
  1169. }
  1170. opdesc := "修改样本来源-" + model.Name
  1171. err := svc.UpdateDonorAndWriteLogBytbl(this.User.AccCode+MicrobialtbName, this.User.AccCode+DonorslogtbName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, model.Name)
  1172. if err == nil {
  1173. errinfo.Message = "操作成功!"
  1174. errinfo.Code = 0
  1175. this.Data["json"] = &errinfo
  1176. this.ServeJSON()
  1177. } else {
  1178. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  1179. errinfo.Code = -1
  1180. this.Data["json"] = &errinfo
  1181. this.ServeJSON()
  1182. }
  1183. }
  1184. // @Title 删除微生物样本来源信息
  1185. // @Description
  1186. // @Success 200 {object} ErrorInfo
  1187. // @Failure 403 :id 为空
  1188. // @router /delmicrobial/:id [delete]
  1189. func (this *SamplesSourceController) DelMicrobial() {
  1190. id := this.Ctx.Input.Param(":id")
  1191. var errinfo ErrorInfo
  1192. if id == "" {
  1193. errinfo.Message = "操作失败!请求信息不完整"
  1194. errinfo.Code = -2
  1195. this.Data["json"] = &errinfo
  1196. this.ServeJSON()
  1197. return
  1198. }
  1199. var entity samplessource.MicrobialInfo
  1200. var entityempty samplessource.MicrobialInfo
  1201. opdesc := "删除生物样本源-" + id
  1202. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1203. err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+MicrobialtbName, BaseOperationLogName, id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "样本来源")
  1204. if err == nil {
  1205. errinfo.Message = "删除成功"
  1206. errinfo.Code = 0
  1207. this.Data["json"] = &errinfo
  1208. this.ServeJSON()
  1209. } else {
  1210. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  1211. errinfo.Code = -1
  1212. this.Data["json"] = &errinfo
  1213. this.ServeJSON()
  1214. }
  1215. }
  1216. type DonorSampleTotalModel struct {
  1217. Samplenum int `json:"samplenum"`
  1218. Sampleprenum int `json:"sampleprenum"`
  1219. Sampleunsavenum int `json:"sampleunsavenum"`
  1220. Samplefilesnum int `json:"samplefilesnum"`
  1221. Allsamplesum int `json:"allsamplesum"`
  1222. }
  1223. // @Title 获取样本统计数据
  1224. // @Description 获取样本统计数据
  1225. // @Success 200 {object} controllers.Request
  1226. // @router /getsampletotal/:id [get]
  1227. func (this *SamplesSourceController) Getsampletotal() {
  1228. id := this.Ctx.Input.Param(":id")
  1229. var model DonorSampleTotalModel
  1230. //设备权限
  1231. svcequip := equipment.GetEquipmentService(utils.DBE)
  1232. poweeids := svcequip.GetPowerEquipmentids(this.User.AccCode, utils.ToStr(this.User.Id))
  1233. //设备中样本总数
  1234. svcsample := samplesinfo.GetSamplesInfoService(utils.DBE)
  1235. wherecout := " DeletionStateCode=0 and SourceId=" + id + " and IState=1 and EquipmentId in(" + strings.Join(poweeids, ",") + ") "
  1236. samplenum := svcsample.GetSampleOwnCountBySourceId(this.User.AccCode, wherecout)
  1237. model.Samplenum = samplenum
  1238. //预录入样本总数
  1239. wherecout = " DeletionStateCode=0 and SourceId=" + id + " and IState in (2,3,4,7,8) "
  1240. sampleprenum := svcsample.GetSampleOwnCountBySourceId(this.User.AccCode, wherecout)
  1241. model.Sampleprenum = sampleprenum
  1242. //待复存样本总数
  1243. wherecout = " DeletionStateCode=0 and SourceId=" + id + " and (IState=6 or ( IState=5 and EquipmentId in(" + strings.Join(poweeids, ",") + ")))"
  1244. sampleunsavenum := svcsample.GetSampleOwnCountBySourceId(this.User.AccCode, wherecout)
  1245. model.Sampleunsavenum = sampleunsavenum
  1246. //归档样本总数
  1247. svcsampleFile := samplesfileinfo.GetSamplesFileInfoService(utils.DBE)
  1248. wheresamplefiles := " DeletionStateCode=0 and SourceId=" + id
  1249. samplefilesnum := svcsampleFile.GetSampleFileCount(this.User.AccCode, wheresamplefiles)
  1250. model.Samplefilesnum = samplefilesnum
  1251. //总数
  1252. model.Allsamplesum = samplenum + sampleprenum + sampleunsavenum + samplefilesnum
  1253. this.Data["json"] = &model
  1254. this.ServeJSON()
  1255. }
  1256. // @Title 获取设备中样本信息
  1257. // @Description 获取设备中样本信息
  1258. // @Success 200 {object} business.device.DeviceChannels
  1259. // @router /getdevicesamples/:id [get]
  1260. func (this *SamplesSourceController) Getdevicesamples() {
  1261. id := this.Ctx.Input.Param(":id")
  1262. //获取分页信息
  1263. page := this.GetPageInfoForm()
  1264. svcequip := equipment.GetEquipmentService(utils.DBE)
  1265. poweeids := svcequip.GetPowerEquipmentids(this.User.AccCode, utils.ToStr(this.User.Id))
  1266. svc := samplesinfo.GetSamplesInfoService(utils.DBE)
  1267. wheresourceid := " IState=1 and DeletionStateCode=0 and SourceId=" + id + " and a.EquipmentId in(" + strings.Join(poweeids, ",") + ")"
  1268. total, data := svc.GetPagingEntitiesWithOrderSearch(this.User.AccCode, page.CurrentPage, page.Size, "Id", wheresourceid)
  1269. var datainfo DataInfo
  1270. datainfo.Items = data
  1271. datainfo.CurrentItemCount = total
  1272. this.Data["json"] = &datainfo
  1273. this.ServeJSON()
  1274. }
  1275. // @Title get 样本来源导出
  1276. // @Description get SampleType by token
  1277. // @Success 200 {object} sampletype.SampleType
  1278. // @router /exportexcel [get]
  1279. func (this *SamplesSourceController) ListToExcel() {
  1280. var title []string
  1281. titlestring := "监护人姓名,身份证号,性别,年龄,出生日期,民族,样本条码,联系号码,邮箱,婚姻状况,所患疾病,职业,工作单位,家庭住址,备注信息,检验单号,病理号,"
  1282. title = strings.Split(titlestring, ",")
  1283. where := " 1=1 "
  1284. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1285. datas := svc.GetSampleSourceInfo(this.User.AccCode+DonorstbName, this.User.AccCode+SampleTestMainName, this.User.AccCode+DonorsDetailName, where)
  1286. f := xlsx.NewFile()
  1287. this.DaySaveXlsxExport("样本来源导出信息", title, datas, f)
  1288. SaveDirectory("static/file/excel/report/" + this.GetAccode())
  1289. f.Save("static/file/excel/report/" + this.GetAccode() + "/" + utils.TimeFormat(time.Now(), "200612") + "样本来源导出信息.xlsx")
  1290. this.Ctx.WriteString("/static/file/excel/report/" + this.GetAccode() + "/" + utils.TimeFormat(time.Now(), "200612") + "样本来源导出信息.xlsx")
  1291. }
  1292. func (this *SamplesSourceController) DaySaveXlsxExport(name string, title []string, datas []samplessource.DonorsInfoWithDetail, f *xlsx.File) {
  1293. sheet, _ := f.AddSheet(name)
  1294. rowhead := sheet.AddRow()
  1295. rowhead.WriteSlice(&title, -1)
  1296. for _, v := range datas {
  1297. strsex := ""
  1298. if v.Sex == 0 {
  1299. strsex = "男"
  1300. } else if v.Sex == 1 {
  1301. strsex = "女"
  1302. } else {
  1303. strsex = ""
  1304. }
  1305. strmarital := ""
  1306. if v.MaritalStatus == 0 {
  1307. strmarital = "未婚"
  1308. } else if v.MaritalStatus == 1 {
  1309. strmarital = "已婚"
  1310. } else if v.MaritalStatus == 2 {
  1311. strmarital = "未知"
  1312. } else {
  1313. strmarital = ""
  1314. }
  1315. datastring := v.Name + "," + v.IdCard + "," + strsex + "," + strconv.Itoa(v.Age) + "," + utils.ToStr(v.Birthday.Format("2006-01-02")) + "," + v.Nation + "," + v.InnerNo + "," + v.Telephone + "," + v.Email + "," + strmarital + "," + v.IllnessName + "," + v.Duty + "," + v.CompanyName + "," + v.HomeAddress + "," + v.Remark + "," + v.InspectionNum + "," + v.PathologicalNum
  1316. cellname := strings.Split(datastring, ",")
  1317. row := sheet.AddRow()
  1318. row.WriteSlice(&cellname, -1)
  1319. }
  1320. sheet.Cols[1].Width = 20
  1321. sheet.Cols[4].Width = 20
  1322. sheet.Cols[6].Width = 20
  1323. sheet.Cols[7].Width = 15
  1324. sheet.Cols[8].Width = 20
  1325. sheet.Cols[12].Width = 20
  1326. sheet.Cols[13].Width = 50
  1327. sheet.Cols[14].Width = 30
  1328. sheet.Cols[15].Width = 20
  1329. sheet.Cols[16].Width = 20
  1330. sheet.Cols[17].Width = 20
  1331. }
  1332. // @Title 导入模板--BEE
  1333. // @Description 下载导入模板
  1334. // @Success 200 {object} controllers.Request
  1335. // @router /exceltosave [put]
  1336. func (this *SamplesSourceController) SaveExcelPost() {
  1337. path := this.GetString("path")
  1338. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1339. uid, _ := utils.StrTo(this.User.Id).Int()
  1340. err, warn1 := svc.InsertExcelAnimal(path, this.User.AccCode+AnimaltbName, this.User.AccCode, this.User.Realname, uid)
  1341. var errinfo ErrorInfo
  1342. if warn1 == "" {
  1343. errinfo.Message = "样本来源数据导入成功!"
  1344. errinfo.Code = 0
  1345. }
  1346. if err != nil {
  1347. errinfo.Message = "样本来源数据导入失败!"
  1348. errinfo.Code = -1
  1349. }
  1350. this.Data["json"] = &errinfo
  1351. this.ServeJSON()
  1352. return
  1353. }
  1354. // @Title 导入模板
  1355. // @Description 下载导入模板
  1356. // @Success 200 {object} controllers.Request
  1357. // @router /exceltosource [put]
  1358. func (this *SamplesSourceController) SaveExcelSource() {
  1359. path := this.GetString("path")
  1360. svc := samplessource.GetSamplesSourceService(utils.DBE)
  1361. uid, _ := utils.StrTo(this.User.Id).Int()
  1362. err, warn1 := svc.InsertExcelSource(path, this.User.AccCode+DonorstbName, this.User.AccCode, this.User.Realname, uid)
  1363. var errinfo ErrorInfo
  1364. if warn1 == "" {
  1365. errinfo.Message = "样本来源数据导入成功!"
  1366. errinfo.Code = 0
  1367. }
  1368. if err != nil {
  1369. errinfo.Message = "样本来源数据导入失败!"
  1370. errinfo.Code = -1
  1371. }
  1372. this.Data["json"] = &errinfo
  1373. this.ServeJSON()
  1374. return
  1375. }