contract.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. package oilcontract
  2. import (
  3. "dashoo.cn/backend/api/business/auditsetting"
  4. "dashoo.cn/backend/api/business/oilcontract/contractReview"
  5. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  6. "dashoo.cn/backend/api/business/organize"
  7. "dashoo.cn/backend/api/business/workflow"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/tealeg/xlsx"
  11. "log"
  12. "os"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "dashoo.cn/backend/api/business/baseUser"
  18. "dashoo.cn/backend/api/business/oilcontract/contract"
  19. . "dashoo.cn/backend/api/controllers"
  20. "dashoo.cn/business2/items"
  21. "dashoo.cn/business2/userRole"
  22. "dashoo.cn/utils"
  23. )
  24. type OilContractController struct {
  25. BaseController
  26. }
  27. // @Title 获取列表
  28. // @Description get user by token
  29. // @Success 200 {object} []oilcontract.OilContract
  30. // @router /list [get]
  31. func (this *OilContractController) GetEntityList() {
  32. //获取分页信息
  33. page := this.GetPageInfoForm()
  34. where := " 1=1 "
  35. orderby := "Id"
  36. asc := false
  37. Order := this.GetString("Order")
  38. Prop := this.GetString("Prop")
  39. if Order != "" && Prop != "" {
  40. orderby = Prop
  41. if Order == "asc" {
  42. asc = true
  43. }
  44. }
  45. Id := this.GetString("Id")
  46. SupplierId := this.GetString("SupplierId")
  47. SupplierName := this.GetString("SupplierName")
  48. ImportSupplierName := this.GetString("ImportSupplierName")
  49. ImportUnitName := this.GetString("ImportUnitName")
  50. Status := this.GetString("Status")
  51. SettleStatus := this.GetString("SettleStatus")
  52. ProjectName := this.GetString("ProjectName")
  53. ContractNo := this.GetString("ContractNo")
  54. ProjectPlace := this.GetString("ProjectPlace")
  55. ProjectOwner := this.GetString("ProjectOwner")
  56. Telephone := this.GetString("Telephone")
  57. ProjectType := this.GetString("ProjectType")
  58. ContractMode := this.GetString("ContractMode")
  59. Amount := this.GetString("Amount")
  60. ContractPeriod := this.GetString("ContractPeriod")
  61. EndDate := this.GetString("EndDate")
  62. StartDate := this.GetString("StartDate")
  63. ConstructionUnit := this.GetString("ConstructionUnit")
  64. ConstructionOwner := this.GetString("ConstructionOwner")
  65. ConstructionTelphone := this.GetString("ConstructionTelphone")
  66. BuildUnit := this.GetString("BuildUnit")
  67. BuildOwner := this.GetString("BuildOwner")
  68. BuildTelphone := this.GetString("BuildTelphone")
  69. SuperviseUnit := this.GetString("SuperviseUnit")
  70. SuperviseOwner := this.GetString("SuperviseOwner")
  71. SuperviseTelphone := this.GetString("SuperviseTelphone")
  72. QualityUnit := this.GetString("QualityUnit")
  73. QualityOwner := this.GetString("QualityOwner")
  74. QualityTelphone := this.GetString("QualityTelphone")
  75. Remark := this.GetString("Remark")
  76. IsDelete := this.GetString("IsDelete")
  77. CreateOn := this.GetString("CreateOn")
  78. CreateUserId := this.GetString("CreateUserId")
  79. CreateBy := this.GetString("CreateBy")
  80. ModifiedOn := this.GetString("ModifiedOn")
  81. ModifiedUserId := this.GetString("ModifiedUserId")
  82. ModifiedBy := this.GetString("ModifiedBy")
  83. ContractName := this.GetString("ContractName")
  84. ContractSonClass := this.GetString("ContractSonClass")
  85. SmallClass := this.GetString("SmallClass")
  86. SignedDate := this.GetString("SignedDate")
  87. People := this.GetString("People")
  88. Number := this.GetString("Number")
  89. ChooseWay := this.GetString("ChooseWay")
  90. ContractMark := this.GetString("ContractMark")
  91. Currency := this.GetString("Currency")
  92. BudgetAmount := this.GetString("BudgetAmount")
  93. PerformAmount := this.GetString("PerformAmount")
  94. IsInternal := this.GetString("IsInternal")
  95. IsForeign := this.GetString("IsForeign")
  96. IsDeal := this.GetString("IsDeal")
  97. MoneyFlows := this.GetString("MoneyFlows")
  98. MoneyChannel := this.GetString("MoneyChannel")
  99. MoneyChannelSon := this.GetString("MoneyChannelSon")
  100. MoneyChannelSmall := this.GetString("MoneyChannelSmall")
  101. SingUnit := this.GetString("SingUnit")
  102. Place := this.GetString("Place")
  103. DisputeResolution := this.GetString("DisputeResolution")
  104. SubmitDate := this.GetString("SubmitDate")
  105. SealName := this.GetString("SealName")
  106. PoNumber := this.GetString("PoNumber")
  107. SubPackage := this.GetString("SubPackage")
  108. ImportStatus := this.GetString("ImportStatus")
  109. ContractClass := this.GetString("ContractClass")
  110. ClassName := this.GetString("ClassName")
  111. if Id != "" {
  112. where = where + " and Id like '%" + Id + "%'"
  113. }
  114. if ContractClass != "" {
  115. where = where + " and ContractClass='" + ContractClass + "' "
  116. }
  117. if ClassName != "" {
  118. where = where + " and ClassName='" + ClassName + "' "
  119. }
  120. if SupplierId != "" {
  121. where = where + " and SupplierId like '%" + SupplierId + "%'"
  122. }
  123. if SupplierName != "" {
  124. where = where + " and SupplierName like '%" + SupplierName + "%'"
  125. }
  126. if ImportSupplierName != "" {
  127. where = where + " and ImportSupplierName like '%" + ImportSupplierName + "%'"
  128. }
  129. if ImportUnitName != "" {
  130. where = where + " and ImportSecondUnit like '%" + ImportUnitName + "%'"
  131. }
  132. if Status != "" {
  133. where = where + " and Status=" + Status + " "
  134. }
  135. if SettleStatus != "" {
  136. where = where + " and SettleStatus='" + SettleStatus + "' "
  137. }
  138. if ProjectName != "" {
  139. where = where + " and ProjectName like '%" + ProjectName + "%'"
  140. }
  141. if ContractNo != "" {
  142. where = where + " and ContractNo like '%" + ContractNo + "%'"
  143. }
  144. if ProjectPlace != "" {
  145. where = where + " and ProjectPlace like '%" + ProjectPlace + "%'"
  146. }
  147. if ProjectOwner != "" {
  148. where = where + " and ProjectOwner like '%" + ProjectOwner + "%'"
  149. }
  150. if Telephone != "" {
  151. where = where + " and Telephone like '%" + Telephone + "%'"
  152. }
  153. if ProjectType != "" {
  154. where = where + " and ProjectType like '%" + ProjectType + "%'"
  155. }
  156. if ContractMode != "" {
  157. where = where + " and ContractMode like '%" + ContractMode + "%'"
  158. }
  159. if Amount != "" {
  160. where = where + " and Amount like '%" + Amount + "%'"
  161. }
  162. if ContractPeriod != "" {
  163. where = where + " and ContractPeriod like '%" + ContractPeriod + "%'"
  164. }
  165. if EndDate != "" {
  166. where = where + " and EndDate like '%" + EndDate + "%'"
  167. }
  168. if StartDate != "" {
  169. where = where + " and StartDate like '%" + StartDate + "%'"
  170. }
  171. if ConstructionUnit != "" {
  172. where = where + " and ConstructionUnit like '%" + ConstructionUnit + "%'"
  173. }
  174. if ConstructionOwner != "" {
  175. where = where + " and ConstructionOwner like '%" + ConstructionOwner + "%'"
  176. }
  177. if ConstructionTelphone != "" {
  178. where = where + " and ConstructionTelphone like '%" + ConstructionTelphone + "%'"
  179. }
  180. if BuildUnit != "" {
  181. where = where + " and BuildUnit like '%" + BuildUnit + "%'"
  182. }
  183. if BuildOwner != "" {
  184. where = where + " and BuildOwner like '%" + BuildOwner + "%'"
  185. }
  186. if BuildTelphone != "" {
  187. where = where + " and BuildTelphone like '%" + BuildTelphone + "%'"
  188. }
  189. if SuperviseUnit != "" {
  190. where = where + " and SuperviseUnit like '%" + SuperviseUnit + "%'"
  191. }
  192. if SuperviseOwner != "" {
  193. where = where + " and SuperviseOwner like '%" + SuperviseOwner + "%'"
  194. }
  195. if SuperviseTelphone != "" {
  196. where = where + " and SuperviseTelphone like '%" + SuperviseTelphone + "%'"
  197. }
  198. if QualityUnit != "" {
  199. where = where + " and QualityUnit like '%" + QualityUnit + "%'"
  200. }
  201. if QualityOwner != "" {
  202. where = where + " and QualityOwner like '%" + QualityOwner + "%'"
  203. }
  204. if QualityTelphone != "" {
  205. where = where + " and QualityTelphone like '%" + QualityTelphone + "%'"
  206. }
  207. if Remark != "" {
  208. where = where + " and Remark like '%" + Remark + "%'"
  209. }
  210. if IsDelete != "" {
  211. where = where + " and IsDelete like '%" + IsDelete + "%'"
  212. }
  213. //if CreateOn != "" {
  214. // where = where + " and CreateOn like '%" + CreateOn + "%'"
  215. //}
  216. if CreateUserId != "" {
  217. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  218. }
  219. if CreateBy != "" {
  220. where = where + " and CreateBy like '%" + CreateBy + "%'"
  221. }
  222. if ModifiedOn != "" {
  223. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  224. }
  225. if ModifiedUserId != "" {
  226. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  227. }
  228. if ModifiedBy != "" {
  229. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  230. }
  231. if CreateOn != "" {
  232. dates := strings.Split(CreateOn, ",")
  233. if len(dates) == 2 {
  234. minDate := dates[0]
  235. maxDate := dates[1]
  236. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  237. }
  238. }
  239. if SubPackage != "" {
  240. where = where + " and SubPackage like '%" + SubPackage + "%'"
  241. }
  242. if ContractName != "" {
  243. where = where + " and ContractName like '%" + ContractName + "%'"
  244. }
  245. if ContractSonClass != "" {
  246. where = where + " and ContractSonClass like '%" + ContractSonClass + "%'"
  247. }
  248. if SmallClass != "" {
  249. where = where + " and SmallClass like '%" + SmallClass + "%'"
  250. }
  251. if People != "" {
  252. where = where + " and People like '%" + People + "%'"
  253. }
  254. if Number != "" {
  255. where = where + " and Number like '%" + Number + "%'"
  256. }
  257. if ChooseWay != "" {
  258. where = where + " and ChooseWay like '%" + ChooseWay + "%'"
  259. }
  260. if ContractMark != "" {
  261. where = where + " and ContractMark like '%" + ContractMark + "%'"
  262. }
  263. if Currency != "" {
  264. where = where + " and Currency like '%" + Currency + "%'"
  265. }
  266. if BudgetAmount != "" {
  267. where = where + " and BudgetAmount like '%" + BudgetAmount + "%'"
  268. }
  269. if PerformAmount != "" {
  270. where = where + " and PerformAmount like '%" + PerformAmount + "%'"
  271. }
  272. if IsInternal != "" {
  273. where = where + " and IsInternal like '%" + IsInternal + "%'"
  274. }
  275. if IsForeign != "" {
  276. where = where + " and IsForeign like '%" + IsForeign + "%'"
  277. }
  278. if IsDeal != "" {
  279. where = where + " and IsDeal like '%" + IsDeal + "%'"
  280. }
  281. if MoneyFlows != "" {
  282. where = where + " and MoneyFlows like '%" + MoneyFlows + "%'"
  283. }
  284. if MoneyChannel != "" {
  285. where = where + " and MoneyChannel like '%" + MoneyChannel + "%'"
  286. }
  287. if MoneyChannelSon != "" {
  288. where = where + " and MoneyChannelSon like '%" + MoneyChannelSon + "%'"
  289. }
  290. if MoneyChannelSmall != "" {
  291. where = where + " and MoneyChannelSmall like '%" + MoneyChannelSmall + "%'"
  292. }
  293. if SingUnit != "" {
  294. where = where + " and SingUnit like '%" + SingUnit + "%'"
  295. }
  296. if Place != "" {
  297. where = where + " and Place like '%" + Place + "%'"
  298. }
  299. if DisputeResolution != "" {
  300. where = where + " and DisputeResolution like '%" + DisputeResolution + "%'"
  301. }
  302. if SubmitDate != "" {
  303. where = where + " and SubmitDate like '%" + SubmitDate + "%'"
  304. }
  305. if SealName != "" {
  306. where = where + " and SealName like '%" + SealName + "%'"
  307. }
  308. if PoNumber != "" {
  309. where = where + " and PoNumber like '%" + PoNumber + "%'"
  310. }
  311. if SignedDate != "" {
  312. where = where + " and PoNumber like '%" + SignedDate + "%'"
  313. }
  314. if ImportStatus != "" {
  315. where = where + " and ImportStatus = " + ImportStatus
  316. } else {
  317. where = where + " and ImportStatus != 0"
  318. }
  319. // 企管法规处可看所有合同, 获取企管法规处人员
  320. var settingReg auditsetting.Base_OilAuditSetting
  321. orgSvc := organize.GetOrganizeService(utils.DBE)
  322. wherePRegAudit := "AuditStepCode='PROF_REGULATION'"
  323. orgSvc.GetEntity(&settingReg, wherePRegAudit) // PROF_AUDIT
  324. res1 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingReg.RoleId))
  325. // 所有业务处室分办单位可查看所有合同 TODO 待确认
  326. var settingProf auditsetting.Base_OilAuditSetting
  327. wherePAudit := "AuditStepCode='PROF_RECE'"
  328. orgSvc.GetEntity(&settingProf, wherePAudit) // PROF_AUDIT
  329. res2 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingProf.RoleId))
  330. if !res1 && !res2 {
  331. where = where + " and SecondUnit= " + strconv.Itoa(this.User.UnitId)
  332. }
  333. svc := contract.GetOilContractService(utils.DBE)
  334. var list []contract.OilContract
  335. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  336. var datainfo DataInfo
  337. datainfo.Items = list
  338. datainfo.CurrentItemCount = total
  339. datainfo.PageIndex = page.CurrentPage
  340. datainfo.ItemsPerPage = page.Size
  341. this.Data["json"] = &datainfo
  342. this.ServeJSON()
  343. }
  344. // @Title 获取字典列表
  345. // @Description get user by token
  346. // @Success 200 {object} map[string]interface{}
  347. // @router /dictlist [get]
  348. func (this *OilContractController) GetDictList() {
  349. dictList := make(map[string]interface{})
  350. dictSvc := items.GetItemsService(utils.DBE)
  351. userSvc := baseUser.GetBaseUserService(utils.DBE)
  352. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  353. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  354. var userEntity userRole.Base_User
  355. userSvc.GetEntityById(this.User.Id, &userEntity)
  356. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  357. dictList["ContractClass"] = dictSvc.GetKeyValueItems("ContractClass")
  358. dictList["ProjectType"] = dictSvc.GetKeyValueItems("ProjectType")
  359. dictList["ContractMode"] = dictSvc.GetKeyValueItems("ContractMode")
  360. dictList["CurrencyType"] = dictSvc.GetKeyValueItems("CurrencyType")
  361. //var dictCustomer []svccustomer.Customer
  362. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  363. //dictList["EntrustCorp"] = &dictCustomer
  364. var datainfo DataInfo
  365. datainfo.Items = dictList
  366. this.Data["json"] = &datainfo
  367. this.ServeJSON()
  368. }
  369. // @Title 完成合同
  370. // @Description get user by token
  371. // @Success 200 {object} map[string]interface{}
  372. // @router /finish/:id [get]
  373. //func (this *OilContractController) Finish(){
  374. // id := this.Ctx.Input.Param(":id")
  375. // var errinfo ErrorInfo
  376. // if id == "" {
  377. // errinfo.Message = "操作失败!请求信息不完整"
  378. // errinfo.Code = -2
  379. // this.Data["json"] = &errinfo
  380. // this.ServeJSON()
  381. // return
  382. // }
  383. // var model contract.OilContract
  384. // svc := contract.GetOilContractService(utils.DBE)
  385. // model.Status = 2
  386. // cols := []string{
  387. // "Status",
  388. // }
  389. // err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
  390. // if err == nil {
  391. // errinfo.Message = "修改成功!"
  392. // errinfo.Code = 0
  393. // this.Data["json"] = &errinfo
  394. // this.ServeJSON()
  395. // } else {
  396. // errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  397. // errinfo.Code = -1
  398. // this.Data["json"] = &errinfo
  399. // this.ServeJSON()
  400. // }
  401. //}
  402. // @Title 获取实体
  403. // @Description 获取实体
  404. // @Success 200 {object} oilcontract.OilContract
  405. // @router /get/:id [get]
  406. func (this *OilContractController) GetEntity() {
  407. Id := this.Ctx.Input.Param(":id")
  408. var model contract.OilContract
  409. svc := contract.GetOilContractService(utils.DBE)
  410. svc.GetEntityByIdBytbl(OilContractName, Id, &model)
  411. this.Data["json"] = &model
  412. this.ServeJSON()
  413. }
  414. // @Title get 导入excel
  415. // @Description 导入excel
  416. // @Success 200 {object} controllers.Request
  417. // @router /importexcel [get]
  418. func (this *OilContractController) ImportExcel() {
  419. go func() {
  420. defer func() {
  421. if err := recover(); err != nil {
  422. log.Println("合同导入err", err)
  423. }
  424. }()
  425. url := this.GetString("ExcelUrl")
  426. //var errLineNum string
  427. if url == "" {
  428. fmt.Println("文件不能为空!")
  429. }
  430. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
  431. filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  432. //60.30.245.229 替换成23
  433. url = strings.Replace(url, "60.30.245.229", "10.76.248.23", -1)
  434. utils.DownloadFile(url, filename, _dir)
  435. t := time.Now()
  436. filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/" + filename
  437. xlFile, err := xlsx.OpenFile(filePath)
  438. //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
  439. if err != nil {
  440. fmt.Printf("open failed: %s\n", err)
  441. }
  442. var sheet = xlFile.Sheets[0]
  443. // 插入字段
  444. //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"
  445. //columnArr := strings.Split(Fstrs, ",")
  446. //timeTemplate1 := "2006/01/02 15:04:05" //常规类型
  447. svc := contract.GetOilContractService(utils.DBE)
  448. for i := 1; i < len(sheet.Rows); i++ {
  449. var con contract.OilContract
  450. var con1 contract.OilContract
  451. lineNo := strconv.Itoa(i + 1)
  452. fmt.Println(lineNo)
  453. if sheet.Rows[i].Cells[2].String() != "" {
  454. svc.GetEntityByWhere(OilContractName, "ContractNo = '"+sheet.Rows[i].Cells[2].String()+"'", &con1)
  455. if con1.Id > 0 {
  456. con1.ContractName = sheet.Rows[i].Cells[3].String()
  457. con1.Amount = sheet.Rows[i].Cells[4].String()
  458. if con1.Amount == "" {
  459. con1.Amount = "0"
  460. }
  461. con1.ClassName = sheet.Rows[i].Cells[0].String()
  462. if con1.ClassName == "买卖合同" {
  463. con1.ContractClass = "01"
  464. } else {
  465. con1.ContractClass = "03"
  466. }
  467. //con1.ContractSonClass = sheet.Rows[i].Cells[4].String()
  468. //con1.SmallClass = sheet.Rows[i].Cells[5].String()
  469. con1.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[7].Value), time.Local)
  470. con1.Number = sheet.Rows[i].Cells[10].String()
  471. //con1.ChooseWay = sheet.Rows[i].Cells[11].String()
  472. //con1.ContractMark = sheet.Rows[i].Cells[14].String()
  473. //con1.Currency = sheet.Rows[i].Cells[15].String()
  474. //con1.BudgetAmount = sheet.Rows[i].Cells[16].String()
  475. if con.BudgetAmount == "" {
  476. con.BudgetAmount = "0"
  477. }
  478. //con1.PerformAmount = sheet.Rows[i].Cells[17].String()
  479. if con1.PerformAmount == "" {
  480. con1.PerformAmount = "0"
  481. }
  482. con1.IsYearMoney = con1.PerformAmount
  483. con1.IsInternal = 0
  484. //if sheet.Rows[i].Cells[18].String() == "是" {
  485. // con1.IsInternal = 1
  486. //}
  487. con1.IsForeign = 0
  488. //if sheet.Rows[i].Cells[19].String() == "是" {
  489. // con1.IsForeign = 1
  490. //}
  491. con1.IsDeal = 0
  492. //if sheet.Rows[i].Cells[20].String() == "是" {
  493. // con1.IsDeal = 1
  494. //}
  495. //con1.MoneyFlows = sheet.Rows[i].Cells[21].String()
  496. //con1.MoneyChannel = sheet.Rows[i].Cells[22].String()
  497. //con1.MoneyChannelSon = sheet.Rows[i].Cells[23].String()
  498. //con1.MoneyChannelSmall = sheet.Rows[i].Cells[24].String()
  499. //con1.SingUnit = sheet.Rows[i].Cells[25].String()
  500. //con1.Place = sheet.Rows[i].Cells[28].String()
  501. con1.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[8].Value), time.Local)
  502. con1.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  503. con1.YearDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  504. //con1.DisputeResolution = sheet.Rows[i].Cells[31].String()
  505. //con1.Remark = sheet.Rows[i].Cells[32].String()
  506. if con1.ProjectOwner != sheet.Rows[i].Cells[6].String() {
  507. con1.ProjectOwner = con1.ProjectOwner + "," + sheet.Rows[i].Cells[6].String()
  508. }
  509. //con1.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[34].Value), time.Local)
  510. //con1.SealName = sheet.Rows[i].Cells[42].String()
  511. //con1.PoNumber = sheet.Rows[i].Cells[31].String()
  512. //con1.ImportStatus = 0
  513. svc.UpdateEntityById(con1.Id, &con1)
  514. continue
  515. }
  516. }
  517. con.ClassName = sheet.Rows[i].Cells[0].String()
  518. if con.ClassName == "买卖合同" {
  519. con.ContractClass = "01"
  520. } else {
  521. con.ContractClass = "03"
  522. }
  523. con.ImportSupplierName = sheet.Rows[i].Cells[1].String()
  524. con.SupplierName = con.ImportSupplierName
  525. con.ContractNo = sheet.Rows[i].Cells[2].String()
  526. con.ContractName = sheet.Rows[i].Cells[3].String()
  527. con.Amount = sheet.Rows[i].Cells[4].String()
  528. if con.Amount == "" {
  529. con.Amount = "0"
  530. }
  531. con.ImportSecondUnit = sheet.Rows[i].Cells[5].String()
  532. con.ProjectOwner = sheet.Rows[i].Cells[6].String()
  533. //con.ContractSonClass = sheet.Rows[i].Cells[4].String()
  534. //con.SmallClass = sheet.Rows[i].Cells[5].String()
  535. //con.SignedDate = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
  536. con.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[7].Value), time.Local)
  537. con.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[8].Value), time.Local)
  538. con.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  539. con.YearDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  540. var supp supplier.OilSupplier
  541. svc.GetEntityByWhere(OilSupplierName, "SupplierName = '"+con.ImportSupplierName+"'", &supp)
  542. if supp.Id > 0 {
  543. con.SupplierId = supp.Id
  544. }
  545. var org organize.Base_Organize
  546. svc.GetEntityByWhere("Base_Organize", "FullName = '"+sheet.Rows[i].Cells[5].String()+"'", &org)
  547. if org.Id > 0 {
  548. con.SecondUnit = org.Id
  549. con.SecondUnitName = org.Fullname
  550. }
  551. con.Number = sheet.Rows[i].Cells[10].String()
  552. //con.ChooseWay = sheet.Rows[i].Cells[11].String()
  553. //con.ContractMark = sheet.Rows[i].Cells[14].String()
  554. //con.Currency = sheet.Rows[i].Cells[15].String()
  555. //con.BudgetAmount = sheet.Rows[i].Cells[16].String()
  556. if con.BudgetAmount == "" {
  557. con.BudgetAmount = "0"
  558. }
  559. //con.PerformAmount = sheet.Rows[i].Cells[17].String()
  560. if con.PerformAmount == "" {
  561. con.PerformAmount = "0"
  562. }
  563. con.IsYearMoney = con.PerformAmount
  564. con.IsInternal = 0
  565. //if sheet.Rows[i].Cells[18].String() == "是" {
  566. // con.IsInternal = 1
  567. //}
  568. con.IsForeign = 0
  569. //if sheet.Rows[i].Cells[19].String() == "是" {
  570. // con.IsForeign = 1
  571. //}
  572. con.IsDeal = 0
  573. //if sheet.Rows[i].Cells[20].String() == "是" {
  574. // con.IsDeal = 1
  575. //}
  576. //con.MoneyFlows = sheet.Rows[i].Cells[21].String()
  577. //con.MoneyChannel = sheet.Rows[i].Cells[22].String()
  578. //con.MoneyChannelSon = sheet.Rows[i].Cells[23].String()
  579. //con.MoneyChannelSmall = sheet.Rows[i].Cells[24].String()
  580. //con.SingUnit = sheet.Rows[i].Cells[25].String()
  581. //con.Place = sheet.Rows[i].Cells[28].String()
  582. //con.DisputeResolution = sheet.Rows[i].Cells[31].String()
  583. //con.Remark = sheet.Rows[i].Cells[32].String()
  584. //con.ProjectOwner = sheet.Rows[i].Cells[33].String()
  585. //con.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[34].Value), time.Local)
  586. //con.SealName = sheet.Rows[i].Cells[42].String()
  587. //con.PoNumber = sheet.Rows[i].Cells[32].String()
  588. con.ImportStatus = 0
  589. con.Status = 1
  590. con.SettleStatus = "1"
  591. _, err = svc.InsertEntityBytbl(OilContractName, &con)
  592. if err != nil {
  593. fmt.Println(err)
  594. }
  595. }
  596. os.Remove(filePath)
  597. elapsed := time.Since(t)
  598. log.Println(elapsed)
  599. }()
  600. var errorinfo ErrorDataInfo
  601. errorinfo.Code = 0
  602. errorinfo.Message = "导入中,请稍后!"
  603. this.Data["json"] = &errorinfo
  604. this.ServeJSON()
  605. }
  606. // @Title 从数据录入数据导出到word文档
  607. // @Description 数据存入word
  608. // @Success 200 {object} controllers.Request
  609. // @router /exportword/:id [get]
  610. func (this *OilContractController) DocExport() {
  611. // 填物资类信息表首页信息
  612. Id := this.Ctx.Input.Param(":id")
  613. var Url string
  614. var fileName string
  615. svcActiviti := workflow.GetActivitiService(utils.DBE)
  616. var model contract.OilContract
  617. svc := contract.GetOilContractService(utils.DBE)
  618. where := "1=1"
  619. where += " AND Id = '" + Id + "'"
  620. svc.GetEntityByWhere(OilContractName, where, &model)
  621. Url = utils.Cfg.MustValue("workflow", "contractUrl")
  622. fileName = "合同导出模板.docx"
  623. model.ProjectName = model.ContractName
  624. model.OpenDate = model.StartDate
  625. model.PlanFinishDate = model.EndDate
  626. datamap := structToMapDemo(model)
  627. //datamap["TableComment"] = []string{"MajorEquipments", "ThreeYears", "Patent", "Winning"}
  628. retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName)
  629. //retDocUrl := svcActiviti.FillWordWatermarkTemplate(datamap, Url, fileName, model.SupplierName)
  630. var datainfo ErrorDataInfo
  631. datainfo.Code = 0
  632. datainfo.Item = retDocUrl
  633. datainfo.Message = "导出成功"
  634. this.Data["json"] = &datainfo
  635. this.ServeJSON()
  636. }
  637. // @Title get 导入批量保存
  638. // @Description 数据存入
  639. // @Success 200 {object} controllers.Request
  640. // @router /importbatchsave [post]
  641. func (this *OilContractController) ImportBatchSave() {
  642. sql := "update OilContract set ImportStatus = 1 where SupplierName != '' and ContractClass != '' and SecondUnit != 0 and ContractNo != ''"
  643. _, err := utils.DBE.Query(sql)
  644. var errinfo ErrorInfo
  645. if err == nil {
  646. errinfo.Message = "确认成功!"
  647. errinfo.Code = 0
  648. this.Data["json"] = &errinfo
  649. this.ServeJSON()
  650. } else {
  651. errinfo.Message = "确认失败!" + utils.AlertProcess(err.Error())
  652. errinfo.Code = -1
  653. this.Data["json"] = &errinfo
  654. this.ServeJSON()
  655. }
  656. }
  657. // @Title get 批量修改字段
  658. // @Description 批量修改字段
  659. // @Success 200 {object} controllers.Request
  660. // @router /importUpdate [get]
  661. func (this *OilContractController) ImportUpdate() {
  662. Class := this.GetString("Class")
  663. Value := this.GetString("Value")
  664. Column := this.GetString("Column")
  665. Id := this.GetString("Id")
  666. SupplierId := this.GetString("SupplierId")
  667. var supp supplier.OilSupplier
  668. var con contract.OilContract
  669. svc := supplier.GetOilSupplierService(utils.DBE)
  670. svc.GetEntityById(SupplierId, &supp)
  671. sql := ""
  672. var err error
  673. var errinfo ErrorInfo
  674. where := "1=1"
  675. if Column == "ContractClass" {
  676. if Id != "0" {
  677. where += " and Id = " + Id + " and ImportStatus = 0 and ClassName = '" + Class + "'"
  678. } else {
  679. where += " and ImportStatus = 0 and ClassName = '" + Class + "' and " + Column + " = ''"
  680. }
  681. sql = "update OilContract set " + Column + " = '" + Value + "' where " + where
  682. _, err = utils.DBE.Query(sql)
  683. }
  684. if Column == "SupplierId" {
  685. if Id != "0" {
  686. where += " and Id = " + Id + " and ImportStatus = 0 and ImportSupplierName = '" + Class + "'"
  687. } else {
  688. where += " and ImportStatus = 0 and ImportSupplierName = '" + Class + "' and " + Column + " = 0"
  689. }
  690. sql := "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = " + Value + " where " + where
  691. _, err = utils.DBE.Query(sql)
  692. }
  693. if Column == "SecondUnit" {
  694. var org organize.Base_Organize
  695. svc.GetEntityByWhere("Base_Organize", "Id = "+Value, &org)
  696. if Id != "0" {
  697. where += " and Id = " + Id + " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "'"
  698. sql = "update OilContract set SecondUnitName = '" + org.Fullname + "', " + Column + " = " + Value + " where " + where
  699. } else {
  700. //where += " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "' and " + Column + " = 0"
  701. where += " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "'"
  702. sql = "update OilContract set SecondUnitName = '" + org.Fullname + "'," + Column + " = " + Value + " where " + where
  703. }
  704. _, err = utils.DBE.Query(sql)
  705. }
  706. if Column == "Status" {
  707. where += " and Id = " + Id + " and ImportStatus = 0"
  708. sql := "update OilContract set " + Column + " = " + Value + " where " + where
  709. _, err = utils.DBE.Query(sql)
  710. }
  711. if Column == "ContractNo" {
  712. svc.GetEntityByWhere("OilContract", "ContractNo = '" + Value + "' and Id != " + Id, &con)
  713. if Value == "" {
  714. errinfo.Message = "修改失败!合同编号不能为空"
  715. errinfo.Code = -1
  716. this.Data["json"] = &errinfo
  717. this.ServeJSON()
  718. return
  719. }
  720. if con.Id > 0 {
  721. errinfo.Message = "修改失败!合同编号不能重复"
  722. errinfo.Code = -1
  723. this.Data["json"] = &errinfo
  724. this.ServeJSON()
  725. return
  726. }
  727. where += " and Id = " + Id + " and ImportStatus = 0"
  728. sql := "update OilContract set " + Column + " = '" + Value + "' where " + where
  729. _, err = utils.DBE.Query(sql)
  730. }
  731. if Column == "SettleStatus" {
  732. where += " and Id = " + Id + " and ImportStatus = 0"
  733. sql := "update OilContract set " + Column + " = '" + Value + "' where " + where
  734. _, err = utils.DBE.Query(sql)
  735. }
  736. if err == nil {
  737. errinfo.Message = "修改成功!"
  738. errinfo.Code = 0
  739. this.Data["json"] = &errinfo
  740. this.ServeJSON()
  741. } else {
  742. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  743. errinfo.Code = -1
  744. this.Data["json"] = &errinfo
  745. this.ServeJSON()
  746. }
  747. }
  748. // excel日期字段格式化 yyyy-mm-dd
  749. func convertToFormatDay(excelDaysString string) string {
  750. if strings.Index(excelDaysString, "/") != -1 {
  751. arr := strings.Split(excelDaysString, "/")
  752. if len(arr) == 3 {
  753. if len(arr[1]) == 1 {
  754. arr[1] = "0" + arr[1]
  755. }
  756. if len(arr[2]) == 1 {
  757. arr[2] = "0" + arr[2]
  758. }
  759. excelDaysString = strings.Join(arr, "-")
  760. }
  761. return excelDaysString
  762. }
  763. // 2006-01-02 距离 1900-01-01的天数
  764. baseDiffDay := int64(38719) //在网上工具计算的天数需要加2天,什么原因没弄清楚
  765. curDiffDay := excelDaysString
  766. comma := strings.Index(curDiffDay, ".")
  767. if comma != -1 {
  768. curDiffDay = curDiffDay[0:comma]
  769. }
  770. b, _ := strconv.ParseInt(curDiffDay, 10, 64) //strconv.Atoi(curDiffDay)
  771. // 获取excel的日期距离2006-01-02的天数
  772. realDiffDay := b - baseDiffDay
  773. //fmt.Println("realDiffDay:",realDiffDay)
  774. // 距离2006-01-02 秒数
  775. realDiffSecond := realDiffDay * 24 * 3600
  776. //fmt.Println("realDiffSecond:",realDiffSecond)
  777. // 2006-01-02 15:04:05距离1970-01-01 08:00:00的秒数 网上工具可查出
  778. baseOriginSecond := int64(1136185445)
  779. resultTime := time.Unix((baseOriginSecond + realDiffSecond), 0).Format("2006-01-02")
  780. return resultTime
  781. }
  782. func (this *OilContractController) OperationCell(svc *contract.OilContractSession, lineNo string, columnArr []string, cellsArr []*xlsx.Cell, errLineNum *string) {
  783. defer func() {
  784. if err := recover(); err != nil {
  785. log.Println("err"+lineNo, err)
  786. *errLineNum += lineNo + ","
  787. }
  788. }()
  789. cellsArrLen := len(cellsArr)
  790. var valstr = ""
  791. for i := 0; i < cellsArrLen; i++ {
  792. valstr += "'" + cellsArr[i].String() + "',"
  793. }
  794. valstr = strings.Trim(valstr, ",")
  795. valstr = strings.Replace(valstr, "是", "1", -1)
  796. log.Println(cellsArr[6].String() + "==" + valstr)
  797. var columnstr = ""
  798. for l := 0; l < cellsArrLen; l++ {
  799. columnstr += columnArr[l] + ","
  800. }
  801. columnstr = strings.Trim(columnstr, ",")
  802. //err := svc.InsertTmpOilBasisBuild(columnstr, valstr)
  803. //if err != nil {
  804. // panic(err)
  805. //}
  806. }
  807. func structToMapDemo(obj interface{}) map[string]interface{} {
  808. obj1 := reflect.TypeOf(obj)
  809. obj2 := reflect.ValueOf(obj)
  810. var data = make(map[string]interface{})
  811. for i := 0; i < obj1.NumField(); i++ {
  812. data[obj1.Field(i).Name] = obj2.Field(i).Interface()
  813. }
  814. return data
  815. }
  816. // @Title 添加
  817. // @Description 新增
  818. // @Param body body oilcontract.OilContract
  819. // @Success 200 {object} controllers.Request
  820. // @router /add [post]
  821. func (this *OilContractController) AddEntity() {
  822. var errinfo ErrorDataInfo
  823. var model contract.OilContract
  824. var jsonBlob = this.Ctx.Input.RequestBody
  825. svc := contract.GetOilContractService(utils.DBE)
  826. json.Unmarshal(jsonBlob, &model)
  827. if model.IsYear == 1 && model.IsYearMoney == "" {
  828. errinfo.Message = "跨年当年结算金额必填"
  829. errinfo.Code = -2
  830. this.Data["json"] = &errinfo
  831. this.ServeJSON()
  832. return
  833. }
  834. if model.IsYearMoney == "" {
  835. model.IsYearMoney = model.PerformAmount
  836. }
  837. model.ImportStatus = 2
  838. model.CreateOn = time.Now()
  839. model.CreateBy = this.User.Realname
  840. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  841. model.SecondUnit = this.User.UnitId
  842. var model1 contract.OilContractMoney
  843. var contract contract.OilContract
  844. tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' ")
  845. if tempCount > 0 {
  846. errinfo.Message = "合同编号已存在!"
  847. errinfo.Code = -1
  848. this.Data["json"] = &errinfo
  849. this.ServeJSON()
  850. return
  851. }
  852. _, err := svc.InsertEntityBytbl(OilContractName, &model)
  853. if err == nil {
  854. if model.IsYear == 1 {
  855. svc.GetEntityByWhere(OilContractName, "ContractNo = '"+model.ContractNo+"'", &model)
  856. svc.GetEntityByWhere("OilContractMoney", "Year = '"+time.Now().Format("2006")+"' and ContractId = "+strconv.Itoa(model.Id), &model1)
  857. model1.ContractId = model.Id
  858. model1.Money = model.IsYearMoney
  859. model1.Year = time.Now().Format("2006")
  860. model1.CreateOn = time.Now()
  861. model1.CreateBy = this.User.Realname
  862. model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  863. svc.InsertEntityBytbl("OilContractMoney", &model1)
  864. }
  865. //新增
  866. errinfo.Message = "添加成功!"
  867. errinfo.Code = 0
  868. errinfo.Item = model.Id
  869. this.Data["json"] = &errinfo
  870. this.ServeJSON()
  871. } else {
  872. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  873. errinfo.Code = -1
  874. this.Data["json"] = &errinfo
  875. this.ServeJSON()
  876. }
  877. }
  878. // @Title 修改实体
  879. // @Description 修改实体
  880. // @Param body body oilcontract.OilContract
  881. // @Success 200 {object} controllers.Request
  882. // @router /update/:id [post]
  883. func (this *OilContractController) UpdateEntity() {
  884. id := this.Ctx.Input.Param(":id")
  885. var errinfo ErrorInfo
  886. if id == "" {
  887. errinfo.Message = "操作失败!请求信息不完整"
  888. errinfo.Code = -2
  889. this.Data["json"] = &errinfo
  890. this.ServeJSON()
  891. return
  892. }
  893. var model contract.OilContract
  894. var model1 contract.OilContractMoney
  895. svc := contract.GetOilContractService(utils.DBE)
  896. var jsonBlob = this.Ctx.Input.RequestBody
  897. json.Unmarshal(jsonBlob, &model)
  898. if model.IsYear == 1 && model.IsYearMoney == "" {
  899. errinfo.Message = "跨年当年结算金额必填"
  900. errinfo.Code = -2
  901. this.Data["json"] = &errinfo
  902. this.ServeJSON()
  903. return
  904. }
  905. if model.IsYearMoney == "" {
  906. model.IsYearMoney = model.PerformAmount
  907. }
  908. model.ModifiedOn = time.Now()
  909. model.ModifiedBy = this.User.Realname
  910. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  911. cols := []string{
  912. "Id",
  913. "SupplierId",
  914. "SupplierName",
  915. "Status",
  916. "SettleStatus",
  917. "ProjectName",
  918. "ContractNo",
  919. "ProjectPlace",
  920. "ProjectOwner",
  921. "Telephone",
  922. "ProjectType",
  923. "ContractMode",
  924. "Amount",
  925. "ContractPeriod",
  926. "EndDate",
  927. "YearDate",
  928. "StartDate",
  929. "ConstructionUnit",
  930. "ConstructionOwner",
  931. "ConstructionTelphone",
  932. "BuildUnit",
  933. "BuildOwner",
  934. "BuildTelphone",
  935. "SuperviseUnit",
  936. "SuperviseOwner",
  937. "SuperviseTelphone",
  938. "QualityUnit",
  939. "QualityOwner",
  940. "QualityTelphone",
  941. "Remark",
  942. "IsDelete",
  943. "CreateOn",
  944. "CreateUserId",
  945. "CreateBy",
  946. "ModifiedOn",
  947. "ModifiedUserId",
  948. "ModifiedBy",
  949. "SubPackage",
  950. "ContractName",
  951. "ContractSonClass",
  952. "SmallClass",
  953. "SignedDate",
  954. "People",
  955. "Number",
  956. "ChooseWay",
  957. "ContractMark",
  958. "Currency",
  959. "BudgetAmount",
  960. "PerformAmount",
  961. "IsInternal",
  962. "IsForeign",
  963. "IsDeal",
  964. "MoneyFlows",
  965. "MoneyChannelSon",
  966. "MoneyChannelSmall",
  967. "SingUnit",
  968. "Place",
  969. "DisputeResolution",
  970. "SubmitDate",
  971. "SealName",
  972. "PoNumber",
  973. "IsYearMoney",
  974. "IsYear",
  975. }
  976. var contract contract.OilContract
  977. tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' and id <> "+id)
  978. if tempCount > 0 {
  979. errinfo.Message = "合同编号已存在!"
  980. errinfo.Code = -1
  981. this.Data["json"] = &errinfo
  982. this.ServeJSON()
  983. return
  984. }
  985. date := time.Now().Format("2006-01-02")
  986. date1 := model.EndDate.Format("2006-01-02")
  987. if date >= date1 && model.IsYear == 1{
  988. model.YearDate = model.EndDate.AddDate(1,0,0)
  989. }
  990. err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
  991. if err == nil {
  992. if model.IsYear == 1 && model.IsYearMoney != "" {
  993. svc.GetEntityByWhere("OilContractMoney", "Year = '"+time.Now().Format("2006")+"' and ContractId = "+id, &model1)
  994. if model1.Id > 0 {
  995. model1.Money = model.IsYearMoney
  996. model1.ModifiedOn = time.Now()
  997. model1.ModifiedBy = this.User.Realname
  998. model1.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  999. svc.UpdateEntityBytbl("OilContractMoney", model1.Id, &model1, []string{"Money"})
  1000. } else {
  1001. model1.ContractId, _ = strconv.Atoi(id)
  1002. model1.Money = model.IsYearMoney
  1003. model1.Year = time.Now().Format("2006")
  1004. model1.CreateOn = time.Now()
  1005. model1.CreateBy = this.User.Realname
  1006. model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1007. svc.InsertEntityBytbl("OilContractMoney", &model1)
  1008. }
  1009. }
  1010. errinfo.Message = "修改成功!"
  1011. errinfo.Code = 0
  1012. this.Data["json"] = &errinfo
  1013. this.ServeJSON()
  1014. } else {
  1015. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  1016. errinfo.Code = -1
  1017. this.Data["json"] = &errinfo
  1018. this.ServeJSON()
  1019. }
  1020. }
  1021. // @Title 删除单条信息
  1022. // @Description
  1023. // @Success 200 {object} ErrorInfo
  1024. // @Failure 403 :id 为空
  1025. // @router /delete/:Id [delete]
  1026. func (this *OilContractController) DeleteEntity() {
  1027. Id := this.Ctx.Input.Param(":Id")
  1028. var errinfo ErrorInfo
  1029. if Id == "" {
  1030. errinfo.Message = "操作失败!请求信息不完整"
  1031. errinfo.Code = -2
  1032. this.Data["json"] = &errinfo
  1033. this.ServeJSON()
  1034. return
  1035. }
  1036. // 有没有待审核的评价
  1037. itemsSvc := contractReview.GetOilContractReviewService(utils.DBE)
  1038. var review contractReview.OilContractReview
  1039. //tempCount,_:=itemsSvc.GetCount(&review,"ContractId='" + Id +"' and status > 0 and status < 8 ")
  1040. tempCount, _ := itemsSvc.GetCount(&review, "ContractId='"+Id+"' ")
  1041. if tempCount > 0 {
  1042. errinfo.Message = "该合同存在评价不能删除!"
  1043. errinfo.Code = -1
  1044. this.Data["json"] = &errinfo
  1045. this.ServeJSON()
  1046. return
  1047. }
  1048. var model contract.OilContract
  1049. var entityempty contract.OilContract
  1050. svc := contract.GetOilContractService(utils.DBE)
  1051. opdesc := "删除-" + Id
  1052. err := svc.DeleteOperationAndWriteLogBytbl(OilContractName, BaseOperationLogName, Id, &model, &entityempty,
  1053. utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "合同表")
  1054. if err == nil {
  1055. errinfo.Message = "删除成功"
  1056. errinfo.Code = 0
  1057. this.Data["json"] = &errinfo
  1058. this.ServeJSON()
  1059. } else {
  1060. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  1061. errinfo.Code = -1
  1062. this.Data["json"] = &errinfo
  1063. this.ServeJSON()
  1064. }
  1065. }
  1066. // @Title 获取合同结算金额总数
  1067. // @Description
  1068. // @Success 200 {object} ErrorInfo
  1069. // @Failure 403 :id 为空
  1070. // @router /countMoney/:Id [get]
  1071. func (this *OilContractController) CountMoney() {
  1072. Id := this.Ctx.Input.Param(":Id")
  1073. var errinfo ErrorInfo
  1074. if Id == "" {
  1075. errinfo.Message = "操作失败!请求信息不完整"
  1076. errinfo.Code = -2
  1077. this.Data["json"] = &errinfo
  1078. this.ServeJSON()
  1079. return
  1080. }
  1081. var model contract.OilContractMoney
  1082. svc := contract.GetOilContractService(utils.DBE)
  1083. svc.GetSum1(&model, "ContractId = " + Id + " and Year != '"+time.Now().Format("2006")+"'")
  1084. this.Data["json"] = &model
  1085. this.ServeJSON()
  1086. }
  1087. // @Title 获取跨年记录
  1088. // @Description
  1089. // @Success 200 {object} ErrorInfo
  1090. // @Failure 403 :id 为空
  1091. // @router /yearList/:Id [get]
  1092. func (this *OilContractController) YearList() {
  1093. Id := this.Ctx.Input.Param(":Id")
  1094. var errinfo ErrorInfo
  1095. if Id == "" {
  1096. errinfo.Message = "操作失败!请求信息不完整"
  1097. errinfo.Code = -2
  1098. this.Data["json"] = &errinfo
  1099. this.ServeJSON()
  1100. return
  1101. }
  1102. var model []contract.OilContractMoney1
  1103. svc := contract.GetOilContractService(utils.DBE)
  1104. svc.GetList(&model, "ContractId = " + Id)
  1105. this.Data["json"] = &model
  1106. this.ServeJSON()
  1107. }
  1108. // @Title 获取列表
  1109. // @Description get user by token
  1110. // @Success 200 {object} []oilcontract.OilContract
  1111. // @router /need-eva-list [get]
  1112. func (this *OilContractController) GetNeedEvaList() {
  1113. var list []contract.OilContract
  1114. 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) `
  1115. utils.DBE.Sql(sql).Find(&list)
  1116. var dataInfo DataInfo
  1117. dataInfo.Items = list
  1118. dataInfo.CurrentItemCount = 0
  1119. if list != nil {
  1120. dataInfo.CurrentItemCount = int64(len(list))
  1121. }
  1122. this.Data["json"] = &dataInfo
  1123. this.ServeJSON()
  1124. }
  1125. // @Title 获取上报情况列表
  1126. // @Description
  1127. // @Success 200 {object} ErrorInfo
  1128. // @router /handOnList [post]
  1129. func (this *OilContractController) GetHandOnStatisticsList() {
  1130. var queryParam contract.HandOnStatisticsQuery
  1131. var jsonBlob = this.Ctx.Input.RequestBody
  1132. json.Unmarshal(jsonBlob, &queryParam)
  1133. var models []contract.HandOnStatisticsEntity
  1134. svc := contract.GetOilContractService(utils.DBE)
  1135. total := svc.GetHandOnStatisticsList(queryParam, &models)
  1136. var dataInfo DataInfo
  1137. dataInfo.Items = models
  1138. dataInfo.CurrentItemCount = total
  1139. this.Data["json"] = &dataInfo
  1140. this.ServeJSON()
  1141. }
  1142. // @Title 清空列表
  1143. // @Description
  1144. // @Success 200 {object} ErrorInfo
  1145. // @router /deleteList [get]
  1146. func (this *OilContractController) DeleteList() {
  1147. svc := contract.GetOilContractService(utils.DBE)
  1148. svc.DeleteEntityBytbl(OilContractName, "ImportStatus = 0")
  1149. var errinfo ErrorInfo
  1150. errinfo.Message = "清空成功"
  1151. errinfo.Code = 0
  1152. this.Data["json"] = &errinfo
  1153. this.ServeJSON()
  1154. }
  1155. // @Title 一键更新二级单位名称
  1156. // @Description
  1157. // @Success 200 {object} ErrorInfo
  1158. // @router /updateUnitName/:Id [get]
  1159. func (this *OilContractController) UpdateUnitName() {
  1160. Id := this.Ctx.Input.Param(":Id")
  1161. UnitId := this.GetString("UnitId")
  1162. ContractId := this.GetString("ContractId")
  1163. var errinfo ErrorInfo
  1164. if Id == "" || UnitId == ""{
  1165. errinfo.Message = "操作失败!请求信息不完整"
  1166. errinfo.Code = -2
  1167. this.Data["json"] = &errinfo
  1168. this.ServeJSON()
  1169. return
  1170. }
  1171. var model contract.OilContract
  1172. svc := contract.GetOilContractService(utils.DBE)
  1173. var org organize.Base_Organize
  1174. svc.GetEntityByWhere("Base_Organize", "Id = " + UnitId, &org)
  1175. model.SecondUnit ,_= strconv.Atoi(UnitId)
  1176. model.SecondUnitName = org.Fullname
  1177. where := "SecondUnit = " + Id
  1178. if ContractId != "" {
  1179. where += " and Id = " + ContractId
  1180. }
  1181. svc.UpdateEntityBywheretbl(OilContractName, &model, []string{"SecondUnit", "SecondUnitName"}, where)
  1182. errinfo.Message = "更新成功"
  1183. errinfo.Code = 0
  1184. this.Data["json"] = &errinfo
  1185. this.ServeJSON()
  1186. }