| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- 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 = int64(len(list))
- this.Data["json"] = &dataInfo
- this.ServeJSON()
- }
|