contract.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. package oilcontract
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "time"
  6. "dashoo.cn/backend/api/business/baseUser"
  7. // "dashoo.cn/backend/api/business/items"
  8. "dashoo.cn/backend/api/business/oilcontract/contract"
  9. . "dashoo.cn/backend/api/controllers"
  10. "dashoo.cn/business2/userRole"
  11. "dashoo.cn/utils"
  12. )
  13. type OilContractController struct {
  14. BaseController
  15. }
  16. // @Title 获取列表
  17. // @Description get user by token
  18. // @Success 200 {object} []oilcontract.OilContract
  19. // @router /list [get]
  20. func (this *OilContractController) GetEntityList() {
  21. //获取分页信息
  22. page := this.GetPageInfoForm()
  23. where := " 1=1 "
  24. orderby := "Id"
  25. asc := false
  26. Order := this.GetString("Order")
  27. Prop := this.GetString("Prop")
  28. if Order != "" && Prop != "" {
  29. orderby = Prop
  30. if Order == "asc" {
  31. asc = true
  32. }
  33. }
  34. Id := this.GetString("Id")
  35. SupplierId := this.GetString("SupplierId")
  36. SupplierName := this.GetString("SupplierName")
  37. ProjectName := this.GetString("ProjectName")
  38. ContractNo := this.GetString("ContractNo")
  39. ProjectPlace := this.GetString("ProjectPlace")
  40. ProjectOwner := this.GetString("ProjectOwner")
  41. Telephone := this.GetString("Telephone")
  42. ProjectType := this.GetString("ProjectType")
  43. ContractMode := this.GetString("ContractMode")
  44. Amount := this.GetString("Amount")
  45. ContractPeriod := this.GetString("ContractPeriod")
  46. OpenDate := this.GetString("OpenDate")
  47. PlanFinishDate := this.GetString("PlanFinishDate")
  48. ConstructionUnit := this.GetString("ConstructionUnit")
  49. ConstructionOwner := this.GetString("ConstructionOwner")
  50. ConstructionTelphone := this.GetString("ConstructionTelphone")
  51. BuildUnit := this.GetString("BuildUnit")
  52. BuildOwner := this.GetString("BuildOwner")
  53. BuildTelphone := this.GetString("BuildTelphone")
  54. SuperviseUnit := this.GetString("SuperviseUnit")
  55. SuperviseOwner := this.GetString("SuperviseOwner")
  56. SuperviseTelphone := this.GetString("SuperviseTelphone")
  57. QualityUnit := this.GetString("QualityUnit")
  58. QualityOwner := this.GetString("QualityOwner")
  59. QualityTelphone := this.GetString("QualityTelphone")
  60. Remark := this.GetString("Remark")
  61. IsDelete := this.GetString("IsDelete")
  62. CreateOn := this.GetString("CreateOn")
  63. CreateUserId := this.GetString("CreateUserId")
  64. CreateBy := this.GetString("CreateBy")
  65. ModifiedOn := this.GetString("ModifiedOn")
  66. ModifiedUserId := this.GetString("ModifiedUserId")
  67. ModifiedBy := this.GetString("ModifiedBy")
  68. if Id != "" {
  69. where = where + " and Id like '%" + Id + "%'"
  70. }
  71. if SupplierId != "" {
  72. where = where + " and SupplierId like '%" + SupplierId + "%'"
  73. }
  74. if SupplierName != "" {
  75. where = where + " and SupplierName like '%" + SupplierName + "%'"
  76. }
  77. if ProjectName != "" {
  78. where = where + " and ProjectName like '%" + ProjectName + "%'"
  79. }
  80. if ContractNo != "" {
  81. where = where + " and ContractNo like '%" + ContractNo + "%'"
  82. }
  83. if ProjectPlace != "" {
  84. where = where + " and ProjectPlace like '%" + ProjectPlace + "%'"
  85. }
  86. if ProjectOwner != "" {
  87. where = where + " and ProjectOwner like '%" + ProjectOwner + "%'"
  88. }
  89. if Telephone != "" {
  90. where = where + " and Telephone like '%" + Telephone + "%'"
  91. }
  92. if ProjectType != "" {
  93. where = where + " and ProjectType like '%" + ProjectType + "%'"
  94. }
  95. if ContractMode != "" {
  96. where = where + " and ContractMode like '%" + ContractMode + "%'"
  97. }
  98. if Amount != "" {
  99. where = where + " and Amount like '%" + Amount + "%'"
  100. }
  101. if ContractPeriod != "" {
  102. where = where + " and ContractPeriod like '%" + ContractPeriod + "%'"
  103. }
  104. if OpenDate != "" {
  105. where = where + " and OpenDate like '%" + OpenDate + "%'"
  106. }
  107. if PlanFinishDate != "" {
  108. where = where + " and PlanFinishDate like '%" + PlanFinishDate + "%'"
  109. }
  110. if ConstructionUnit != "" {
  111. where = where + " and ConstructionUnit like '%" + ConstructionUnit + "%'"
  112. }
  113. if ConstructionOwner != "" {
  114. where = where + " and ConstructionOwner like '%" + ConstructionOwner + "%'"
  115. }
  116. if ConstructionTelphone != "" {
  117. where = where + " and ConstructionTelphone like '%" + ConstructionTelphone + "%'"
  118. }
  119. if BuildUnit != "" {
  120. where = where + " and BuildUnit like '%" + BuildUnit + "%'"
  121. }
  122. if BuildOwner != "" {
  123. where = where + " and BuildOwner like '%" + BuildOwner + "%'"
  124. }
  125. if BuildTelphone != "" {
  126. where = where + " and BuildTelphone like '%" + BuildTelphone + "%'"
  127. }
  128. if SuperviseUnit != "" {
  129. where = where + " and SuperviseUnit like '%" + SuperviseUnit + "%'"
  130. }
  131. if SuperviseOwner != "" {
  132. where = where + " and SuperviseOwner like '%" + SuperviseOwner + "%'"
  133. }
  134. if SuperviseTelphone != "" {
  135. where = where + " and SuperviseTelphone like '%" + SuperviseTelphone + "%'"
  136. }
  137. if QualityUnit != "" {
  138. where = where + " and QualityUnit like '%" + QualityUnit + "%'"
  139. }
  140. if QualityOwner != "" {
  141. where = where + " and QualityOwner like '%" + QualityOwner + "%'"
  142. }
  143. if QualityTelphone != "" {
  144. where = where + " and QualityTelphone like '%" + QualityTelphone + "%'"
  145. }
  146. if Remark != "" {
  147. where = where + " and Remark like '%" + Remark + "%'"
  148. }
  149. if IsDelete != "" {
  150. where = where + " and IsDelete like '%" + IsDelete + "%'"
  151. }
  152. if CreateOn != "" {
  153. where = where + " and CreateOn like '%" + CreateOn + "%'"
  154. }
  155. if CreateUserId != "" {
  156. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  157. }
  158. if CreateBy != "" {
  159. where = where + " and CreateBy like '%" + CreateBy + "%'"
  160. }
  161. if ModifiedOn != "" {
  162. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  163. }
  164. if ModifiedUserId != "" {
  165. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  166. }
  167. if ModifiedBy != "" {
  168. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  169. }
  170. if CreateOn != "" {
  171. dates := strings.Split(CreateOn, ",")
  172. if len(dates) == 2 {
  173. minDate := dates[0]
  174. maxDate := dates[1]
  175. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  176. }
  177. }
  178. svc := contract.GetOilContractService(utils.DBE)
  179. var list []contract.OilContract
  180. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  181. var datainfo DataInfo
  182. datainfo.Items = list
  183. datainfo.CurrentItemCount = total
  184. datainfo.PageIndex = page.CurrentPage
  185. datainfo.ItemsPerPage = page.Size
  186. this.Data["json"] = &datainfo
  187. this.ServeJSON()
  188. }
  189. // @Title 获取字典列表
  190. // @Description get user by token
  191. // @Success 200 {object} map[string]interface{}
  192. // @router /dictlist [get]
  193. func (this *OilContractController) GetDictList() {
  194. dictList := make(map[string]interface{})
  195. //dictSvc := items.GetItemsService(utils.DBE)
  196. userSvc := baseUser.GetBaseUserService(utils.DBE)
  197. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  198. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  199. var userEntity userRole.Base_User
  200. userSvc.GetEntityById(this.User.Id, &userEntity)
  201. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  202. //var dictCustomer []svccustomer.Customer
  203. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  204. //dictList["EntrustCorp"] = &dictCustomer
  205. var datainfo DataInfo
  206. datainfo.Items = dictList
  207. this.Data["json"] = &datainfo
  208. this.ServeJSON()
  209. }
  210. // @Title 获取实体
  211. // @Description 获取实体
  212. // @Success 200 {object} oilcontract.OilContract
  213. // @router /get/:id [get]
  214. func (this *OilContractController) GetEntity() {
  215. Id := this.Ctx.Input.Param(":id")
  216. var model contract.OilContract
  217. svc := contract.GetOilContractService(utils.DBE)
  218. svc.GetEntityByIdBytbl(OilContractName, Id, &model)
  219. this.Data["json"] = &model
  220. this.ServeJSON()
  221. }
  222. // @Title 添加
  223. // @Description 新增
  224. // @Param body body oilcontract.OilContract
  225. // @Success 200 {object} controllers.Request
  226. // @router /add [post]
  227. func (this *OilContractController) AddEntity() {
  228. var model contract.OilContract
  229. var jsonBlob = this.Ctx.Input.RequestBody
  230. svc := contract.GetOilContractService(utils.DBE)
  231. json.Unmarshal(jsonBlob, &model)
  232. model.CreateOn = time.Now()
  233. model.CreateBy = this.User.Realname
  234. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  235. _, err := svc.InsertEntityBytbl(OilContractName, &model)
  236. var errinfo ErrorDataInfo
  237. if err == nil {
  238. //新增
  239. errinfo.Message = "添加成功!"
  240. errinfo.Code = 0
  241. errinfo.Item = model.Id
  242. this.Data["json"] = &errinfo
  243. this.ServeJSON()
  244. } else {
  245. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  246. errinfo.Code = -1
  247. this.Data["json"] = &errinfo
  248. this.ServeJSON()
  249. }
  250. }
  251. // @Title 修改实体
  252. // @Description 修改实体
  253. // @Param body body oilcontract.OilContract
  254. // @Success 200 {object} controllers.Request
  255. // @router /update/:id [post]
  256. func (this *OilContractController) UpdateEntity() {
  257. id := this.Ctx.Input.Param(":id")
  258. var errinfo ErrorInfo
  259. if id == "" {
  260. errinfo.Message = "操作失败!请求信息不完整"
  261. errinfo.Code = -2
  262. this.Data["json"] = &errinfo
  263. this.ServeJSON()
  264. return
  265. }
  266. var model contract.OilContract
  267. svc := contract.GetOilContractService(utils.DBE)
  268. var jsonBlob = this.Ctx.Input.RequestBody
  269. json.Unmarshal(jsonBlob, &model)
  270. model.ModifiedOn = time.Now()
  271. model.ModifiedBy = this.User.Realname
  272. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  273. cols := []string{
  274. "Id",
  275. "SupplierId",
  276. "SupplierName",
  277. "ProjectName",
  278. "ContractNo",
  279. "ProjectPlace",
  280. "ProjectOwner",
  281. "Telephone",
  282. "ProjectType",
  283. "ContractMode",
  284. "Amount",
  285. "ContractPeriod",
  286. "OpenDate",
  287. "PlanFinishDate",
  288. "ConstructionUnit",
  289. "ConstructionOwner",
  290. "ConstructionTelphone",
  291. "BuildUnit",
  292. "BuildOwner",
  293. "BuildTelphone",
  294. "SuperviseUnit",
  295. "SuperviseOwner",
  296. "SuperviseTelphone",
  297. "QualityUnit",
  298. "QualityOwner",
  299. "QualityTelphone",
  300. "Remark",
  301. "IsDelete",
  302. "CreateOn",
  303. "CreateUserId",
  304. "CreateBy",
  305. "ModifiedOn",
  306. "ModifiedUserId",
  307. "ModifiedBy",
  308. }
  309. err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
  310. if err == nil {
  311. errinfo.Message = "修改成功!"
  312. errinfo.Code = 0
  313. this.Data["json"] = &errinfo
  314. this.ServeJSON()
  315. } else {
  316. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  317. errinfo.Code = -1
  318. this.Data["json"] = &errinfo
  319. this.ServeJSON()
  320. }
  321. }
  322. // @Title 删除单条信息
  323. // @Description
  324. // @Success 200 {object} ErrorInfo
  325. // @Failure 403 :id 为空
  326. // @router /delete/:Id [delete]
  327. func (this *OilContractController) DeleteEntity() {
  328. Id := this.Ctx.Input.Param(":Id")
  329. var errinfo ErrorInfo
  330. if Id == "" {
  331. errinfo.Message = "操作失败!请求信息不完整"
  332. errinfo.Code = -2
  333. this.Data["json"] = &errinfo
  334. this.ServeJSON()
  335. return
  336. }
  337. var model contract.OilContract
  338. var entityempty contract.OilContract
  339. svc := contract.GetOilContractService(utils.DBE)
  340. opdesc := "删除-" + Id
  341. err := svc.DeleteOperationAndWriteLogBytbl(OilContractName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
  342. if err == nil {
  343. errinfo.Message = "删除成功"
  344. errinfo.Code = 0
  345. this.Data["json"] = &errinfo
  346. this.ServeJSON()
  347. } else {
  348. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  349. errinfo.Code = -1
  350. this.Data["json"] = &errinfo
  351. this.ServeJSON()
  352. }
  353. }