2
3

tmpzcgfSession.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. package tmpzcgf
  2. import (
  3. . "dashoo.cn/backend/api/mydb"
  4. "github.com/go-xorm/xorm"
  5. "math"
  6. "strconv"
  7. )
  8. /** type TmpzcgtSession struct {
  9. MySessionBase
  10. }
  11. func GetTmpzcgtService(session *xorm.Session) *TmpzcgtSession {
  12. s := new(TmpzcgtSession)
  13. s.Session = session
  14. return s
  15. } */
  16. type TmpzcgtSession struct {
  17. MyServiceBase
  18. }
  19. func GetTmpzcgtService(xormEngine *xorm.Engine) *TmpzcgtSession {
  20. s := new(TmpzcgtSession)
  21. s.DBE = xormEngine
  22. return s
  23. }
  24. func (s *TmpzcgtSession) InsertSupplier() error {
  25. sql := `INSERT INTO OilSupplier (
  26. SupplierName,
  27. Grade,
  28. OperType,
  29. Country,
  30. MaunAgent,
  31. ConstructTeam,
  32. CommercialNo,
  33. OrganCode,
  34. CountryTaxNo,
  35. LocalTaxNo,
  36. Address,
  37. ZipCode,
  38. QualitySystemCert,
  39. ProductQualityCert,
  40. MaunLicense,
  41. QualifCert,
  42. QualifCertLevel,
  43. SafetyLicense,
  44. TechServiceLic,
  45. TJInNotify,
  46. SpecIndustryCert,
  47. LegalPerson,
  48. CategoryCode,
  49. CategoryName,
  50. RegCapital,
  51. Currency,
  52. ContactName,
  53. CompanyType,
  54. DepositBank,
  55. BankAccount,
  56. EMail,
  57. BankCreditRating,
  58. Mobile,
  59. Telphone,
  60. Fax,
  61. CompanyTel,
  62. QQ,
  63. CompanyUrl,
  64. Remark,
  65. CreateBy
  66. ) SELECT
  67. 企业名称 AS SupplierName,
  68. 级别 AS Grade,
  69. 经营方式 AS OperType,
  70. 国家 AS Country,
  71. 所代理制造商名称 AS MaunAgent,
  72. 施工队伍名称 AS ConstructTeam,
  73. TRIM(工商注册号) AS CommercialNo,
  74. 组织机构代码 AS OrganCode,
  75. 税务登记证国税编号 AS CountryTaxNo,
  76. 税务登记证地税编号 AS LocalTaxNo,
  77. 单位地址 AS Address,
  78. 邮编 AS ZipCode,
  79. 质量管理体系认证情况及认证机构 AS QualitySystemCert,
  80. 产品质量认证情况及认证机构 AS ProductQualityCert,
  81. 生产制造许可证获证情况及编号 AS MaunLicense,
  82. 企业资质证书编号 AS QualifCert,
  83. 企业资质证书级别 AS QualifCertLevel,
  84. 安全生产许可证 AS SafetyLicense,
  85. 技术服务类准入许可证 AS TechServiceLic,
  86. 外地企业进津备案通知书 AS TJInNotify,
  87. 行业特殊要求的认证证书 AS SpecIndustryCert,
  88. 法定代表人姓名 AS LegalPerson,
  89. 行业类别代码 AS CategoryCode,
  90. 行业类别名称 AS CategoryName,
  91. 注册资本 AS RegCapital,
  92. 币种 AS Currency,
  93. 联系人姓名 AS ContactName,
  94. 公司类型 AS CompanyType,
  95. 开户银行 AS DepositBank,
  96. 银行账号 AS BankAccount,
  97. 电子邮箱 AS EMail,
  98. 银行信用等级 AS BankCreditRating,
  99. 移动电话 AS Mobile,
  100. 固定电话 AS Telphone,
  101. 传真 AS Fax,
  102. 公司电话 AS CompanyTel,
  103. QQ号码 AS QQ,
  104. 公司网址 AS CompanyUrl,
  105. 备注 AS Remark,
  106. '导入' As CreateBy
  107. FROM
  108. tmp_zcgf WHERE ID IN (SELECT MAX(ID) FROM tmp_zcgf WHERE 准入标识 != '取消' GROUP BY 企业名称);`
  109. _, err := s.DBE.Query(sql)
  110. return err
  111. }
  112. func (s *TmpzcgtSession) InsertSupplierCert() error {
  113. sql := "INSERT INTO OilSupplierCert (SupplierId,OutsideFlog, `Status` , Step, WorkerTotal, AccessCardNo,SupplierTypeName,InFlag,EffectStartTime,EffectEndTime,ApplyTime,Remark,CreateBy,GfID) " +
  114. "SELECT -1 As SupplierId,企业名称 AS OutsideFlog,'8' As `Status`, 3 as Step, 1 as WorkerTotal, 准入证号 As AccessCardNo,准入类别 AS SupplierTypeName,准入标识 AS InFlag,有效期起 AS EffectStartTime,有效期止 AS EffectEndTime,年审日期 AS ApplyTime,备注 AS Remark,'导入' As CreateBy,ID " +
  115. "FROM tmp_zcgf WHERE 准入标识 != '取消' ;"
  116. _, err := s.DBE.Query(sql)
  117. return err
  118. }
  119. func (s *TmpzcgtSession) UpdateSupplierCert() error {
  120. sql := "UPDATE `OilSupplierCert` b SET b.SupplierId=IFNULL((SELECT a.Id FROM OilSupplier a WHERE a.SupplierName = b.OutsideFlog AND a.Id IS NOT NULL limit 1), 0)"
  121. _, err := s.DBE.Query(sql)
  122. return err
  123. }
  124. func (s *TmpzcgtSession) UpdateSupplierTypeCodeAndInFlag() error {
  125. sql1 := "update `OilSupplierCert` set SupplierTypeCode = '01' where SupplierTypeName='物资类'"
  126. _, err := s.DBE.Query(sql1)
  127. if err != nil {
  128. return err
  129. }
  130. sql2 := "UPDATE `OilSupplierCert` SET SupplierTypeCode = '02' WHERE SupplierTypeName='基建类'"
  131. _, err = s.DBE.Query(sql2)
  132. if err != nil {
  133. return err
  134. }
  135. sql3 := "UPDATE `OilSupplierCert` SET SupplierTypeCode = '03' WHERE SupplierTypeName='服务类'"
  136. _, err = s.DBE.Query(sql3)
  137. if err != nil {
  138. return err
  139. }
  140. sql31 := "UPDATE `OilSupplierCert` SET SupplierTypeCode = '03' WHERE SupplierTypeName='技术服务类'"
  141. _, err = s.DBE.Query(sql31)
  142. if err != nil {
  143. return err
  144. }
  145. sql4 := "UPDATE `OilSupplierCert` SET InFlag = '1' WHERE InFlag='准入'"
  146. _, err = s.DBE.Query(sql4)
  147. if err != nil {
  148. return err
  149. }
  150. sql5 := "UPDATE `OilSupplierCert` SET InFlag = '2' WHERE InFlag='暂停'"
  151. _, err = s.DBE.Query(sql5)
  152. if err != nil {
  153. return err
  154. }
  155. sql6 := "UPDATE `OilSupplierCert` SET InFlag = '3' WHERE InFlag='取消'"
  156. _, err = s.DBE.Query(sql6)
  157. return err
  158. }
  159. func (s *TmpzcgtSession) InsterAnnual() error {
  160. sql := "INSERT INTO OilAnnualAudit (Status,SupplierTypeName, SupplierName, CreateOn, CreateBy, RecUnitId, ApplyTime, AccessCardNo, OldId) " +
  161. "SELECT '11' as Status ,(CASE 准入类别 WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' END ) SupplierTypeName, " +
  162. "企业名称 AS SupplierName, 申请日期 AS CreateOn, 录入员 AS CreateBy, 推荐单位编码 AS RecUnitId, 年审日期 AS ApplyTime, 准入证号 AS AccessCardNo, id AS oldId " +
  163. "FROM tmp_nianshen"
  164. _, err := s.DBE.Query(sql)
  165. return err
  166. }
  167. func (s *TmpzcgtSession) InsertOilPaymentInfo() error {
  168. sql := "INSERT INTO `OilPaymentInfo` ( " +
  169. "ID_GF," +
  170. "SupplierName," +
  171. "PayDate," +
  172. "Amount," +
  173. "IsPay," +
  174. " PayType," +
  175. "Remark," +
  176. "PayMode," +
  177. "CreateBy" +
  178. ")" +
  179. "SELECT ID_GF, 企业名称 AS SupplierName ,交费日期 AS PayDate, 新准入 AS Amount, '2' AS IsPay,'1' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 新准入 IS NOT NULL" +
  180. " UNION" +
  181. " SELECT ID_GF, 企业名称 AS SupplierName ,交费日期 AS PayDate, 换证 AS Amount , '2' AS IsPay, '4' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 换证 IS NOT NULL" +
  182. " UNION" +
  183. " SELECT ID_GF, 企业名称 AS SupplierName ,交费日期 AS PayDate, 增项 AS Amount , '2' AS IsPay, '3' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 增项 IS NOT NULL" +
  184. " UNION" +
  185. " SELECT ID_GF, 企业名称 AS SupplierName,交费日期 AS PayDate, 年审 AS Amount , '2' AS IsPay, '2' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 年审 IS NOT NULL" +
  186. " UNION" +
  187. " SELECT ID_GF, 企业名称 AS SupplierName,交费日期 AS PayDate, 罚款 AS Amount , '2' AS IsPay, '5' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 罚款 IS NOT NULL" +
  188. " UNION" +
  189. " SELECT ID_GF, 企业名称 AS SupplierName,交费日期 AS PayDate, 其它 AS Amount , '2' AS IsPay, '6' AS PayType , 备注 AS Remark, 交款方式 AS PayMode,收款人 AS CreateBy FROM tmp_jiaofenjl WHERE 其它 IS NOT NULL"
  190. _, err := s.DBE.Query(sql)
  191. return err
  192. }
  193. func (s *TmpzcgtSession) UpdateOilPaymentInfo() error {
  194. // sql := "UPDATE OilPaymentInfo b SET b.SupplierId= (SELECT DISTINCT(a.SupplierId) FROM `OilSupplierCert` a WHERE a.GfId = b.ID_GF )"
  195. sql := "UPDATE OilPaymentInfo b left join `OilSupplierCert` a ON b.ID_GF=a.GfId SET b.SupplierId=a.SupplierId"
  196. _, err := s.DBE.Query(sql)
  197. return err
  198. }
  199. func (s *TmpzcgtSession) InsterBadRecord() error {
  200. sql := "INSERT INTO BadRecord (" +
  201. "Bak1," +
  202. "CreateOn, " +
  203. "Record," +
  204. "CompanyName, " +
  205. "CompanyCode, " +
  206. "CategoryName, " +
  207. "CategoryCode " +
  208. ") " +
  209. "SELECT " +
  210. "gfid AS Bak1 , " +
  211. "日期 AS CreateOn, " +
  212. "内容 AS Record, " +
  213. "'' AS CompanyName, " +
  214. "'' AS CompanyCode, " +
  215. "'' AS CategoryName, " +
  216. "'' AS CategoryCode " +
  217. "FROM tmp_buliangjl WHERE 内容 IS NOT NULL"
  218. _, err := s.DBE.Query(sql)
  219. return err
  220. }
  221. func (s *TmpzcgtSession) UpdateBadRecord() error {
  222. /** sql := "UPDATE BadRecord b SET " +
  223. "b.CompanyCode = (SELECT DISTINCT(a.SupplierId) FROM `OilSupplierCert` a WHERE a.GfId = b.Bak1 AND a.SupplierId IS NOT NULL)," +
  224. "b.CompanyName = (SELECT DISTINCT(a.OutsideFlog) FROM `OilSupplierCert` a WHERE a.GfId = b.Bak1 AND a.OutsideFlog IS NOT NULL) " */
  225. sql := "UPDATE BadRecord b left join `OilSupplierCert` a ON a.GfId = b.Bak1 SET " +
  226. "b.CompanyCode = a.SupplierId," +
  227. "b.CompanyName = a.OutsideFlog " +
  228. " where a.OutsideFlog IS NOT NULL and a.SupplierId IS NOT NULL"
  229. _, err := s.DBE.Query(sql)
  230. return err
  231. }
  232. func (s *TmpzcgtSession) UpdateOilAnnualAudit() error {
  233. /** sql := "UPDATE OilAnnualAudit b SET b.SupplierId = (SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeName )," +
  234. "b.CerId = (SELECT a.Id FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeName )," +
  235. "b.AccessCardNo = (SELECT a.AccessCardNo FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeName )" */
  236. sql := "UPDATE OilAnnualAudit b left join OilSupplierCert a ON (a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeName) SET b.SupplierId = a.SupplierId," +
  237. "b.CerId = a.Id," +
  238. "b.AccessCardNo = a.AccessCardNo"
  239. _, err := s.DBE.Query(sql)
  240. return err
  241. }
  242. func (s *TmpzcgtSession) InsertCertSub() error {
  243. //countSql := "SELECT count(*) FROM tmp_zcgf t " +
  244. // "CROSS JOIN mysql.help_topic b " +
  245. // "ON b.help_topic_id < (LENGTH(t.`准入范围`) - LENGTH(REPLACE(t.`准入范围`, ';', '')) + 1) " +
  246. // "WHERE " +
  247. // "1=1 and 准入标识 != '取消' " +
  248. // "AND LENGTH( SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1) ) > 0 "
  249. //countStr, err := s.DBE.Query(countSql)
  250. ////var total int64
  251. //if len(countStr) > 0 {
  252. // results := countStr[0]
  253. // for _, value := range results {
  254. // total, err = strconv.ParseInt(string(value), 10, 64)
  255. // break
  256. // }
  257. //n := math.Ceil(float64(total) / 2000)
  258. //for i:=0; i <= int(n); i++ {
  259. // start := strconv.Itoa(i * 2000)
  260. // end := strconv.Itoa(2000)
  261. sql := "INSERT `OilSupplierCertSub` (" +
  262. "OldId," +
  263. "AppendStatus," +
  264. "`Type`," +
  265. "CreateBy," +
  266. "Remark," +
  267. "SupplierTypeCode," +
  268. "`Code`," +
  269. "`Name`" +
  270. ") SELECT " +
  271. "t.`ID` AS OldId , '1' AS AppendStatus, '1' AS `Type`, '导入1' AS CreateBy, t.企业名称 As Remark, " +
  272. "(CASE t.`准入类别` WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' END) AS SupplierTypeCode," +
  273. "REPLACE(SUBSTRING_INDEX (SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,1),'BM','') AS `code`, " +
  274. "SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,-1)AS `name` " +
  275. "FROM tmp_zcgf t " +
  276. "CROSS JOIN mysql.help_topic b " +
  277. "ON b.help_topic_id < (LENGTH(t.`准入范围`) - LENGTH(REPLACE(t.`准入范围`, ';', '')) + 1) " +
  278. "WHERE " +
  279. "1=1 and 准入标识 != '取消' " +
  280. "AND LENGTH( SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1) ) > 0 "
  281. //"ORDER BY t.ID, SupplierTypeCode, `code` " +
  282. //"limit " + start + "," + end
  283. _, err := s.DBE.Query(sql)
  284. //}
  285. //}
  286. return err
  287. }
  288. func (s *TmpzcgtSession) UpdateCertSub() error {
  289. /*sql := "UPDATE OilSupplierCertSub b SET b.SupplierId = IFNULL((SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode AND a.SupplierId IS NOT NULL limit 1 ), 0)," +
  290. "b.SupplierCertId = IFNULL((SELECT a.Id FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode limit 1), 0) " +
  291. " where b.Type = '1' and b.CreateBy='导入1'"*/
  292. sql := "UPDATE OilSupplierCertSub b left join OilSupplierCert a on (a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode) SET b.SupplierId = IFNULL(a.SupplierId, 0)," +
  293. "b.SupplierCertId = IFNULL(a.Id, 0) " +
  294. " where b.Type = '1' and b.CreateBy='导入1' AND a.SupplierId IS NOT NULL"
  295. _, err := s.DBE.Query(sql)
  296. return err
  297. }
  298. func (s *TmpzcgtSession) UpdateCertSub01classId(where string) error {
  299. sql1 := "UPDATE OilSupplierCertSub left join OilGoodsAptitudeClass a ON a.Code = b.Code b SET b.SubClassId = a.Id " +
  300. "WHERE b.SupplierTypeCode = '01'" + where
  301. _, err := s.DBE.Query(sql1)
  302. return err
  303. }
  304. func (s *TmpzcgtSession) UpdateCertSub02classId(where string) error {
  305. sql2 := "UPDATE OilSupplierCertSub b left join OilBasisBuild a ON a.Code = b.Code SET b.SubClassId = a.Id " +
  306. "WHERE b.SupplierTypeCode = '02'" + where
  307. _, err := s.DBE.Query(sql2)
  308. return err
  309. }
  310. func (s *TmpzcgtSession) UpdateCertSub03classId(where string) error {
  311. /** sql3 := "UPDATE OilSupplierCertSub b SET b.SubClassId = (SELECT a.Id FROM OilBasisBuild a WHERE a.Code = b.Code ) " +
  312. "WHERE b.SupplierTypeCode = '03'" + where */
  313. sql3 := "UPDATE OilSupplierCertSub b left join OilBasisBuild a ON a.Code = b.Code SET b.SubClassId = a.Id " +
  314. "WHERE b.SupplierTypeCode = '03'" + where
  315. _, err := s.DBE.Query(sql3)
  316. return err
  317. }
  318. func (s *TmpzcgtSession) InsertOilSupplierCertAppend() error {
  319. //sql := " INSERT INTO OilSupplierCertAppend (OldId,CreateOn,AppendType,SupplierName,CreateBy,RecUnitId,ApplyDate) " +
  320. //"select Max(id) as OldId,申请日期 as CreateOn, (case 准入类别 when '物资类' then '01' when '基建类' then '02' when '服务类' then '03' WHEN '技术服务类' THEN '03' end) AppendType, "+
  321. // "企业名称 as SupplierName, 录入员 as CreateBy, 推荐单位编码 as RecUnitId, 申请日期 as ApplyDate "+
  322. // "from tmp_zengxiang "+
  323. // "group by id,申请日期,企业名称,录入员,推荐单位编码,申请日期,准入类别"
  324. countSql := "SELECT count(*) from (select a.申请日期 from tmp_zengxiang a WHERE 企业名称 != '' GROUP BY a.`申请日期`, a.`企业名称`, a.`准入类别`) b"
  325. countStr, err := s.DBE.Query(countSql)
  326. var total int64
  327. if len(countStr) > 0 {
  328. results := countStr[0]
  329. for _, value := range results {
  330. total, err = strconv.ParseInt(string(value), 10, 64)
  331. break
  332. }
  333. n := math.Ceil(float64(total) / 2000)
  334. for i:=0; i <= int(n); i++ {
  335. start := strconv.Itoa(i * 2000)
  336. end := strconv.Itoa(2000)
  337. sql := "INSERT INTO OilSupplierCertAppend " +
  338. "(Status,CreateOn,SupplierName,AppendType,CreateBy,ApplyDate,OldId) " +
  339. "SELECT '11' as Status, a.`申请日期` AS CreateOn, a.`企业名称` AS SupplierName, (CASE 准入类别 WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' END) AppendType, " +
  340. "'导入' AS CreateBy,a.`申请日期` AS ApplyDate, MAX(a.id) AS OldId " +
  341. "FROM tmp_zengxiang a WHERE 企业名称 != '' GROUP BY a.`申请日期`, a.`企业名称`, a.`准入类别` ORDER BY a.`申请日期`, a.`准入类别`, a.`准入类别` " +
  342. "limit " + start + "," + end
  343. _, err = s.DBE.Query(sql)
  344. }
  345. }
  346. return err
  347. }
  348. func (s *TmpzcgtSession) InsertOilInfoChange() error {
  349. sql := "INSERT INTO OilInfoChange (Status,AccessCardNo,SupplierName,OldSupplierName,SupplierTypeName,SupplierTypeCode,OilCertificateNo,Grade,OperType,Country,MaunAgent,ConstructTeam,CommercialNo,OrganCode,CountryTaxNo,LocalTaxNo, " +
  350. "Address,ZipCode,QualitySystemCert,ProductQualityCert,MaunLicense,QualifCert,QualifCertLevel,SafetyLicense,TechServiceLic,TJInNotify, " +
  351. "SpecIndustryCert,LegalPerson,CategoryCode,CategoryName,RegCapital,Currency,ContactName,CompanyType,DepositBank,BankAccount,EMail, " +
  352. "BankCreditRating,Mobile,Telphone,Fax,CompanyTel,QQ,CompanyUrl,Remark,CreateOn,CreateBy,HouseNo) " +
  353. "select '11' as Status, 准入证号 as AccessCardNo, 企业名称 as SupplierName, 曾用名 as OldSupplierName, 准入类别 as SupplierTypeName,(case 准入类别 when '物资类' then '01' when '基建类' then '02' when '服务类' then '03' WHEN '技术服务类' THEN '03' end) SupplierTypeCode, " +
  354. "中石油供应商证书号 as OilCertificateNo, 级别 as Grade, 经营方式 as OperType, 国家 as Country, 所代理制造商名称 as MaunAgent, 施工队伍名称 as ConstructTeam, 工商注册号 as CommercialNo, 组织机构代码 as OrganCode, " +
  355. "税务登记证国税编号 as CountryTaxNo, 税务登记证地税编号 as LocalTaxNo, 单位地址 as Address, 邮编 AS ZipCode, 质量管理体系认证情况及认证机构 AS QualitySystemCert, 产品质量认证情况及认证机构 AS ProductQualityCert, " +
  356. "生产制造许可证获证情况及编号 AS MaunLicense, 企业资质证书编号 AS QualifCert, 企业资质证书级别 AS QualifCertLevel, 安全生产许可证 AS SafetyLicense, 技术服务类准入许可证 AS TechServiceLic, 外地企业进津备案通知书 AS TJInNotify, " +
  357. "行业特殊要求的认证证书 AS SpecIndustryCert, 法定代表人姓名 AS LegalPerson, 行业类别代码 AS CategoryCode, 行业类别名称 AS CategoryName, 注册资本 AS RegCapital, 币种 AS Currency, 联系人姓名 AS ContactName, 公司类型 AS CompanyType, " +
  358. "开户银行 AS DepositBank, 银行账号 AS BankAccount, 电子邮箱 AS EMail, 银行信用等级 AS BankCreditRating, 移动电话 AS Mobile, 固定电话 AS Telphone, 传真 AS Fax, 公司电话 AS CompanyTel, QQ号码 AS QQ, 公司网址 AS CompanyUrl, " +
  359. "申请变更原因及内容 AS Remark, 审核日期 as CreateOn, 录入员 as CreateBy,ID AS HouseNo from tmp_biangenxinxi "
  360. _, err := s.DBE.Query(sql)
  361. return err
  362. }
  363. func (s *TmpzcgtSession) InsertOilSupplierCertSub() error {
  364. sql := "insert into OilSupplierCertSub (ModifiedBy,Type, OldId, SupplierTypeCode, Code, Name, Remark, CreateOn, CreateBy) " +
  365. "select 企业名称 as ModifiedBy,'3' as Type, id as OldId, ( case 准入类别 when '物资类' then '01' when '基建类' then '02' when '服务类' then '03' WHEN '技术服务类' THEN '03' end ) SupplierTypeCode, 物资编码 as Code, 产品名称 as Name, 备注 as Remark, 申请日期 as CreateOn, 录入员 as CreateBy " +
  366. "ORDER BY a.`申请日期`, a.`准入类别`, a.`准入类别` " +
  367. "from tmp_zengxiang "
  368. _, err := s.DBE.Query(sql)
  369. //return err
  370. countSql := "SELECT count(*) from tmp_zengxiang"
  371. countStr, err := s.DBE.Query(countSql)
  372. var total int64
  373. if len(countStr) > 0 {
  374. results := countStr[0]
  375. for _, value := range results {
  376. total, err = strconv.ParseInt(string(value), 10, 64)
  377. break
  378. }
  379. n := math.Ceil(float64(total) / 2000)
  380. for i:=0; i <= int(n); i++ {
  381. start := strconv.Itoa(i * 2000)
  382. end := strconv.Itoa(2000)
  383. sql := "insert into OilSupplierCertSub (ModifiedBy,Type, OldId, SupplierTypeCode, Code, Name, Remark, CreateOn, CreateBy) " +
  384. "select 企业名称 as ModifiedBy,'3' as Type, id as OldId, ( case 准入类别 when '物资类' then '01' when '基建类' then '02' when '服务类' then '03' WHEN '技术服务类' THEN '03' end ) SupplierTypeCode, 物资编码 as Code, 产品名称 as Name, 备注 as Remark, 申请日期 as CreateOn, 录入员 as CreateBy " +
  385. "from tmp_zengxiang " +
  386. "limit " + start + "," + end
  387. _, err = s.DBE.Query(sql)
  388. s.UpdateCertSubIsType2()
  389. s.UpdateOilSupplierCertSub()
  390. }
  391. }
  392. return err
  393. }
  394. func (s *TmpzcgtSession) UpdateOilInfoChange() error {
  395. // sql := "UPDATE OilInfoChange b SET b.SupplierId=IFNULL((SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId = b.HouseNo limit 1), 0)"
  396. sql := "UPDATE OilInfoChange b SET b.SupplierId=IFNULL((SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId = b.HouseNo limit 1), 0)"
  397. _, err := s.DBE.Query(sql)
  398. return err
  399. }
  400. func (s *TmpzcgtSession) UpOilSupplierCertAppend() error {
  401. /** sql := "UPDATE OilSupplierCertAppend b SET " +
  402. "b.SupplierId = IFNULL((SELECT a.`SupplierId` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType limit 1), 0), " +
  403. "b.SupplierCertId = IFNULL((SELECT a.`Id` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType limit 1), 0) " */
  404. sql := "UPDATE OilSupplierCertAppend b left join OilSupplierCert a ON (a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType) SET " +
  405. "b.SupplierId = IFNULL(a.`SupplierId`, 0), " +
  406. "b.SupplierCertId = IFNULL(a.`Id`, 0) "
  407. _, err := s.DBE.Query(sql)
  408. return err
  409. }
  410. func (s *TmpzcgtSession) UpdateCertSubIsType2() error {
  411. /** sql := "UPDATE OilSupplierCertSub b SET " +
  412. "b.SupplierId = IFNULL((SELECT a.`SupplierId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0), " +
  413. "b.SupplierCertId = IFNULL((SELECT a.`SupplierCertId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0), " +
  414. "b.SupplierCertAppendId = IFNULL((SELECT a.`Id` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0) " +
  415. where */
  416. sql := "UPDATE OilSupplierCertSub b left join OilSupplierCertAppend a ON (a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn) SET " +
  417. "b.SupplierId = IFNULL(a.`SupplierId`, 0), " +
  418. "b.SupplierCertId = IFNULL(a.`SupplierCertId`, 0), " +
  419. "b.SupplierCertAppendId = IFNULL(a.`Id`, 0) " +
  420. "where b.Type = '3' and (b.SupplierId is null or b.SupplierId = 0)"
  421. _, err := s.DBE.Query(sql)
  422. return err
  423. }
  424. // 导入资质名称
  425. func (s *TmpzcgtSession) InsertFileName() error {
  426. sql := "INSERT INTO `OilSupplierFile` (SupplierId, SupplierCertSubId, Remark, NeedFileType, OtherRemark, SupplierTypeCode,CreateBy) " +
  427. "SELECT 0 AS SupplierId, 0 AS SupplierCertSubId, z.企业名称 AS Remark ,f.类别 AS NeedFileType, f.说明 AS OtherRemark, " +
  428. "( CASE 准入类别 WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' else '000' END ) SupplierTypeCode, " +
  429. "'导入' AS CreateBy " +
  430. "FROM `tmp_file` f " +
  431. "LEFT JOIN `tmp_zcgf` z ON (f.ID_GF = z.ID) " +
  432. "WHERE z.企业名称 IS NOT NULL "
  433. _, err := s.DBE.Query(sql)
  434. return err
  435. }
  436. func (s *TmpzcgtSession) UpdateSupplierFileSId() error {
  437. sql := "UPDATE `OilSupplierFile` b left join `OilSupplier` a ON (a.SupplierName = b.Remark AND a.Id IS NOT NULL) SET b.SupplierId = IFNULL(a.Id, 0) "
  438. _, err := s.DBE.Query(sql)
  439. return err
  440. }
  441. // 编码扩充开始
  442. func (s *TmpzcgtSession) UpdateOilSupplierCertSub() error {
  443. sql := "update OilSupplierCertSub certsub LEFT JOIN OilGoodsAptitudeClass aptclass ON aptclass.CODE like CONCAT(certsub.Code, '%') and LENGTH(aptclass.CODE) = 8 SET certsub.Name = aptclass.Name, certsub.Code = aptclass.Code where SupplierTypeCode='01' and LENGTH(certsub.CODE) != 8"
  444. _, err := s.DBE.Query(sql)
  445. return err
  446. }