Browse Source

后端: 合同管理列表 除企管法规处以外的部门只能看自己添加或导入的。导入合同记录导入人及导入时间

baichengfei 4 years ago
parent
commit
64249eebc4

+ 4 - 2
src/dashoo.cn/backend/api/business/oilcontract/contract/contract.go

@@ -3,6 +3,7 @@ package contract
 import (
 	"time"
 )
+
 type OilContract struct {
 	Id                   int       `json:"Id" xorm:"not null pk autoincr INT(11) 'Id'"`
 	SupplierId           int       `json:"SupplierId" xorm:"default 0 comment('供应商ID') INT(11) 'SupplierId'"`
@@ -40,6 +41,7 @@ type OilContract struct {
 	CreateOn             time.Time `json:"CreateOn" xorm:"DATETIME 'CreateOn'"`
 	CreateUserId         int       `json:"CreateUserId" xorm:"INT(11) 'CreateUserId'"`
 	CreateBy             string    `json:"CreateBy" xorm:"VARCHAR(50) 'CreateBy'"`
+	SecondUnit           int       `json:"SecondUnit" xorm:"INT(11) 'SecondUnit'"`
 	ModifiedOn           time.Time `json:"ModifiedOn" xorm:"DATETIME 'ModifiedOn'"`
 	ModifiedUserId       int       `json:"ModifiedUserId" xorm:"INT(11) 'ModifiedUserId'"`
 	ModifiedBy           string    `json:"ModifiedBy" xorm:"default '1' VARCHAR(50) 'ModifiedBy'"`
@@ -70,5 +72,5 @@ type OilContract struct {
 	PoNumber             string    `json:"PoNumber" xorm:"comment('po编码') VARCHAR(500) 'PoNumber'"`
 }
 type OilContractItems struct {
-	Items		   []OilContract
-}
+	Items []OilContract
+}

+ 76 - 65
src/dashoo.cn/backend/api/controllers/oilcontract/contract.go

@@ -1,7 +1,9 @@
 package oilcontract
 
 import (
+	"dashoo.cn/backend/api/business/auditsetting"
 	"dashoo.cn/backend/api/business/oilcontract/contractReview"
+	"dashoo.cn/backend/api/business/organize"
 	"dashoo.cn/backend/api/business/workflow"
 	"encoding/json"
 	"fmt"
@@ -349,7 +351,15 @@ func (this *OilContractController) GetEntityList() {
 		where = where + " and PoNumber like '%" + SignedDate + "%'"
 	}
 
-
+	// 企管法规处可看所有合同, 获取企管法规处人员
+	var setting auditsetting.Base_OilAuditSetting
+	orgSvc := organize.GetOrganizeService(utils.DBE)
+	whereAudit := "AuditStepCode='PROF_REGULATION'"
+	orgSvc.GetEntity(&setting, whereAudit)
+	res := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(setting.RoleId))
+	if !res {
+		where = where + " and SecondUnit= " + strconv.Itoa(this.User.UnitId)
+	}
 
 	svc := contract.GetOilContractService(utils.DBE)
 	var list []contract.OilContract
@@ -382,7 +392,6 @@ func (this *OilContractController) GetDictList() {
 	dictList["ContractMode"] = dictSvc.GetKeyValueItems("ContractMode")
 	dictList["CurrencyType"] = dictSvc.GetKeyValueItems("CurrencyType")
 
-
 	//var dictCustomer []svccustomer.Customer
 	//customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
 	//dictList["EntrustCorp"] = &dictCustomer
@@ -441,6 +450,7 @@ func (this *OilContractController) GetEntity() {
 	this.Data["json"] = &model
 	this.ServeJSON()
 }
+
 // @Title get 导入excel
 // @Description 数据存入word
 // @Success 200 {object} controllers.Request
@@ -491,41 +501,41 @@ func (this *OilContractController) ImportExcel() {
 		lineNo := strconv.Itoa(i + 1)
 		fmt.Println(lineNo)
 		tmp := make(map[string]string)
-		tmp["ContractNo"]    = sheet.Rows[i].Cells[0].String()
-		tmp["ContractName"]  = sheet.Rows[i].Cells[1].String()
-		tmp["Amount"]        = sheet.Rows[i].Cells[2].String()
-		tmp["SourceContractClass"]    = sheet.Rows[i].Cells[3].String()
+		tmp["ContractNo"] = sheet.Rows[i].Cells[0].String()
+		tmp["ContractName"] = sheet.Rows[i].Cells[1].String()
+		tmp["Amount"] = sheet.Rows[i].Cells[2].String()
+		tmp["SourceContractClass"] = sheet.Rows[i].Cells[3].String()
 
 		tmp["ContractSonClass"] = sheet.Rows[i].Cells[4].String()
-		tmp["SmallClass"]    = sheet.Rows[i].Cells[5].String()
-		tmp["SignedDate"]    = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
-		tmp["SourceSupplierName"]  = sheet.Rows[i].Cells[7].String()
-
-		tmp["People"]        = sheet.Rows[i].Cells[8].String()
-		tmp["Number"]        = sheet.Rows[i].Cells[9].String()
-		tmp["ChooseWay"]     = sheet.Rows[i].Cells[10].String()
-		tmp["ContractMark"]  = sheet.Rows[i].Cells[11].String()
-		tmp["Currency"]      = sheet.Rows[i].Cells[12].String()
-		tmp["BudgetAmount"]      = sheet.Rows[i].Cells[13].String()
-		tmp["PerformAmount"]     = sheet.Rows[i].Cells[14].String()
-		tmp["IsInternal"]        = sheet.Rows[i].Cells[15].String()
-		tmp["IsForeign"]         = sheet.Rows[i].Cells[16].String()
-		tmp["IsDeal"]            = sheet.Rows[i].Cells[17].String()
-		tmp["MoneyFlows"]        = sheet.Rows[i].Cells[18].String()
-		tmp["MoneyChannel"]      = sheet.Rows[i].Cells[19].String()
-		tmp["MoneyChannelSon"]   = sheet.Rows[i].Cells[20].String()
+		tmp["SmallClass"] = sheet.Rows[i].Cells[5].String()
+		tmp["SignedDate"] = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
+		tmp["SourceSupplierName"] = sheet.Rows[i].Cells[7].String()
+
+		tmp["People"] = sheet.Rows[i].Cells[8].String()
+		tmp["Number"] = sheet.Rows[i].Cells[9].String()
+		tmp["ChooseWay"] = sheet.Rows[i].Cells[10].String()
+		tmp["ContractMark"] = sheet.Rows[i].Cells[11].String()
+		tmp["Currency"] = sheet.Rows[i].Cells[12].String()
+		tmp["BudgetAmount"] = sheet.Rows[i].Cells[13].String()
+		tmp["PerformAmount"] = sheet.Rows[i].Cells[14].String()
+		tmp["IsInternal"] = sheet.Rows[i].Cells[15].String()
+		tmp["IsForeign"] = sheet.Rows[i].Cells[16].String()
+		tmp["IsDeal"] = sheet.Rows[i].Cells[17].String()
+		tmp["MoneyFlows"] = sheet.Rows[i].Cells[18].String()
+		tmp["MoneyChannel"] = sheet.Rows[i].Cells[19].String()
+		tmp["MoneyChannelSon"] = sheet.Rows[i].Cells[20].String()
 		tmp["MoneyChannelSmall"] = sheet.Rows[i].Cells[21].String()
 		tmp["SingUnit"] = sheet.Rows[i].Cells[22].String()
-		tmp["Place"]    = sheet.Rows[i].Cells[23].String()
-
-		tmp["StartDate"]    = convertToFormatDay(sheet.Rows[i].Cells[24].Value)
-		tmp["EndDate"]      = convertToFormatDay(sheet.Rows[i].Cells[25].Value)
-		tmp["DisputeResolution"]      = sheet.Rows[i].Cells[26].String()
-		tmp["Remark"]                 = sheet.Rows[i].Cells[27].String()
-		tmp["ProjectOwner"]           = sheet.Rows[i].Cells[28].String()
-		tmp["SubmitDate"]             = convertToFormatDay(sheet.Rows[i].Cells[29].Value)
-		tmp["SealName"]      = sheet.Rows[i].Cells[30].String()
-		tmp["PoNumber"]      = sheet.Rows[i].Cells[31].String()
+		tmp["Place"] = sheet.Rows[i].Cells[23].String()
+
+		tmp["StartDate"] = convertToFormatDay(sheet.Rows[i].Cells[24].Value)
+		tmp["EndDate"] = convertToFormatDay(sheet.Rows[i].Cells[25].Value)
+		tmp["DisputeResolution"] = sheet.Rows[i].Cells[26].String()
+		tmp["Remark"] = sheet.Rows[i].Cells[27].String()
+		tmp["ProjectOwner"] = sheet.Rows[i].Cells[28].String()
+		tmp["SubmitDate"] = convertToFormatDay(sheet.Rows[i].Cells[29].Value)
+		tmp["SealName"] = sheet.Rows[i].Cells[30].String()
+		tmp["PoNumber"] = sheet.Rows[i].Cells[31].String()
 		codemap[i-1] = tmp
 		//this.OperationCell(svc, lineNo, columnArr, sheet.Rows[i].Cells, &errLineNum)
 	}
@@ -584,64 +594,64 @@ func (this *OilContractController) DocExport() {
 // @Description 数据存入
 // @Success 200 {object} controllers.Request
 // @router /importbatchsave [post]
-func (this *OilContractController) ImportBatchSave(){
+func (this *OilContractController) ImportBatchSave() {
 	var model contract.OilContractItems
 	var jsonBlob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonBlob, &model)
 	var errinfo ErrorInfo
 	svc := contract.GetOilContractService(utils.DBE)
 	// 新增配置项
-	for i,v := range model.Items{
+	for i, v := range model.Items {
 		fmt.Print(i)
 		if v.SupplierName == "" || v.SupplierId == 0 {
-			errinfo.Message = "操作失败!未选择供应商名称,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!未选择供应商名称,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 		if v.ContractClass == "" {
-			errinfo.Message = "操作失败!未选择合同分类,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!未选择合同分类,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 		if v.ContractNo == "" {
-			errinfo.Message = "操作失败!合同编号不能为空,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!合同编号不能为空,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 		if v.ContractName == "" {
-			errinfo.Message = "操作失败!合同名称不能为空,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!合同名称不能为空,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 
-		var noCount   = 0
+		var noCount = 0
 		var nameCount = 0
-		for ii,vv := range model.Items{
+		for ii, vv := range model.Items {
 			fmt.Print(ii)
 			if vv.ContractNo == v.ContractNo {
-				noCount ++
+				noCount++
 			}
 			if vv.ContractName == v.ContractName {
-				nameCount ++
+				nameCount++
 			}
 		}
-		if noCount >= 2{
-			errinfo.Message = "操作失败!合同编号已存在,行号:" + strconv.Itoa (i + 1)
+		if noCount >= 2 {
+			errinfo.Message = "操作失败!合同编号已存在,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
-		if nameCount >= 2{
-			errinfo.Message = "操作失败!合同名称已存在,行号:" + strconv.Itoa (i + 1)
+		if nameCount >= 2 {
+			errinfo.Message = "操作失败!合同名称已存在,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
@@ -649,26 +659,30 @@ func (this *OilContractController) ImportBatchSave(){
 		}
 
 		var contract contract.OilContract
-		tempCount,_:= svc.GetCount(&contract,"ContractNo='" + v.ContractNo + "'")
+		tempCount, _ := svc.GetCount(&contract, "ContractNo='"+v.ContractNo+"'")
 		if tempCount > 0 {
-			errinfo.Message = "操作失败!合同编号已存在,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!合同编号已存在,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 
-		tempCount2,_:= svc.GetCount(&contract,"ContractName='" + v.ContractName + "'")
+		tempCount2, _ := svc.GetCount(&contract, "ContractName='"+v.ContractName+"'")
 		if tempCount2 > 0 {
-			errinfo.Message = "操作失败!合同名称已存在,行号:" + strconv.Itoa (i + 1)
+			errinfo.Message = "操作失败!合同名称已存在,行号:" + strconv.Itoa(i+1)
 			errinfo.Code = -2
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 			return
 		}
 
+		model.Items[i].CreateUserId, _ = strconv.Atoi(this.User.Id)
+		model.Items[i].CreateOn = time.Now()
+		model.Items[i].CreateBy = this.User.Realname
+
 	}
-	_ , err := svc.DBE.Insert(model.Items)
+	_, err := svc.DBE.Insert(model.Items)
 	if err == nil {
 		errinfo.Message = "导入成功!"
 		errinfo.Code = 0
@@ -682,20 +696,18 @@ func (this *OilContractController) ImportBatchSave(){
 	}
 }
 
-
-
 // excel日期字段格式化 yyyy-mm-dd
-func convertToFormatDay(excelDaysString string)string{
+func convertToFormatDay(excelDaysString string) string {
 	// 2006-01-02 距离 1900-01-01的天数
 	baseDiffDay := int64(38719) //在网上工具计算的天数需要加2天,什么原因没弄清楚
 	curDiffDay := excelDaysString
 
 	comma := strings.Index(curDiffDay, ".")
-	if(comma != -1){
-		curDiffDay =  curDiffDay[0:comma]
+	if comma != -1 {
+		curDiffDay = curDiffDay[0:comma]
 	}
 
-	b,_ :=  strconv.ParseInt(curDiffDay, 10, 64)  //strconv.Atoi(curDiffDay)
+	b, _ := strconv.ParseInt(curDiffDay, 10, 64) //strconv.Atoi(curDiffDay)
 	// 获取excel的日期距离2006-01-02的天数
 	realDiffDay := b - baseDiffDay
 	//fmt.Println("realDiffDay:",realDiffDay)
@@ -719,13 +731,13 @@ func (this *OilContractController) OperationCell(svc *contract.OilContractSessio
 	cellsArrLen := len(cellsArr)
 	var valstr = ""
 
-	for i := 0; i < cellsArrLen;i++ {
+	for i := 0; i < cellsArrLen; i++ {
 		valstr += "'" + cellsArr[i].String() + "',"
 	}
 	valstr = strings.Trim(valstr, ",")
 	valstr = strings.Replace(valstr, "是", "1", -1)
 	log.Println(cellsArr[6].String() + "==" + valstr)
-	var columnstr= ""
+	var columnstr = ""
 	for l := 0; l < cellsArrLen; l++ {
 		columnstr += columnArr[l] + ","
 	}
@@ -738,7 +750,6 @@ func (this *OilContractController) OperationCell(svc *contract.OilContractSessio
 
 }
 
-
 func structToMapDemo(obj interface{}) map[string]interface{} {
 	obj1 := reflect.TypeOf(obj)
 	obj2 := reflect.ValueOf(obj)
@@ -748,6 +759,7 @@ func structToMapDemo(obj interface{}) map[string]interface{} {
 	}
 	return data
 }
+
 // @Title 添加
 // @Description 新增
 // @Param 	body body oilcontract.OilContract
@@ -766,7 +778,7 @@ func (this *OilContractController) AddEntity() {
 	model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
 
 	var contract contract.OilContract
-	tempCount,_:=svc.GetCount(&contract,"ContractNo='" + model.ContractNo +"' ")
+	tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' ")
 	if tempCount > 0 {
 		errinfo.Message = "合同编号已存在!"
 		errinfo.Code = -1
@@ -777,7 +789,6 @@ func (this *OilContractController) AddEntity() {
 
 	_, err := svc.InsertEntityBytbl(OilContractName, &model)
 
-
 	if err == nil {
 		//新增
 		errinfo.Message = "添加成功!"
@@ -938,7 +949,7 @@ func (this *OilContractController) UpdateEntity() {
 	}
 
 	var contract contract.OilContract
-	tempCount,_:=svc.GetCount(&contract,"ContractNo='" + model.ContractNo +"' and id <> " + id)
+	tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' and id <> "+id)
 	if tempCount > 0 {
 		errinfo.Message = "合同编号已存在!"
 		errinfo.Code = -1
@@ -981,7 +992,7 @@ func (this *OilContractController) DeleteEntity() {
 	itemsSvc := contractReview.GetOilContractReviewService(utils.DBE)
 	var review contractReview.OilContractReview
 	//tempCount,_:=itemsSvc.GetCount(&review,"ContractId='" + Id +"' and status > 0 and status < 8 ")
-	tempCount,_:=itemsSvc.GetCount(&review,"ContractId='" + Id +"' ")
+	tempCount, _ := itemsSvc.GetCount(&review, "ContractId='"+Id+"' ")
 	if tempCount > 0 {
 		errinfo.Message = "该合同存在评价不能删除!"
 		errinfo.Code = -1