|
|
@@ -0,0 +1,443 @@
|
|
|
+package oilcontract
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "dashoo.cn/backend/api/business/baseUser"
|
|
|
+ // "dashoo.cn/backend/api/business/items"
|
|
|
+ "dashoo.cn/backend/api/business/oilcontract/contract"
|
|
|
+ . "dashoo.cn/backend/api/controllers"
|
|
|
+ "dashoo.cn/business2/userRole"
|
|
|
+ "dashoo.cn/utils"
|
|
|
+)
|
|
|
+
|
|
|
+type OilContractController struct {
|
|
|
+ BaseController
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 获取列表
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object} []oilcontract.OilContract
|
|
|
+// @router /list [get]
|
|
|
+func (this *OilContractController) GetEntityList() {
|
|
|
+
|
|
|
+ //获取分页信息
|
|
|
+ page := this.GetPageInfoForm()
|
|
|
+ where := " 1=1 "
|
|
|
+ orderby := "Id"
|
|
|
+ asc := false
|
|
|
+ Order := this.GetString("Order")
|
|
|
+ Prop := this.GetString("Prop")
|
|
|
+ if Order != "" && Prop != "" {
|
|
|
+ orderby = Prop
|
|
|
+ if Order == "asc" {
|
|
|
+ asc = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Id := this.GetString("Id")
|
|
|
+ SupplierId := this.GetString("SupplierId")
|
|
|
+ SupplierName := this.GetString("SupplierName")
|
|
|
+ ProjectName := this.GetString("ProjectName")
|
|
|
+ ContractNo := this.GetString("ContractNo")
|
|
|
+ ProjectPlace := this.GetString("ProjectPlace")
|
|
|
+ ProjectOwner := this.GetString("ProjectOwner")
|
|
|
+ Telephone := this.GetString("Telephone")
|
|
|
+ ProjectType := this.GetString("ProjectType")
|
|
|
+ ContractMode := this.GetString("ContractMode")
|
|
|
+ Amount := this.GetString("Amount")
|
|
|
+ ContractPeriod := this.GetString("ContractPeriod")
|
|
|
+ OpenDate := this.GetString("OpenDate")
|
|
|
+ PlanFinishDate := this.GetString("PlanFinishDate")
|
|
|
+ ConstructionUnit := this.GetString("ConstructionUnit")
|
|
|
+ ConstructionOwner := this.GetString("ConstructionOwner")
|
|
|
+ ConstructionTelphone := this.GetString("ConstructionTelphone")
|
|
|
+ BuildUnit := this.GetString("BuildUnit")
|
|
|
+ BuildOwner := this.GetString("BuildOwner")
|
|
|
+ BuildTelphone := this.GetString("BuildTelphone")
|
|
|
+ SuperviseUnit := this.GetString("SuperviseUnit")
|
|
|
+ SuperviseOwner := this.GetString("SuperviseOwner")
|
|
|
+ SuperviseTelphone := this.GetString("SuperviseTelphone")
|
|
|
+ QualityUnit := this.GetString("QualityUnit")
|
|
|
+ QualityOwner := this.GetString("QualityOwner")
|
|
|
+ QualityTelphone := this.GetString("QualityTelphone")
|
|
|
+ Remark := this.GetString("Remark")
|
|
|
+ IsDelete := this.GetString("IsDelete")
|
|
|
+ CreateOn := this.GetString("CreateOn")
|
|
|
+ CreateUserId := this.GetString("CreateUserId")
|
|
|
+ CreateBy := this.GetString("CreateBy")
|
|
|
+ ModifiedOn := this.GetString("ModifiedOn")
|
|
|
+ ModifiedUserId := this.GetString("ModifiedUserId")
|
|
|
+ ModifiedBy := this.GetString("ModifiedBy")
|
|
|
+
|
|
|
+ if Id != "" {
|
|
|
+ where = where + " and Id like '%" + Id + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if SupplierId != "" {
|
|
|
+ where = where + " and SupplierId like '%" + SupplierId + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if SupplierName != "" {
|
|
|
+ where = where + " and SupplierName like '%" + SupplierName + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ProjectName != "" {
|
|
|
+ where = where + " and ProjectName like '%" + ProjectName + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ContractNo != "" {
|
|
|
+ where = where + " and ContractNo like '%" + ContractNo + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ProjectPlace != "" {
|
|
|
+ where = where + " and ProjectPlace like '%" + ProjectPlace + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ProjectOwner != "" {
|
|
|
+ where = where + " and ProjectOwner like '%" + ProjectOwner + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if Telephone != "" {
|
|
|
+ where = where + " and Telephone like '%" + Telephone + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ProjectType != "" {
|
|
|
+ where = where + " and ProjectType like '%" + ProjectType + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ContractMode != "" {
|
|
|
+ where = where + " and ContractMode like '%" + ContractMode + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if Amount != "" {
|
|
|
+ where = where + " and Amount like '%" + Amount + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ContractPeriod != "" {
|
|
|
+ where = where + " and ContractPeriod like '%" + ContractPeriod + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if OpenDate != "" {
|
|
|
+ where = where + " and OpenDate like '%" + OpenDate + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if PlanFinishDate != "" {
|
|
|
+ where = where + " and PlanFinishDate like '%" + PlanFinishDate + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ConstructionUnit != "" {
|
|
|
+ where = where + " and ConstructionUnit like '%" + ConstructionUnit + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ConstructionOwner != "" {
|
|
|
+ where = where + " and ConstructionOwner like '%" + ConstructionOwner + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ConstructionTelphone != "" {
|
|
|
+ where = where + " and ConstructionTelphone like '%" + ConstructionTelphone + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if BuildUnit != "" {
|
|
|
+ where = where + " and BuildUnit like '%" + BuildUnit + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if BuildOwner != "" {
|
|
|
+ where = where + " and BuildOwner like '%" + BuildOwner + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if BuildTelphone != "" {
|
|
|
+ where = where + " and BuildTelphone like '%" + BuildTelphone + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if SuperviseUnit != "" {
|
|
|
+ where = where + " and SuperviseUnit like '%" + SuperviseUnit + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if SuperviseOwner != "" {
|
|
|
+ where = where + " and SuperviseOwner like '%" + SuperviseOwner + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if SuperviseTelphone != "" {
|
|
|
+ where = where + " and SuperviseTelphone like '%" + SuperviseTelphone + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if QualityUnit != "" {
|
|
|
+ where = where + " and QualityUnit like '%" + QualityUnit + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if QualityOwner != "" {
|
|
|
+ where = where + " and QualityOwner like '%" + QualityOwner + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if QualityTelphone != "" {
|
|
|
+ where = where + " and QualityTelphone like '%" + QualityTelphone + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if Remark != "" {
|
|
|
+ where = where + " and Remark like '%" + Remark + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if IsDelete != "" {
|
|
|
+ where = where + " and IsDelete like '%" + IsDelete + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if CreateOn != "" {
|
|
|
+ where = where + " and CreateOn like '%" + CreateOn + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if CreateUserId != "" {
|
|
|
+ where = where + " and CreateUserId like '%" + CreateUserId + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if CreateBy != "" {
|
|
|
+ where = where + " and CreateBy like '%" + CreateBy + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ModifiedOn != "" {
|
|
|
+ where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ModifiedUserId != "" {
|
|
|
+ where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if ModifiedBy != "" {
|
|
|
+ where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if CreateOn != "" {
|
|
|
+ dates := strings.Split(CreateOn, ",")
|
|
|
+ if len(dates) == 2 {
|
|
|
+ minDate := dates[0]
|
|
|
+ maxDate := dates[1]
|
|
|
+ where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ svc := contract.GetOilContractService(utils.DBE)
|
|
|
+ var list []contract.OilContract
|
|
|
+ total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = list
|
|
|
+ datainfo.CurrentItemCount = total
|
|
|
+ datainfo.PageIndex = page.CurrentPage
|
|
|
+ datainfo.ItemsPerPage = page.Size
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 获取字典列表
|
|
|
+// @Description get user by token
|
|
|
+// @Success 200 {object} map[string]interface{}
|
|
|
+// @router /dictlist [get]
|
|
|
+func (this *OilContractController) GetDictList() {
|
|
|
+ dictList := make(map[string]interface{})
|
|
|
+ //dictSvc := items.GetItemsService(utils.DBE)
|
|
|
+ userSvc := baseUser.GetBaseUserService(utils.DBE)
|
|
|
+ //customerSvc := svccustomer.GetCustomerService(utils.DBE)
|
|
|
+ //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
|
|
|
+ var userEntity userRole.Base_User
|
|
|
+ userSvc.GetEntityById(this.User.Id, &userEntity)
|
|
|
+ dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
|
|
|
+
|
|
|
+ //var dictCustomer []svccustomer.Customer
|
|
|
+ //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
|
|
|
+ //dictList["EntrustCorp"] = &dictCustomer
|
|
|
+
|
|
|
+ var datainfo DataInfo
|
|
|
+ datainfo.Items = dictList
|
|
|
+ this.Data["json"] = &datainfo
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 获取实体
|
|
|
+// @Description 获取实体
|
|
|
+// @Success 200 {object} oilcontract.OilContract
|
|
|
+// @router /get/:id [get]
|
|
|
+func (this *OilContractController) GetEntity() {
|
|
|
+ Id := this.Ctx.Input.Param(":id")
|
|
|
+
|
|
|
+ var model contract.OilContract
|
|
|
+ svc := contract.GetOilContractService(utils.DBE)
|
|
|
+ svc.GetEntityByIdBytbl(OilContractName, Id, &model)
|
|
|
+
|
|
|
+ this.Data["json"] = &model
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 添加
|
|
|
+// @Description 新增
|
|
|
+// @Param body body oilcontract.OilContract
|
|
|
+// @Success 200 {object} controllers.Request
|
|
|
+// @router /add [post]
|
|
|
+func (this *OilContractController) AddEntity() {
|
|
|
+ var model contract.OilContract
|
|
|
+ var jsonBlob = this.Ctx.Input.RequestBody
|
|
|
+ svc := contract.GetOilContractService(utils.DBE)
|
|
|
+
|
|
|
+ json.Unmarshal(jsonBlob, &model)
|
|
|
+ model.CreateOn = time.Now()
|
|
|
+ model.CreateBy = this.User.Realname
|
|
|
+ model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
|
|
|
+
|
|
|
+ _, err := svc.InsertEntityBytbl(OilContractName, &model)
|
|
|
+
|
|
|
+ var errinfo ErrorDataInfo
|
|
|
+ if err == nil {
|
|
|
+ //新增
|
|
|
+ errinfo.Message = "添加成功!"
|
|
|
+ errinfo.Code = 0
|
|
|
+ errinfo.Item = model.Id
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 修改实体
|
|
|
+// @Description 修改实体
|
|
|
+// @Param body body oilcontract.OilContract
|
|
|
+// @Success 200 {object} controllers.Request
|
|
|
+// @router /update/:id [post]
|
|
|
+func (this *OilContractController) UpdateEntity() {
|
|
|
+ id := this.Ctx.Input.Param(":id")
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if id == "" {
|
|
|
+ errinfo.Message = "操作失败!请求信息不完整"
|
|
|
+ errinfo.Code = -2
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var model contract.OilContract
|
|
|
+ svc := contract.GetOilContractService(utils.DBE)
|
|
|
+
|
|
|
+ var jsonBlob = this.Ctx.Input.RequestBody
|
|
|
+ json.Unmarshal(jsonBlob, &model)
|
|
|
+ model.ModifiedOn = time.Now()
|
|
|
+ model.ModifiedBy = this.User.Realname
|
|
|
+ model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
|
|
|
+
|
|
|
+ cols := []string{
|
|
|
+
|
|
|
+ "Id",
|
|
|
+
|
|
|
+ "SupplierId",
|
|
|
+
|
|
|
+ "SupplierName",
|
|
|
+
|
|
|
+ "ProjectName",
|
|
|
+
|
|
|
+ "ContractNo",
|
|
|
+
|
|
|
+ "ProjectPlace",
|
|
|
+
|
|
|
+ "ProjectOwner",
|
|
|
+
|
|
|
+ "Telephone",
|
|
|
+
|
|
|
+ "ProjectType",
|
|
|
+
|
|
|
+ "ContractMode",
|
|
|
+
|
|
|
+ "Amount",
|
|
|
+
|
|
|
+ "ContractPeriod",
|
|
|
+
|
|
|
+ "OpenDate",
|
|
|
+
|
|
|
+ "PlanFinishDate",
|
|
|
+
|
|
|
+ "ConstructionUnit",
|
|
|
+
|
|
|
+ "ConstructionOwner",
|
|
|
+
|
|
|
+ "ConstructionTelphone",
|
|
|
+
|
|
|
+ "BuildUnit",
|
|
|
+
|
|
|
+ "BuildOwner",
|
|
|
+
|
|
|
+ "BuildTelphone",
|
|
|
+
|
|
|
+ "SuperviseUnit",
|
|
|
+
|
|
|
+ "SuperviseOwner",
|
|
|
+
|
|
|
+ "SuperviseTelphone",
|
|
|
+
|
|
|
+ "QualityUnit",
|
|
|
+
|
|
|
+ "QualityOwner",
|
|
|
+
|
|
|
+ "QualityTelphone",
|
|
|
+
|
|
|
+ "Remark",
|
|
|
+
|
|
|
+ "IsDelete",
|
|
|
+
|
|
|
+ "CreateOn",
|
|
|
+
|
|
|
+ "CreateUserId",
|
|
|
+
|
|
|
+ "CreateBy",
|
|
|
+
|
|
|
+ "ModifiedOn",
|
|
|
+
|
|
|
+ "ModifiedUserId",
|
|
|
+
|
|
|
+ "ModifiedBy",
|
|
|
+ }
|
|
|
+ err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "修改成功!"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 删除单条信息
|
|
|
+// @Description
|
|
|
+// @Success 200 {object} ErrorInfo
|
|
|
+// @Failure 403 :id 为空
|
|
|
+// @router /delete/:Id [delete]
|
|
|
+func (this *OilContractController) DeleteEntity() {
|
|
|
+ Id := this.Ctx.Input.Param(":Id")
|
|
|
+ var errinfo ErrorInfo
|
|
|
+ if Id == "" {
|
|
|
+ errinfo.Message = "操作失败!请求信息不完整"
|
|
|
+ errinfo.Code = -2
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var model contract.OilContract
|
|
|
+ var entityempty contract.OilContract
|
|
|
+ svc := contract.GetOilContractService(utils.DBE)
|
|
|
+ opdesc := "删除-" + Id
|
|
|
+ err := svc.DeleteOperationAndWriteLogBytbl(OilContractName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "钻井日报")
|
|
|
+ if err == nil {
|
|
|
+ errinfo.Message = "删除成功"
|
|
|
+ errinfo.Code = 0
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ } else {
|
|
|
+ errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
|
|
|
+ errinfo.Code = -1
|
|
|
+ this.Data["json"] = &errinfo
|
|
|
+ this.ServeJSON()
|
|
|
+ }
|
|
|
+}
|