customer.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. package family
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "dashoo.cn/backend/api/business/customer"
  6. . "dashoo.cn/backend/api/controllers"
  7. "dashoo.cn/utils"
  8. )
  9. type CustomerController struct {
  10. BaseController
  11. }
  12. //保存附件UI model
  13. type contractFormmodel struct {
  14. PId int
  15. AttachmodelList []customer.ContractAttachmentarrt // 上传附件
  16. }
  17. // @Title 根据用户AccCode get检验主表 客户原始信息内容
  18. // @Description get user by token
  19. // @Success 200 {object} models.Userblood
  20. // @router /customerlist [get]
  21. func (this *CustomerController) Customerlist() {
  22. page := this.GetPageInfoForm()
  23. danwei := this.GetString("danwei")
  24. lianxiren := this.GetString("lianxiren")
  25. telephone := this.GetString("telephone")
  26. CreateBy := this.GetString("CreateBy")
  27. var list []customer.Customer
  28. svc := customer.GetCustomerService(utils.DBE)
  29. where := " 1=1 "
  30. orderby := "Id"
  31. asc := false
  32. Order := this.GetString("Order")
  33. Prop := this.GetString("Prop")
  34. if Order != "" && Prop != "" {
  35. orderby = Prop
  36. if Order == "asc" {
  37. asc = true
  38. }
  39. }
  40. if danwei != "" {
  41. where = where + " and CustomerName like '%" + danwei + "%'"
  42. }
  43. if CreateBy != "" {
  44. where = where + " and CreateBy like '%" + CreateBy + "%'"
  45. }
  46. if lianxiren != "" {
  47. where = where + " and Person like '%" + lianxiren + "%'"
  48. }
  49. if telephone != "" {
  50. where = where + " and Telephone like '%" + telephone + "%'"
  51. }
  52. CreateOn := this.GetString("CreateOn")
  53. if CreateOn != "" {
  54. dates := strings.Split(CreateOn, ",")
  55. if len(dates) == 2 {
  56. minDate := dates[0]
  57. maxDate := dates[1]
  58. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  59. }
  60. }
  61. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  62. var datainfo DataInfo
  63. datainfo.Items = list
  64. datainfo.CurrentItemCount = total
  65. this.Data["json"] = &datainfo
  66. this.ServeJSON()
  67. }
  68. // @Title 添加客户原始信息内容
  69. // @Description 新增客户原始信息内容
  70. // @Param body body business.device.DeviceChannels "客户原始信息内容"
  71. // @Success 200 {object} controllers.Request
  72. // @router /customerlistadd [post]
  73. func (this *CustomerController) Customerlistadd() {
  74. var testlistentity customer.Customer
  75. var jsonblob = this.Ctx.Input.RequestBody
  76. json.Unmarshal(jsonblob, &testlistentity)
  77. testlistentity.CreateBy = this.User.Realname
  78. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  79. testlistentity.AuthCode = utils.GetGuid()
  80. svc := customer.GetCustomerService(utils.DBE)
  81. _, err := svc.InsertEntityBytbl(this.User.AccCode+CustomerName, &testlistentity)
  82. var errinfo ErrorInfo
  83. if err == nil {
  84. errinfo.Message = "操作成功!"
  85. errinfo.Code = 0
  86. this.Data["json"] = &errinfo
  87. this.ServeJSON()
  88. } else {
  89. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  90. errinfo.Code = -1
  91. this.Data["json"] = &errinfo
  92. this.ServeJSON()
  93. }
  94. }
  95. // @Title 获取编辑时的客户原始信息内容
  96. // @Description 获取编辑时的客户原始信息内容
  97. // @Success 200 {object} business.device.DeviceChannels
  98. // @router /getcustomerlist/:id [get]
  99. func (this *CustomerController) Getcustomerlist() {
  100. id := this.Ctx.Input.Param(":id")
  101. var model customer.Customer
  102. svc := customer.GetCustomerService(utils.DBE)
  103. svc.GetEntityByIdBytbl(this.User.AccCode+CustomerName, id, &model) //修改时获取列表
  104. var datainfo DataInfo
  105. datainfo.Items = model
  106. this.Data["json"] = &datainfo
  107. this.ServeJSON()
  108. }
  109. // @Title 编辑试管信息
  110. // @Description 编辑试管信息
  111. // @Param id path string true "需要修改的试管信息"
  112. // @Param body body business.device.DeviceChannels "试管信息"
  113. // @Success 200 {object} controllers.Request
  114. // @router /customerlistedit/:id [put]
  115. func (this *CustomerController) Customerlistedit() {
  116. id := this.Ctx.Input.Param(":id")
  117. var errinfo ErrorInfo
  118. if id == "" {
  119. errinfo.Message = "操作失败!请求信息不完整"
  120. errinfo.Code = -2
  121. this.Data["json"] = &errinfo
  122. this.ServeJSON()
  123. return
  124. }
  125. var model customer.Customer
  126. var jsonblob = this.Ctx.Input.RequestBody
  127. json.Unmarshal(jsonblob, &model)
  128. var entityempty customer.Customer
  129. model.ModifiedBy = this.User.Realname
  130. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  131. svc := customer.GetCustomerService(utils.DBE)
  132. opdesc := "检验-" + model.Person
  133. var cols []string = []string{"CustomerName", "Person", "Telephone", "Mailbox", "Address", "AuthCode", "CustomerName", "CustomerCode", "Established", "EmployeesNum", "EnterpriseType", "ZipCode", "FaxTelephone", "Website", "Representative", "MainBusiness", "ViceBusiness", "ModifiedBy", "ModifiedUserId"}
  134. err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+CustomerName, BaseOperationLogName, id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "客户管理")
  135. if err == nil {
  136. errinfo.Message = "操作成功!"
  137. errinfo.Code = 0
  138. this.Data["json"] = &errinfo
  139. this.ServeJSON()
  140. } else {
  141. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  142. errinfo.Code = -1
  143. this.Data["json"] = &errinfo
  144. this.ServeJSON()
  145. }
  146. }
  147. // @Title 删除单条信息
  148. // @Description
  149. // @Success 200 {object} ErrorInfo
  150. // @Failure 403 :id 为空
  151. // @router /customerlistdelete/:Id [delete]
  152. func (this *CustomerController) Customerlistdelete() {
  153. Id := this.Ctx.Input.Param(":Id")
  154. var errinfo ErrorInfo
  155. if Id == "" {
  156. errinfo.Message = "操作失败!请求信息不完整"
  157. errinfo.Code = -2
  158. this.Data["json"] = &errinfo
  159. this.ServeJSON()
  160. return
  161. }
  162. where := " Id= " + Id
  163. svc := customer.GetCustomerService(utils.DBE)
  164. err := svc.DeleteEntityBytbl(this.User.AccCode+CustomerName, where)
  165. if err == nil {
  166. errinfo.Message = "删除成功"
  167. errinfo.Code = 0
  168. this.Data["json"] = &errinfo
  169. this.ServeJSON()
  170. } else {
  171. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  172. errinfo.Code = -1
  173. this.Data["json"] = &errinfo
  174. this.ServeJSON()
  175. }
  176. }
  177. // @Title 判断合同是否存在
  178. // @Description get user by token
  179. // @Success 200 {object} models.Userblood
  180. // @router /contractNoorlist [get]
  181. func (this *CustomerController) ContractNoorlist() {
  182. ContractNo := this.GetString("ContractNo")
  183. svc := customer.GetCustomerService(utils.DBE)
  184. where := " ContractNo= '" + ContractNo + "'"
  185. total := svc.GetContractNo(this.User.AccCode+CellsContractName, where)
  186. var datainfo DataInfo
  187. datainfo.Items = total
  188. this.Data["json"] = &datainfo
  189. this.ServeJSON()
  190. }
  191. // @Title 保存附件
  192. // @Description 保存附件
  193. // @Success 200 {object}
  194. // @router /savesampleattach [put]
  195. func (this *CustomerController) SaveSampleAttach() {
  196. // 获得前端传输的model
  197. var jsonblob = this.Ctx.Input.RequestBody
  198. var upmodel contractFormmodel
  199. json.Unmarshal(jsonblob, &upmodel)
  200. var errinfo ErrorInfo
  201. if len(upmodel.AttachmodelList) == 0 {
  202. errinfo.Message = "上传失败!无附件信息"
  203. errinfo.Code = -3
  204. this.Data["json"] = &errinfo
  205. this.ServeJSON()
  206. return
  207. }
  208. //---附件---
  209. var attachmodel customer.CellsContractAttachment
  210. attachmodel.CreateBy = this.User.Realname
  211. attachmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  212. attachmodel.PId = upmodel.PId
  213. svc := customer.GetCustomerService(utils.DBE)
  214. var err error
  215. for _, val := range upmodel.AttachmodelList {
  216. attachmodel.FileId = val.FileId
  217. attachmodel.FileName = val.FileName
  218. attachmodel.FileSize = val.FileSize
  219. attachmodel.Host = val.Host
  220. attachmodel.UploadDesc = val.UploadDesc
  221. _, err = svc.InsertEntityBytbl(this.User.AccCode+CellsContractAttachmentName, &attachmodel)
  222. }
  223. if err == nil {
  224. errinfo.Message = "保存成功"
  225. errinfo.Code = 0
  226. this.Data["json"] = &errinfo
  227. this.ServeJSON()
  228. } else {
  229. errinfo.Message = "上传失败!" + utils.AlertProcess(err.Error())
  230. errinfo.Code = -1
  231. this.Data["json"] = &errinfo
  232. this.ServeJSON()
  233. }
  234. }
  235. // @Title 质量管理根据id信息查询附件
  236. // @Description get user by token
  237. // @Success 200 {object} models.Userblood
  238. // @router /getcontractAttachment [get]
  239. func (this *CustomerController) GetcontractAttachment() {
  240. PId := this.GetString("PId")
  241. svc := customer.GetCustomerService(utils.DBE)
  242. where := " PId= '" + PId + "'"
  243. total := svc.GetCustomerAttachment(this.User.AccCode+CellsContractAttachmentName, where)
  244. var datainfo DataInfo
  245. datainfo.Items = total
  246. this.Data["json"] = &datainfo
  247. this.ServeJSON()
  248. }
  249. // @Title 根据id删除合同管理附件
  250. // @Description
  251. // @Success 200 {object} ErrorInfo
  252. // @Failure 403 :id 为空
  253. // @router /contractAttachmentdeletearrt/:Id [delete]
  254. func (this *CustomerController) ContractAttachmentdeletearrt() {
  255. Id := this.Ctx.Input.Param(":Id")
  256. var errinfo ErrorInfo
  257. if Id == "" {
  258. errinfo.Message = "操作失败!请求信息不完整"
  259. errinfo.Code = -2
  260. this.Data["json"] = &errinfo
  261. this.ServeJSON()
  262. return
  263. }
  264. where := " PId= " + Id
  265. svc := customer.GetCustomerService(utils.DBE)
  266. err := svc.DeleteEntityBytbl(this.User.AccCode+CellsContractAttachmentName, where)
  267. if err == nil {
  268. errinfo.Message = "删除成功"
  269. errinfo.Code = 0
  270. this.Data["json"] = &errinfo
  271. this.ServeJSON()
  272. } else {
  273. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  274. errinfo.Code = -1
  275. this.Data["json"] = &errinfo
  276. this.ServeJSON()
  277. }
  278. }
  279. // @Title 更改用户授权码
  280. // @Description 更改用户授权码
  281. // @Param body body business.device.DeviceChannels "更改用户授权码"
  282. // @Success 200 {object} controllers.Request
  283. // @router /authCodeedit [get]
  284. func (this *CustomerController) GetauthCode() {
  285. var testlistentity customer.Customer
  286. var jsonblob = this.Ctx.Input.RequestBody
  287. json.Unmarshal(jsonblob, &testlistentity)
  288. testlistentity.AuthCode = utils.GetGuid()
  289. var datainfo DataInfo
  290. datainfo.Items = testlistentity.AuthCode
  291. this.Data["json"] = &datainfo
  292. this.ServeJSON()
  293. }