2
3

supplierfile.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  4. "dashoo.cn/business2/parameter"
  5. "encoding/json"
  6. "strconv"
  7. "strings"
  8. //"strings"
  9. //"time"
  10. //"fmt"
  11. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  12. . "dashoo.cn/backend/api/controllers"
  13. "dashoo.cn/utils"
  14. )
  15. type SupplierfileController struct {
  16. BaseController
  17. }
  18. // @Title 文件上传
  19. // @Description get user by tokenaddsubfile
  20. // @Success 200 {object} models.Userblood
  21. // @router /filelistall [get]
  22. func (this *SupplierfileController) AllFileList() {
  23. page := this.GetPageInfoForm()
  24. var list []supplierfile.OilSupplierFile
  25. svc := supplierfile.GetSupplierfileService(utils.DBE)
  26. where := " 1=1"
  27. orderby := "Id"
  28. asc := true
  29. Order := this.GetString("Order")
  30. Prop := this.GetString("Prop")
  31. if Order != "" && Prop != "" {
  32. orderby = Prop
  33. if Order == "asc" {
  34. asc = true
  35. }
  36. }
  37. SupplierId := this.GetString("SupplierId")
  38. if SupplierId != "" {
  39. where = where + " and SupplierId = '" + SupplierId + "'"
  40. }
  41. SupplierTypeCode := this.GetString("SupplierTypeCode")
  42. if SupplierTypeCode != "" {
  43. where = where + " and SupplierTypeCode in ( '000', '" + SupplierTypeCode + "')"
  44. }
  45. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  46. var datainfo DataInfo
  47. datainfo.Items = list
  48. datainfo.CurrentItemCount = total
  49. this.Data["json"] = &datainfo
  50. this.ServeJSON()
  51. }
  52. // @Title 文件上传
  53. // @Description get user by tokenaddsubfile
  54. // @Success 200 {object} models.Userblood
  55. // @router /filelistappend [get]
  56. func (this *SupplierfileController) FileListAppend() {
  57. page := this.GetPageInfoForm()
  58. var list []supplierfile.OilSupplierFile
  59. svc := supplierfile.GetSupplierfileService(utils.DBE)
  60. where := " 1=1"
  61. orderby := "Id"
  62. asc := true
  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. SupplierId := this.GetString("SupplierId")
  72. if SupplierId != "" {
  73. where = where + " and SupplierId = '" + SupplierId + "'"
  74. }
  75. SupplierTypeCode := this.GetString("SupplierTypeCode")
  76. if SupplierTypeCode != "" {
  77. where = where + " and SupplierTypeCode in ( '000', '" + SupplierTypeCode + "')"
  78. }
  79. where = where + " and SupType != 1"
  80. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  81. var datainfo DataInfo
  82. datainfo.Items = list
  83. datainfo.CurrentItemCount = total
  84. this.Data["json"] = &datainfo
  85. this.ServeJSON()
  86. }
  87. // @Title 文件上传
  88. // @Description get user by tokenaddsubfile
  89. // @Success 200 {object} models.Userblood
  90. // @router /filelist [get]
  91. func (this *SupplierfileController) FileList() {
  92. page := this.GetPageInfoForm()
  93. var list []supplierfile.OilSupplierFile
  94. svc := supplierfile.GetSupplierfileService(utils.DBE)
  95. where := " 1=1"
  96. orderby := "Id"
  97. asc := true
  98. Order := this.GetString("Order")
  99. Prop := this.GetString("Prop")
  100. if Order != "" && Prop != "" {
  101. orderby = Prop
  102. if Order == "asc" {
  103. asc = true
  104. }
  105. }
  106. SupplierId := this.GetString("SupplierId")
  107. if SupplierId != "" {
  108. where = where + " and SupplierId = '" + SupplierId + "'"
  109. }
  110. SupplierTypeCode := this.GetString("SupplierTypeCode")
  111. if SupplierTypeCode != "" {
  112. where = where + " and SupplierTypeCode in ( '000', '" + SupplierTypeCode + "')"
  113. }
  114. InStyle := this.GetString("InStyle")
  115. if InStyle != "4" {
  116. //paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  117. //var needFileType string
  118. //needFileType = paramSvc.GetBaseparameterMessage("GFGL", "paramset", "CooperationFile")
  119. where = where + " and NeedFileType not like '%战略%' "
  120. }
  121. where = where + " and SupType != 2"
  122. SubClassIds := this.GetString("SubClassIds")
  123. if SubClassIds!=""{
  124. inWhere:="("+SubClassIds+")"
  125. sql:=" SupplierId="+SupplierId+" and SubClassId in "+inWhere
  126. var result []suppliercertsub.OilSupplierCert2File
  127. svc.GetEntities(&result,sql)
  128. str:=""
  129. if result!=nil{
  130. for i:=0;i<len(result);i++{
  131. str = str + "'"+result[i].NeedFileType+"',"
  132. }
  133. }
  134. where=where +" and NeedFileType in ("+str[0:len(str)-1]+")"
  135. }
  136. total := svc.GetPagingEntitiesWithoutAccCode(page.CurrentPage, page.Size, orderby, asc, &list, where)
  137. var datainfo DataInfo
  138. datainfo.Items = list
  139. datainfo.CurrentItemCount = total
  140. this.Data["json"] = &datainfo
  141. this.ServeJSON()
  142. }
  143. // @Title 文件上传
  144. // @Description 文件上传
  145. // @Success 200 {object} controllers.Request
  146. // @router /addsubfile [post]
  147. func (this *SupplierfileController) AddSubfile() {
  148. var model supplierfile.OilSupplierFile
  149. svc := supplierfile.GetSupplierfileService(utils.DBE)
  150. var jsonblob = this.Ctx.Input.RequestBody
  151. json.Unmarshal(jsonblob, &model)
  152. model.FileUrl = strings.Trim(model.FileUrl, "$")
  153. model.FileName = strings.Trim(model.FileName, "$")
  154. model.CreateBy = this.User.Realname
  155. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  156. var list []supplierfile.OilSupplierFile
  157. where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  158. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  159. hasField := ""
  160. for i := 0; i < len(list); i++ {
  161. hasField += list[i].NeedFileType + ","
  162. }
  163. var errinfo ErrorDataInfo
  164. if strings.Contains(hasField, model.NeedFileType+",") {
  165. //已存在,不能重复添加
  166. errinfo.Message = "操作失败!不能重复添加"
  167. errinfo.Code = -1
  168. this.Data["json"] = &errinfo
  169. this.ServeJSON()
  170. return
  171. }
  172. _, err := svc.InsertEntityBytbl(OilSupplierFileName, &model)
  173. if err == nil {
  174. errinfo.Message = "操作成功!"
  175. errinfo.Code = 0
  176. errinfo.Item = model.Id
  177. this.Data["json"] = &errinfo
  178. this.ServeJSON()
  179. } else {
  180. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  181. errinfo.Code = -1
  182. this.Data["json"] = &errinfo
  183. this.ServeJSON()
  184. }
  185. }
  186. // @Title 获取字典列表
  187. // @Description get user by token
  188. // @Success 200 {object} map[string]interface{}
  189. // @router /dictlist [get]
  190. func (this *SupplierfileController) GetDictList() {
  191. dictList := make(map[string]interface{})
  192. var ysname string
  193. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  194. ysname = paramSvc.GetBaseparameterMessage("", "paramset", "YaSuoBao")
  195. dictList["YaSuoName"] = ysname
  196. var datainfo DataInfo
  197. datainfo.Items = dictList
  198. this.Data["json"] = &datainfo
  199. this.ServeJSON()
  200. }
  201. // @Title 更新文件上传
  202. // @Description 更新文件上传
  203. // @Param id path string true
  204. // @Success 200 {object}
  205. // @router /editsubfile/:id [put]
  206. func (this *SupplierfileController) EditSubfile() {
  207. id := this.Ctx.Input.Param(":id")
  208. var errinfo ErrorInfo
  209. if id == "" {
  210. errinfo.Message = "操作失败!请求信息不完整"
  211. errinfo.Code = -2
  212. this.Data["json"] = &errinfo
  213. this.ServeJSON()
  214. return
  215. }
  216. var model supplierfile.OilSupplierFile
  217. var jsonblob = this.Ctx.Input.RequestBody
  218. json.Unmarshal(jsonblob, &model)
  219. svc := supplierfile.GetSupplierfileService(utils.DBE)
  220. var list []supplierfile.OilSupplierFile
  221. where := "SupplierId = '" + strconv.Itoa(model.SupplierId) + "'"
  222. svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
  223. var entity supplierfile.OilSupplierFile
  224. model.FileUrl = strings.Trim(model.FileUrl, "$")
  225. model.FileName = strings.Trim(model.FileName, "$")
  226. model.ModifiedBy = this.User.Realname
  227. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  228. opdesc := "编辑文件上传-" + model.NeedFileType
  229. var cols []string = []string{"SupplierCertSubId", "CertSubName", "NeedFileType", "NeedFileCode", "FileName", "EffectDate", "FileUrl", "OtherRemark", "Remark", "IsDelete", "ModifiedBy", "ModifiedUserId"}
  230. err := svc.UpdateOperationAndWriteLogBytbl(OilSupplierFileName, BaseOperationLogName, id, &model, &entity, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "文件上传")
  231. if err == nil {
  232. errinfo.Message = "操作成功!"
  233. errinfo.Code = 0
  234. this.Data["json"] = &errinfo
  235. this.ServeJSON()
  236. } else {
  237. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  238. errinfo.Code = -1
  239. this.Data["json"] = &errinfo
  240. this.ServeJSON()
  241. }
  242. }
  243. // @Title 删除文件上传
  244. // @Description
  245. // @Success 200 {object} ErrorInfo
  246. // @Failure 403 :id 为空
  247. // @router /subfiledelete/:Id [delete]
  248. func (this *SupplierfileController) SubfileDelete() {
  249. Id := this.Ctx.Input.Param(":Id")
  250. var errinfo ErrorInfo
  251. if Id == "" {
  252. errinfo.Message = "操作失败!请求信息不完整"
  253. errinfo.Code = -2
  254. this.Data["json"] = &errinfo
  255. this.ServeJSON()
  256. return
  257. }
  258. where := " Id= " + Id
  259. svc := supplierfile.GetSupplierfileService(utils.DBE)
  260. err := svc.DeleteEntityBytbl(OilSupplierFileName, where)
  261. if err == nil {
  262. errinfo.Message = "删除成功"
  263. errinfo.Code = 0
  264. this.Data["json"] = &errinfo
  265. this.ServeJSON()
  266. } else {
  267. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  268. errinfo.Code = -1
  269. this.Data["json"] = &errinfo
  270. this.ServeJSON()
  271. }
  272. }