Browse Source

合同项目评价配置;合同审核工作流基本代码

baichengfei 5 years ago
parent
commit
b547dbfd27

+ 21 - 0
src/dashoo.cn/backend/api/business/oilcontract/contractReviewWorkFlow/contractReviewWorkFlow.go

@@ -0,0 +1,21 @@
+package contractReviewWorkFlow
+
+import (
+	"time"
+)
+
+type OilContractReviewWorkFlow struct {
+	Id             int       `json:"Id" xorm:"not null pk INT(11) 'Id'"`
+	Contracteid    int       `json:"ContractEId" xorm:"not null comment('评价表id') INT(11) 'ContractEId'"`
+	Workflowid     string    `json:"WorkflowId" xorm:"default '0' comment('工作流的ID') VARCHAR(50) 'WorkflowId'"`
+	Businesskey    string    `json:"BusinessKey" xorm:"VARCHAR(255) 'BusinessKey'"`
+	Processkey     string    `json:"ProcessKey" xorm:"comment('工作流名称') VARCHAR(255) 'ProcessKey'"`
+	Backremark     string    `json:"BackRemark" xorm:"comment('退回原因') VARCHAR(255) 'BackRemark'"`
+	Reviewtype     int       `json:"ReviewType" xorm:"default 1 comment('审核类型 1 日常审核 2 年审') INT(11) 'ReviewType'"`
+	CreateOn       time.Time `json:"CreateOn" xorm:"DATETIME 'CreateOn'"`
+	CreateUserId   int       `json:"CreateUserId" xorm:"INT(11) 'CreateUserId'"`
+	CreateBy       string    `json:"CreateBy" xorm:"VARCHAR(50) 'CreateBy'"`
+	ModifiedOn     time.Time `json:"ModifiedOn" xorm:"DATETIME 'ModifiedOn'"`
+	ModifiedUserId int       `json:"ModifiedUserId" xorm:"INT(11) 'ModifiedUserId'"`
+	ModifiedBy     string    `json:"ModifiedBy" xorm:"VARCHAR(50) 'ModifiedBy'"`
+}

+ 16 - 0
src/dashoo.cn/backend/api/business/oilcontract/contractReviewWorkFlow/contractReviewWorkFlowService.go

@@ -0,0 +1,16 @@
+package contractReviewWorkFlow
+
+import (
+	. "dashoo.cn/backend/api/mydb"
+	"github.com/go-xorm/xorm"
+)
+
+type OilContractReviewWorkFlowService struct {
+	MyServiceBase
+}
+
+func GetOilContractReviewWorkFlowService(xormEngine *xorm.Engine) *OilContractReviewWorkFlowService {
+	s := new(OilContractReviewWorkFlowService)
+	s.DBE = xormEngine
+	return s
+}

+ 1 - 0
src/dashoo.cn/backend/api/controllers/base.go

@@ -289,6 +289,7 @@ var (
 	ManufacturerName                         string = "Manufacturer"
 	OilContractName                          string = "OilContract"                //合同表
 	OilContractEvaluationItemsName           string = "OilContractEvaluationItems" //合同业绩评价项目
+	OilContractReviewWorkFlowName            string = "OilContractReviewWorkFlow"  //合同审核工作流
 	OilEvaluationItemsName                   string = "OilEvaluationItems"         //业绩评价项目
 	OilContractOffGradeName					 string = "OilContractOffGrade"        //业绩评价不合格原因
 )

+ 290 - 0
src/dashoo.cn/backend/api/controllers/oilcontract/contractReviewWorkFlow.go

@@ -0,0 +1,290 @@
+package oilcontract
+
+import (
+	"dashoo.cn/backend/api/business/oilcontract/contractReviewWorkFlow"
+	"encoding/json"
+	"strings"
+	"time"
+
+	"dashoo.cn/backend/api/business/baseUser"
+	_ "dashoo.cn/backend/api/business/OilContract/contractReviewWorkFlow"
+	//	"dashoo.cn/backend/api/business/items"
+	. "dashoo.cn/backend/api/controllers"
+	"dashoo.cn/business2/userRole"
+	"dashoo.cn/utils"
+)
+
+type OilContractReviewWorkFlowController struct {
+	BaseController
+}
+
+// @Title 获取列表
+// @Description get user by token
+// @Success 200 {object} []contractReviewWorkFlow.OilContractReviewWorkFlow
+// @router /list [get]
+func (this *OilContractReviewWorkFlowController) 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")
+	ContractEId := this.GetString("ContractEId")
+	WorkflowId := this.GetString("WorkflowId")
+	BusinessKey := this.GetString("BusinessKey")
+	ProcessKey := this.GetString("ProcessKey")
+	BackRemark := this.GetString("BackRemark")
+	ReviewType := this.GetString("ReviewType")
+	CreateOn := this.GetString("CreateOn")
+	CreateUserId := this.GetString("CreateUserId")
+	CreateBy := this.GetString("CreateBy")
+
+	if Id != "" {
+		where = where + " and Id like '%" + Id + "%'"
+	}
+
+
+	if ContractEId != "" {
+		where = where + " and ContractEId like '%" + ContractEId + "%'"
+	}
+
+
+	if WorkflowId != "" {
+		where = where + " and WorkflowId like '%" + WorkflowId + "%'"
+	}
+
+
+	if BusinessKey != "" {
+		where = where + " and BusinessKey like '%" + BusinessKey + "%'"
+	}
+
+
+	if ProcessKey != "" {
+		where = where + " and ProcessKey like '%" + ProcessKey + "%'"
+	}
+
+
+	if BackRemark != "" {
+		where = where + " and BackRemark like '%" + BackRemark + "%'"
+	}
+
+
+	if ReviewType != "" {
+		where = where + " and ReviewType like '%" + ReviewType + "%'"
+	}
+
+
+	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 CreateOn != "" {
+		dates := strings.Split(CreateOn, ",")
+		if len(dates) == 2 {
+			minDate := dates[0]
+			maxDate := dates[1]
+			where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
+		}
+	}
+
+	svc := contractReviewWorkFlow.GetOilContractReviewWorkFlowService(utils.DBE)
+	var list []contractReviewWorkFlow.OilContractReviewWorkFlow
+	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 *OilContractReviewWorkFlowController) 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} contractReviewWorkFlow.OilContractReviewWorkFlow
+// @router /get/:id [get]
+func (this *OilContractReviewWorkFlowController) GetEntity() {
+	Id := this.Ctx.Input.Param(":id")
+
+	var model contractReviewWorkFlow.OilContractReviewWorkFlow
+	svc := contractReviewWorkFlow.GetOilContractReviewWorkFlowService(utils.DBE)
+	svc.GetEntityByIdBytbl(OilContractReviewWorkFlowName, Id, &model)
+
+	this.Data["json"] = &model
+	this.ServeJSON()
+}
+
+// @Title 添加
+// @Description 新增
+// @Param 	body body contractReviewWorkFlow.OilContractReviewWorkFlow
+// @Success	200	{object} controllers.Request
+// @router /add [post]
+func (this *OilContractReviewWorkFlowController) AddEntity() {
+	var model contractReviewWorkFlow.OilContractReviewWorkFlow
+	var jsonBlob = this.Ctx.Input.RequestBody
+	svc := contractReviewWorkFlow.GetOilContractReviewWorkFlowService(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(this.User.AccCode+OilContractReviewWorkFlowName, &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 contractReviewWorkFlow.OilContractReviewWorkFlow
+// @Success	200	{object} controllers.Request
+// @router /update/:id [post]
+func (this *OilContractReviewWorkFlowController) 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 contractReviewWorkFlow.OilContractReviewWorkFlow
+	svc := contractReviewWorkFlow.GetOilContractReviewWorkFlowService(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",
+
+		"ContractEId",
+
+		"WorkflowId",
+
+		"BusinessKey",
+
+		"ProcessKey",
+
+		"BackRemark",
+
+		"ReviewType",
+
+		"CreateOn",
+
+		"CreateUserId",
+
+		"CreateBy",
+
+
+	}
+	err := svc.UpdateEntityBytbl(this.User.AccCode+OilContractReviewWorkFlowName, 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 *OilContractReviewWorkFlowController) 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 contractReviewWorkFlow.OilContractReviewWorkFlow
+	var entityempty contractReviewWorkFlow.OilContractReviewWorkFlow
+	svc := contractReviewWorkFlow.GetOilContractReviewWorkFlowService(utils.DBE)
+	opdesc := "删除-" + Id
+	err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+OilContractReviewWorkFlowName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
+	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()
+	}
+}
+
+

+ 125 - 54
src/dashoo.cn/backend/api/controllers/oilcontract/evaluationItems.go

@@ -2,6 +2,7 @@ package oilcontract
 
 import (
 	"encoding/json"
+	"strconv"
 	"strings"
 	"time"
 
@@ -186,23 +187,55 @@ func (this *OilEvaluationItemsController) AddEntity() {
 	model.CreateOn = time.Now()
 	model.CreateBy = this.User.Realname
 	model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-
-	_, err := svc.InsertEntityBytbl(OilEvaluationItemsName, &model)
-
 	var errinfo ErrorDataInfo
-	if err == nil {
-		//新增
-		errinfo.Message = "添加成功!"
-		errinfo.Code = 0
-		errinfo.Item = model.Id
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
+	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()
+		}
+	}()
+	if model.NormalScore == "0" {
+		panic("评分不能为0!")
+	}
+	// 二级分数和不能大于所属一级
+	if model.LevelCode == 2 {
+		sql := "SELECT SUM(NormalScore) AS NormalScoreSum FROM OilEvaluationItems where ParentId = " + strconv.Itoa(model.ParentId)
+		var resultsSlice, _ = svc.DBE.Query(sql)
+		var ScoreSum float64
+		if len(resultsSlice) > 0 {
+			results := resultsSlice[0]
+			for _, value := range results {
+				ScoreSum, _ = strconv.ParseFloat(string(value), 64)
+				break
+			}
+		}
+		var model1 evaluationItems.OilEvaluationItems
+		svc := evaluationItems.GetOilEvaluationItemsService(utils.DBE)
+		svc.GetEntityByIdBytbl(OilEvaluationItemsName, model.ParentId, &model1)
+
+		if model1.NormalScore == "" {
+			panic("此二级没有一级!")
+		}
+		var Score float64
+		Score,_ = strconv.ParseFloat(model1.NormalScore, 64)
+		Sum,_ := strconv.ParseFloat(model.NormalScore,  64)
+		if  ScoreSum + Sum  != Score {
+			panic("二级分数和应等于所属一级!")
+		}
 	} else {
-		errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
-		errinfo.Code = -1
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
+		model.ParentId = 0
 	}
+
+	svc.InsertEntityBytbl(OilEvaluationItemsName, &model)
+
 }
 
 // @Title 修改实体
@@ -213,12 +246,22 @@ func (this *OilEvaluationItemsController) AddEntity() {
 func (this *OilEvaluationItemsController) UpdateEntity() {
 	id := this.Ctx.Input.Param(":id")
 	var errinfo ErrorInfo
+	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()
+		}
+	}()
 	if id == "" {
-		errinfo.Message = "操作失败!请求信息不完整"
-		errinfo.Code = -2
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
-		return
+		panic("操作失败!请求信息不完整")
 	}
 
 	var model evaluationItems.OilEvaluationItems
@@ -230,6 +273,35 @@ func (this *OilEvaluationItemsController) UpdateEntity() {
 	model.ModifiedBy = this.User.Realname
 	model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
 
+	// 二级分数和不能大于所属一级
+	if model.LevelCode == 2 {
+		sql := "SELECT SUM(NormalScore) AS NormalScoreSum FROM OilEvaluationItems where Id != " + id + " and ParentId = " + strconv.Itoa(model.ParentId)
+		var resultsSlice, _ = svc.DBE.Query(sql)
+		var ScoreSum float64
+		if len(resultsSlice) > 0 {
+			results := resultsSlice[0]
+			for _, value := range results {
+				ScoreSum, _ = strconv.ParseFloat(string(value), 64)
+				break
+			}
+		}
+		var model1 evaluationItems.OilEvaluationItems
+		svc := evaluationItems.GetOilEvaluationItemsService(utils.DBE)
+		svc.GetEntityByIdBytbl(OilEvaluationItemsName, model.ParentId, &model1)
+
+		if model1.NormalScore == "" {
+			panic("此二级没有一级!")
+		}
+		var Score float64
+		Score,_ = strconv.ParseFloat(model1.NormalScore, 64)
+		Sum,_ := strconv.ParseFloat(model.NormalScore,  64)
+		if  ScoreSum + Sum  != Score {
+			panic("二级分数和应等于所属一级!")
+		}
+	} else {
+		model.ParentId = 0
+	}
+
 	cols := []string{
 
 		"Id",
@@ -250,30 +322,13 @@ func (this *OilEvaluationItemsController) UpdateEntity() {
 
 		"IsDelete",
 
-		"CreateOn",
-
-		"CreateUserId",
-
-		"CreateBy",
-
 		"ModifiedOn",
 
 		"ModifiedUserId",
 
 		"ModifiedBy",
 	}
-	err := svc.UpdateEntityBytbl(OilEvaluationItemsName, 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()
-	}
+	svc.UpdateEntityBytbl(OilEvaluationItemsName, id, &model, cols)
 }
 
 // @Title 删除单条信息
@@ -284,27 +339,43 @@ func (this *OilEvaluationItemsController) UpdateEntity() {
 func (this *OilEvaluationItemsController) DeleteEntity() {
 	Id := this.Ctx.Input.Param(":Id")
 	var errinfo ErrorInfo
+	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()
+		}
+	}()
 	if Id == "" {
-		errinfo.Message = "操作失败!请求信息不完整"
-		errinfo.Code = -2
-		this.Data["json"] = &errinfo
-		this.ServeJSON()
-		return
+		panic("操作失败!请求信息不完整!")
 	}
+
 	var model evaluationItems.OilEvaluationItems
 	var entityempty evaluationItems.OilEvaluationItems
 	svc := evaluationItems.GetOilEvaluationItemsService(utils.DBE)
-	opdesc := "删除-" + Id
-	err := svc.DeleteOperationAndWriteLogBytbl(OilEvaluationItemsName, 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()
+
+	sql := "SELECT Id FROM OilEvaluationItems where ParentId = " + Id + " limit 1"
+	var resultsSlice, _ = svc.DBE.Query(sql)
+	var itemId int64
+	if len(resultsSlice) > 0 {
+		results := resultsSlice[0]
+		for _, value := range results {
+			itemId, _ = strconv.ParseInt(string(value), 10, 64)
+			break
+		}
+	}
+	// 一级下有二级不能删
+	if itemId > 0 {
+		panic("一级下有二级不能删!")
 	}
+
+	opdesc := "删除-" + Id
+	svc.DeleteOperationAndWriteLogBytbl(OilEvaluationItemsName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "评价项目配置")
 }