oilsupplierService.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. package supplier
  2. import (
  3. . "dashoo.cn/backend/api/mydb"
  4. "dashoo.cn/utils"
  5. "github.com/go-xorm/xorm"
  6. "strconv"
  7. )
  8. type OilSupplierService struct {
  9. MyServiceBase
  10. }
  11. func GetOilSupplierService(xormEngine *xorm.Engine) *OilSupplierService {
  12. s := new(OilSupplierService)
  13. s.DBE = xormEngine
  14. return s
  15. }
  16. //
  17. func (s *OilSupplierService) GetMyPagingEntitiesWithOrderBytbl(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
  18. var resultsSlice []map[string][]byte
  19. //获取总记录数
  20. sqlCount := `select count(*) from ` + supplierTableName + ` a `
  21. sqlCount += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  22. sqlCount += ` where ` + where
  23. var sql string
  24. sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, b.InFlag, b.ApplyTime,b.EffectEndTime, `
  25. sql += ` b.WorkerTotal, `
  26. sql += ` b.ContractNum, `
  27. sql += ` b.UniversityNum, `
  28. sql += ` b.TechnicalNum, `
  29. sql += ` b.AboveProfNum, `
  30. sql += ` b.MiddleProfNum, `
  31. sql += ` b.NationalRegNum, `
  32. sql += ` b.NationalCertTotal, `
  33. sql += ` b.DesignerTotal, `
  34. sql += ` b.SkillerTotal, `
  35. sql += ` b.Status, `
  36. sql += ` b.WorkflowId, b.CreateOn ,b.ProcessKey,b.BusinessKey,b.BackRemark,b.IsRestrict`
  37. sql += ` from ` + supplierTableName + ` a `
  38. sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  39. sql += ` where ` + where
  40. if asc {
  41. sql += ` order by ` + orderby + ` ASC `
  42. } else {
  43. sql += ` order by ` + orderby + ` DESC `
  44. }
  45. if pageIndex != 0 && itemsPerPage !=0 {
  46. sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
  47. }
  48. s.DBE.SQL(sql).Find(entitiesPtr)
  49. resultsSlice, _ = s.DBE.Query(sqlCount)
  50. if len(resultsSlice) > 0 {
  51. results := resultsSlice[0]
  52. for _, value := range results {
  53. total, _ = strconv.ParseInt(string(value), 10, 64)
  54. break
  55. }
  56. }
  57. return total
  58. }
  59. func (s *OilSupplierService) GetMyPagingEntitiesWithOrderBytbl2(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string, code string, Ids string) (total int64) {
  60. var resultsSlice []map[string][]byte
  61. //获取总记录数
  62. sqlCount := `select count(DISTINCT b.Id) from ` + supplierTableName + ` a `
  63. sqlCount += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  64. sqlCount += ` where ` + where
  65. if code != "" {
  66. sqlCount += ` and b.Id in (` + Ids + ")"
  67. }
  68. var sql string
  69. sql = `select DISTINCT b.Id as CertId, a.*, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, b.InFlag, b.ApplyTime,b.EffectEndTime, `
  70. sql += ` b.WorkerTotal, `
  71. sql += ` b.ContractNum, `
  72. sql += ` b.UniversityNum, `
  73. sql += ` b.TechnicalNum, `
  74. sql += ` b.AboveProfNum, `
  75. sql += ` b.MiddleProfNum, `
  76. sql += ` b.NationalRegNum, `
  77. sql += ` b.NationalCertTotal, `
  78. sql += ` b.DesignerTotal, `
  79. sql += ` b.SkillerTotal, `
  80. sql += ` b.Status, `
  81. sql += ` b.WorkflowId, b.CreateOn ,b.ProcessKey,b.BusinessKey,b.BackRemark,b.IsRestrict`
  82. sql += ` from ` + supplierTableName + ` a `
  83. sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  84. sql += ` where ` + where
  85. if code != "" {
  86. sql += ` and b.Id in (` + Ids + ")"
  87. }
  88. if asc {
  89. sql += ` order by ` + orderby + ` ASC `
  90. } else {
  91. sql += ` order by ` + orderby + ` DESC `
  92. }
  93. if pageIndex != 0 && itemsPerPage !=0 {
  94. sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
  95. }
  96. s.DBE.SQL(sql).Find(entitiesPtr)
  97. resultsSlice, _ = s.DBE.Query(sqlCount)
  98. if len(resultsSlice) > 0 {
  99. results := resultsSlice[0]
  100. for _, value := range results {
  101. total, _ = strconv.ParseInt(string(value), 10, 64)
  102. break
  103. }
  104. }
  105. return total
  106. }
  107. func (s *OilSupplierService) CheckRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
  108. //获取分页信息
  109. where2 := " b.SupplierTypeCode = '" + typeCode
  110. where := ""
  111. if SupplierName != "" {
  112. where = where + " or a.SupplierName = '" + SupplierName + "'"
  113. }
  114. if CommercialNo != "" {
  115. where = where + " or a.CommercialNo = '" + CommercialNo + "'"
  116. }
  117. if OrganCode != "" {
  118. where = where + " or a.OrganCode = '" + OrganCode + "'"
  119. }
  120. if BankAccount != "" {
  121. where = where + " or a.BankAccount = '" + BankAccount + "'"
  122. }
  123. if CompanyUrl != "" {
  124. where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
  125. }
  126. if len(where) > 0 {
  127. where2 += " and (1=0 " + where + ")"
  128. var sql string
  129. sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
  130. sql += ` b.WorkerTotal, `
  131. sql += ` b.ContractNum, `
  132. sql += ` b.UniversityNum, `
  133. sql += ` b.TechnicalNum, `
  134. sql += ` b.AboveProfNum, `
  135. sql += ` b.MiddleProfNum, `
  136. sql += ` b.NationalRegNum, `
  137. sql += ` b.NationalCertTotal, `
  138. sql += ` b.DesignerTotal, `
  139. sql += ` b.SkillerTotal, `
  140. sql += ` b.Status, `
  141. sql += ` b.WorkflowId `
  142. sql += ` from ` + supplierTableName + ` a `
  143. sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  144. sql += ` where ` + where2
  145. s.DBE.SQL(sql).Find(entitiesPtr)
  146. }
  147. }
  148. func (s *OilSupplierService) CheckUpdateRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, supplierId, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
  149. //获取分页信息
  150. where2 := " a.Id != '" + supplierId + "'"
  151. where := ""
  152. if SupplierName != "" {
  153. where = where + " or a.SupplierName = '" + SupplierName + "'"
  154. }
  155. if CommercialNo != "" {
  156. where = where + " or a.CommercialNo = '" + CommercialNo + "'"
  157. }
  158. if OrganCode != "" {
  159. where = where + " or a.OrganCode = '" + OrganCode + "'"
  160. }
  161. if BankAccount != "" {
  162. where = where + " or a.BankAccount = '" + BankAccount + "'"
  163. }
  164. if CompanyUrl != "" {
  165. where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
  166. }
  167. if len(where) > 0 {
  168. where2 += " and (1=0 " + where + ")"
  169. var sql string
  170. sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
  171. sql += ` b.WorkerTotal, `
  172. sql += ` b.ContractNum, `
  173. sql += ` b.UniversityNum, `
  174. sql += ` b.TechnicalNum, `
  175. sql += ` b.AboveProfNum, `
  176. sql += ` b.MiddleProfNum, `
  177. sql += ` b.NationalRegNum, `
  178. sql += ` b.NationalCertTotal, `
  179. sql += ` b.DesignerTotal, `
  180. sql += ` b.SkillerTotal, `
  181. sql += ` b.Status, `
  182. sql += ` b.WorkflowId `
  183. sql += ` from ` + supplierTableName + ` a `
  184. sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  185. sql += ` where ` + where2
  186. s.DBE.SQL(sql).Find(entitiesPtr)
  187. }
  188. }
  189. func (s *OilSupplierService) CanUpdateSupplier(oilSupplierCertTableName string, supplierId int) (bool){
  190. session := s.DBE.NewSession()
  191. sessionSvc := GetOilSupplierSession(session)
  192. defer session.Close()
  193. session.Begin()
  194. result := sessionSvc.CanUpdateSupplier(oilSupplierCertTableName, supplierId)
  195. session.Commit()
  196. return result
  197. }
  198. func (s *OilSupplierService) GetUpdateCols(oilSupplierCertTableName string, supplierTypeCode string, supplierId int) ([]string){
  199. session := s.DBE.NewSession()
  200. sessionSvc := GetOilSupplierSession(session)
  201. defer session.Close()
  202. session.Begin()
  203. cols := sessionSvc.GetUpdateCols(oilSupplierCertTableName, supplierTypeCode, supplierId)
  204. session.Commit()
  205. return cols
  206. }
  207. func (s *OilSupplierService) GetProOrTreeList(ids string, entitiesPtr interface{}){
  208. where := " Id in ("+ids+")"
  209. sql := "SELECT Id, FullName, ParentId FROM Base_Organize where " + where
  210. s.DBE.SQL(sql).Find(entitiesPtr)
  211. return
  212. }
  213. func (s *OilSupplierService) GetMyTodoEntitie(supplierTableName, supplierCertTableName string, entitiesPtr interface{}, where string) bool {
  214. var sql string
  215. sql = `select a.Id, a.SupplierName, b.Id as CertId, b.SupplierTypeCode, '1' as Type, b.Status `
  216. sql += ` from ` + supplierTableName + ` a `
  217. sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  218. sql += ` where ` + where
  219. has,_ := s.DBE.SQL(sql).Get(entitiesPtr)
  220. return has
  221. }
  222. func (s *OilSupplierService) GetExpireFile(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
  223. var sql string
  224. sql = `SELECT a.Id, a.SupplierName, a.Mobile, a.CreateBy, a.ContactName, a.CreateUserId, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
  225. sql += ` FROM ` + supplierTableName + ` a `
  226. sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
  227. sql += ` where ` + where
  228. sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
  229. err := s.DBE.SQL(sql).Find(entitiesPtr)
  230. return err
  231. }
  232. func (s *OilSupplierService) GetExpireFileList(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
  233. var sql string
  234. sql = `SELECT a.Id, a.SupplierName, a.Mobile, b.SupplierTypeCode`
  235. sql += ` FROM ` + supplierTableName + ` a `
  236. sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
  237. sql += ` where ` + where
  238. sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile, b.SupplierTypeCode `
  239. err := s.DBE.SQL(sql).Find(entitiesPtr)
  240. return err
  241. }
  242. func (s *OilSupplierService) GetInterfaceData(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
  243. var sql string
  244. sql = `SELECT a.Id, a.SupplierName, a.RegCapital, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
  245. sql += ` FROM ` + supplierTableName + ` a `
  246. sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
  247. sql += ` where ` + where
  248. sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
  249. err := s.DBE.SQL(sql).Find(entitiesPtr)
  250. return err
  251. }
  252. func (s *OilSupplierService) GetProcessInfoWithOrderBytbl(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
  253. var resultsSlice []map[string][]byte
  254. //获取总记录数
  255. sqlCount := `select count(*) from ` + supplierCertTableName + ` a `
  256. sqlCount += ` where ` + where
  257. var sql string
  258. sql = `select a.SupplierName, b.Id, b.AccessCardNo, b.CreateOn, b.ModifiedOn As AddinTime, a.Mobile, `
  259. sql += ` b.Status, b.SupplierTypeCode, `
  260. sql += ` b.WorkflowId, b.ProcessKey, '1' as Type, b.CreateOn,`
  261. sql += ` org.FullName As RecUnitName,`
  262. sql += ` u.Realname as ContactName,`
  263. sql += ` u.Telephone as Mobile`
  264. sql += ` from ` + supplierTableName + ` a `
  265. sql += ` left join ` + supplierCertTableName + ` b on b.SupplierId = a.Id`
  266. sql += ` Left join Base_User u on a.CreateUserId = u.Id `
  267. sql += ` LEFT JOIN Base_Organize org ON b.CommitComId = org.Id`
  268. sql += ` where ` + where
  269. if asc {
  270. sql += ` order by ` + orderby + ` ASC `
  271. } else {
  272. sql += ` order by ` + orderby + ` DESC `
  273. }
  274. if (pageIndex != 0 && itemsPerPage != 0) {
  275. sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
  276. }
  277. s.DBE.SQL(sql).Find(entitiesPtr)
  278. resultsSlice, _ = s.DBE.Query(sqlCount)
  279. if len(resultsSlice) > 0 {
  280. results := resultsSlice[0]
  281. for _, value := range results {
  282. total, _ = strconv.ParseInt(string(value), 10, 64)
  283. break
  284. }
  285. }
  286. return total
  287. }
  288. func (s *OilSupplierService) GetCertIds( entitiesPtr interface{}, where string) {
  289. sql := "SELECT GROUP_CONCAT(DISTINCT SupplierCertId) as Ids from OilSupplierCertSub where " + where + " ORDER BY SupplierCertId"
  290. s.DBE.SQL(sql).Get(entitiesPtr)
  291. }