| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207 |
- package oilcontract
- import (
- "dashoo.cn/backend/api/business/auditsetting"
- "dashoo.cn/backend/api/business/oilcontract/contractReview"
- "dashoo.cn/backend/api/business/oilsupplier/supplier"
- "dashoo.cn/backend/api/business/organize"
- "dashoo.cn/backend/api/business/workflow"
- "encoding/json"
- "fmt"
- "github.com/tealeg/xlsx"
- "log"
- "os"
- "reflect"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/baseUser"
- "dashoo.cn/backend/api/business/oilcontract/contract"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/business2/items"
- "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")
- Status := this.GetString("Status")
- SettleStatus := this.GetString("SettleStatus")
- 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")
- ContractName := this.GetString("ContractName")
- ContractSonClass := this.GetString("ContractSonClass")
- SmallClass := this.GetString("SmallClass")
- SignedDate := this.GetString("SignedDate")
- People := this.GetString("People")
- Number := this.GetString("Number")
- ChooseWay := this.GetString("ChooseWay")
- ContractMark := this.GetString("ContractMark")
- Currency := this.GetString("Currency")
- BudgetAmount := this.GetString("BudgetAmount")
- PerformAmount := this.GetString("PerformAmount")
- IsInternal := this.GetString("IsInternal")
- IsForeign := this.GetString("IsForeign")
- IsDeal := this.GetString("IsDeal")
- MoneyFlows := this.GetString("MoneyFlows")
- MoneyChannel := this.GetString("MoneyChannel")
- MoneyChannelSon := this.GetString("MoneyChannelSon")
- MoneyChannelSmall := this.GetString("MoneyChannelSmall")
- SingUnit := this.GetString("SingUnit")
- Place := this.GetString("Place")
- DisputeResolution := this.GetString("DisputeResolution")
- SubmitDate := this.GetString("SubmitDate")
- SealName := this.GetString("SealName")
- PoNumber := this.GetString("PoNumber")
- SubPackage := this.GetString("SubPackage")
- ImportStatus := this.GetString("ImportStatus")
- 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 Status != "" {
- where = where + " and Status=" + Status + " "
- }
- if SettleStatus != "" {
- where = where + " and SettleStatus='" + SettleStatus + "' "
- }
- 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 + "'"
- }
- }
- if SubPackage != "" {
- where = where + " and SubPackage like '%" + SubPackage + "%'"
- }
- if ContractName != "" {
- where = where + " and ContractName like '%" + ContractName + "%'"
- }
- if ContractSonClass != "" {
- where = where + " and ContractSonClass like '%" + ContractSonClass + "%'"
- }
- if SmallClass != "" {
- where = where + " and SmallClass like '%" + SmallClass + "%'"
- }
- if People != "" {
- where = where + " and People like '%" + People + "%'"
- }
- if Number != "" {
- where = where + " and Number like '%" + Number + "%'"
- }
- if ChooseWay != "" {
- where = where + " and ChooseWay like '%" + ChooseWay + "%'"
- }
- if ContractMark != "" {
- where = where + " and ContractMark like '%" + ContractMark + "%'"
- }
- if Currency != "" {
- where = where + " and Currency like '%" + Currency + "%'"
- }
- if BudgetAmount != "" {
- where = where + " and BudgetAmount like '%" + BudgetAmount + "%'"
- }
- if PerformAmount != "" {
- where = where + " and PerformAmount like '%" + PerformAmount + "%'"
- }
- if IsInternal != "" {
- where = where + " and IsInternal like '%" + IsInternal + "%'"
- }
- if IsForeign != "" {
- where = where + " and IsForeign like '%" + IsForeign + "%'"
- }
- if IsDeal != "" {
- where = where + " and IsDeal like '%" + IsDeal + "%'"
- }
- if MoneyFlows != "" {
- where = where + " and MoneyFlows like '%" + MoneyFlows + "%'"
- }
- if MoneyChannel != "" {
- where = where + " and MoneyChannel like '%" + MoneyChannel + "%'"
- }
- if MoneyChannelSon != "" {
- where = where + " and MoneyChannelSon like '%" + MoneyChannelSon + "%'"
- }
- if MoneyChannelSmall != "" {
- where = where + " and MoneyChannelSmall like '%" + MoneyChannelSmall + "%'"
- }
- if SingUnit != "" {
- where = where + " and SingUnit like '%" + SingUnit + "%'"
- }
- if Place != "" {
- where = where + " and Place like '%" + Place + "%'"
- }
- if DisputeResolution != "" {
- where = where + " and DisputeResolution like '%" + DisputeResolution + "%'"
- }
- if SubmitDate != "" {
- where = where + " and SubmitDate like '%" + SubmitDate + "%'"
- }
- if SealName != "" {
- where = where + " and SealName like '%" + SealName + "%'"
- }
- if PoNumber != "" {
- where = where + " and PoNumber like '%" + PoNumber + "%'"
- }
- if SignedDate != "" {
- where = where + " and PoNumber like '%" + SignedDate + "%'"
- }
- if ImportStatus != "" {
- where = where + " and ImportStatus = " + ImportStatus
- } else {
- where = where + " and ImportStatus != 0"
- }
- // 企管法规处可看所有合同, 获取企管法规处人员
- 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
- 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)
- dictList["ContractClass"] = dictSvc.GetKeyValueItems("ContractClass")
- dictList["ProjectType"] = dictSvc.GetKeyValueItems("ProjectType")
- dictList["ContractMode"] = dictSvc.GetKeyValueItems("ContractMode")
- dictList["CurrencyType"] = dictSvc.GetKeyValueItems("CurrencyType")
- //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 get user by token
- // @Success 200 {object} map[string]interface{}
- // @router /finish/:id [get]
- //func (this *OilContractController) Finish(){
- // 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)
- // model.Status = 2
- // cols := []string{
- // "Status",
- // }
- // 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} 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 get 导入excel
- // @Description 导入excel
- // @Success 200 {object} controllers.Request
- // @router /importexcel [get]
- func (this *OilContractController) ImportExcel() {
- go func() {
- url := this.GetString("ExcelUrl")
- //var errLineNum string
- if url == "" {
- fmt.Println("文件不能为空!")
- }
- _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
- filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
- utils.DownloadFile(url, filename, _dir)
- t := time.Now()
- filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/" + filename
- xlFile, err := xlsx.OpenFile(filePath)
- //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
- if err != nil {
- fmt.Printf("open failed: %s\n", err)
- }
- var sheet = xlFile.Sheets[0]
- // 插入字段
- //Fstrs := "ContractNo,ContractName,Amount,ContractType,ContractSonClass,SmallClass,SignedDate,Number,ChooseWay,ContractMark,Currency,BudgetAmount,PerformAmount,IsInternal,IsForeign,IsDeal,MoneyFlows,MoneyChannel,MoneyChannelSon,MoneyChannelSmall,SingUnit,Place,StartDate,EndDate,DisputeResolution,Remark,ProjectOwner,SubmitDate,SealName,PoNumber"
- //columnArr := strings.Split(Fstrs, ",")
- //timeTemplate1 := "2006/01/02 15:04:05" //常规类型
- svc := contract.GetOilContractService(utils.DBE)
- for i := 1; i < len(sheet.Rows); i++ {
- var con contract.OilContract
- var con1 contract.OilContract
- lineNo := strconv.Itoa(i + 1)
- fmt.Println(lineNo)
- svc.GetEntityByWhere(OilContractName, "ContractNo = '"+sheet.Rows[i].Cells[0].String()+"'", &con1)
- if con1.Id > 0 {
- con1.ContractName = sheet.Rows[i].Cells[1].String()
- con1.Amount = sheet.Rows[i].Cells[2].String()
- con1.ClassName = sheet.Rows[i].Cells[3].String()
- con1.ContractSonClass = sheet.Rows[i].Cells[4].String()
- con1.SmallClass = sheet.Rows[i].Cells[5].String()
- con1.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[6].Value), time.Local)
- con1.Number = sheet.Rows[i].Cells[9].String()
- con1.ChooseWay = sheet.Rows[i].Cells[10].String()
- con1.ContractMark = sheet.Rows[i].Cells[11].String()
- con1.Currency = sheet.Rows[i].Cells[12].String()
- con1.BudgetAmount = sheet.Rows[i].Cells[13].String()
- con1.PerformAmount = sheet.Rows[i].Cells[14].String()
- con1.IsYearMoney = con1.PerformAmount
- con1.IsInternal = 0
- if sheet.Rows[i].Cells[15].String() == "是" {
- con1.IsInternal = 1
- }
- con1.IsForeign = 0
- if sheet.Rows[i].Cells[16].String() == "是" {
- con1.IsForeign = 1
- }
- con1.IsDeal = 0
- if sheet.Rows[i].Cells[17].String() == "是" {
- con1.IsDeal = 1
- }
- con1.MoneyFlows = sheet.Rows[i].Cells[18].String()
- con1.MoneyChannel = sheet.Rows[i].Cells[19].String()
- con1.MoneyChannelSon = sheet.Rows[i].Cells[20].String()
- con1.MoneyChannelSmall = sheet.Rows[i].Cells[21].String()
- con1.SingUnit = sheet.Rows[i].Cells[22].String()
- con1.Place = sheet.Rows[i].Cells[23].String()
- con1.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[24].Value), time.Local)
- con1.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[25].Value), time.Local)
- con1.DisputeResolution = sheet.Rows[i].Cells[26].String()
- con1.Remark = sheet.Rows[i].Cells[27].String()
- if con1.ProjectOwner != sheet.Rows[i].Cells[28].String() {
- con1.ProjectOwner = con1.ProjectOwner + "," + sheet.Rows[i].Cells[28].String()
- }
- con1.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[29].Value), time.Local)
- con1.SealName = sheet.Rows[i].Cells[30].String()
- con1.PoNumber = sheet.Rows[i].Cells[31].String()
- con1.ImportStatus = 0
- svc.UpdateEntityById(con1.Id, &con1)
- continue
- }
- con.ContractNo = sheet.Rows[i].Cells[0].String()
- con.ContractName = sheet.Rows[i].Cells[1].String()
- con.Amount = sheet.Rows[i].Cells[2].String()
- con.ClassName = sheet.Rows[i].Cells[3].String()
- con.ContractSonClass = sheet.Rows[i].Cells[4].String()
- con.SmallClass = sheet.Rows[i].Cells[5].String()
- //con.SignedDate = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
- con.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[6].Value), time.Local)
- con.ImportSecondUnit = sheet.Rows[i].Cells[7].String()
- con.ImportSupplierName = sheet.Rows[i].Cells[8].String()
- var supp supplier.OilSupplier
- svc.GetEntityByWhere(OilSupplierName, "SupplierName = '"+con.ImportSupplierName+"'", &supp)
- if supp.Id > 0 {
- con.SupplierId = supp.Id
- }
- var org organize.Base_Organize
- svc.GetEntityByWhere("Base_Organize", "FullName = '"+sheet.Rows[i].Cells[7].String()+"'", &org)
- if org.Id > 0 {
- con.SecondUnit = org.Id
- con.SecondUnitName = org.Fullname
- }
- con.Number = sheet.Rows[i].Cells[9].String()
- con.ChooseWay = sheet.Rows[i].Cells[10].String()
- con.ContractMark = sheet.Rows[i].Cells[11].String()
- con.Currency = sheet.Rows[i].Cells[12].String()
- con.BudgetAmount = sheet.Rows[i].Cells[13].String()
- con.PerformAmount = sheet.Rows[i].Cells[14].String()
- con.IsYearMoney = con.PerformAmount
- con.IsInternal = 0
- if sheet.Rows[i].Cells[15].String() == "是" {
- con.IsInternal = 1
- }
- con.IsForeign = 0
- if sheet.Rows[i].Cells[16].String() == "是" {
- con.IsForeign = 1
- }
- con.IsDeal = 0
- if sheet.Rows[i].Cells[17].String() == "是" {
- con.IsDeal = 1
- }
- con.MoneyFlows = sheet.Rows[i].Cells[18].String()
- con.MoneyChannel = sheet.Rows[i].Cells[19].String()
- con.MoneyChannelSon = sheet.Rows[i].Cells[20].String()
- con.MoneyChannelSmall = sheet.Rows[i].Cells[21].String()
- con.SingUnit = sheet.Rows[i].Cells[22].String()
- con.Place = sheet.Rows[i].Cells[23].String()
- con.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[24].Value), time.Local)
- con.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[25].Value), time.Local)
- con.DisputeResolution = sheet.Rows[i].Cells[26].String()
- con.Remark = sheet.Rows[i].Cells[27].String()
- con.ProjectOwner = sheet.Rows[i].Cells[28].String()
- con.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[29].Value), time.Local)
- con.SealName = sheet.Rows[i].Cells[30].String()
- con.PoNumber = sheet.Rows[i].Cells[31].String()
- con.ImportStatus = 0
- con.Status = 1
- con.SettleStatus = "1"
- _, err = svc.InsertEntityBytbl(OilContractName, &con)
- if err != nil {
- fmt.Println(err)
- }
- }
- os.Remove(filePath)
- elapsed := time.Since(t)
- log.Println(elapsed)
- }()
- var errorinfo ErrorDataInfo
- errorinfo.Code = 0
- errorinfo.Message = "导入中,请稍后!"
- this.Data["json"] = &errorinfo
- this.ServeJSON()
- }
- // @Title 从数据录入数据导出到word文档
- // @Description 数据存入word
- // @Success 200 {object} controllers.Request
- // @router /exportword/:id [get]
- func (this *OilContractController) DocExport() {
- // 填物资类信息表首页信息
- Id := this.Ctx.Input.Param(":id")
- var Url string
- var fileName string
- svcActiviti := workflow.GetActivitiService(utils.DBE)
- var model contract.OilContract
- svc := contract.GetOilContractService(utils.DBE)
- where := "1=1"
- where += " AND Id = '" + Id + "'"
- svc.GetEntityByWhere(OilContractName, where, &model)
- Url = utils.Cfg.MustValue("workflow", "contractUrl")
- fileName = "合同导出模板.docx"
- datamap := structToMapDemo(model)
- //datamap["TableComment"] = []string{"MajorEquipments", "ThreeYears", "Patent", "Winning"}
- retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName)
- //retDocUrl := svcActiviti.FillWordWatermarkTemplate(datamap, Url, fileName, model.SupplierName)
- var datainfo ErrorDataInfo
- datainfo.Code = 0
- datainfo.Item = retDocUrl
- datainfo.Message = "导出成功"
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title get 导入批量保存
- // @Description 数据存入
- // @Success 200 {object} controllers.Request
- // @router /importbatchsave [post]
- func (this *OilContractController) ImportBatchSave() {
- sql := "update OilContract set ImportStatus = 1 where SupplierId != 0 and ContractClass != '' and SecondUnit != 0"
- _, err := utils.DBE.Query(sql)
- var errinfo ErrorInfo
- 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 get 批量修改字段
- // @Description 批量修改字段
- // @Success 200 {object} controllers.Request
- // @router /importUpdate [get]
- func (this *OilContractController) ImportUpdate() {
- Class := this.GetString("Class")
- Value := this.GetString("Value")
- Column := this.GetString("Column")
- Id := this.GetString("Id")
- SupplierId := this.GetString("SupplierId")
- var supp supplier.OilSupplier
- svc := supplier.GetOilSupplierService(utils.DBE)
- svc.GetEntityById(SupplierId, &supp)
- sql := ""
- var err error
- where := "1=1"
- if Column == "ContractClass" {
- if Id != "" {
- where += " and Id = " + Id + " and ImportStatus = 0 and ClassName = '" + Class + "'"
- sql = "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = '" + Value + "' where " + where
- } else {
- where += " and ImportStatus = 0 and ClassName = '" + Class + "' and " + Column + " = ''"
- sql = "update OilContract set " + Column + " = '" + Value + "' where " + where
- }
- _, err = utils.DBE.Query(sql)
- }
- if Column == "SupplierId" {
- if Id != "" {
- where += " and Id = " + Id + " and ImportStatus = 0 and ImportSupplierName = '" + Class + "'"
- } else {
- where += " and ImportStatus = 0 and ImportSupplierName = '" + Class + "' and " + Column + " = 0"
- }
- sql := "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = " + Value + " where " + where
- _, err = utils.DBE.Query(sql)
- }
- if Column == "SecondUnit" {
- var org organize.Base_Organize
- svc.GetEntityByWhere("Base_Organize", "Id = "+Value, &org)
- if Id != "" {
- where += " and Id = " + Id + " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "'"
- sql = "update OilContract set SecondUnitName = '" + org.Fullname + "',SupplierName = '" + supp.SupplierName + "', " + Column + " = " + Value + " where " + where
- } else {
- where += " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "' and " + Column + " = 0"
- sql = "update OilContract set SecondUnitName = '" + org.Fullname + "'," + Column + " = " + Value + " where " + where
- }
- _, err = utils.DBE.Query(sql)
- }
- if Column == "Status" {
- where += " and Id = " + Id + " and ImportStatus = 0"
- sql := "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = " + Value + " where " + where
- _, err = utils.DBE.Query(sql)
- }
- if Column == "SettleStatus" {
- where += " and Id = " + Id + " and ImportStatus = 0"
- sql := "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = '" + Value + "' where " + where
- _, err = utils.DBE.Query(sql)
- }
- var errinfo ErrorInfo
- 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()
- }
- }
- // excel日期字段格式化 yyyy-mm-dd
- 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]
- }
- b, _ := strconv.ParseInt(curDiffDay, 10, 64) //strconv.Atoi(curDiffDay)
- // 获取excel的日期距离2006-01-02的天数
- realDiffDay := b - baseDiffDay
- //fmt.Println("realDiffDay:",realDiffDay)
- // 距离2006-01-02 秒数
- realDiffSecond := realDiffDay * 24 * 3600
- //fmt.Println("realDiffSecond:",realDiffSecond)
- // 2006-01-02 15:04:05距离1970-01-01 08:00:00的秒数 网上工具可查出
- baseOriginSecond := int64(1136185445)
- resultTime := time.Unix((baseOriginSecond + realDiffSecond), 0).Format("2006-01-02")
- return resultTime
- }
- func (this *OilContractController) OperationCell(svc *contract.OilContractSession, lineNo string, columnArr []string, cellsArr []*xlsx.Cell, errLineNum *string) {
- defer func() {
- if err := recover(); err != nil {
- log.Println("err"+lineNo, err)
- *errLineNum += lineNo + ","
- }
- }()
- cellsArrLen := len(cellsArr)
- var valstr = ""
- 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 = ""
- for l := 0; l < cellsArrLen; l++ {
- columnstr += columnArr[l] + ","
- }
- columnstr = strings.Trim(columnstr, ",")
- //err := svc.InsertTmpOilBasisBuild(columnstr, valstr)
- //if err != nil {
- // panic(err)
- //}
- }
- func structToMapDemo(obj interface{}) map[string]interface{} {
- obj1 := reflect.TypeOf(obj)
- obj2 := reflect.ValueOf(obj)
- var data = make(map[string]interface{})
- for i := 0; i < obj1.NumField(); i++ {
- data[obj1.Field(i).Name] = obj2.Field(i).Interface()
- }
- return data
- }
- // @Title 添加
- // @Description 新增
- // @Param body body oilcontract.OilContract
- // @Success 200 {object} controllers.Request
- // @router /add [post]
- func (this *OilContractController) AddEntity() {
- var errinfo ErrorDataInfo
- var model contract.OilContract
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := contract.GetOilContractService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- if model.IsYear == 1 && model.IsYearMoney == "" {
- errinfo.Message = "跨年当年结算金额必填"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- if model.IsYearMoney == "" {
- model.IsYearMoney = model.PerformAmount
- }
- model.ImportStatus = 2
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- model.SecondUnit = this.User.UnitId
- var model1 contract.OilContractMoney
- var contract contract.OilContract
- tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' ")
- if tempCount > 0 {
- errinfo.Message = "合同编号已存在!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- _, err := svc.InsertEntityBytbl(OilContractName, &model)
- if err == nil {
- if model.IsYear == 1 {
- svc.GetEntityByWhere(OilContractName, "ContractNo = '"+model.ContractNo+"'", &model)
- svc.GetEntityByWhere("OilContractMoney", "Year = '"+time.Now().Format("2006")+"' and ContractId = "+strconv.Itoa(model.Id), &model1)
- model1.ContractId = model.Id
- model1.Money = model.IsYearMoney
- model1.Year = time.Now().Format("2006")
- model1.CreateOn = time.Now()
- model1.CreateBy = this.User.Realname
- model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntityBytbl("OilContractMoney", &model1)
- }
- //新增
- 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
- var model1 contract.OilContractMoney
- svc := contract.GetOilContractService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- if model.IsYear == 1 && model.IsYearMoney == "" {
- errinfo.Message = "跨年当年结算金额必填"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- if model.IsYearMoney == "" {
- model.IsYearMoney = model.PerformAmount
- }
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "Id",
- "SupplierId",
- "SupplierName",
- "Status",
- "SettleStatus",
- "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",
- "SubPackage",
- "ContractName",
- "ContractSonClass",
- "SmallClass",
- "SignedDate",
- "People",
- "Number",
- "ChooseWay",
- "ContractMark",
- "Currency",
- "BudgetAmount",
- "PerformAmount",
- "IsInternal",
- "IsForeign",
- "IsDeal",
- "MoneyFlows",
- "MoneyChannelSon",
- "MoneyChannelSmall",
- "SingUnit",
- "Place",
- "DisputeResolution",
- "SubmitDate",
- "SealName",
- "PoNumber",
- "IsYearMoney",
- "IsYear",
- }
- var contract contract.OilContract
- tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' and id <> "+id)
- if tempCount > 0 {
- errinfo.Message = "合同编号已存在!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
- if err == nil {
- if model.IsYear == 1 && model.IsYearMoney != "" {
- svc.GetEntityByWhere("OilContractMoney", "Year = '"+time.Now().Format("2006")+"' and ContractId = "+id, &model1)
- if model1.Id > 0 {
- model1.Money = model.IsYearMoney
- model1.ModifiedOn = time.Now()
- model1.ModifiedBy = this.User.Realname
- model1.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.UpdateEntityBytbl("OilContractMoney", model1.Id, &model1, []string{"Money"})
- } else {
- model1.ContractId, _ = strconv.Atoi(id)
- model1.Money = model.IsYearMoney
- model1.Year = time.Now().Format("2006")
- model1.CreateOn = time.Now()
- model1.CreateBy = this.User.Realname
- model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc.InsertEntityBytbl("OilContractMoney", &model1)
- }
- }
- 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
- }
- // 有没有待审核的评价
- 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+"' ")
- if tempCount > 0 {
- errinfo.Message = "该合同存在评价不能删除!"
- errinfo.Code = -1
- 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()
- }
- }
- // @Title 获取合同结算金额总数
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /countMoney/:Id [get]
- func (this *OilContractController) CountMoney() {
- 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.OilContractMoney
- svc := contract.GetOilContractService(utils.DBE)
- svc.GetSum(&model, "Year != '"+time.Now().Format("2006")+"'")
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object} []oilcontract.OilContract
- // @router /need-eva-list [get]
- func (this *OilContractController) GetNeedEvaList() {
- var list []contract.OilContract
- sql := ` select a.* from OilContract a left join OilContractReview b on b.ContractId=a.Id where a.SecondUnit=` + strconv.Itoa(this.User.UnitId) + ` and (b.Status=0 or b.Status=NULL) `
- utils.DBE.Sql(sql).Find(&list)
- var dataInfo DataInfo
- dataInfo.Items = list
- dataInfo.CurrentItemCount = 0
- if list != nil {
- dataInfo.CurrentItemCount = int64(len(list))
- }
- this.Data["json"] = &dataInfo
- this.ServeJSON()
- }
- // @Title 获取上报情况列表
- // @Description
- // @Success 200 {object} ErrorInfo
- // @router /handOnList [post]
- func (this *OilContractController) GetHandOnStatisticsList() {
- var queryParam contract.HandOnStatisticsQuery
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &queryParam)
- var models []contract.HandOnStatisticsEntity
- svc := contract.GetOilContractService(utils.DBE)
- total := svc.GetHandOnStatisticsList(queryParam, &models)
- var dataInfo DataInfo
- dataInfo.Items = models
- dataInfo.CurrentItemCount = total
- this.Data["json"] = &dataInfo
- this.ServeJSON()
- }
|