2
3

supplierfile.go 8.8 KB

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