contract.go 38 KB

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