| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- package oilsupplier
- import (
- "dashoo.cn/backend/api/business/audithistory"
- "dashoo.cn/backend/api/business/auditsetting"
- "dashoo.cn/backend/api/business/oilsupplier/oilcatalog"
- "dashoo.cn/backend/api/business/oilsupplier/oilcatalogsub"
- "dashoo.cn/backend/api/business/workflow"
- "dashoo.cn/business3/parameter"
- "dashoo.cn/utils"
- "encoding/json"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/baseUser"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/business3/userRole"
- )
- type OilCatalogSubController struct {
- BaseController
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object} []limsoilcatalogsub.OilCatalogSub
- // @router /list [get]
- func (this *OilCatalogSubController) 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")
- Type := this.GetString("Type")
- Status := this.GetString("Status")
- SubmitterId := this.GetString("SubmitterId")
- Submitter := this.GetString("Submitter")
- DeptId := this.GetString("DeptId")
- Dept := this.GetString("Dept")
- FirstAudit := this.GetString("FirstAudit")
- SecondAudit := this.GetString("SecondAudit")
- BusinessKey := this.GetString("BusinessKey")
- ProcessKey := this.GetString("ProcessKey")
- CreateUserId := this.GetString("CreateUserId")
- CreateOn := this.GetString("CreateOn")
- CreateBy := this.GetString("CreateBy")
- ModifiedOn := this.GetString("ModifiedOn")
- ModifiedUserId := this.GetString("ModifiedUserId")
- ModifiedBy := this.GetString("ModifiedBy")
- SubmitOn := this.GetString("SubmitOn")
- if Id != "" {
- where = where + " and Id = " + Id
- }
- if Type != "" {
- where = where + " and Type = '" + Type + "'"
- }
- if Status != "" {
- where = where + " and Status = '" + Status + "'"
- }
- if SubmitterId != "" {
- where = where + " and SubmitterId = " + SubmitterId
- }
- if Submitter != "" {
- where = where + " and Submitter like '%" + Submitter + "%'"
- }
- if DeptId != "" {
- where = where + " and DeptId = " + DeptId
- }
- if Dept != "" {
- where = where + " and Dept like '%" + Dept + "%'"
- }
- if FirstAudit != "" {
- where = where + " and FirstAudit = " + FirstAudit
- }
- if SecondAudit != "" {
- where = where + " and SecondAudit = " + SecondAudit
- }
- if BusinessKey != "" {
- where = where + " and BusinessKey = '" + BusinessKey + "'"
- }
- if ProcessKey != "" {
- where = where + " and ProcessKey = '" + ProcessKey + "'"
- }
- if CreateUserId != "" {
- where = where + " and CreateUserId =" + this.User.Id
- }
- if CreateBy != "" {
- where = where + " and CreateBy like '%" + CreateBy + "%'"
- }
- if ModifiedOn != "" {
- where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
- }
- if ModifiedUserId != "" {
- where = where + " and ModifiedUserId =" + 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 + "'"
- }
- }
- if SubmitOn != "" {
- dates := strings.Split(SubmitOn, ",")
- if len(dates) == 2 {
- minDate := dates[0]
- maxDate := dates[1]
- where = where + " and SubmitOn>='" + minDate + "' and SubmitOn<='" + maxDate + "'"
- }
- }
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- var list []oilcatalogsub.OilCatalogSub
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, 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 *OilCatalogSubController) 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", this.User.AccCode)
- var userEntity userRole.Base_User
- userSvc.GetEntityById(this.User.Id, &userEntity)
- dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
- //var dictCustomer []svccustomer.Customer
- //customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
- //dictList["EntrustCorp"] = &dictCustomer
- var datainfo DataInfo
- datainfo.Items = dictList
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取实体
- // @Description 获取实体
- // @Success 200 {object} oilcatalogsub.OilCatalogSub
- // @router /get/:id [get]
- func (this *OilCatalogSubController) GetEntity() {
- Id := this.Ctx.Input.Param(":id")
- var model oilcatalogsub.OilCatalogSub
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- svc.GetEntityByIdBytbl(OilCatalogSubName, Id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 添加
- // @Description 新增
- // @Param body body oilcatalogsub.OilCatalogSub
- // @Success 200 {object} controllers.Request
- // @router /add [post]
- func (this *OilCatalogSubController) AddEntity() {
- var model oilcatalogsub.OilCatalogSub
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- model.Status = "0"
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- _, err := svc.InsertEntityBytbl(OilCatalogSubName, &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 oilcatalogsub.OilCatalogSub
- // @Success 200 {object} controllers.Request
- // @router /update/:id [post]
- func (this *OilCatalogSubController) 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 oilcatalogsub.OilCatalogSub
- svc := oilcatalogsub.GetOilCatalogSubService(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",
- "Type",
- "Status",
- "SubmitterId",
- "Submitter",
- "DeptId",
- "Dept",
- "FirstAudit",
- "SecondAudit",
- "BusinessKey",
- "ProcessKey",
- "CreateUserId",
- "CreateOn",
- "CreateBy",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(OilCatalogSubName, 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 *OilCatalogSubController) 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 oilcatalogsub.OilCatalogSub
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- err := svc.DeleteEntityById(Id, &model)
- 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 /deleteentityanditems/:Id [delete]
- func (this *OilCatalogSubController) DeleteEntityAndItems() {
- 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 oilcatalogsub.OilCatalogSub
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- where := "SubId=" + Id
- svc.DeleteEntityBytbl(OilCatalogName, where)
- err := svc.DeleteEntityById(Id, &model)
- 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} controllers.Request
- // @router /commitaudit/:id [post]
- func (this *OilCatalogSubController) CommitAuditEntity() {
- Id := this.Ctx.Input.Param(":id")
- var entity oilcatalogsub.OilCatalogSub
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- svc.GetEntityById(Id, &entity)
- var catalogsub oilcatalogsub.OilCatalogSub
- // 更新主表状态
- cols := []string{"Status", "AuditIndex"}
- catalogsub.Status = oilcatalogsub.FIRST_TRIAL_STATUS
- catalogsub.AuditIndex = entity.AuditIndex + 1
- where := "Id=" + Id
- svc.UpdateEntityBywheretbl(OilCatalogSubName, &catalogsub, cols, where)
- //更新从表状态
- var catalog oilcatalog.OilCatalog
- cols = []string{"Status"}
- catalog.Status = "1"
- where = "SubId=" + Id + " and CatalogType=" + entity.Type
- svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
- //启动工作流
- svcActiviti := workflow.GetActivitiService(utils.DBE)
- processInstanceId := ""
- businessKey := Id + "-" + strconv.Itoa(catalogsub.AuditIndex)
- processKey := workflow.OIL_Catalog
- processInstanceId = svcActiviti.StartProcess2(processKey, businessKey, this.User.Id, "1", "", "")
- //提交到初审
- var ActiComplete workflow.ActiCompleteVM
- ActiComplete.ProcessKey = processKey
- ActiComplete.BusinessKey = businessKey
- ActiComplete.UserNames = strconv.Itoa(entity.FirstAudit)
- ActiComplete.UserId = this.User.Id
- ActiComplete.Result = "1"
- ActiComplete.Remarks = entity.Remark
- ActiComplete.CallbackUrl = ""
- receiveVal := svcActiviti.TaskComplete(ActiComplete)
- cols1 := []string{"WorkflowId", "BusinessKey", "ProcessKey"}
- catalogsub.BusinessKey = businessKey
- catalogsub.ProcessKey = processKey
- catalogsub.WorkflowId = processInstanceId
- wheresub := "Id=" + Id
- svc.UpdateEntityBywheretbl(OilCatalogSubName, &catalogsub, cols1, wheresub)
- var audithistoryentity audithistory.Base_AuditHistory
- audithistoryentity.EntityId = entity.Id
- audithistoryentity.WorkflowId = entity.WorkflowId
- audithistoryentity.Process = ActiComplete.ProcessKey
- audithistoryentity.BusinessKey = ActiComplete.BusinessKey
- audithistoryentity.Type = ""
- audithistoryentity.BackStep = entity.Status
- audithistoryentity.Index = entity.AuditIndex
- audithistoryentity.CreateOn = time.Now()
- audithistoryentity.CreateBy = this.User.Realname
- audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntity(audithistoryentity)
- var errinfo ErrorInfo
- if receiveVal == "true" {
- errinfo.Message = "提交成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "工作流异常,请联系管理员!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- // @Title 审批
- // @Description 审批
- // @Param body body suppliercert.OilSupplierCert
- // @Success 200 {object} controllers.Request
- // @router /auditentity/:id [post]
- func (this *OilCatalogSubController) AuditEntity() {
- var dataother ShenHeModel
- Id := this.Ctx.Input.Param(":id")
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &dataother)
- var entity oilcatalogsub.OilCatalogSub
- var catalog oilcatalog.OilCatalog
- svc := oilcatalogsub.GetOilCatalogSubService(utils.DBE)
- svc.GetEntityById(Id, &entity)
- var errinfo ErrorDataInfo
- defer func() { //finally处理失败的异常
- if err := recover(); err != nil {
- errinfo.Message = "提交失败," + err.(string)
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- //返回正确结果
- errinfo.Message = "审核提交成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }()
- //remarks := ""
- status := ""
- backstatus := "0"
- var userIds string
- if entity.Status == oilcatalogsub.FIRST_TRIAL_STATUS {
- userIds = utils.ToStr(entity.SecondAudit)
- status = oilcatalogsub.SECOND_TRIAL_STATUS
- backstatus = oilcatalogsub.NOPASS_STATUS
- } else if entity.Status == oilcatalogsub.SECOND_TRIAL_STATUS {
- backstatus = oilcatalogsub.NO_SECOND_TRIAL_STATUS
- status = oilcatalogsub.CENT_AUDIT_STATUS
- paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
- topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
- var userlist []userRole.Base_User
- var setting auditsetting.Base_OilAuditSetting
- usvc := userRole.GetUserService(utils.DBE)
- where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
- usvc.GetEntity(&setting, where)
- ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
- tempstr := strings.Join(ids, ",")
- uids := strings.Replace(tempstr, "uid_", "", -1)
- uids = strings.Trim(uids, ",")
- if uids != "" {
- where := "Id in (" + uids + ")" + " and UnitId=" + topid
- usvc.GetEntities(&userlist, where)
- }
- for _, tmpUser := range userlist {
- userIds += strconv.Itoa(tmpUser.Id) + ","
- }
- userIds = strings.Trim(userIds, ",")
- } else if entity.Status == oilcatalogsub.CENT_AUDIT_STATUS {
- userIds = this.User.Id
- status = oilcatalogsub.ALL_PASE_STATUS
- backstatus = oilcatalogsub.NO_CENT_AUDIT_STATUS
- }
- svcActiviti := workflow.GetActivitiService(utils.DBE)
- var ActiComplete workflow.ActiCompleteVM
- ActiComplete.ProcessKey = entity.ProcessKey
- ActiComplete.BusinessKey = entity.BusinessKey
- ActiComplete.UserNames = userIds
- ActiComplete.UserId = this.User.Id
- ActiComplete.Remarks = dataother.AuditorRemark
- ActiComplete.CallbackUrl = ""
- if dataother.SuccessStatus == 1 {
- ActiComplete.Result = "1"
- receiveVal := svcActiviti.TaskComplete(ActiComplete)
- if receiveVal == "true" {
- // 更新主表状态
- if entity.Status == oilcatalogsub.CENT_AUDIT_STATUS {
- catalog.Status = "2"
- } else {
- catalog.Status = "1"
- }
- entity.Status = status
- cols := []string{
- "Status",
- }
- svc.UpdateEntityByIdCols(Id, &entity, cols)
- // 从表状态
- where := "SubId=" + Id + " and CatalogType=" + entity.Type
- svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
- errinfo.Message = "提交成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "工作流异常,请联系管理员!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- } else {
- ActiComplete.Result = "0"
- receiveVal := svcActiviti.TaskComplete(ActiComplete)
- if receiveVal == "true" {
- // 更新主表状态
- entity.Status = backstatus
- cols := []string{
- "Status",
- }
- svc.UpdateEntityByIdCols(Id, entity, cols)
- // 从表状态
- catalog.Status = "0"
- where := "SubId=" + Id + " and CatalogType=" + entity.Type
- svc.UpdateEntityBywheretbl(OilCatalogName, &catalog, cols, where)
- errinfo.Message = "提交成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "工作流异常,请联系管理员!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- }
|