contract.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  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. . "github.com/linxGnu/goseaweedfs"
  24. )
  25. type OilContractController struct {
  26. BaseController
  27. }
  28. // @Title 获取列表
  29. // @Description get user by token
  30. // @Success 200 {object} []oilcontract.OilContract
  31. // @router /list [get]
  32. func (this *OilContractController) GetEntityList() {
  33. //获取分页信息
  34. page := this.GetPageInfoForm()
  35. where := " 1=1 "
  36. orderby := "Id"
  37. asc := false
  38. Order := this.GetString("Order")
  39. Prop := this.GetString("Prop")
  40. if Order != "" && Prop != "" {
  41. orderby = Prop
  42. if Order == "asc" {
  43. asc = true
  44. }
  45. }
  46. Id := this.GetString("Id")
  47. SupplierId := this.GetString("SupplierId")
  48. SupplierName := this.GetString("SupplierName")
  49. ImportSupplierName := this.GetString("ImportSupplierName")
  50. ImportUnitName := this.GetString("ImportUnitName")
  51. Status := this.GetString("Status")
  52. SettleStatus := this.GetString("SettleStatus")
  53. ProjectName := this.GetString("ProjectName")
  54. ContractNo := this.GetString("ContractNo")
  55. ProjectPlace := this.GetString("ProjectPlace")
  56. ProjectOwner := this.GetString("ProjectOwner")
  57. Telephone := this.GetString("Telephone")
  58. ProjectType := this.GetString("ProjectType")
  59. ContractMode := this.GetString("ContractMode")
  60. Amount := this.GetString("Amount")
  61. ContractPeriod := this.GetString("ContractPeriod")
  62. EndDate := this.GetString("EndDate")
  63. StartDate := this.GetString("StartDate")
  64. ConstructionUnit := this.GetString("ConstructionUnit")
  65. ConstructionOwner := this.GetString("ConstructionOwner")
  66. ConstructionTelphone := this.GetString("ConstructionTelphone")
  67. BuildUnit := this.GetString("BuildUnit")
  68. BuildOwner := this.GetString("BuildOwner")
  69. BuildTelphone := this.GetString("BuildTelphone")
  70. SuperviseUnit := this.GetString("SuperviseUnit")
  71. SuperviseOwner := this.GetString("SuperviseOwner")
  72. SuperviseTelphone := this.GetString("SuperviseTelphone")
  73. QualityUnit := this.GetString("QualityUnit")
  74. QualityOwner := this.GetString("QualityOwner")
  75. QualityTelphone := this.GetString("QualityTelphone")
  76. Remark := this.GetString("Remark")
  77. IsDelete := this.GetString("IsDelete")
  78. CreateOn := this.GetString("CreateOn")
  79. CreateOn1 := this.GetString("CreateOn1")
  80. CreateUserId := this.GetString("CreateUserId")
  81. CreateBy := this.GetString("CreateBy")
  82. ModifiedOn := this.GetString("ModifiedOn")
  83. ModifiedUserId := this.GetString("ModifiedUserId")
  84. ModifiedBy := this.GetString("ModifiedBy")
  85. ContractName := this.GetString("ContractName")
  86. ContractSonClass := this.GetString("ContractSonClass")
  87. SmallClass := this.GetString("SmallClass")
  88. SignedDate := this.GetString("SignedDate")
  89. People := this.GetString("People")
  90. Number := this.GetString("Number")
  91. ChooseWay := this.GetString("ChooseWay")
  92. ContractMark := this.GetString("ContractMark")
  93. Currency := this.GetString("Currency")
  94. BudgetAmount := this.GetString("BudgetAmount")
  95. PerformAmount := this.GetString("PerformAmount")
  96. IsInternal := this.GetString("IsInternal")
  97. IsForeign := this.GetString("IsForeign")
  98. IsDeal := this.GetString("IsDeal")
  99. MoneyFlows := this.GetString("MoneyFlows")
  100. MoneyChannel := this.GetString("MoneyChannel")
  101. MoneyChannelSon := this.GetString("MoneyChannelSon")
  102. MoneyChannelSmall := this.GetString("MoneyChannelSmall")
  103. SingUnit := this.GetString("SingUnit")
  104. Place := this.GetString("Place")
  105. DisputeResolution := this.GetString("DisputeResolution")
  106. SubmitDate := this.GetString("SubmitDate")
  107. SealName := this.GetString("SealName")
  108. PoNumber := this.GetString("PoNumber")
  109. SubPackage := this.GetString("SubPackage")
  110. ImportStatus := this.GetString("ImportStatus")
  111. ContractClass := this.GetString("ContractClass")
  112. ClassName := this.GetString("ClassName")
  113. SecondUnit := this.GetString("SecondUnit")
  114. ImportSecondUnit := this.GetString("ImportSecondUnit")
  115. if Id != "" {
  116. where = where + " and Id like '%" + Id + "%'"
  117. }
  118. if ContractClass != "" {
  119. where = where + " and ContractClass='" + ContractClass + "' "
  120. }
  121. if SecondUnit != "" {
  122. where = where + " and SecondUnit=" + SecondUnit + " "
  123. }
  124. if ImportSecondUnit != "" {
  125. where = where + " and SecondUnit=" + ImportSecondUnit + " "
  126. }
  127. if ClassName != "" {
  128. where = where + " and ClassName='" + ClassName + "' "
  129. }
  130. if SupplierId != "" {
  131. where = where + " and SupplierId like '%" + SupplierId + "%'"
  132. }
  133. if SupplierName != "" {
  134. where = where + " and SupplierName like '%" + SupplierName + "%'"
  135. }
  136. if ImportSupplierName != "" {
  137. where = where + " and ImportSupplierName like '%" + ImportSupplierName + "%'"
  138. }
  139. if ImportUnitName != "" {
  140. where = where + " and ImportSecondUnit like '%" + ImportUnitName + "%'"
  141. }
  142. if Status != "" {
  143. where = where + " and Status=" + Status + " "
  144. }
  145. if SettleStatus != "" {
  146. where = where + " and SettleStatus='" + SettleStatus + "' "
  147. }
  148. if ProjectName != "" {
  149. where = where + " and ProjectName like '%" + ProjectName + "%'"
  150. }
  151. if ContractNo != "" {
  152. where = where + " and ContractNo like '%" + ContractNo + "%'"
  153. }
  154. if ProjectPlace != "" {
  155. where = where + " and ProjectPlace like '%" + ProjectPlace + "%'"
  156. }
  157. if ProjectOwner != "" {
  158. where = where + " and ProjectOwner like '%" + ProjectOwner + "%'"
  159. }
  160. if Telephone != "" {
  161. where = where + " and Telephone like '%" + Telephone + "%'"
  162. }
  163. if ProjectType != "" {
  164. where = where + " and ProjectType like '%" + ProjectType + "%'"
  165. }
  166. if ContractMode != "" {
  167. where = where + " and ContractMode like '%" + ContractMode + "%'"
  168. }
  169. if Amount != "" {
  170. where = where + " and Amount like '%" + Amount + "%'"
  171. }
  172. if ContractPeriod != "" {
  173. where = where + " and ContractPeriod like '%" + ContractPeriod + "%'"
  174. }
  175. if EndDate != "" {
  176. where = where + " and EndDate like '%" + EndDate + "%'"
  177. }
  178. if StartDate != "" {
  179. where = where + " and StartDate like '%" + StartDate + "%'"
  180. }
  181. if ConstructionUnit != "" {
  182. where = where + " and ConstructionUnit like '%" + ConstructionUnit + "%'"
  183. }
  184. if ConstructionOwner != "" {
  185. where = where + " and ConstructionOwner like '%" + ConstructionOwner + "%'"
  186. }
  187. if ConstructionTelphone != "" {
  188. where = where + " and ConstructionTelphone like '%" + ConstructionTelphone + "%'"
  189. }
  190. if BuildUnit != "" {
  191. where = where + " and BuildUnit like '%" + BuildUnit + "%'"
  192. }
  193. if BuildOwner != "" {
  194. where = where + " and BuildOwner like '%" + BuildOwner + "%'"
  195. }
  196. if BuildTelphone != "" {
  197. where = where + " and BuildTelphone like '%" + BuildTelphone + "%'"
  198. }
  199. if SuperviseUnit != "" {
  200. where = where + " and SuperviseUnit like '%" + SuperviseUnit + "%'"
  201. }
  202. if SuperviseOwner != "" {
  203. where = where + " and SuperviseOwner like '%" + SuperviseOwner + "%'"
  204. }
  205. if SuperviseTelphone != "" {
  206. where = where + " and SuperviseTelphone like '%" + SuperviseTelphone + "%'"
  207. }
  208. if QualityUnit != "" {
  209. where = where + " and QualityUnit like '%" + QualityUnit + "%'"
  210. }
  211. if QualityOwner != "" {
  212. where = where + " and QualityOwner like '%" + QualityOwner + "%'"
  213. }
  214. if QualityTelphone != "" {
  215. where = where + " and QualityTelphone like '%" + QualityTelphone + "%'"
  216. }
  217. if Remark != "" {
  218. where = where + " and Remark like '%" + Remark + "%'"
  219. }
  220. if IsDelete != "" {
  221. where = where + " and IsDelete like '%" + IsDelete + "%'"
  222. }
  223. //if CreateOn != "" {
  224. // where = where + " and CreateOn like '%" + CreateOn + "%'"
  225. //}
  226. if CreateUserId != "" {
  227. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  228. }
  229. if CreateBy != "" {
  230. where = where + " and CreateBy like '%" + CreateBy + "%'"
  231. }
  232. if ModifiedOn != "" {
  233. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  234. }
  235. if ModifiedUserId != "" {
  236. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  237. }
  238. if ModifiedBy != "" {
  239. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  240. }
  241. if CreateOn != "" {
  242. dates := strings.Split(CreateOn, ",")
  243. if len(dates) == 2 {
  244. minDate := dates[0]
  245. maxDate := dates[1]
  246. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  247. }
  248. }
  249. if CreateOn1 != "" {
  250. dates := strings.Split(CreateOn1, ",")
  251. if len(dates) == 2 {
  252. minDate := dates[0]
  253. maxDate := dates[1]
  254. where = where + " and StartDate>='" + minDate + "' and EndDate<='" + maxDate + "'"
  255. }
  256. }
  257. if SubPackage != "" {
  258. where = where + " and SubPackage like '%" + SubPackage + "%'"
  259. }
  260. if ContractName != "" {
  261. where = where + " and ContractName like '%" + ContractName + "%'"
  262. }
  263. if ContractSonClass != "" {
  264. where = where + " and ContractSonClass like '%" + ContractSonClass + "%'"
  265. }
  266. if SmallClass != "" {
  267. where = where + " and SmallClass like '%" + SmallClass + "%'"
  268. }
  269. if People != "" {
  270. where = where + " and People like '%" + People + "%'"
  271. }
  272. if Number != "" {
  273. where = where + " and Number like '%" + Number + "%'"
  274. }
  275. if ChooseWay != "" {
  276. where = where + " and ChooseWay like '%" + ChooseWay + "%'"
  277. }
  278. if ContractMark != "" {
  279. where = where + " and ContractMark like '%" + ContractMark + "%'"
  280. }
  281. if Currency != "" {
  282. where = where + " and Currency like '%" + Currency + "%'"
  283. }
  284. if BudgetAmount != "" {
  285. where = where + " and BudgetAmount like '%" + BudgetAmount + "%'"
  286. }
  287. if PerformAmount != "" {
  288. where = where + " and PerformAmount like '%" + PerformAmount + "%'"
  289. }
  290. if IsInternal != "" {
  291. where = where + " and IsInternal like '%" + IsInternal + "%'"
  292. }
  293. if IsForeign != "" {
  294. where = where + " and IsForeign like '%" + IsForeign + "%'"
  295. }
  296. if IsDeal != "" {
  297. where = where + " and IsDeal like '%" + IsDeal + "%'"
  298. }
  299. if MoneyFlows != "" {
  300. where = where + " and MoneyFlows like '%" + MoneyFlows + "%'"
  301. }
  302. if MoneyChannel != "" {
  303. where = where + " and MoneyChannel like '%" + MoneyChannel + "%'"
  304. }
  305. if MoneyChannelSon != "" {
  306. where = where + " and MoneyChannelSon like '%" + MoneyChannelSon + "%'"
  307. }
  308. if MoneyChannelSmall != "" {
  309. where = where + " and MoneyChannelSmall like '%" + MoneyChannelSmall + "%'"
  310. }
  311. if SingUnit != "" {
  312. where = where + " and SingUnit like '%" + SingUnit + "%'"
  313. }
  314. if Place != "" {
  315. where = where + " and Place like '%" + Place + "%'"
  316. }
  317. if DisputeResolution != "" {
  318. where = where + " and DisputeResolution like '%" + DisputeResolution + "%'"
  319. }
  320. if SubmitDate != "" {
  321. where = where + " and SubmitDate like '%" + SubmitDate + "%'"
  322. }
  323. if SealName != "" {
  324. where = where + " and SealName like '%" + SealName + "%'"
  325. }
  326. if PoNumber != "" {
  327. where = where + " and PoNumber like '%" + PoNumber + "%'"
  328. }
  329. if SignedDate != "" {
  330. where = where + " and PoNumber like '%" + SignedDate + "%'"
  331. }
  332. if ImportStatus != "" {
  333. where = where + " and ImportStatus = " + ImportStatus
  334. } else {
  335. where = where + " and ImportStatus != 0"
  336. }
  337. // 企管法规处可看所有合同, 获取企管法规处人员
  338. var settingReg auditsetting.Base_OilAuditSetting
  339. orgSvc := organize.GetOrganizeService(utils.DBE)
  340. wherePRegAudit := "AuditStepCode='PROF_REGULATION'"
  341. orgSvc.GetEntity(&settingReg, wherePRegAudit) // PROF_AUDIT
  342. res1 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingReg.RoleId))
  343. // 所有业务处室分办单位可查看所有合同 TODO 待确认
  344. var settingProf auditsetting.Base_OilAuditSetting
  345. wherePAudit := "AuditStepCode='PROF_RECE'"
  346. orgSvc.GetEntity(&settingProf, wherePAudit) // PROF_AUDIT
  347. res2 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingProf.RoleId))
  348. if !res1 && !res2 {
  349. where = where + " and SecondUnit= " + strconv.Itoa(this.User.UnitId)
  350. }
  351. svc := contract.GetOilContractService(utils.DBE)
  352. var list []contract.OilContract
  353. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  354. var datainfo DataInfo
  355. datainfo.Items = list
  356. datainfo.CurrentItemCount = total
  357. datainfo.PageIndex = page.CurrentPage
  358. datainfo.ItemsPerPage = page.Size
  359. this.Data["json"] = &datainfo
  360. this.ServeJSON()
  361. }
  362. // @Title get 导出列表
  363. // @Description
  364. // @Success 200 {object}
  365. // @router /exportList [get]
  366. func (this *OilContractController) ExportList() {
  367. //获取分页信息
  368. page := this.GetPageInfoForm()
  369. where := " 1=1 "
  370. orderby := "Id"
  371. asc := false
  372. Order := this.GetString("Order")
  373. Prop := this.GetString("Prop")
  374. if Order != "" && Prop != "" {
  375. orderby = Prop
  376. if Order == "asc" {
  377. asc = true
  378. }
  379. }
  380. Id := this.GetString("Id")
  381. SupplierId := this.GetString("SupplierId")
  382. SupplierName := this.GetString("SupplierName")
  383. ImportSupplierName := this.GetString("ImportSupplierName")
  384. ImportUnitName := this.GetString("ImportUnitName")
  385. Status := this.GetString("Status")
  386. SettleStatus := this.GetString("SettleStatus")
  387. ProjectName := this.GetString("ProjectName")
  388. ContractNo := this.GetString("ContractNo")
  389. ProjectPlace := this.GetString("ProjectPlace")
  390. ProjectOwner := this.GetString("ProjectOwner")
  391. Telephone := this.GetString("Telephone")
  392. ProjectType := this.GetString("ProjectType")
  393. ContractMode := this.GetString("ContractMode")
  394. Amount := this.GetString("Amount")
  395. ContractPeriod := this.GetString("ContractPeriod")
  396. EndDate := this.GetString("EndDate")
  397. StartDate := this.GetString("StartDate")
  398. ConstructionUnit := this.GetString("ConstructionUnit")
  399. ConstructionOwner := this.GetString("ConstructionOwner")
  400. ConstructionTelphone := this.GetString("ConstructionTelphone")
  401. BuildUnit := this.GetString("BuildUnit")
  402. BuildOwner := this.GetString("BuildOwner")
  403. BuildTelphone := this.GetString("BuildTelphone")
  404. SuperviseUnit := this.GetString("SuperviseUnit")
  405. SuperviseOwner := this.GetString("SuperviseOwner")
  406. SuperviseTelphone := this.GetString("SuperviseTelphone")
  407. QualityUnit := this.GetString("QualityUnit")
  408. QualityOwner := this.GetString("QualityOwner")
  409. QualityTelphone := this.GetString("QualityTelphone")
  410. Remark := this.GetString("Remark")
  411. IsDelete := this.GetString("IsDelete")
  412. CreateOn := this.GetString("CreateOn")
  413. CreateOn1 := this.GetString("CreateOn1")
  414. CreateUserId := this.GetString("CreateUserId")
  415. CreateBy := this.GetString("CreateBy")
  416. ModifiedOn := this.GetString("ModifiedOn")
  417. ModifiedUserId := this.GetString("ModifiedUserId")
  418. ModifiedBy := this.GetString("ModifiedBy")
  419. ContractName := this.GetString("ContractName")
  420. ContractSonClass := this.GetString("ContractSonClass")
  421. SmallClass := this.GetString("SmallClass")
  422. SignedDate := this.GetString("SignedDate")
  423. People := this.GetString("People")
  424. Number := this.GetString("Number")
  425. ChooseWay := this.GetString("ChooseWay")
  426. ContractMark := this.GetString("ContractMark")
  427. Currency := this.GetString("Currency")
  428. BudgetAmount := this.GetString("BudgetAmount")
  429. PerformAmount := this.GetString("PerformAmount")
  430. IsInternal := this.GetString("IsInternal")
  431. IsForeign := this.GetString("IsForeign")
  432. IsDeal := this.GetString("IsDeal")
  433. MoneyFlows := this.GetString("MoneyFlows")
  434. MoneyChannel := this.GetString("MoneyChannel")
  435. MoneyChannelSon := this.GetString("MoneyChannelSon")
  436. MoneyChannelSmall := this.GetString("MoneyChannelSmall")
  437. SingUnit := this.GetString("SingUnit")
  438. Place := this.GetString("Place")
  439. DisputeResolution := this.GetString("DisputeResolution")
  440. SubmitDate := this.GetString("SubmitDate")
  441. SealName := this.GetString("SealName")
  442. PoNumber := this.GetString("PoNumber")
  443. SubPackage := this.GetString("SubPackage")
  444. ImportStatus := this.GetString("ImportStatus")
  445. ContractClass := this.GetString("ContractClass")
  446. ClassName := this.GetString("ClassName")
  447. SecondUnit := this.GetString("SecondUnit")
  448. ImportSecondUnit := this.GetString("ImportSecondUnit")
  449. if Id != "" {
  450. where = where + " and Id like '%" + Id + "%'"
  451. }
  452. if ContractClass != "" {
  453. where = where + " and ContractClass='" + ContractClass + "' "
  454. }
  455. if SecondUnit != "" {
  456. where = where + " and SecondUnit=" + SecondUnit + " "
  457. }
  458. if ImportSecondUnit != "" {
  459. where = where + " and SecondUnit=" + ImportSecondUnit + " "
  460. }
  461. if ClassName != "" {
  462. where = where + " and ClassName='" + ClassName + "' "
  463. }
  464. if SupplierId != "" {
  465. where = where + " and SupplierId like '%" + SupplierId + "%'"
  466. }
  467. if SupplierName != "" {
  468. where = where + " and SupplierName like '%" + SupplierName + "%'"
  469. }
  470. if ImportSupplierName != "" {
  471. where = where + " and ImportSupplierName like '%" + ImportSupplierName + "%'"
  472. }
  473. if ImportUnitName != "" {
  474. where = where + " and ImportSecondUnit like '%" + ImportUnitName + "%'"
  475. }
  476. if Status != "" {
  477. where = where + " and Status=" + Status + " "
  478. }
  479. if SettleStatus != "" {
  480. where = where + " and SettleStatus='" + SettleStatus + "' "
  481. }
  482. if ProjectName != "" {
  483. where = where + " and ProjectName like '%" + ProjectName + "%'"
  484. }
  485. if ContractNo != "" {
  486. where = where + " and ContractNo like '%" + ContractNo + "%'"
  487. }
  488. if ProjectPlace != "" {
  489. where = where + " and ProjectPlace like '%" + ProjectPlace + "%'"
  490. }
  491. if ProjectOwner != "" {
  492. where = where + " and ProjectOwner like '%" + ProjectOwner + "%'"
  493. }
  494. if Telephone != "" {
  495. where = where + " and Telephone like '%" + Telephone + "%'"
  496. }
  497. if ProjectType != "" {
  498. where = where + " and ProjectType like '%" + ProjectType + "%'"
  499. }
  500. if ContractMode != "" {
  501. where = where + " and ContractMode like '%" + ContractMode + "%'"
  502. }
  503. if Amount != "" {
  504. where = where + " and Amount like '%" + Amount + "%'"
  505. }
  506. if ContractPeriod != "" {
  507. where = where + " and ContractPeriod like '%" + ContractPeriod + "%'"
  508. }
  509. if EndDate != "" {
  510. where = where + " and EndDate like '%" + EndDate + "%'"
  511. }
  512. if StartDate != "" {
  513. where = where + " and StartDate like '%" + StartDate + "%'"
  514. }
  515. if ConstructionUnit != "" {
  516. where = where + " and ConstructionUnit like '%" + ConstructionUnit + "%'"
  517. }
  518. if ConstructionOwner != "" {
  519. where = where + " and ConstructionOwner like '%" + ConstructionOwner + "%'"
  520. }
  521. if ConstructionTelphone != "" {
  522. where = where + " and ConstructionTelphone like '%" + ConstructionTelphone + "%'"
  523. }
  524. if BuildUnit != "" {
  525. where = where + " and BuildUnit like '%" + BuildUnit + "%'"
  526. }
  527. if BuildOwner != "" {
  528. where = where + " and BuildOwner like '%" + BuildOwner + "%'"
  529. }
  530. if BuildTelphone != "" {
  531. where = where + " and BuildTelphone like '%" + BuildTelphone + "%'"
  532. }
  533. if SuperviseUnit != "" {
  534. where = where + " and SuperviseUnit like '%" + SuperviseUnit + "%'"
  535. }
  536. if SuperviseOwner != "" {
  537. where = where + " and SuperviseOwner like '%" + SuperviseOwner + "%'"
  538. }
  539. if SuperviseTelphone != "" {
  540. where = where + " and SuperviseTelphone like '%" + SuperviseTelphone + "%'"
  541. }
  542. if QualityUnit != "" {
  543. where = where + " and QualityUnit like '%" + QualityUnit + "%'"
  544. }
  545. if QualityOwner != "" {
  546. where = where + " and QualityOwner like '%" + QualityOwner + "%'"
  547. }
  548. if QualityTelphone != "" {
  549. where = where + " and QualityTelphone like '%" + QualityTelphone + "%'"
  550. }
  551. if Remark != "" {
  552. where = where + " and Remark like '%" + Remark + "%'"
  553. }
  554. if IsDelete != "" {
  555. where = where + " and IsDelete like '%" + IsDelete + "%'"
  556. }
  557. //if CreateOn != "" {
  558. // where = where + " and CreateOn like '%" + CreateOn + "%'"
  559. //}
  560. if CreateUserId != "" {
  561. where = where + " and CreateUserId like '%" + CreateUserId + "%'"
  562. }
  563. if CreateBy != "" {
  564. where = where + " and CreateBy like '%" + CreateBy + "%'"
  565. }
  566. if ModifiedOn != "" {
  567. where = where + " and ModifiedOn like '%" + ModifiedOn + "%'"
  568. }
  569. if ModifiedUserId != "" {
  570. where = where + " and ModifiedUserId like '%" + ModifiedUserId + "%'"
  571. }
  572. if ModifiedBy != "" {
  573. where = where + " and ModifiedBy like '%" + ModifiedBy + "%'"
  574. }
  575. if CreateOn != "" {
  576. dates := strings.Split(CreateOn, ",")
  577. if len(dates) == 2 {
  578. minDate := dates[0]
  579. maxDate := dates[1]
  580. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  581. }
  582. }
  583. if CreateOn1 != "" {
  584. dates := strings.Split(CreateOn1, ",")
  585. if len(dates) == 2 {
  586. minDate := dates[0]
  587. maxDate := dates[1]
  588. where = where + " and StartDate>='" + minDate + "' and EndDate<='" + maxDate + "'"
  589. }
  590. }
  591. if SubPackage != "" {
  592. where = where + " and SubPackage like '%" + SubPackage + "%'"
  593. }
  594. if ContractName != "" {
  595. where = where + " and ContractName like '%" + ContractName + "%'"
  596. }
  597. if ContractSonClass != "" {
  598. where = where + " and ContractSonClass like '%" + ContractSonClass + "%'"
  599. }
  600. if SmallClass != "" {
  601. where = where + " and SmallClass like '%" + SmallClass + "%'"
  602. }
  603. if People != "" {
  604. where = where + " and People like '%" + People + "%'"
  605. }
  606. if Number != "" {
  607. where = where + " and Number like '%" + Number + "%'"
  608. }
  609. if ChooseWay != "" {
  610. where = where + " and ChooseWay like '%" + ChooseWay + "%'"
  611. }
  612. if ContractMark != "" {
  613. where = where + " and ContractMark like '%" + ContractMark + "%'"
  614. }
  615. if Currency != "" {
  616. where = where + " and Currency like '%" + Currency + "%'"
  617. }
  618. if BudgetAmount != "" {
  619. where = where + " and BudgetAmount like '%" + BudgetAmount + "%'"
  620. }
  621. if PerformAmount != "" {
  622. where = where + " and PerformAmount like '%" + PerformAmount + "%'"
  623. }
  624. if IsInternal != "" {
  625. where = where + " and IsInternal like '%" + IsInternal + "%'"
  626. }
  627. if IsForeign != "" {
  628. where = where + " and IsForeign like '%" + IsForeign + "%'"
  629. }
  630. if IsDeal != "" {
  631. where = where + " and IsDeal like '%" + IsDeal + "%'"
  632. }
  633. if MoneyFlows != "" {
  634. where = where + " and MoneyFlows like '%" + MoneyFlows + "%'"
  635. }
  636. if MoneyChannel != "" {
  637. where = where + " and MoneyChannel like '%" + MoneyChannel + "%'"
  638. }
  639. if MoneyChannelSon != "" {
  640. where = where + " and MoneyChannelSon like '%" + MoneyChannelSon + "%'"
  641. }
  642. if MoneyChannelSmall != "" {
  643. where = where + " and MoneyChannelSmall like '%" + MoneyChannelSmall + "%'"
  644. }
  645. if SingUnit != "" {
  646. where = where + " and SingUnit like '%" + SingUnit + "%'"
  647. }
  648. if Place != "" {
  649. where = where + " and Place like '%" + Place + "%'"
  650. }
  651. if DisputeResolution != "" {
  652. where = where + " and DisputeResolution like '%" + DisputeResolution + "%'"
  653. }
  654. if SubmitDate != "" {
  655. where = where + " and SubmitDate like '%" + SubmitDate + "%'"
  656. }
  657. if SealName != "" {
  658. where = where + " and SealName like '%" + SealName + "%'"
  659. }
  660. if PoNumber != "" {
  661. where = where + " and PoNumber like '%" + PoNumber + "%'"
  662. }
  663. if SignedDate != "" {
  664. where = where + " and PoNumber like '%" + SignedDate + "%'"
  665. }
  666. if ImportStatus != "" {
  667. where = where + " and ImportStatus = " + ImportStatus
  668. } else {
  669. where = where + " and ImportStatus != 0"
  670. }
  671. // 企管法规处可看所有合同, 获取企管法规处人员
  672. var settingReg auditsetting.Base_OilAuditSetting
  673. orgSvc := organize.GetOrganizeService(utils.DBE)
  674. wherePRegAudit := "AuditStepCode='PROF_REGULATION'"
  675. orgSvc.GetEntity(&settingReg, wherePRegAudit) // PROF_AUDIT
  676. res1 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingReg.RoleId))
  677. // 所有业务处室分办单位可查看所有合同 TODO 待确认
  678. var settingProf auditsetting.Base_OilAuditSetting
  679. wherePAudit := "AuditStepCode='PROF_RECE'"
  680. orgSvc.GetEntity(&settingProf, wherePAudit) // PROF_AUDIT
  681. res2 := orgSvc.UserInRoleById(this.User.Id, strconv.Itoa(settingProf.RoleId))
  682. if !res1 && !res2 {
  683. where = where + " and SecondUnit= " + strconv.Itoa(this.User.UnitId)
  684. }
  685. svc := contract.GetOilContractService(utils.DBE)
  686. var list []contract.OilContract
  687. svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  688. fileTitle := "合同列表"
  689. //自定义显示列
  690. title := strings.Split("企业名称,项目建设单位,合同名称,合同编号,合同类别,企业类别,履行状态,项目负责人,合同总金额,履行期限(始),履行期限(止),备注", ",")
  691. f := xlsx.NewFile()
  692. sheet, _ := f.AddSheet(fileTitle)
  693. row := sheet.AddRow()
  694. row.WriteSlice(&title, -1)
  695. // 与表头顺序一一对应 ↓
  696. nilTime := time.Time{}
  697. for _, item := range list {
  698. var dataArr []string
  699. dataArr = append(dataArr, item.SupplierName)
  700. dataArr = append(dataArr, item.SecondUnitName)
  701. dataArr = append(dataArr, item.ContractName)
  702. dataArr = append(dataArr, item.ContractNo)
  703. dataArr = append(dataArr, item.ClassName)
  704. // 企业类别
  705. if item.ContractClass == "01" {
  706. dataArr = append(dataArr, "供应商")
  707. } else if item.ContractClass == "02" {
  708. dataArr = append(dataArr, "承包商")
  709. } else if item.ContractClass == "03" {
  710. dataArr = append(dataArr, "服务商")
  711. } else {
  712. dataArr = append(dataArr, "")
  713. }
  714. if item.Status == 1 {
  715. dataArr = append(dataArr, "未履行")
  716. } else if item.Status == 2 {
  717. dataArr = append(dataArr, "履行中")
  718. } else if item.Status == 3 {
  719. dataArr = append(dataArr, "已完结")
  720. } else {
  721. dataArr = append(dataArr, "")
  722. }
  723. dataArr = append(dataArr, item.ProjectOwner)
  724. dataArr = append(dataArr, item.Amount)
  725. if item.StartDate == nilTime {
  726. dataArr = append(dataArr, "")
  727. } else {
  728. dataArr = append(dataArr, item.StartDate.Format("2006-01-02 15:04:05"))
  729. }
  730. if item.EndDate == nilTime {
  731. dataArr = append(dataArr, "")
  732. } else {
  733. dataArr = append(dataArr, item.EndDate.Format("2006-01-02 15:04:05"))
  734. }
  735. dataArr = append(dataArr, item.Remark)
  736. row := sheet.AddRow()
  737. row.WriteSlice(&dataArr, -1)
  738. }
  739. for c, cl := 0, len(sheet.Cols); c < cl; c++ {
  740. sheet.Cols[c].Width = 20
  741. }
  742. dir := "static/file/excel/report/" + this.GetAccode()
  743. SaveDirectory(dir)
  744. path := dir + "/" + "contract_export_" + utils.TimeFormat(time.Now(), "20060102") + fileTitle + ".xlsx"
  745. f.Save(path)
  746. var sw *Seaweed
  747. var filer []string
  748. if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
  749. filer = []string{_filer}
  750. }
  751. sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
  752. _, _, fID, _ := sw.UploadFile(path, "", "")
  753. retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
  754. os.Remove(path)
  755. this.Data["json"] = retDocUrl
  756. this.ServeJSON()
  757. }
  758. // @Title 获取字典列表
  759. // @Description get user by token
  760. // @Success 200 {object} map[string]interface{}
  761. // @router /dictlist [get]
  762. func (this *OilContractController) GetDictList() {
  763. dictList := make(map[string]interface{})
  764. dictSvc := items.GetItemsService(utils.DBE)
  765. userSvc := baseUser.GetBaseUserService(utils.DBE)
  766. //customerSvc := svccustomer.GetCustomerService(utils.DBE)
  767. //dictList["WellNo"] = dictSvc.GetKeyValueItems("WellNo", "")
  768. var userEntity userRole.Base_User
  769. userSvc.GetEntityById(this.User.Id, &userEntity)
  770. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId("", userEntity.Departmentid)
  771. dictList["ContractClass"] = dictSvc.GetKeyValueItems("ContractClass")
  772. dictList["ProjectType"] = dictSvc.GetKeyValueItems("ProjectType")
  773. dictList["ContractMode"] = dictSvc.GetKeyValueItems("ContractMode")
  774. dictList["CurrencyType"] = dictSvc.GetKeyValueItems("CurrencyType")
  775. //var dictCustomer []svccustomer.Customer
  776. //customerSvc.GetEntitysByWhere("" + CustomerName, "", &dictCustomer)
  777. //dictList["EntrustCorp"] = &dictCustomer
  778. var datainfo DataInfo
  779. datainfo.Items = dictList
  780. this.Data["json"] = &datainfo
  781. this.ServeJSON()
  782. }
  783. // @Title 完成合同
  784. // @Description get user by token
  785. // @Success 200 {object} map[string]interface{}
  786. // @router /finish/:id [get]
  787. //func (this *OilContractController) Finish(){
  788. // id := this.Ctx.Input.Param(":id")
  789. // var errinfo ErrorInfo
  790. // if id == "" {
  791. // errinfo.Message = "操作失败!请求信息不完整"
  792. // errinfo.Code = -2
  793. // this.Data["json"] = &errinfo
  794. // this.ServeJSON()
  795. // return
  796. // }
  797. // var model contract.OilContract
  798. // svc := contract.GetOilContractService(utils.DBE)
  799. // model.Status = 2
  800. // cols := []string{
  801. // "Status",
  802. // }
  803. // err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
  804. // if err == nil {
  805. // errinfo.Message = "修改成功!"
  806. // errinfo.Code = 0
  807. // this.Data["json"] = &errinfo
  808. // this.ServeJSON()
  809. // } else {
  810. // errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  811. // errinfo.Code = -1
  812. // this.Data["json"] = &errinfo
  813. // this.ServeJSON()
  814. // }
  815. //}
  816. // @Title 获取实体
  817. // @Description 获取实体
  818. // @Success 200 {object} oilcontract.OilContract
  819. // @router /get/:id [get]
  820. func (this *OilContractController) GetEntity() {
  821. Id := this.Ctx.Input.Param(":id")
  822. var model contract.OilContract
  823. svc := contract.GetOilContractService(utils.DBE)
  824. svc.GetEntityByIdBytbl(OilContractName, Id, &model)
  825. this.Data["json"] = &model
  826. this.ServeJSON()
  827. }
  828. // @Title get 导入excel
  829. // @Description 导入excel
  830. // @Success 200 {object} controllers.Request
  831. // @router /importexcel [get]
  832. func (this *OilContractController) ImportExcel() {
  833. go func() {
  834. defer func() {
  835. if err := recover(); err != nil {
  836. log.Println("合同导入err", err)
  837. }
  838. }()
  839. url := this.GetString("ExcelUrl")
  840. //var errLineNum string
  841. if url == "" {
  842. fmt.Println("文件不能为空!")
  843. }
  844. _dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
  845. filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
  846. //60.30.245.229 替换成23
  847. url = strings.Replace(url, "60.30.245.229", "10.76.248.23", -1)
  848. utils.DownloadFile(url, filename, _dir)
  849. t := time.Now()
  850. filePath := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx/" + filename
  851. xlFile, err := xlsx.OpenFile(filePath)
  852. //excelFileName := "F:/物资类项目与资质对照表-2017.xlsx"
  853. if err != nil {
  854. fmt.Printf("open failed: %s\n", err)
  855. }
  856. var sheet = xlFile.Sheets[0]
  857. // 插入字段
  858. //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"
  859. //columnArr := strings.Split(Fstrs, ",")
  860. //timeTemplate1 := "2006/01/02 15:04:05" //常规类型
  861. svc := contract.GetOilContractService(utils.DBE)
  862. for i := 1; i < len(sheet.Rows); i++ {
  863. var con contract.OilContract
  864. var con1 contract.OilContract
  865. lineNo := strconv.Itoa(i + 1)
  866. fmt.Println(lineNo)
  867. if sheet.Rows[i].Cells[2].String() != "" {
  868. svc.GetEntityByWhere(OilContractName, "ContractNo = '"+sheet.Rows[i].Cells[2].String()+"'", &con1)
  869. if con1.Id > 0 {
  870. con1.ContractName = sheet.Rows[i].Cells[3].String()
  871. con1.Amount = sheet.Rows[i].Cells[4].String()
  872. if con1.Amount == "" {
  873. con1.Amount = "0"
  874. }
  875. con1.ClassName = sheet.Rows[i].Cells[0].String()
  876. if con1.ClassName == "买卖合同" {
  877. con1.ContractClass = "01"
  878. } else {
  879. con1.ContractClass = "03"
  880. }
  881. //con1.ContractSonClass = sheet.Rows[i].Cells[4].String()
  882. //con1.SmallClass = sheet.Rows[i].Cells[5].String()
  883. con1.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[7].Value), time.Local)
  884. con1.Number = sheet.Rows[i].Cells[10].String()
  885. //con1.ChooseWay = sheet.Rows[i].Cells[11].String()
  886. //con1.ContractMark = sheet.Rows[i].Cells[14].String()
  887. //con1.Currency = sheet.Rows[i].Cells[15].String()
  888. //con1.BudgetAmount = sheet.Rows[i].Cells[16].String()
  889. if con.BudgetAmount == "" {
  890. con.BudgetAmount = "0"
  891. }
  892. //con1.PerformAmount = sheet.Rows[i].Cells[17].String()
  893. if con1.PerformAmount == "" {
  894. con1.PerformAmount = "0"
  895. }
  896. con1.IsYearMoney = con1.PerformAmount
  897. con1.IsInternal = 0
  898. //if sheet.Rows[i].Cells[18].String() == "是" {
  899. // con1.IsInternal = 1
  900. //}
  901. con1.IsForeign = 0
  902. //if sheet.Rows[i].Cells[19].String() == "是" {
  903. // con1.IsForeign = 1
  904. //}
  905. con1.IsDeal = 0
  906. //if sheet.Rows[i].Cells[20].String() == "是" {
  907. // con1.IsDeal = 1
  908. //}
  909. //con1.MoneyFlows = sheet.Rows[i].Cells[21].String()
  910. //con1.MoneyChannel = sheet.Rows[i].Cells[22].String()
  911. //con1.MoneyChannelSon = sheet.Rows[i].Cells[23].String()
  912. //con1.MoneyChannelSmall = sheet.Rows[i].Cells[24].String()
  913. //con1.SingUnit = sheet.Rows[i].Cells[25].String()
  914. //con1.Place = sheet.Rows[i].Cells[28].String()
  915. con1.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[8].Value), time.Local)
  916. con1.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  917. con1.YearDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  918. //con1.DisputeResolution = sheet.Rows[i].Cells[31].String()
  919. //con1.Remark = sheet.Rows[i].Cells[32].String()
  920. if con1.ProjectOwner != sheet.Rows[i].Cells[6].String() {
  921. con1.ProjectOwner = con1.ProjectOwner + "," + sheet.Rows[i].Cells[6].String()
  922. }
  923. //con1.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[34].Value), time.Local)
  924. //con1.SealName = sheet.Rows[i].Cells[42].String()
  925. //con1.PoNumber = sheet.Rows[i].Cells[31].String()
  926. //con1.ImportStatus = 0
  927. svc.UpdateEntityById(con1.Id, &con1)
  928. continue
  929. }
  930. }
  931. con.ClassName = sheet.Rows[i].Cells[0].String()
  932. if con.ClassName == "买卖合同" {
  933. con.ContractClass = "01"
  934. } else {
  935. con.ContractClass = "03"
  936. }
  937. con.ImportSupplierName = sheet.Rows[i].Cells[1].String()
  938. con.SupplierName = con.ImportSupplierName
  939. con.ContractNo = sheet.Rows[i].Cells[2].String()
  940. con.ContractName = sheet.Rows[i].Cells[3].String()
  941. con.Amount = sheet.Rows[i].Cells[4].String()
  942. if con.Amount == "" {
  943. con.Amount = "0"
  944. }
  945. con.ImportSecondUnit = sheet.Rows[i].Cells[5].String()
  946. con.ProjectOwner = sheet.Rows[i].Cells[6].String()
  947. //con.ContractSonClass = sheet.Rows[i].Cells[4].String()
  948. //con.SmallClass = sheet.Rows[i].Cells[5].String()
  949. //con.SignedDate = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
  950. con.SignedDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[7].Value), time.Local)
  951. con.StartDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[8].Value), time.Local)
  952. con.EndDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  953. con.YearDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[9].Value), time.Local)
  954. var supp supplier.OilSupplier
  955. //svc.GetEntityByWhere(OilSupplierName, "SupplierName = '"+con.ImportSupplierName+"'", &supp)
  956. svc.GetJoinBySelect1("b.SupplierTypeCode='" + con.ContractClass + "' AND a.SupplierName = '"+con.ImportSupplierName+"'", &supp)
  957. if supp.Id > 0 {
  958. con.SupplierId = supp.Id
  959. }
  960. var org organize.Base_Organize
  961. svc.GetEntityByWhere("Base_Organize", "ParentId in (100000004,100000005,100000009) and FullName = '"+sheet.Rows[i].Cells[5].String()+"'", &org)
  962. if org.Id > 0 {
  963. con.SecondUnit = org.Id
  964. con.SecondUnitName = org.Fullname
  965. }
  966. con.Number = sheet.Rows[i].Cells[10].String()
  967. //con.ChooseWay = sheet.Rows[i].Cells[11].String()
  968. //con.ContractMark = sheet.Rows[i].Cells[14].String()
  969. //con.Currency = sheet.Rows[i].Cells[15].String()
  970. //con.BudgetAmount = sheet.Rows[i].Cells[16].String()
  971. if con.BudgetAmount == "" {
  972. con.BudgetAmount = "0"
  973. }
  974. //con.PerformAmount = sheet.Rows[i].Cells[17].String()
  975. if con.PerformAmount == "" {
  976. con.PerformAmount = "0"
  977. }
  978. con.IsYearMoney = con.Amount
  979. con.IsInternal = 0
  980. //if sheet.Rows[i].Cells[18].String() == "是" {
  981. // con.IsInternal = 1
  982. //}
  983. con.IsForeign = 0
  984. //if sheet.Rows[i].Cells[19].String() == "是" {
  985. // con.IsForeign = 1
  986. //}
  987. con.IsDeal = 0
  988. //if sheet.Rows[i].Cells[20].String() == "是" {
  989. // con.IsDeal = 1
  990. //}
  991. //con.MoneyFlows = sheet.Rows[i].Cells[21].String()
  992. //con.MoneyChannel = sheet.Rows[i].Cells[22].String()
  993. //con.MoneyChannelSon = sheet.Rows[i].Cells[23].String()
  994. //con.MoneyChannelSmall = sheet.Rows[i].Cells[24].String()
  995. //con.SingUnit = sheet.Rows[i].Cells[25].String()
  996. //con.Place = sheet.Rows[i].Cells[28].String()
  997. //con.DisputeResolution = sheet.Rows[i].Cells[31].String()
  998. //con.Remark = sheet.Rows[i].Cells[32].String()
  999. //con.ProjectOwner = sheet.Rows[i].Cells[33].String()
  1000. //con.SubmitDate, _ = time.ParseInLocation("2006-01-02", convertToFormatDay(sheet.Rows[i].Cells[34].Value), time.Local)
  1001. //con.SealName = sheet.Rows[i].Cells[42].String()
  1002. //con.PoNumber = sheet.Rows[i].Cells[32].String()
  1003. con.ImportStatus = 0
  1004. con.Status = 1
  1005. con.SettleStatus = "1"
  1006. _, err = svc.InsertEntityBytbl(OilContractName, &con)
  1007. if err != nil {
  1008. fmt.Println(err)
  1009. }
  1010. }
  1011. os.Remove(filePath)
  1012. elapsed := time.Since(t)
  1013. log.Println(elapsed)
  1014. }()
  1015. var errorinfo ErrorDataInfo
  1016. errorinfo.Code = 0
  1017. errorinfo.Message = "导入中,请稍后!"
  1018. this.Data["json"] = &errorinfo
  1019. this.ServeJSON()
  1020. }
  1021. // @Title 从数据录入数据导出到word文档
  1022. // @Description 数据存入word
  1023. // @Success 200 {object} controllers.Request
  1024. // @router /exportword/:id [get]
  1025. func (this *OilContractController) DocExport() {
  1026. // 填物资类信息表首页信息
  1027. Id := this.Ctx.Input.Param(":id")
  1028. var Url string
  1029. var fileName string
  1030. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1031. var model contract.OilContract
  1032. svc := contract.GetOilContractService(utils.DBE)
  1033. where := "1=1"
  1034. where += " AND Id = '" + Id + "'"
  1035. svc.GetEntityByWhere(OilContractName, where, &model)
  1036. Url = utils.Cfg.MustValue("workflow", "contractUrl")
  1037. fileName = "合同导出模板.docx"
  1038. model.ProjectName = model.ContractName
  1039. model.OpenDate = model.StartDate
  1040. model.PlanFinishDate = model.EndDate
  1041. datamap := structToMapDemo(model)
  1042. //datamap["TableComment"] = []string{"MajorEquipments", "ThreeYears", "Patent", "Winning"}
  1043. retDocUrl := svcActiviti.FillWordTemplate(datamap, Url, fileName)
  1044. //retDocUrl := svcActiviti.FillWordWatermarkTemplate(datamap, Url, fileName, model.SupplierName)
  1045. var datainfo ErrorDataInfo
  1046. datainfo.Code = 0
  1047. datainfo.Item = retDocUrl
  1048. datainfo.Message = "导出成功"
  1049. this.Data["json"] = &datainfo
  1050. this.ServeJSON()
  1051. }
  1052. // @Title get 导入批量保存
  1053. // @Description 数据存入
  1054. // @Success 200 {object} controllers.Request
  1055. // @router /importbatchsave [post]
  1056. func (this *OilContractController) ImportBatchSave() {
  1057. sql := "update OilContract set ImportStatus = 1 where SupplierName != '' and ContractClass != '' and SecondUnit != 0 and ContractNo != ''"
  1058. _, err := utils.DBE.Query(sql)
  1059. var errinfo ErrorInfo
  1060. if err == nil {
  1061. errinfo.Message = "确认成功!"
  1062. errinfo.Code = 0
  1063. this.Data["json"] = &errinfo
  1064. this.ServeJSON()
  1065. } else {
  1066. errinfo.Message = "确认失败!" + utils.AlertProcess(err.Error())
  1067. errinfo.Code = -1
  1068. this.Data["json"] = &errinfo
  1069. this.ServeJSON()
  1070. }
  1071. }
  1072. // @Title get 批量修改字段
  1073. // @Description 批量修改字段
  1074. // @Success 200 {object} controllers.Request
  1075. // @router /importUpdate [get]
  1076. func (this *OilContractController) ImportUpdate() {
  1077. Class := this.GetString("Class")
  1078. Value := this.GetString("Value")
  1079. Column := this.GetString("Column")
  1080. Id := this.GetString("Id")
  1081. SupplierId := this.GetString("SupplierId")
  1082. var supp supplier.OilSupplier
  1083. var con contract.OilContract
  1084. svc := supplier.GetOilSupplierService(utils.DBE)
  1085. svc.GetEntityById(SupplierId, &supp)
  1086. sql := ""
  1087. var err error
  1088. var errinfo ErrorInfo
  1089. where := "1=1"
  1090. if Column == "ContractClass" {
  1091. if Id != "0" {
  1092. where += " and Id = " + Id + " and ImportStatus = 0 and ClassName = '" + Class + "'"
  1093. } else {
  1094. where += " and ImportStatus = 0 and ClassName = '" + Class + "' and " + Column + " = ''"
  1095. }
  1096. sql = "update OilContract set " + Column + " = '" + Value + "' where " + where
  1097. _, err = utils.DBE.Query(sql)
  1098. }
  1099. if Column == "SupplierId" {
  1100. if Id != "0" {
  1101. where += " and Id = " + Id + " and ImportStatus = 0 and ImportSupplierName = '" + Class + "'"
  1102. } else {
  1103. where += " and ImportStatus = 0 and ImportSupplierName = '" + Class + "' and " + Column + " = 0"
  1104. }
  1105. sql := "update OilContract set SupplierName = '" + supp.SupplierName + "', " + Column + " = " + Value + " where " + where
  1106. _, err = utils.DBE.Query(sql)
  1107. }
  1108. if Column == "SecondUnit" {
  1109. var org organize.Base_Organize
  1110. svc.GetEntityByWhere("Base_Organize", "Id = "+Value, &org)
  1111. if Id != "0" {
  1112. where += " and Id = " + Id + " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "'"
  1113. sql = "update OilContract set SecondUnitName = '" + org.Fullname + "', " + Column + " = " + Value + " where " + where
  1114. } else {
  1115. //where += " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "' and " + Column + " = 0"
  1116. where += " and ImportStatus = 0 and ImportSecondUnit = '" + Class + "'"
  1117. sql = "update OilContract set SecondUnitName = '" + org.Fullname + "'," + Column + " = " + Value + " where " + where
  1118. }
  1119. _, err = utils.DBE.Query(sql)
  1120. }
  1121. if Column == "Status" {
  1122. where += " and Id = " + Id + " and ImportStatus = 0"
  1123. sql := "update OilContract set " + Column + " = " + Value + " where " + where
  1124. _, err = utils.DBE.Query(sql)
  1125. }
  1126. if Column == "ContractNo" {
  1127. svc.GetEntityByWhere("OilContract", "ContractNo = '"+Value+"' and Id != "+Id, &con)
  1128. if Value == "" {
  1129. errinfo.Message = "修改失败!合同编号不能为空"
  1130. errinfo.Code = -1
  1131. this.Data["json"] = &errinfo
  1132. this.ServeJSON()
  1133. return
  1134. }
  1135. if con.Id > 0 {
  1136. errinfo.Message = "修改失败!合同编号不能重复"
  1137. errinfo.Code = -1
  1138. this.Data["json"] = &errinfo
  1139. this.ServeJSON()
  1140. return
  1141. }
  1142. where += " and Id = " + Id + " and ImportStatus = 0"
  1143. sql := "update OilContract set " + Column + " = '" + Value + "' where " + where
  1144. _, err = utils.DBE.Query(sql)
  1145. }
  1146. if Column == "SettleStatus" {
  1147. where += " and Id = " + Id + " and ImportStatus = 0"
  1148. sql := "update OilContract set " + Column + " = '" + Value + "' where " + where
  1149. _, err = utils.DBE.Query(sql)
  1150. }
  1151. if err == nil {
  1152. errinfo.Message = "修改成功!"
  1153. errinfo.Code = 0
  1154. this.Data["json"] = &errinfo
  1155. this.ServeJSON()
  1156. } else {
  1157. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  1158. errinfo.Code = -1
  1159. this.Data["json"] = &errinfo
  1160. this.ServeJSON()
  1161. }
  1162. }
  1163. // excel日期字段格式化 yyyy-mm-dd
  1164. func convertToFormatDay(excelDaysString string) string {
  1165. if strings.Index(excelDaysString, "/") != -1 {
  1166. arr := strings.Split(excelDaysString, "/")
  1167. if len(arr) == 3 {
  1168. if len(arr[1]) == 1 {
  1169. arr[1] = "0" + arr[1]
  1170. }
  1171. if len(arr[2]) == 1 {
  1172. arr[2] = "0" + arr[2]
  1173. }
  1174. excelDaysString = strings.Join(arr, "-")
  1175. }
  1176. return excelDaysString
  1177. }
  1178. // 2006-01-02 距离 1900-01-01的天数
  1179. baseDiffDay := int64(38719) //在网上工具计算的天数需要加2天,什么原因没弄清楚
  1180. curDiffDay := excelDaysString
  1181. comma := strings.Index(curDiffDay, ".")
  1182. if comma != -1 {
  1183. curDiffDay = curDiffDay[0:comma]
  1184. }
  1185. b, _ := strconv.ParseInt(curDiffDay, 10, 64) //strconv.Atoi(curDiffDay)
  1186. // 获取excel的日期距离2006-01-02的天数
  1187. realDiffDay := b - baseDiffDay
  1188. //fmt.Println("realDiffDay:",realDiffDay)
  1189. // 距离2006-01-02 秒数
  1190. realDiffSecond := realDiffDay * 24 * 3600
  1191. //fmt.Println("realDiffSecond:",realDiffSecond)
  1192. // 2006-01-02 15:04:05距离1970-01-01 08:00:00的秒数 网上工具可查出
  1193. baseOriginSecond := int64(1136185445)
  1194. resultTime := time.Unix((baseOriginSecond + realDiffSecond), 0).Format("2006-01-02")
  1195. return resultTime
  1196. }
  1197. func (this *OilContractController) OperationCell(svc *contract.OilContractSession, lineNo string, columnArr []string, cellsArr []*xlsx.Cell, errLineNum *string) {
  1198. defer func() {
  1199. if err := recover(); err != nil {
  1200. log.Println("err"+lineNo, err)
  1201. *errLineNum += lineNo + ","
  1202. }
  1203. }()
  1204. cellsArrLen := len(cellsArr)
  1205. var valstr = ""
  1206. for i := 0; i < cellsArrLen; i++ {
  1207. valstr += "'" + cellsArr[i].String() + "',"
  1208. }
  1209. valstr = strings.Trim(valstr, ",")
  1210. valstr = strings.Replace(valstr, "是", "1", -1)
  1211. log.Println(cellsArr[6].String() + "==" + valstr)
  1212. var columnstr = ""
  1213. for l := 0; l < cellsArrLen; l++ {
  1214. columnstr += columnArr[l] + ","
  1215. }
  1216. columnstr = strings.Trim(columnstr, ",")
  1217. //err := svc.InsertTmpOilBasisBuild(columnstr, valstr)
  1218. //if err != nil {
  1219. // panic(err)
  1220. //}
  1221. }
  1222. func structToMapDemo(obj interface{}) map[string]interface{} {
  1223. obj1 := reflect.TypeOf(obj)
  1224. obj2 := reflect.ValueOf(obj)
  1225. var data = make(map[string]interface{})
  1226. for i := 0; i < obj1.NumField(); i++ {
  1227. data[obj1.Field(i).Name] = obj2.Field(i).Interface()
  1228. }
  1229. return data
  1230. }
  1231. // @Title 添加
  1232. // @Description 新增
  1233. // @Param body body oilcontract.OilContract
  1234. // @Success 200 {object} controllers.Request
  1235. // @router /add [post]
  1236. func (this *OilContractController) AddEntity() {
  1237. var errinfo ErrorDataInfo
  1238. var model contract.OilContract
  1239. var model2 contract.OilContractMoney
  1240. var jsonBlob = this.Ctx.Input.RequestBody
  1241. svc := contract.GetOilContractService(utils.DBE)
  1242. json.Unmarshal(jsonBlob, &model)
  1243. json.Unmarshal(jsonBlob, &model2)
  1244. if model.IsYear == 1 && model.IsYearMoney == "" {
  1245. errinfo.Message = "跨年当年结算金额必填"
  1246. errinfo.Code = -2
  1247. this.Data["json"] = &errinfo
  1248. this.ServeJSON()
  1249. return
  1250. }
  1251. if model.IsYearMoney == "" {
  1252. //model.IsYearMoney = model.PerformAmount
  1253. model.IsYearMoney = model.Amount
  1254. }
  1255. model.ImportStatus = 2
  1256. model.BudgetAmount = "0"
  1257. model.PerformAmount = "0"
  1258. model.CreateOn = time.Now()
  1259. model.CreateBy = this.User.Realname
  1260. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1261. model.SecondUnit = this.User.UnitId
  1262. var org organize.Base_Organize
  1263. svc.GetEntityByWhere("Base_Organize", "Id = "+strconv.Itoa(this.User.UnitId), &org)
  1264. if org.Id > 0 {
  1265. model.SecondUnitName = org.Fullname
  1266. }
  1267. var supp supplier.OilSupplier
  1268. model.SupplierName = model.ImportSupplierName
  1269. svc.GetJoinBySelect1("b.SupplierTypeCode='" + model.ContractClass + "' AND a.SupplierName = '"+model.ImportSupplierName+"'", &supp)
  1270. if supp.Id > 0 {
  1271. model.SupplierId = supp.Id
  1272. }
  1273. var model1 contract.OilContractMoney
  1274. var contract contract.OilContract
  1275. tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' ")
  1276. if tempCount > 0 {
  1277. errinfo.Message = "合同编号已存在!"
  1278. errinfo.Code = -1
  1279. this.Data["json"] = &errinfo
  1280. this.ServeJSON()
  1281. return
  1282. }
  1283. _, err := svc.InsertEntityBytbl(OilContractName, &model)
  1284. if err == nil {
  1285. if model.IsYear == 1 {
  1286. svc.GetEntityByWhere(OilContractName, "ContractNo = '"+model.ContractNo+"'", &model)
  1287. //svc.GetEntityByWhere("OilContractMoney", "Year = '"+time.Now().Format("2006")+"' and ContractId = "+strconv.Itoa(model.Id), &model1)
  1288. model1.ContractId = model.Id
  1289. model1.Money = model.IsYearMoney
  1290. model1.Year = model2.Year
  1291. model1.CreateOn = time.Now()
  1292. model1.CreateBy = this.User.Realname
  1293. model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1294. svc.InsertEntityBytbl("OilContractMoney", &model1)
  1295. }
  1296. //新增
  1297. errinfo.Message = "添加成功!"
  1298. errinfo.Code = 0
  1299. errinfo.Item = model.Id
  1300. this.Data["json"] = &errinfo
  1301. this.ServeJSON()
  1302. } else {
  1303. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  1304. errinfo.Code = -1
  1305. this.Data["json"] = &errinfo
  1306. this.ServeJSON()
  1307. }
  1308. }
  1309. // @Title 修改实体
  1310. // @Description 修改实体
  1311. // @Param body body oilcontract.OilContract
  1312. // @Success 200 {object} controllers.Request
  1313. // @router /update/:id [post]
  1314. func (this *OilContractController) UpdateEntity() {
  1315. id := this.Ctx.Input.Param(":id")
  1316. var errinfo ErrorInfo
  1317. if id == "" {
  1318. errinfo.Message = "操作失败!请求信息不完整"
  1319. errinfo.Code = -2
  1320. this.Data["json"] = &errinfo
  1321. this.ServeJSON()
  1322. return
  1323. }
  1324. var model contract.OilContract
  1325. var model1 contract.OilContractMoney
  1326. var model2 contract.OilContractMoney
  1327. svc := contract.GetOilContractService(utils.DBE)
  1328. var jsonBlob = this.Ctx.Input.RequestBody
  1329. json.Unmarshal(jsonBlob, &model)
  1330. json.Unmarshal(jsonBlob, &model2)
  1331. if model.IsYear == 1 && model.IsYearMoney == "" {
  1332. errinfo.Message = "跨年当年结算金额必填"
  1333. errinfo.Code = -2
  1334. this.Data["json"] = &errinfo
  1335. this.ServeJSON()
  1336. return
  1337. }
  1338. if model.IsYearMoney == "" {
  1339. model.IsYearMoney = model.PerformAmount
  1340. }
  1341. model.ModifiedOn = time.Now()
  1342. model.ModifiedBy = this.User.Realname
  1343. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1344. cols := []string{
  1345. "Id",
  1346. "SupplierId",
  1347. "SupplierName",
  1348. "Status",
  1349. "SettleStatus",
  1350. "ProjectName",
  1351. "ContractNo",
  1352. "ProjectPlace",
  1353. "ProjectOwner",
  1354. "Telephone",
  1355. "ProjectType",
  1356. "ContractMode",
  1357. "Amount",
  1358. "ContractPeriod",
  1359. "EndDate",
  1360. "YearDate",
  1361. "StartDate",
  1362. "ConstructionUnit",
  1363. "ConstructionOwner",
  1364. "ConstructionTelphone",
  1365. "BuildUnit",
  1366. "BuildOwner",
  1367. "BuildTelphone",
  1368. "SuperviseUnit",
  1369. "SuperviseOwner",
  1370. "SuperviseTelphone",
  1371. "QualityUnit",
  1372. "QualityOwner",
  1373. "QualityTelphone",
  1374. "Remark",
  1375. "IsDelete",
  1376. "CreateOn",
  1377. "CreateUserId",
  1378. "CreateBy",
  1379. "ModifiedOn",
  1380. "ModifiedUserId",
  1381. "ModifiedBy",
  1382. "SubPackage",
  1383. "ContractName",
  1384. "ContractSonClass",
  1385. "SmallClass",
  1386. "SignedDate",
  1387. "People",
  1388. "Number",
  1389. "ChooseWay",
  1390. "ContractMark",
  1391. "Currency",
  1392. "BudgetAmount",
  1393. "PerformAmount",
  1394. "IsInternal",
  1395. "IsForeign",
  1396. "IsDeal",
  1397. "MoneyFlows",
  1398. "MoneyChannelSon",
  1399. "MoneyChannelSmall",
  1400. "SingUnit",
  1401. "Place",
  1402. "DisputeResolution",
  1403. "SubmitDate",
  1404. "SealName",
  1405. "PoNumber",
  1406. "IsYearMoney",
  1407. "IsYear",
  1408. "ClassName",
  1409. "ImportSupplierName",
  1410. }
  1411. var contract contract.OilContract
  1412. tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' and id <> "+id)
  1413. if tempCount > 0 {
  1414. errinfo.Message = "合同编号已存在!"
  1415. errinfo.Code = -1
  1416. this.Data["json"] = &errinfo
  1417. this.ServeJSON()
  1418. return
  1419. }
  1420. date := time.Now().Format("2006-01-02")
  1421. date1 := model.EndDate.Format("2006-01-02")
  1422. if date >= date1 && model.IsYear == 1 {
  1423. model.YearDate = model.EndDate.AddDate(1, 0, 0)
  1424. }
  1425. var supp supplier.OilSupplier
  1426. if model.ImportStatus == 2 {
  1427. model.SupplierName = model.ImportSupplierName
  1428. svc.GetJoinBySelect1("b.SupplierTypeCode='" + model.ContractClass + "' AND a.SupplierName = '"+model.ImportSupplierName+"'", &supp)
  1429. model.SupplierId = supp.Id
  1430. }
  1431. if model.Status == 3 {
  1432. var review contractReview.OilContractReview
  1433. svc.GetEntityByWhere(OilContractReviewName, "Status = 8 and ContractId = '" + strconv.Itoa(model.Id) + "'", &review)
  1434. if review.Id == 0 {
  1435. errinfo.Message = "没有已完成评价不能选履行完毕!"
  1436. errinfo.Code = -1
  1437. this.Data["json"] = &errinfo
  1438. this.ServeJSON()
  1439. return
  1440. }
  1441. }
  1442. err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
  1443. if err == nil {
  1444. if model.IsYear == 1 && model.IsYearMoney != "" {
  1445. svc.GetEntityByWhere("OilContractMoney", "Year = '"+model2.Year+"' and ContractId = "+id, &model1)
  1446. if model1.Id > 0 {
  1447. model1.Money = model.IsYearMoney
  1448. model1.ModifiedOn = time.Now()
  1449. model1.ModifiedBy = this.User.Realname
  1450. model1.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1451. svc.UpdateEntityBytbl("OilContractMoney", model1.Id, &model1, []string{"Money"})
  1452. } else {
  1453. model1.ContractId, _ = strconv.Atoi(id)
  1454. model1.Money = model.IsYearMoney
  1455. model1.Year = model2.Year
  1456. model1.CreateOn = time.Now()
  1457. model1.CreateBy = this.User.Realname
  1458. model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1459. svc.InsertEntityBytbl("OilContractMoney", &model1)
  1460. }
  1461. }
  1462. errinfo.Message = "修改成功!"
  1463. errinfo.Code = 0
  1464. this.Data["json"] = &errinfo
  1465. this.ServeJSON()
  1466. } else {
  1467. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  1468. errinfo.Code = -1
  1469. this.Data["json"] = &errinfo
  1470. this.ServeJSON()
  1471. }
  1472. }
  1473. // @Title 删除单条信息
  1474. // @Description
  1475. // @Success 200 {object} ErrorInfo
  1476. // @Failure 403 :id 为空
  1477. // @router /delete/:Id [delete]
  1478. func (this *OilContractController) DeleteEntity() {
  1479. Id := this.Ctx.Input.Param(":Id")
  1480. var errinfo ErrorInfo
  1481. if Id == "" {
  1482. errinfo.Message = "操作失败!请求信息不完整"
  1483. errinfo.Code = -2
  1484. this.Data["json"] = &errinfo
  1485. this.ServeJSON()
  1486. return
  1487. }
  1488. // 有没有待审核的评价
  1489. itemsSvc := contractReview.GetOilContractReviewService(utils.DBE)
  1490. var review contractReview.OilContractReview
  1491. //tempCount,_:=itemsSvc.GetCount(&review,"ContractId='" + Id +"' and status > 0 and status < 8 ")
  1492. tempCount, _ := itemsSvc.GetCount(&review, "ContractId='"+Id+"' ")
  1493. if tempCount > 0 {
  1494. errinfo.Message = "该合同存在评价不能删除!"
  1495. errinfo.Code = -1
  1496. this.Data["json"] = &errinfo
  1497. this.ServeJSON()
  1498. return
  1499. }
  1500. var model contract.OilContract
  1501. var entityempty contract.OilContract
  1502. svc := contract.GetOilContractService(utils.DBE)
  1503. opdesc := "删除-" + Id
  1504. err := svc.DeleteOperationAndWriteLogBytbl(OilContractName, BaseOperationLogName, Id, &model, &entityempty,
  1505. utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "合同表")
  1506. if err == nil {
  1507. errinfo.Message = "删除成功"
  1508. errinfo.Code = 0
  1509. this.Data["json"] = &errinfo
  1510. this.ServeJSON()
  1511. } else {
  1512. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  1513. errinfo.Code = -1
  1514. this.Data["json"] = &errinfo
  1515. this.ServeJSON()
  1516. }
  1517. }
  1518. // @Title 获取合同结算金额总数
  1519. // @Description
  1520. // @Success 200 {object} ErrorInfo
  1521. // @Failure 403 :id 为空
  1522. // @router /countMoney/:Id [get]
  1523. func (this *OilContractController) CountMoney() {
  1524. Id := this.Ctx.Input.Param(":Id")
  1525. var errinfo ErrorInfo
  1526. if Id == "" {
  1527. errinfo.Message = "操作失败!请求信息不完整"
  1528. errinfo.Code = -2
  1529. this.Data["json"] = &errinfo
  1530. this.ServeJSON()
  1531. return
  1532. }
  1533. var model contract.OilContractMoney
  1534. svc := contract.GetOilContractService(utils.DBE)
  1535. svc.GetSum1(&model, "ContractId = "+Id+" and Year != '"+time.Now().Format("2006")+"'")
  1536. this.Data["json"] = &model
  1537. this.ServeJSON()
  1538. }
  1539. // @Title 获取跨年记录
  1540. // @Description
  1541. // @Success 200 {object} ErrorInfo
  1542. // @Failure 403 :id 为空
  1543. // @router /yearList/:Id [get]
  1544. func (this *OilContractController) YearList() {
  1545. Id := this.Ctx.Input.Param(":Id")
  1546. var errinfo ErrorInfo
  1547. if Id == "" {
  1548. errinfo.Message = "操作失败!请求信息不完整"
  1549. errinfo.Code = -2
  1550. this.Data["json"] = &errinfo
  1551. this.ServeJSON()
  1552. return
  1553. }
  1554. var model []contract.OilContractMoney1
  1555. svc := contract.GetOilContractService(utils.DBE)
  1556. svc.GetList(&model, "ContractId = "+Id)
  1557. this.Data["json"] = &model
  1558. this.ServeJSON()
  1559. }
  1560. // @Title 获取列表
  1561. // @Description get user by token
  1562. // @Success 200 {object} []oilcontract.OilContract
  1563. // @router /need-eva-list [get]
  1564. func (this *OilContractController) GetNeedEvaList() {
  1565. var list []contract.OilContract
  1566. // TODO 加年度
  1567. sql := ` select a.* from OilContract a left join OilContractReview b on b.ContractId=a.Id where a.ImportStatus > 0 and a.Status = 2 and a.SecondUnit=` + strconv.Itoa(this.User.UnitId) + ` and (b.Status < 0 or b.Status is NULL) `
  1568. utils.DBE.Sql(sql).Find(&list)
  1569. var dataInfo DataInfo
  1570. dataInfo.Items = list
  1571. dataInfo.CurrentItemCount = 0
  1572. if list != nil {
  1573. dataInfo.CurrentItemCount = int64(len(list))
  1574. }
  1575. this.Data["json"] = &dataInfo
  1576. this.ServeJSON()
  1577. }
  1578. // @Title 获取上报情况列表
  1579. // @Description
  1580. // @Success 200 {object} ErrorInfo
  1581. // @router /handOnList [post]
  1582. func (this *OilContractController) GetHandOnStatisticsList() {
  1583. var queryParam contract.HandOnStatisticsQuery
  1584. var jsonBlob = this.Ctx.Input.RequestBody
  1585. json.Unmarshal(jsonBlob, &queryParam)
  1586. var models []contract.HandOnStatisticsEntity
  1587. svc := contract.GetOilContractService(utils.DBE)
  1588. total := svc.GetHandOnStatisticsList(queryParam, &models)
  1589. var dataInfo DataInfo
  1590. dataInfo.Items = models
  1591. dataInfo.CurrentItemCount = total
  1592. this.Data["json"] = &dataInfo
  1593. this.ServeJSON()
  1594. }
  1595. // @Title 清空列表
  1596. // @Description
  1597. // @Success 200 {object} ErrorInfo
  1598. // @router /deleteList [get]
  1599. func (this *OilContractController) DeleteList() {
  1600. svc := contract.GetOilContractService(utils.DBE)
  1601. svc.DeleteEntityBytbl(OilContractName, "ImportStatus = 0")
  1602. var errinfo ErrorInfo
  1603. errinfo.Message = "清空成功"
  1604. errinfo.Code = 0
  1605. this.Data["json"] = &errinfo
  1606. this.ServeJSON()
  1607. }
  1608. // @Title 一键更新二级单位名称
  1609. // @Description
  1610. // @Success 200 {object} ErrorInfo
  1611. // @router /updateUnitName/:Id [get]
  1612. func (this *OilContractController) UpdateUnitName() {
  1613. Id := this.Ctx.Input.Param(":Id")
  1614. UnitId := this.GetString("UnitId")
  1615. ContractId := this.GetString("ContractId")
  1616. var errinfo ErrorInfo
  1617. if Id == "" || UnitId == "" {
  1618. errinfo.Message = "操作失败!请求信息不完整"
  1619. errinfo.Code = -2
  1620. this.Data["json"] = &errinfo
  1621. this.ServeJSON()
  1622. return
  1623. }
  1624. var model contract.OilContract
  1625. svc := contract.GetOilContractService(utils.DBE)
  1626. var org organize.Base_Organize
  1627. svc.GetEntityByWhere("Base_Organize", "Id = "+UnitId, &org)
  1628. model.SecondUnit, _ = strconv.Atoi(UnitId)
  1629. model.SecondUnitName = org.Fullname
  1630. where := "SecondUnit = " + Id
  1631. if ContractId != "" {
  1632. where += " and Id = " + ContractId
  1633. }
  1634. svc.UpdateEntityBywheretbl(OilContractName, &model, []string{"SecondUnit", "SecondUnitName"}, where)
  1635. errinfo.Message = "更新成功"
  1636. errinfo.Code = 0
  1637. this.Data["json"] = &errinfo
  1638. this.ServeJSON()
  1639. }