|
|
@@ -0,0 +1,98 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/kataras/iris/v12/mvc"
|
|
|
+ "xps/datamodels"
|
|
|
+ "xps/service/system"
|
|
|
+)
|
|
|
+
|
|
|
+type EntCatController struct {
|
|
|
+ Base
|
|
|
+ Service system.EntCatService
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) BeforeActivation(b mvc.BeforeActivation) {
|
|
|
+ b.Handle("GET", "/", "GetByList")
|
|
|
+ b.Handle("GET", "/page", "GetByPage")
|
|
|
+ b.Handle("GET", "/{entCatId:int64}", "GetById")
|
|
|
+ b.Handle("POST", "/add", "Create")
|
|
|
+ b.Handle("PUT", "/update", "Update")
|
|
|
+ b.Handle("DELETE", "/{entCatId:int64}", "DeleteByID")
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) GetByList() *JsonResult {
|
|
|
+ params := c.buildParams()
|
|
|
+ data, err := c.Service.GetByList(params)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ }
|
|
|
+ return ResultOk("获取成功", data)
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) GetByPage() *JsonResult {
|
|
|
+ params := c.buildParams()
|
|
|
+ data, err := c.Service.GetByPage(params)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ } else {
|
|
|
+ return ResultOk("获取成功", data)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) GetById(entCatId int64) *JsonResult {
|
|
|
+ data, err := c.Service.GetById(entCatId)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ } else {
|
|
|
+ return ResultOk("获取成功", data)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) Create() *JsonResult {
|
|
|
+ userId := c.GetCurUserId()
|
|
|
+
|
|
|
+ entCat := datamodels.EntCat{}
|
|
|
+ entCat.CreatedBy = userId
|
|
|
+ err := c.Ctx.ReadJSON(&entCat)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr("读取数据失败", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ err = c.Service.Create(&entCat)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ } else {
|
|
|
+ return ResultOk("新增成功", nil)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) Update() *JsonResult {
|
|
|
+ userId := c.GetCurUserId()
|
|
|
+
|
|
|
+ entCat := datamodels.EntCat{}
|
|
|
+ if err := c.Ctx.ReadJSON(&entCat); err != nil {
|
|
|
+ return ResultErr("读取数据失败", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ entCat.UpdatedBy = userId
|
|
|
+ err := c.Service.Update(&entCat)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ } else {
|
|
|
+ return ResultOk("更新成功", nil)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EntCatController) DeleteByID(entCatId int64) *JsonResult {
|
|
|
+ userId := c.GetCurUserId()
|
|
|
+
|
|
|
+ var m = make(map[string]interface{})
|
|
|
+ m["entCatId"] = entCatId
|
|
|
+ m["deletedBy"] = userId
|
|
|
+ err := c.Service.Delete(m)
|
|
|
+ if err != nil {
|
|
|
+ return ResultErr(err.Error(), nil)
|
|
|
+ } else {
|
|
|
+ return ResultOk("删除成功", nil)
|
|
|
+ }
|
|
|
+}
|