2
3

oilsupplierService.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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, `
  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`
  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) CheckRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
  60. //获取分页信息
  61. where2 := " b.SupplierTypeCode = '" + typeCode + "'"
  62. where := ""
  63. if SupplierName != "" {
  64. where = where + " or a.SupplierName = '" + SupplierName + "'"
  65. }
  66. if CommercialNo != "" {
  67. where = where + " or a.CommercialNo = '" + CommercialNo + "'"
  68. }
  69. if OrganCode != "" {
  70. where = where + " or a.OrganCode = '" + OrganCode + "'"
  71. }
  72. if BankAccount != "" {
  73. where = where + " or a.BankAccount = '" + BankAccount + "'"
  74. }
  75. if CompanyUrl != "" {
  76. where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
  77. }
  78. if len(where) > 0 {
  79. where2 += " and (1=0 " + where + ")"
  80. var sql string
  81. sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
  82. sql += ` b.WorkerTotal, `
  83. sql += ` b.ContractNum, `
  84. sql += ` b.UniversityNum, `
  85. sql += ` b.TechnicalNum, `
  86. sql += ` b.AboveProfNum, `
  87. sql += ` b.MiddleProfNum, `
  88. sql += ` b.NationalRegNum, `
  89. sql += ` b.NationalCertTotal, `
  90. sql += ` b.DesignerTotal, `
  91. sql += ` b.SkillerTotal, `
  92. sql += ` b.Status, `
  93. sql += ` b.WorkflowId `
  94. sql += ` from ` + supplierTableName + ` a `
  95. sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  96. sql += ` where ` + where2
  97. s.DBE.SQL(sql).Find(entitiesPtr)
  98. }
  99. }
  100. func (s *OilSupplierService) CheckUpdateRepeatApplyInfo(supplierTableName, supplierCertTableName, typeCode, supplierId, SupplierName, CommercialNo, OrganCode, BankAccount, CompanyUrl string, entitiesPtr interface{}) {
  101. //获取分页信息
  102. where2 := " a.Id != '" + supplierId + "'"
  103. where := ""
  104. if SupplierName != "" {
  105. where = where + " or a.SupplierName = '" + SupplierName + "'"
  106. }
  107. if CommercialNo != "" {
  108. where = where + " or a.CommercialNo = '" + CommercialNo + "'"
  109. }
  110. if OrganCode != "" {
  111. where = where + " or a.OrganCode = '" + OrganCode + "'"
  112. }
  113. if BankAccount != "" {
  114. where = where + " or a.BankAccount = '" + BankAccount + "'"
  115. }
  116. if CompanyUrl != "" {
  117. where = where + " or a.CompanyUrl = '" + CompanyUrl + "'"
  118. }
  119. if len(where) > 0 {
  120. where2 += " and (1=0 " + where + ")"
  121. var sql string
  122. sql = `select a.*, b.Id as CertId, b.AccessCardNo, b.SupplierTypeCode, b.SupplierTypeName, `
  123. sql += ` b.WorkerTotal, `
  124. sql += ` b.ContractNum, `
  125. sql += ` b.UniversityNum, `
  126. sql += ` b.TechnicalNum, `
  127. sql += ` b.AboveProfNum, `
  128. sql += ` b.MiddleProfNum, `
  129. sql += ` b.NationalRegNum, `
  130. sql += ` b.NationalCertTotal, `
  131. sql += ` b.DesignerTotal, `
  132. sql += ` b.SkillerTotal, `
  133. sql += ` b.Status, `
  134. sql += ` b.WorkflowId `
  135. sql += ` from ` + supplierTableName + ` a `
  136. sql += ` right join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  137. sql += ` where ` + where2
  138. s.DBE.SQL(sql).Find(entitiesPtr)
  139. }
  140. }
  141. func (s *OilSupplierService) CanUpdateSupplier(oilSupplierCertTableName string, supplierId int) (bool){
  142. session := s.DBE.NewSession()
  143. sessionSvc := GetOilSupplierSession(session)
  144. defer session.Close()
  145. session.Begin()
  146. result := sessionSvc.CanUpdateSupplier(oilSupplierCertTableName, supplierId)
  147. session.Commit()
  148. return result
  149. }
  150. func (s *OilSupplierService) GetUpdateCols(oilSupplierCertTableName string, supplierTypeCode string, supplierId int) ([]string){
  151. session := s.DBE.NewSession()
  152. sessionSvc := GetOilSupplierSession(session)
  153. defer session.Close()
  154. session.Begin()
  155. cols := sessionSvc.GetUpdateCols(oilSupplierCertTableName, supplierTypeCode, supplierId)
  156. session.Commit()
  157. return cols
  158. }
  159. func (s *OilSupplierService) GetProOrTreeList(ids string, entitiesPtr interface{}){
  160. where := " Id in ("+ids+")"
  161. sql := "SELECT Id, FullName, ParentId FROM Base_Organize where " + where
  162. s.DBE.SQL(sql).Find(entitiesPtr)
  163. return
  164. }
  165. func (s *OilSupplierService) GetMyTodoEntitie(supplierTableName, supplierCertTableName string, entitiesPtr interface{}, where string) bool {
  166. var sql string
  167. sql = `select a.Id, a.SupplierName, b.Id as CertId, b.SupplierTypeCode, '1' Type, b.Status `
  168. sql += ` from ` + supplierTableName + ` a `
  169. sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  170. sql += ` where ` + where
  171. has,_ := s.DBE.SQL(sql).Get(entitiesPtr)
  172. return has
  173. }
  174. func (s *OilSupplierService) GetExpireFile(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
  175. var sql string
  176. sql = `SELECT a.Id, a.SupplierName, a.Mobile, a.CreateBy, a.ContactName, a.CreateUserId, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
  177. sql += ` FROM ` + supplierTableName + ` a `
  178. sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
  179. sql += ` where ` + where
  180. sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
  181. err := s.DBE.SQL(sql).Find(entitiesPtr)
  182. return err
  183. }
  184. func (s *OilSupplierService) GetInterfaceData(supplierTableName, supplierFileTableName string, entitiesPtr interface{}, where string) error {
  185. var sql string
  186. sql = `SELECT a.Id, a.SupplierName, a.RegCapital, GROUP_CONCAT(b.NeedFileType SEPARATOR ';' ) NeedAllFile `
  187. sql += ` FROM ` + supplierTableName + ` a `
  188. sql += ` left join ` + supplierFileTableName + " b ON a.Id=b.SupplierId "
  189. sql += ` where ` + where
  190. sql += ` GROUP BY a.Id, a.SupplierName, a.Mobile `
  191. err := s.DBE.SQL(sql).Find(entitiesPtr)
  192. return err
  193. }
  194. func (s *OilSupplierService) GetProcessInfoWithOrderBytbl(supplierTableName, supplierCertTableName string, pageIndex, itemsPerPage int64, orderby string, asc bool, entitiesPtr interface{}, where string) (total int64) {
  195. var resultsSlice []map[string][]byte
  196. //获取总记录数
  197. sqlCount := `select count(*) from ` + supplierCertTableName + ` a `
  198. sqlCount += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  199. sqlCount += ` where ` + where
  200. var sql string
  201. sql = `select a.SupplierName, b.Id, `
  202. sql += ` b.Status, b.SupplierTypeCode, `
  203. sql += ` b.WorkflowId, b.ProcessKey, '1' as Type, b.CreateOn`
  204. sql += ` from ` + supplierTableName + ` a `
  205. sql += ` left join ` + supplierCertTableName + " b on b.SupplierId = a.Id"
  206. sql += ` where ` + where
  207. if asc {
  208. sql += ` order by ` + orderby + ` ASC `
  209. } else {
  210. sql += ` order by ` + orderby + ` DESC `
  211. }
  212. if (pageIndex != 0 && itemsPerPage !=0) {
  213. sql += ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
  214. }
  215. s.DBE.SQL(sql).Find(entitiesPtr)
  216. resultsSlice, _ = s.DBE.Query(sqlCount)
  217. if len(resultsSlice) > 0 {
  218. results := resultsSlice[0]
  219. for _, value := range results {
  220. total, _ = strconv.ParseInt(string(value), 10, 64)
  221. break
  222. }
  223. }
  224. return total
  225. }