infochange.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. package oilsupplier
  2. import (
  3. "dashoo.cn/backend/api/business/audithistory"
  4. "dashoo.cn/backend/api/business/auditsetting"
  5. "dashoo.cn/backend/api/business/oilsupplier/infochange"
  6. "dashoo.cn/backend/api/business/oilsupplier/supplier"
  7. "dashoo.cn/backend/api/business/oilsupplier/suppliercert"
  8. "dashoo.cn/backend/api/business/oilsupplier/supplierfile"
  9. "dashoo.cn/backend/api/business/register"
  10. "dashoo.cn/business2/parameter"
  11. "dashoo.cn/business2/permission"
  12. "dashoo.cn/business2/userRole"
  13. "encoding/json"
  14. "fmt"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. "dashoo.cn/backend/api/business/oilsupplier/annualaudit"
  20. "dashoo.cn/backend/api/business/workflow"
  21. . "dashoo.cn/backend/api/controllers"
  22. "dashoo.cn/utils"
  23. )
  24. type InfoChangeController struct {
  25. BaseController
  26. }
  27. type InfoShenHeModel struct {
  28. InfoId int
  29. SuccessStatus int
  30. AuditorRemark string
  31. SuppId int
  32. }
  33. type InfoChangeItemsAll struct {
  34. InfochangeForm []infoitems
  35. SupplierId string
  36. MInfoId string
  37. }
  38. type infoitems struct {
  39. SelectItem string
  40. SelectItemName string
  41. BeChangeInfo string
  42. ChangeInfo string
  43. }
  44. // @Title 获取实体
  45. // @Description 获取实体
  46. // @Success 200 {object} annualaudit.OilAnnualAudit
  47. // @router /get/:id [get]
  48. func (this *InfoChangeController) GetEntity() {
  49. CertId := this.Ctx.Input.Param(":id")
  50. var model []infochange.OilInfoChangeItem
  51. svc := infochange.GetInfoChangeService(utils.DBE)
  52. where := " SupplierId = " + CertId
  53. svc.GetEntitysByWhere(OilInfoChangeItemName, where, &model)
  54. var datainfo DataInfo
  55. datainfo.Items = model
  56. this.Data["json"] = &datainfo
  57. this.ServeJSON()
  58. }
  59. // @Title 获取实体
  60. // @Description 获取实体
  61. // @Success 200 {object} annualaudit.OilAnnualAudit
  62. // @router /getmain/:id [get]
  63. func (this *InfoChangeController) GetMainEntity() {
  64. Id := this.Ctx.Input.Param(":id")
  65. var model []infochange.OilInfoChange
  66. svc := infochange.GetInfoChangeService(utils.DBE)
  67. where := " Id = " + Id
  68. svc.GetEntitysByWhere(OilInfoChangeName, where, &model)
  69. var datainfo DataInfo
  70. datainfo.Items = model
  71. this.Data["json"] = &datainfo
  72. this.ServeJSON()
  73. }
  74. // @Title 获取实体
  75. // @Description 获取实体
  76. // @Success 200 {object} annualaudit.OilAnnualAudit
  77. // @router /getAccessCardNo/:id [get]
  78. func (this *InfoChangeController) GetAccessCardNo() {
  79. SuppId := this.Ctx.Input.Param(":id")
  80. var model []suppliercert.OilSupplierCert
  81. svc := infochange.GetInfoChangeService(utils.DBE)
  82. where := " SupplierId = " + SuppId
  83. svc.GetEntitysByOrderbyWhere(OilSupplierCertName, where, "SupplierTypeCode asc", &model)
  84. var datainfo DataInfo
  85. datainfo.Items = model
  86. this.Data["json"] = &datainfo
  87. this.ServeJSON()
  88. }
  89. // @Title 获取实体
  90. // @Description 获取实体
  91. // @Success 200 {object} annualaudit.OilAnnualAudit
  92. // @router /auditget/:id [get]
  93. func (this *InfoChangeController) GetEntityThen() {
  94. InfoId := this.Ctx.Input.Param(":id")
  95. var model []infochange.OilInfoChangeItem
  96. svc := infochange.GetInfoChangeService(utils.DBE)
  97. where := " InfoId = " + InfoId
  98. svc.GetEntitysByWhere(OilInfoChangeItemName, where, &model)
  99. var datainfo DataInfo
  100. datainfo.Items = model
  101. this.Data["json"] = &datainfo
  102. this.ServeJSON()
  103. }
  104. // @Title 获取列表
  105. // @Description get user by token
  106. // @Success 200 {object} []supplier.OilSupplier
  107. // @router /supplist [get]
  108. func (this *InfoChangeController) GetSuppList() {
  109. //获取分页信息
  110. page := this.GetPageInfoForm()
  111. where := " 1=1 "
  112. orderby := "b.Id"
  113. asc := false
  114. Order := this.GetString("Order")
  115. Prop := this.GetString("Prop")
  116. if Order != "" && Prop != "" {
  117. orderby = Prop
  118. if Order == "asc" {
  119. asc = true
  120. }
  121. }
  122. SupplierName := this.GetString("SupplierName")
  123. OilCertificateNo := this.GetString("OilCertificateNo")
  124. Grade := this.GetString("Grade")
  125. MgrUnit := this.GetString("MgrUnit")
  126. OperType := this.GetString("OperType")
  127. Country := this.GetString("Country")
  128. MaunAgent := this.GetString("MaunAgent")
  129. ConstructTeam := this.GetString("ConstructTeam")
  130. CommercialNo := this.GetString("CommercialNo")
  131. OrganCode := this.GetString("OrganCode")
  132. CountryTaxNo := this.GetString("CountryTaxNo")
  133. LocalTaxNo := this.GetString("LocalTaxNo")
  134. Address := this.GetString("Address")
  135. Province := this.GetString("Province")
  136. City := this.GetString("City")
  137. Street := this.GetString("Street")
  138. HouseNo := this.GetString("HouseNo")
  139. ZipCode := this.GetString("ZipCode")
  140. QualitySystemCert := this.GetString("QualitySystemCert")
  141. ProductQualityCert := this.GetString("ProductQualityCert")
  142. MaunLicense := this.GetString("MaunLicense")
  143. QualifCert := this.GetString("QualifCert")
  144. QualifCertLevel := this.GetString("QualifCertLevel")
  145. SafetyLicense := this.GetString("SafetyLicense")
  146. TechServiceLic := this.GetString("TechServiceLic")
  147. TJInNotify := this.GetString("TJInNotify")
  148. SpecIndustryCert := this.GetString("SpecIndustryCert")
  149. LegalPerson := this.GetString("LegalPerson")
  150. CategoryCode := this.GetString("CategoryCode")
  151. CategoryName := this.GetString("CategoryName")
  152. RegCapital := this.GetString("RegCapital")
  153. Currency := this.GetString("Currency")
  154. ContactName := this.GetString("ContactName")
  155. CompanyType := this.GetString("CompanyType")
  156. SetupTime := this.GetString("SetupTime")
  157. DepositBank := this.GetString("DepositBank")
  158. BankAccount := this.GetString("BankAccount")
  159. EMail := this.GetString("EMail")
  160. BankCreditRating := this.GetString("BankCreditRating")
  161. Mobile := this.GetString("Mobile")
  162. Telphone := this.GetString("Telphone")
  163. Fax := this.GetString("Fax")
  164. CompanyTel := this.GetString("CompanyTel")
  165. QQ := this.GetString("QQ")
  166. CompanyUrl := this.GetString("CompanyUrl")
  167. SpecSupplier := this.GetString("SpecSupplier")
  168. SpecTypeCode := this.GetString("SpecTypeCode")
  169. SpecTypeName := this.GetString("SpecTypeName")
  170. Remark := this.GetString("Remark")
  171. CreateOn := this.GetString("CreateOn")
  172. if SupplierName != "" {
  173. where = where + " and a.SupplierName like '%" + SupplierName + "%'"
  174. }
  175. if OilCertificateNo != "" {
  176. where = where + " and a.OilCertificateNo like '%" + OilCertificateNo + "%'"
  177. }
  178. if Grade != "" {
  179. where = where + " and a.Grade like '%" + Grade + "%'"
  180. }
  181. if MgrUnit != "" {
  182. where = where + " and a.MgrUnit like '%" + MgrUnit + "%'"
  183. }
  184. if OperType != "" {
  185. where = where + " and a.OperType like '%" + OperType + "%'"
  186. }
  187. if Country != "" {
  188. where = where + " and a.Country like '%" + Country + "%'"
  189. }
  190. if MaunAgent != "" {
  191. where = where + " and a.MaunAgent like '%" + MaunAgent + "%'"
  192. }
  193. if ConstructTeam != "" {
  194. where = where + " and a.ConstructTeam like '%" + ConstructTeam + "%'"
  195. }
  196. if CommercialNo != "" {
  197. where = where + " and a.CommercialNo like '%" + CommercialNo + "%'"
  198. }
  199. if OrganCode != "" {
  200. where = where + " and a.OrganCode like '%" + OrganCode + "%'"
  201. }
  202. if CountryTaxNo != "" {
  203. where = where + " and a.CountryTaxNo like '%" + CountryTaxNo + "%'"
  204. }
  205. if LocalTaxNo != "" {
  206. where = where + " and a.LocalTaxNo like '%" + LocalTaxNo + "%'"
  207. }
  208. if Address != "" {
  209. where = where + " and a.Address like '%" + Address + "%'"
  210. }
  211. if Province != "" {
  212. where = where + " and a.Province like '%" + Province + "%'"
  213. }
  214. if City != "" {
  215. where = where + " and a.City like '%" + City + "%'"
  216. }
  217. if Street != "" {
  218. where = where + " and a.Street like '%" + Street + "%'"
  219. }
  220. if HouseNo != "" {
  221. where = where + " and a.HouseNo like '%" + HouseNo + "%'"
  222. }
  223. if ZipCode != "" {
  224. where = where + " and a.ZipCode like '%" + ZipCode + "%'"
  225. }
  226. if QualitySystemCert != "" {
  227. where = where + " and a.QualitySystemCert like '%" + QualitySystemCert + "%'"
  228. }
  229. if ProductQualityCert != "" {
  230. where = where + " and a.ProductQualityCert like '%" + ProductQualityCert + "%'"
  231. }
  232. if MaunLicense != "" {
  233. where = where + " and a.MaunLicense like '%" + MaunLicense + "%'"
  234. }
  235. if QualifCert != "" {
  236. where = where + " and a.QualifCert like '%" + QualifCert + "%'"
  237. }
  238. if QualifCertLevel != "" {
  239. where = where + " and a.QualifCertLevel like '%" + QualifCertLevel + "%'"
  240. }
  241. if SafetyLicense != "" {
  242. where = where + " and a.SafetyLicense like '%" + SafetyLicense + "%'"
  243. }
  244. if TechServiceLic != "" {
  245. where = where + " and a.TechServiceLic like '%" + TechServiceLic + "%'"
  246. }
  247. if TJInNotify != "" {
  248. where = where + " and a.TJInNotify like '%" + TJInNotify + "%'"
  249. }
  250. if SpecIndustryCert != "" {
  251. where = where + " and a.SpecIndustryCert like '%" + SpecIndustryCert + "%'"
  252. }
  253. if LegalPerson != "" {
  254. where = where + " and a.LegalPerson like '%" + LegalPerson + "%'"
  255. }
  256. if CategoryCode != "" {
  257. where = where + " and a.CategoryCode like '%" + CategoryCode + "%'"
  258. }
  259. if CategoryName != "" {
  260. where = where + " and a.CategoryName like '%" + CategoryName + "%'"
  261. }
  262. if RegCapital != "" {
  263. where = where + " and a.RegCapital like '%" + RegCapital + "%'"
  264. }
  265. if Currency != "" {
  266. where = where + " and a.Currency like '%" + Currency + "%'"
  267. }
  268. if ContactName != "" {
  269. where = where + " and a.ContactName like '%" + ContactName + "%'"
  270. }
  271. if CompanyType != "" {
  272. where = where + " and a.CompanyType like '%" + CompanyType + "%'"
  273. }
  274. if SetupTime != "" {
  275. where = where + " and a.SetupTime like '%" + SetupTime + "%'"
  276. }
  277. if DepositBank != "" {
  278. where = where + " and a.DepositBank like '%" + DepositBank + "%'"
  279. }
  280. if BankAccount != "" {
  281. where = where + " and a.BankAccount like '%" + BankAccount + "%'"
  282. }
  283. if EMail != "" {
  284. where = where + " and a.EMail like '%" + EMail + "%'"
  285. }
  286. if BankCreditRating != "" {
  287. where = where + " and a.BankCreditRating like '%" + BankCreditRating + "%'"
  288. }
  289. if Mobile != "" {
  290. where = where + " and a.Mobile like '%" + Mobile + "%'"
  291. }
  292. if Telphone != "" {
  293. where = where + " and a.Telphone like '%" + Telphone + "%'"
  294. }
  295. if Fax != "" {
  296. where = where + " and a.Fax like '%" + Fax + "%'"
  297. }
  298. if CompanyTel != "" {
  299. where = where + " and a.CompanyTel like '%" + CompanyTel + "%'"
  300. }
  301. if QQ != "" {
  302. where = where + " and a.QQ like '%" + QQ + "%'"
  303. }
  304. if CompanyUrl != "" {
  305. where = where + " and a.CompanyUrl like '%" + CompanyUrl + "%'"
  306. }
  307. if SpecSupplier != "" {
  308. where = where + " and a.SpecSupplier like '%" + SpecSupplier + "%'"
  309. }
  310. if SpecTypeCode != "" {
  311. where = where + " and a.SpecTypeCode like '%" + SpecTypeCode + "%'"
  312. }
  313. if SpecTypeName != "" {
  314. where = where + " and a.SpecTypeName like '%" + SpecTypeName + "%'"
  315. }
  316. if Remark != "" {
  317. where = where + " and a.Remark like '%" + Remark + "%'"
  318. }
  319. if CreateOn != "" {
  320. dates := strings.Split(CreateOn, ",")
  321. if len(dates) == 2 {
  322. minDate := dates[0]
  323. maxDate := dates[1]
  324. where = where + " and a.CreateOn>='" + minDate + "' and a.CreateOn<='" + maxDate + "'"
  325. }
  326. }
  327. svc := infochange.GetInfoChangeService(utils.DBE)
  328. var registerUser register.OilCorporateInfo
  329. sql := " UserName='" + this.User.Username + "'"
  330. svc.GetEntity(&registerUser, sql)
  331. //企业用户必须加创建人条件
  332. if this.User.IsCompanyUser == 1 {
  333. where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='" + registerUser.CommercialNo + "')"
  334. } else {
  335. //超级管理员和有查看所有数据权限的用户不加条件
  336. svcPerm := permission.GetPermissionService(utils.DBE)
  337. isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.marketAccess.AllRecord")
  338. if !svcPerm.IsAdmin(this.User.Id) && !isauth {
  339. where = where + " and (b.CreateUserId = '" + this.User.Id + "' or a.CommercialNo='" + registerUser.CommercialNo + "')"
  340. }
  341. }
  342. var list []infochange.SuppModelInfo
  343. total := svc.GetSuppPagingEntitiesWithOrderBytbl(OilSupplierName, OilInfoChangeName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  344. //total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  345. var datainfo DataInfo
  346. datainfo.Items = list
  347. datainfo.CurrentItemCount = total
  348. datainfo.PageIndex = page.CurrentPage
  349. datainfo.ItemsPerPage = page.Size
  350. this.Data["json"] = &datainfo
  351. this.ServeJSON()
  352. }
  353. // @Title 获取列表
  354. // @Description get user by token
  355. // @Success 200 {object} []infochange.OilInfoChange
  356. // @router /alllist [get]
  357. func (this *InfoChangeController) GetAllEntityList() {
  358. //获取分页信息
  359. page := this.GetPageInfoForm()
  360. where := " 1=1 and b.OldSupplierName is not null"
  361. orderby := "a.Id"
  362. asc := false
  363. Order := this.GetString("Order")
  364. Prop := this.GetString("Prop")
  365. if Order != "" && Prop != "" {
  366. orderby = "a." + Prop
  367. if Order == "asc" {
  368. asc = true
  369. }
  370. }
  371. SupplierName := this.GetString("SupplierName")
  372. if SupplierName != "" {
  373. where = where + " and a.SupplierName like '%" + SupplierName + "%'"
  374. }
  375. svc := infochange.GetInfoChangeService(utils.DBE)
  376. var list []infochange.OilUsedName
  377. total := svc.GetUsedNameWithOrderBytbl(OilSupplierName, OilInfoChangeName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  378. var datainfo DataInfo
  379. datainfo.Items = list
  380. datainfo.CurrentItemCount = total
  381. this.Data["json"] = &datainfo
  382. this.ServeJSON()
  383. }
  384. // @Title 获取列表
  385. // @Description get user by token
  386. // @Success 200 {object} []infochange.OilInfoChange
  387. // @router /list [get]
  388. func (this *InfoChangeController) GetEntityList() {
  389. //获取分页信息
  390. page := this.GetPageInfoForm()
  391. where := " 1=1 "
  392. orderby := "Id"
  393. asc := false
  394. Order := this.GetString("Order")
  395. Prop := this.GetString("Prop")
  396. if Order != "" && Prop != "" {
  397. orderby = Prop
  398. if Order == "asc" {
  399. asc = true
  400. }
  401. }
  402. SupplierTypeName := this.GetString("SupplierTypeName")
  403. RecUnitId := this.GetString("RecUnitId")
  404. AccessCardNo := this.GetString("AccessCardNo")
  405. SupplierName := this.GetString("SupplierName")
  406. CreateOn := this.GetString("CreateOn")
  407. if SupplierTypeName != "" {
  408. where = where + " and SupplierTypeName like '%" + SupplierTypeName + "%'"
  409. }
  410. if RecUnitId != "" {
  411. where = where + " and RecUnitId like '%" + RecUnitId + "%'"
  412. }
  413. if AccessCardNo != "" {
  414. where = where + " and AccessCardNo like '%" + AccessCardNo + "%'"
  415. }
  416. if SupplierName != "" {
  417. where = where + " and SupplierName like '%" + SupplierName + "%'"
  418. }
  419. if CreateOn != "" {
  420. dates := strings.Split(CreateOn, ",")
  421. if len(dates) == 2 {
  422. minDate := dates[0]
  423. maxDate := dates[1]
  424. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  425. }
  426. }
  427. //找出待办任务
  428. actisvc := workflow.GetActivitiService(utils.DBE)
  429. certIdList := actisvc.GetMyTasks(workflow.OIL_INFO_CHANGE, this.User.Id)
  430. appendIdarr := strings.Split(certIdList, ",")
  431. for i, item := range appendIdarr {
  432. idx := strings.Index(item, "-")
  433. if idx >= 0 {
  434. appendIdarr[i] = strings.Split(item, "-")[0]
  435. }
  436. }
  437. certIdList = strings.Join(appendIdarr, ",")
  438. svc := infochange.GetInfoChangeService(utils.DBE)
  439. var list []infochange.OilInfoChange
  440. var total int64 = 0
  441. if certIdList != "" {
  442. where += " and Id in (" + certIdList + ")"
  443. total = svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  444. }
  445. var datainfo DataInfo
  446. datainfo.Items = list
  447. datainfo.CurrentItemCount = total
  448. datainfo.PageIndex = page.CurrentPage
  449. datainfo.ItemsPerPage = page.Size
  450. this.Data["json"] = &datainfo
  451. this.ServeJSON()
  452. }
  453. // @Title 获取实体
  454. // @Description 获取实体
  455. // @Success 200 {object} annualaudit.OilAnnualAudit
  456. // @router /getinfoforitem [get]
  457. func (this *InfoChangeController) GetInfoForItem() {
  458. certId := this.GetString("certId")
  459. selctitem := this.GetString("selctitem")
  460. svc := infochange.GetInfoChangeService(utils.DBE)
  461. where := "Id =" + utils.ToStr(certId)
  462. var selecteditem = svc.GetInfoforItem(""+OilSupplierName, selctitem, where)
  463. this.Data["json"] = &selecteditem
  464. this.ServeJSON()
  465. }
  466. // @Title 获取实体
  467. // @Description 获取实体
  468. // @Success 200 {object} supplier.OilSupplier
  469. // @router /getchangelist/:id [get]
  470. func (this *InfoChangeController) GetChangeEntity() {
  471. Id := this.Ctx.Input.Param(":id")
  472. InfoId := this.GetString("InfomainId")
  473. var models [2]supplier.OilSupplier
  474. var model supplier.OilSupplier
  475. var enumModel supplier.OilSupplier
  476. svc := supplier.GetOilSupplierService(utils.DBE)
  477. svc.GetEntityByIdBytbl(OilSupplierName, Id, &model)
  478. models[0] = model
  479. var infoitems []infochange.OilInfoChangeItem
  480. where := " SupplierId = " + Id +" and InfoId ="+InfoId
  481. where = where + " and ChangeStatus = 0"
  482. svc.GetEntitysByWhere(OilInfoChangeItemName, where, &infoitems)
  483. tmpModel := &model
  484. enumModel = *tmpModel
  485. immumodel := reflect.ValueOf(&enumModel)
  486. elem := immumodel.Elem()
  487. if len(infoitems) == 0 {
  488. models[1] = enumModel
  489. this.Data["json"] = &models
  490. this.ServeJSON()
  491. return
  492. } else {
  493. for _, info := range infoitems {
  494. fmt.Println(info.SelectItem)
  495. fmt.Println(";;;;;;;;;", elem.FieldByName(info.SelectItem).Type().String())
  496. if elem.FieldByName(info.SelectItem).Type().String() == "int64" {
  497. intchangeinfo, _ := strconv.ParseInt(info.ChangeInfo, 10, 64)
  498. elem.FieldByName(info.SelectItem).SetInt(intchangeinfo)
  499. } else if elem.FieldByName(info.SelectItem).Type().String() == "float64" {
  500. floatchangeinfo, _ := strconv.ParseFloat(info.ChangeInfo, 64)
  501. elem.FieldByName(info.SelectItem).SetFloat(floatchangeinfo)
  502. } else if elem.FieldByName(info.SelectItem).Type().String() == "time.Time" {
  503. t, _ := time.Parse("2006-01-02", info.ChangeInfo)
  504. elem.FieldByName(info.SelectItem).Set(reflect.ValueOf(t))
  505. } else {
  506. elem.FieldByName(info.SelectItem).SetString(info.ChangeInfo)
  507. }
  508. }
  509. models[1] = enumModel
  510. this.Data["json"] = &models
  511. this.ServeJSON()
  512. }
  513. }
  514. // @Title 获取列表
  515. // @Description get user by token
  516. // @Success 200 {object} []annualaudit.OilAnnualAudit
  517. // @router /mytasks [get]
  518. func (this *InfoChangeController) GetMyTaskEntityList() {
  519. //获取分页信息
  520. page := this.GetPageInfoForm()
  521. where := " 1=1 "
  522. orderby := "Id"
  523. asc := false
  524. Order := this.GetString("Order")
  525. Prop := this.GetString("Prop")
  526. if Order != "" && Prop != "" {
  527. orderby = Prop
  528. if Order == "asc" {
  529. asc = true
  530. }
  531. }
  532. SupplierTypeName := this.GetString("SupplierTypeName")
  533. RecUnitId := this.GetString("RecUnitId")
  534. AccessCardNo := this.GetString("AccessCardNo")
  535. SupplierName := this.GetString("SupplierName")
  536. CreateOn := this.GetString("CreateOn")
  537. if SupplierTypeName != "" {
  538. where = where + " and SupplierTypeName like '%" + SupplierTypeName + "%'"
  539. }
  540. if RecUnitId != "" {
  541. where = where + " and RecUnitId like '%" + RecUnitId + "%'"
  542. }
  543. if AccessCardNo != "" {
  544. where = where + " and AccessCardNo like '%" + AccessCardNo + "%'"
  545. }
  546. if SupplierName != "" {
  547. where = where + " and SupplierName like '%" + SupplierName + "%'"
  548. }
  549. if CreateOn != "" {
  550. dates := strings.Split(CreateOn, ",")
  551. if len(dates) == 2 {
  552. minDate := dates[0]
  553. maxDate := dates[1]
  554. where = where + " and CreateOn>='" + minDate + "' and CreateOn<='" + maxDate + "'"
  555. }
  556. }
  557. svc := annualaudit.GetOilAnnualAuditService(utils.DBE)
  558. var list []annualaudit.OilAnnualAudit
  559. //找出待办任务
  560. actisvc := workflow.GetActivitiService(utils.DBE)
  561. certIdList := actisvc.GetMyTasks(workflow.OIL_AUDIT_APPLY, this.User.Id)
  562. where += " and Id in (" + certIdList + ")"
  563. where += " and Status != -2 "
  564. //根据部门查询待办任务
  565. total := svc.GetPagingEntitiesWithOrderBytbl("", page.CurrentPage, page.Size, orderby, asc, &list, where)
  566. //total := svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, OilSupplierCertName, page.CurrentPage, page.Size, orderby, asc, &list, where)
  567. var datainfo DataInfo
  568. datainfo.Items = list
  569. datainfo.CurrentItemCount = total
  570. datainfo.PageIndex = page.CurrentPage
  571. datainfo.ItemsPerPage = page.Size
  572. this.Data["json"] = &datainfo
  573. this.ServeJSON()
  574. }
  575. // @Title 删除单条信息
  576. // @Description
  577. // @Success 200 {object} ErrorInfo
  578. // @Failure 403 :id 为空
  579. // @router /delete/:Id [delete]
  580. func (this *InfoChangeController) DeleteEntity() {
  581. Id := this.Ctx.Input.Param(":Id")
  582. var errinfo ErrorInfo
  583. if Id == "" {
  584. errinfo.Message = "操作失败!请求信息不完整"
  585. errinfo.Code = -2
  586. this.Data["json"] = &errinfo
  587. this.ServeJSON()
  588. return
  589. }
  590. var model infochange.OilInfoChangeItem
  591. var entityempty infochange.OilInfoChangeItem
  592. svc := infochange.GetInfoChangeService(utils.DBE)
  593. opdesc := "删除-" + Id
  594. err := svc.DeleteOperationAndWriteLogBytbl(""+OilInfoChangeItemName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, "", "信息变更")
  595. if err == nil {
  596. errinfo.Message = "删除成功"
  597. errinfo.Code = 0
  598. this.Data["json"] = &errinfo
  599. this.ServeJSON()
  600. } else {
  601. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  602. errinfo.Code = -1
  603. this.Data["json"] = &errinfo
  604. this.ServeJSON()
  605. }
  606. }
  607. // @Title 添加
  608. // @Description 新增
  609. // @Success 200 {object} controllers.Request
  610. // @router /addinfochangeitem [post]
  611. func (this *InfoChangeController) AddInfoChangeItem() {
  612. var model infochange.OilInfoChangeItem
  613. var jsonBlob = this.Ctx.Input.RequestBody
  614. svc := infochange.GetInfoChangeService(utils.DBE)
  615. json.Unmarshal(jsonBlob, &model)
  616. model.CreateOn = time.Now()
  617. model.CreateBy = this.User.Realname
  618. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  619. _, err := svc.InsertEntityBytbl(""+OilInfoChangeItemName, &model)
  620. var errinfo ErrorDataInfo
  621. if err == nil {
  622. //新增
  623. errinfo.Message = "添加成功!"
  624. errinfo.Code = 0
  625. errinfo.Item = model.Id
  626. this.Data["json"] = &errinfo
  627. this.ServeJSON()
  628. } else {
  629. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  630. errinfo.Code = -1
  631. this.Data["json"] = &errinfo
  632. this.ServeJSON()
  633. }
  634. }
  635. // @Title 添加
  636. // @Description 新增
  637. // @Success 200 {object} controllers.Request
  638. // @router /addinfochangeitemch [post]
  639. func (this *InfoChangeController) AddInfoChangeItemCh() {
  640. var model InfoChangeItemsAll
  641. var jsonBlob = this.Ctx.Input.RequestBody
  642. svc := infochange.GetInfoChangeService(utils.DBE)
  643. json.Unmarshal(jsonBlob, &model)
  644. var err error
  645. where := " SupplierId = " + model.SupplierId
  646. where = where + " and InfoId = " + model.MInfoId
  647. var deleteEntity infochange.OilInfoChangeItem
  648. delMainId, _ := strconv.Atoi(model.MInfoId)
  649. deleteEntity.InfoId = delMainId
  650. svc.DBE.Delete(deleteEntity)
  651. var infoitementitys []infochange.OilInfoChangeItem
  652. for i := 0; i < len(model.InfochangeForm); i++ {
  653. var infoitementity infochange.OilInfoChangeItem
  654. infoitementity.SelectItem = model.InfochangeForm[i].SelectItem
  655. infoitementity.SelectItemName = model.InfochangeForm[i].SelectItemName
  656. infoitementity.ChangeInfo = model.InfochangeForm[i].ChangeInfo
  657. infoitementity.BeChangeInfo = model.InfochangeForm[i].BeChangeInfo
  658. infoitementity.ChangeStatus = 0
  659. infoitementity.SupplierId, _ = strconv.Atoi(model.SupplierId)
  660. infoitementity.InfoId, _ = strconv.Atoi(model.MInfoId)
  661. infoitementity.CreateOn = time.Now()
  662. infoitementity.CreateBy = this.User.Realname
  663. infoitementity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  664. infoitementitys = append(infoitementitys, infoitementity)
  665. }
  666. _, err = svc.InsertEntityBytbl(""+OilInfoChangeItemName, &infoitementitys)
  667. var errinfo ErrorDataInfo
  668. if err == nil {
  669. //新增
  670. errinfo.Message = "添加成功!"
  671. errinfo.Code = 0
  672. //errinfo.Item = model.Id
  673. this.Data["json"] = &errinfo
  674. this.ServeJSON()
  675. } else {
  676. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  677. errinfo.Code = -1
  678. this.Data["json"] = &errinfo
  679. this.ServeJSON()
  680. }
  681. }
  682. // @Title 获取二级初审人员
  683. // @Description 获取二级初审人员
  684. // @router /getauditerbydept/:deptId [get]
  685. func (this *InfoChangeController) GetAuditerByDept() {
  686. Id := this.Ctx.Input.Param(":deptId")
  687. //var auditWorkflow auditsetting.Base_OilAuditSetting
  688. rsvc := auditsetting.GetOilAuditSettingService(utils.DBE)
  689. //rsvc.GetAuditStepRoleEntity(OilAuditSettingName, Id, workflow.FIRST_TRIAL, &auditWorkflow)
  690. var userlist []userRole.Base_User
  691. where := " CompanyId = " + Id
  692. rsvc.GetEntities(&userlist, where)
  693. var datainfo ErrorDataInfo
  694. datainfo.Item = userlist
  695. this.Data["json"] = &datainfo
  696. this.ServeJSON()
  697. }
  698. // @Title 获取企业法规处人员
  699. // @Description 获取企业法规处人员
  700. // @router /getauditer [get]
  701. func (this *InfoChangeController) GetAuditer() {
  702. //svc := infochange.GetInfoChangeService(utils.DBE)
  703. //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
  704. var userlist []userRole.Base_User
  705. var setting auditsetting.Base_OilAuditSetting
  706. svc := userRole.GetUserService(utils.DBE)
  707. where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
  708. svc.GetEntity(&setting, where)
  709. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  710. topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
  711. ids := svc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  712. tempstr := strings.Join(ids, ",")
  713. userIds := strings.Replace(tempstr, "uid_", "", -1)
  714. userIds = strings.Trim(userIds, ",")
  715. if userIds != "" {
  716. where := "Id in (" + userIds + ")" + "and UnitId=" + topid
  717. svc.GetEntities(&userlist, where)
  718. }
  719. //var users []userRole.Base_RoleList
  720. //certSrv.GetAuditUser("100000178", workflow.PROF_REGULATION, &users)
  721. //var users []suppliercert.UserList
  722. // where := "OrganizeId=100000178 and AuditStepCode='" + workflow.PROF_REGULATION + "'"
  723. //svc.GetEntitysByWhere(OilAuditSettingName, where, &users)
  724. var datainfo ErrorDataInfo
  725. datainfo.Item = userlist
  726. this.Data["json"] = &datainfo
  727. this.ServeJSON()
  728. }
  729. // @Title 添加
  730. // @Description 新增信息变更
  731. // @Success 200 {object} controllers.Request
  732. // @router /addinfomain [post]
  733. func (this *InfoChangeController) AddInfoMain() {
  734. SupplierId := this.GetString("SupplierId")
  735. Remark := this.GetString("Remark")
  736. var infochmain infochange.OilInfoChange
  737. var infochm []infochange.OilInfoChange
  738. var suppliermodel supplier.OilSupplier
  739. var errinfo ErrorDataInfo
  740. svc := infochange.GetInfoChangeService(utils.DBE)
  741. where := " SupplierId = " + SupplierId + " and Status < 4"
  742. svc.GetEntitysByWhere(OilInfoChangeName, where, &infochm)
  743. if len(infochm) > 0 {
  744. errinfo.Message = "有已提交在申请中的信息变更,请审批完成后再提交!"
  745. errinfo.Code = -1
  746. this.Data["json"] = &errinfo
  747. this.ServeJSON()
  748. return
  749. }
  750. svc.GetEntityById(SupplierId, &suppliermodel)
  751. infochmain.Status = "0"
  752. infochmain.SupplierName = suppliermodel.SupplierName
  753. infochmain.OldSupplierName = suppliermodel.SupplierName
  754. infochmain.PACNumber = suppliermodel.PACNumber
  755. infochmain.SupplierCertificate = suppliermodel.SupplierCertificate
  756. infochmain.MgrUnit = suppliermodel.MgrUnit
  757. infochmain.OilCertificateNo = suppliermodel.OilCertificateNo
  758. infochmain.OperType = suppliermodel.OperType
  759. infochmain.Country = suppliermodel.Country
  760. infochmain.MaunAgent = suppliermodel.MaunAgent
  761. infochmain.CommercialNo = suppliermodel.CommercialNo
  762. infochmain.OrganCode = suppliermodel.OrganCode
  763. infochmain.SupplierId, _ = strconv.Atoi(SupplierId)
  764. infochmain.Remark = Remark
  765. infochmain.CreateOn = time.Now()
  766. infochmain.CreateBy = this.User.Realname
  767. infochmain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  768. _, err := svc.InsertEntityBytbl(OilInfoChangeName, &infochmain)
  769. if err == nil {
  770. errinfo.Message = "添加成功!"
  771. errinfo.Code = 0
  772. errinfo.Item = infochmain.Id
  773. this.Data["json"] = &errinfo
  774. this.ServeJSON()
  775. } else {
  776. errinfo.Message = "添加失败!"
  777. errinfo.Code = -1
  778. this.Data["json"] = &errinfo
  779. this.ServeJSON()
  780. }
  781. }
  782. // @Title 获取信息变更企业名称
  783. // @Description 获取实体
  784. // @Success 200 {object}
  785. // @router /addsupplierlist [get]
  786. func (this *InfoChangeController) GetAddSupplierList() {
  787. svc := infochange.GetInfoChangeService(utils.DBE)
  788. var supplierlist []annualaudit.Suppliername
  789. where := "1=1"
  790. //企业用户必须加创建人条件
  791. if this.User.IsCompanyUser == 1 {
  792. where = where + " and a.CreateUserId = '" + this.User.Id + "'"
  793. } else {
  794. //超级管理员和有查看所有数据权限的用户不加条件
  795. svcPerm := permission.GetPermissionService(utils.DBE)
  796. isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.marketAccess.AllRecord")
  797. if !svcPerm.IsAdmin(this.User.Id) && !isauth {
  798. where = where + " and a.CreateUserId = '" + this.User.Id + "'"
  799. }
  800. }
  801. supplierlist = svc.GetSupplierList(""+OilSupplierName, where)
  802. var datainfo DataInfo
  803. datainfo.Items = supplierlist
  804. this.Data["json"] = &datainfo
  805. this.ServeJSON()
  806. }
  807. // @Title 提交审批
  808. // @Description 提交审批
  809. // @Success 200 {object} controllers.Request
  810. // @router /commitaudit/:id [post]
  811. func (this *InfoChangeController) CommitAuditEntity() {
  812. //suppId := this.Ctx.Input.Param(":id")
  813. firstAudit := this.GetString("auditer")
  814. fushenauditer := this.GetString("fushenauditer")
  815. Remark := this.GetString("Remark")
  816. InfoId := this.GetString("MInfoId")
  817. //取出审批列表
  818. svc := infochange.GetInfoChangeService(utils.DBE)
  819. var infochangeentity infochange.OilInfoChange
  820. infwhere := " Id = " + InfoId
  821. svc.GetEntity(&infochangeentity, infwhere)
  822. var errinfo ErrorDataInfo
  823. defer func() { //finally处理失败的异常
  824. if err := recover(); err != nil {
  825. errinfo.Message = "提交失败," + err.(string)
  826. errinfo.Code = -1
  827. this.Data["json"] = &errinfo
  828. this.ServeJSON()
  829. } else {
  830. //返回正确结果
  831. errinfo.Message = "审核提交成功"
  832. errinfo.Code = 0
  833. this.Data["json"] = &errinfo
  834. this.ServeJSON()
  835. }
  836. }()
  837. svcActiviti := workflow.GetActivitiService(utils.DBE)
  838. processInstanceId := ""
  839. businessKey := ""
  840. businessKey = InfoId + "-" + strconv.Itoa(infochangeentity.AuditIndex)
  841. processInstanceId = svcActiviti.StartProcess(workflow.OIL_INFO_CHANGE, businessKey, this.User.Id)
  842. var ActiComplete workflow.ActiCompleteVM
  843. ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE
  844. ActiComplete.BusinessKey = businessKey
  845. ActiComplete.UserNames = firstAudit
  846. ActiComplete.UserId = this.User.Id
  847. ActiComplete.Result = "1"
  848. ActiComplete.Remarks = Remark
  849. ActiComplete.CallbackUrl = ""
  850. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  851. if receiveVal == "true" {
  852. errinfo.Message = "提交成功!"
  853. errinfo.Code = 0
  854. this.Data["json"] = &errinfo
  855. this.ServeJSON()
  856. } else {
  857. errinfo.Message = "工作流异常,请联系管理员!"
  858. errinfo.Code = -1
  859. this.Data["json"] = &errinfo
  860. this.ServeJSON()
  861. return
  862. }
  863. //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态
  864. infochangeentity.WorkFlowId = processInstanceId
  865. infochangeentity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审
  866. infochangeentity.FirstAudit, _ = strconv.Atoi(firstAudit)
  867. infochangeentity.SecondAudit, _ = strconv.Atoi(fushenauditer)
  868. infochangeentity.AuditIndex = infochangeentity.AuditIndex + 1
  869. infochangeentity.BusinessKey = ActiComplete.BusinessKey
  870. infochangeentity.CreateOn = time.Now()
  871. infochangeentity.CreateBy = this.User.Realname
  872. infochangeentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  873. cols := []string{
  874. "Id",
  875. "WorkflowId",
  876. "Status",
  877. "Step",
  878. "FirstAudit",
  879. "SecondAudit",
  880. "AuditIndex",
  881. "BusinessKey",
  882. "CreateOn",
  883. "CreateBy",
  884. "CreateUserId",
  885. }
  886. svc.UpdateEntityByIdCols(InfoId, infochangeentity, cols)
  887. }
  888. // @Title 提交审批
  889. // @Description 提交审批
  890. // @Success 200 {object} controllers.Request
  891. // @router /audit/:id [post]
  892. func (this *InfoChangeController) AuditEntity() {
  893. suppId := this.Ctx.Input.Param(":id")
  894. firstAudit := this.GetString("auditer")
  895. Remark := this.GetString("Remark")
  896. InfoId := this.GetString("MInfoId")
  897. //取出审批列表
  898. svc := infochange.GetInfoChangeService(utils.DBE)
  899. var infoitems []infochange.OilInfoChangeItem
  900. where := " SupplierId = " + suppId
  901. svc.GetEntities(&infoitems, where)
  902. var infochangeentity infochange.OilInfoChange
  903. infwhere := " Id = " + InfoId
  904. svc.GetEntity(&infochangeentity, infwhere)
  905. var infomodel infochange.OilInfoChangeItem
  906. var errinfo ErrorDataInfo
  907. defer func() { //finally处理失败的异常
  908. if err := recover(); err != nil {
  909. errinfo.Message = "提交失败," + err.(string)
  910. errinfo.Code = -1
  911. this.Data["json"] = &errinfo
  912. this.ServeJSON()
  913. } else {
  914. //返回正确结果
  915. errinfo.Message = "审核提交成功"
  916. errinfo.Code = 0
  917. this.Data["json"] = &errinfo
  918. this.ServeJSON()
  919. }
  920. }()
  921. var items string
  922. for i := 0; i < len(infoitems); i++ {
  923. items = fmt.Sprintf("%s %s %s %s", items, infoitems[i].SelectItem, ","+infoitems[i].BeChangeInfo, ","+infoitems[i].ChangeInfo+";")
  924. }
  925. items = strings.Trim(items, ";")
  926. infowhere := " Id = " + InfoId
  927. svc.Updateentityinfo(OilInfoChangeName, items, infowhere)
  928. //修改从表infoid
  929. for i := 0; i < len(infoitems); i++ {
  930. infomodel.InfoId, _ = strconv.Atoi(InfoId)
  931. err := svc.UpdateEntityBytbl(OilInfoChangeItemName, infoitems[i].Id, &infomodel, []string{"InfoId"})
  932. fmt.Println(err)
  933. }
  934. svcActiviti := workflow.GetActivitiService(utils.DBE)
  935. processInstanceId := ""
  936. businessKey := ""
  937. if infochangeentity.WorkFlowId == "0" || len(infochangeentity.WorkFlowId) <= 0 {
  938. //启动工作流
  939. businessKey = InfoId + "-" + strconv.Itoa(infochangeentity.AuditIndex)
  940. processInstanceId = svcActiviti.StartProcess(workflow.OIL_INFO_CHANGE, businessKey, this.User.Id)
  941. }
  942. var ActiComplete workflow.ActiCompleteVM
  943. ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE
  944. ActiComplete.BusinessKey = businessKey
  945. ActiComplete.UserNames = firstAudit
  946. ActiComplete.UserId = this.User.Id
  947. ActiComplete.Result = "1"
  948. ActiComplete.Remarks = Remark
  949. ActiComplete.CallbackUrl = ""
  950. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  951. if receiveVal == "true" {
  952. errinfo.Message = "提交成功!"
  953. errinfo.Code = 0
  954. this.Data["json"] = &errinfo
  955. this.ServeJSON()
  956. } else {
  957. errinfo.Message = "工作流异常,请联系管理员!"
  958. errinfo.Code = -1
  959. this.Data["json"] = &errinfo
  960. this.ServeJSON()
  961. return
  962. }
  963. //记下workflowID(首次提交时才会记录,中间状态请忽略) 及审批状态
  964. infochangeentity.WorkFlowId = processInstanceId
  965. infochangeentity.Status = suppliercert.FIRST_TRIAL_STATUS //二级单位初审
  966. infochangeentity.AuditIndex = infochangeentity.AuditIndex + 1
  967. infochangeentity.BusinessKey = ActiComplete.BusinessKey
  968. infochangeentity.CreateOn = time.Now()
  969. infochangeentity.CreateBy = this.User.Realname
  970. infochangeentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  971. cols := []string{
  972. "Id",
  973. "WorkflowId",
  974. "Status",
  975. "Step",
  976. "FirstAudit",
  977. "AuditIndex",
  978. "BusinessKey",
  979. "CreateOn",
  980. "CreateBy",
  981. "CreateUserId",
  982. }
  983. svc.UpdateEntityByIdCols(InfoId, infochangeentity, cols)
  984. }
  985. // @Title 审批
  986. // @Description 审批
  987. // @Success 200 {object} controllers.Request
  988. // @router /infoaudit [post]
  989. func (this *InfoChangeController) InfoAudit() {
  990. svc := infochange.GetInfoChangeService(utils.DBE)
  991. var jsonblob = this.Ctx.Input.RequestBody
  992. var dataother InfoShenHeModel
  993. json.Unmarshal(jsonblob, &dataother)
  994. //取出审批列表
  995. var infoid = dataother.InfoId
  996. var infomodel infochange.OilInfoChange
  997. svc.GetEntityById(utils.ToStr(dataother.InfoId), &infomodel)
  998. var infoitems []infochange.OilInfoChangeItem
  999. where := "SupplierId = " + utils.ToStr(dataother.SuppId) +" and InfoId = " +utils.ToStr(dataother.InfoId)
  1000. svc.GetEntities(&infoitems, where)
  1001. var errinfo ErrorDataInfo
  1002. defer func() { //finally处理失败的异常
  1003. if err := recover(); err != nil {
  1004. errinfo.Message = "提交失败," + err.(string)
  1005. errinfo.Code = -1
  1006. this.Data["json"] = &errinfo
  1007. this.ServeJSON()
  1008. } else {
  1009. //返回正确结果
  1010. errinfo.Message = "审核提交成功"
  1011. errinfo.Code = 0
  1012. this.Data["json"] = &errinfo
  1013. this.ServeJSON()
  1014. }
  1015. }()
  1016. //审核状态判断进行的操作
  1017. step := 2
  1018. status := ""
  1019. backstatus := "0"
  1020. var userIds string
  1021. if infomodel.Status == suppliercert.FIRST_TRIAL_STATUS {
  1022. userIds = utils.ToStr(infomodel.SecondAudit)
  1023. status = suppliercert.SECOND_TRIAL_STATUS
  1024. step = 2
  1025. backstatus = suppliercert.NOPASS_STATUS
  1026. } else if infomodel.Status == suppliercert.SECOND_TRIAL_STATUS {
  1027. status = suppliercert.CENT_AUDIT_STATUS
  1028. backstatus = suppliercert.NO_SECOND_TRIAL_STATUS
  1029. step = 2
  1030. //dictSvc := items.GetItemsService(utils.DBE)
  1031. //deptIds := dictSvc.GetKeyValueItems("CENT_AUDIT")
  1032. //var users []userRole.Base_RoleList
  1033. //certSrv := suppliercert.GetOilSupplierCertService(utils.DBE)
  1034. //for _, dept := range deptIds {
  1035. // certSrv.GetAuditUser(dept.Value, workflow.PROF_REGULATION, &users)
  1036. // for _, tmpUser := range users {
  1037. // userIds += strconv.FormatInt(tmpUser.Id, 10) + ","
  1038. // }
  1039. //}
  1040. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  1041. topid := paramSvc.GetBaseparameterMessage("", "paramset", "CENT_AUDIT")
  1042. var userlist []userRole.Base_User
  1043. var setting auditsetting.Base_OilAuditSetting
  1044. usvc := userRole.GetUserService(utils.DBE)
  1045. where := "AuditStepCode='" + workflow.PROF_REGULATION + "'"
  1046. svc.GetEntity(&setting, where)
  1047. ids := usvc.GetUserIdsByRoleId(strconv.Itoa(setting.RoleId))
  1048. tempstr := strings.Join(ids, ",")
  1049. uids := strings.Replace(tempstr, "uid_", "", -1)
  1050. uids = strings.Trim(uids, ",")
  1051. if uids != "" {
  1052. where := "Id in (" + uids + ")" + " and UnitId=" + topid
  1053. svc.GetEntities(&userlist, where)
  1054. }
  1055. for _, tmpUser := range userlist {
  1056. userIds += strconv.Itoa(tmpUser.Id) + ","
  1057. }
  1058. userIds = strings.Trim(userIds, ",")
  1059. } else if infomodel.Status == suppliercert.CENT_AUDIT_STATUS {
  1060. status = suppliercert.ALL_PASE_STATUS
  1061. step = 3
  1062. backstatus = suppliercert.NO_THIRD_TRIAL_STATUS
  1063. }
  1064. svcActiviti := workflow.GetActivitiService(utils.DBE)
  1065. var ActiComplete workflow.ActiCompleteVM
  1066. ActiComplete.ProcessKey = workflow.OIL_INFO_CHANGE
  1067. ActiComplete.BusinessKey = infomodel.BusinessKey
  1068. ActiComplete.UserNames = userIds
  1069. ActiComplete.UserId = this.User.Id
  1070. ActiComplete.Remarks = dataother.AuditorRemark
  1071. ActiComplete.CallbackUrl = ""
  1072. var myerr error
  1073. if dataother.SuccessStatus == 1 {
  1074. ActiComplete.Result = "1"
  1075. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  1076. if infomodel.Status == suppliercert.CENT_AUDIT_STATUS {
  1077. //信息更新
  1078. var infochangeitemmodel infochange.OilInfoChangeItem
  1079. var supmodel supplier.OilSupplier
  1080. infochangeitemmodel.ChangeStatus = 1
  1081. infomodel.Status = status
  1082. itemswhere := "InfoId = " + utils.ToStr(infoid)
  1083. myerr = svc.UpdateEntityBywheretbl(OilInfoChangeItemName, &infochangeitemmodel, []string{"ChangeStatus"}, itemswhere)
  1084. myerr = this.updatesupplier(OilSupplierName, dataother.SuppId, infoitems, supmodel)
  1085. //资质更新
  1086. where := "SupplierId = " + utils.ToStr(dataother.SuppId) + " and SupType = 2"
  1087. var supfilemodel supplierfile.OilSupplierFile
  1088. supfilemodel.SupType = 3
  1089. svc.UpdateEntityBywheretbl(OilSupplierFileName, &supfilemodel, []string{"SupType"}, where)
  1090. //var qualdetail []qualchange.OilQualChangeDetail
  1091. //svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"SupType"})
  1092. //where := "SupplierId = " + utils.ToStr(dataother.SuppId)
  1093. //svc.GetEntities(&qualdetail, where)
  1094. //if len(qualdetail) > 0 {
  1095. // for i := 0; i < len(qualdetail); i++ {
  1096. // var supfilemodel supplierfile.OilSupplierFile
  1097. // supfilemodel.FileName = qualdetail[i].FileName
  1098. // supfilemodel.FileUrl = qualdetail[i].FileUrl
  1099. // supfilemodel.EffectDate = qualdetail[i].EffectDate
  1100. // supfilemodel.SupType = 3
  1101. // svc.UpdateEntityBytbl(OilSupplierFileName, qualdetail[i].FileId, &supfilemodel, []string{"FileName", "FileUrl", "EffectDate","SupType"})
  1102. // }
  1103. //}
  1104. }
  1105. infomodel.Status = status
  1106. infomodel.Step = step
  1107. if receiveVal == "true" {
  1108. cols := []string{
  1109. "Id",
  1110. "Status",
  1111. "Step",
  1112. }
  1113. _, myerr = svc.UpdateEntityByIdCols(infoid, infomodel, cols)
  1114. if myerr == nil {
  1115. errinfo.Message = "提交成功!"
  1116. errinfo.Code = 0
  1117. this.Data["json"] = &errinfo
  1118. this.ServeJSON()
  1119. } else {
  1120. errinfo.Message = "提交失败!"
  1121. errinfo.Code = -1
  1122. this.Data["json"] = &errinfo
  1123. this.ServeJSON()
  1124. }
  1125. } else {
  1126. errinfo.Message = "工作流异常,请联系管理员!"
  1127. errinfo.Code = -1
  1128. this.Data["json"] = &errinfo
  1129. this.ServeJSON()
  1130. return
  1131. }
  1132. } else {
  1133. ActiComplete.Result = "0"
  1134. receiveVal := svcActiviti.TaskComplete(ActiComplete)
  1135. if receiveVal == "true" {
  1136. if infomodel.Status == suppliercert.CENT_AUDIT_STATUS {
  1137. infomodel.Status = backstatus
  1138. } else {
  1139. infomodel.Status = backstatus
  1140. // 审批历史
  1141. var audithistoryentity audithistory.Base_AuditHistory
  1142. audithistoryentity.EntityId = infoid
  1143. audithistoryentity.WorkflowId = infomodel.WorkFlowId
  1144. audithistoryentity.Process = ActiComplete.ProcessKey
  1145. audithistoryentity.BusinessKey = ActiComplete.BusinessKey
  1146. audithistoryentity.Type = "04"
  1147. audithistoryentity.BackStep = infomodel.Status
  1148. audithistoryentity.Index = infomodel.AuditIndex
  1149. audithistoryentity.CreateOn = time.Now()
  1150. audithistoryentity.CreateBy = this.User.Realname
  1151. audithistoryentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1152. _, myerr = svc.InsertEntity(audithistoryentity)
  1153. infomodel.WorkFlowId = ""
  1154. }
  1155. infomodel.Step = 1
  1156. cols := []string{
  1157. "Status",
  1158. "Step",
  1159. }
  1160. _, myerr := svc.UpdateEntityByIdCols(infoid, infomodel, cols)
  1161. if myerr == nil {
  1162. errinfo.Message = "提交成功!"
  1163. errinfo.Code = 0
  1164. this.Data["json"] = &errinfo
  1165. this.ServeJSON()
  1166. } else {
  1167. errinfo.Message = "提交失败!"
  1168. errinfo.Code = -1
  1169. this.Data["json"] = &errinfo
  1170. this.ServeJSON()
  1171. }
  1172. } else {
  1173. errinfo.Message = "工作流异常,请联系管理员!"
  1174. errinfo.Code = -1
  1175. this.Data["json"] = &errinfo
  1176. this.ServeJSON()
  1177. return
  1178. }
  1179. }
  1180. }
  1181. //更新供方信息表
  1182. func (this *InfoChangeController) updatesupplier(supname string, suppid int, infoitems []infochange.OilInfoChangeItem, supmodel supplier.OilSupplier) error {
  1183. svc := infochange.GetInfoChangeService(utils.DBE)
  1184. var err error
  1185. if len(infoitems) > 0 {
  1186. for i := 0; i < len(infoitems); i++ {
  1187. //var cols []string
  1188. //cols = append(cols, infoitems[i].SelectItem)
  1189. where := " Id = " + utils.ToStr(suppid)
  1190. var sql string
  1191. sql = `UPDATE ` + supname + ` set ` + infoitems[i].SelectItem + ` = ` + infoitems[i].ChangeInfo + ` where ` + where
  1192. _, err = svc.DBE.Exec(sql)
  1193. //err = svc.UpdateEntityBytbl(OilSupplierName, suppid, &supmodel, cols)
  1194. }
  1195. }
  1196. return err
  1197. }