5c95ef46e8855ebcbd0853b806adcfba476fe1e3.svn-base 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.chinacreator.videoalliance.order.dao;
  2. import java.sql.SQLException;
  3. import org.apache.commons.lang.math.NumberUtils;
  4. import org.springframework.cache.annotation.Cacheable;
  5. import org.springframework.stereotype.Component;
  6. import com.chinacreator.common.support.cache.annotation.CacheName;
  7. import com.chinacreator.videoalliance.common.util.DataSource;
  8. import com.frameworkset.common.poolman.SQLExecutor;
  9. /**
  10. * 黑白名单
  11. * @author 范秋海
  12. */
  13. @Component
  14. @CacheName("BlackWhite")
  15. public class BlackWhiteDao {
  16. /**
  17. * 检查用户是否为黑名单用户
  18. * @param userid
  19. * @param cpid 为0时,表示所有CP有效
  20. * @return
  21. * @throws SQLException
  22. */
  23. @Cacheable(value="BlackWhite", key="#userid.concat(#cpid) + 'Black'")
  24. public boolean isBlackUser(String userid, String cpid) throws SQLException {
  25. String sql = "select count(userid) from TB_BLACKWHITE_LIST where userid=? and (cpid='0' or cpid=?) and type=1 AND (STATUS is null or STATUS = 0) ";
  26. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, cpid), 0) > 0;
  27. }
  28. /**
  29. * 检查用户是否为白名单用户
  30. * @param userid
  31. * @param cpid 为0时,表示所有CP有效
  32. * @return
  33. * @throws SQLException
  34. */
  35. @Cacheable(value="BlackWhite", key="#userid.concat(#cpid) + 'White'")
  36. public boolean isWhiteUser(String userid, String cpid) throws SQLException {
  37. String sql = "select count(userid) from TB_BLACKWHITE_LIST where userid=? and (cpid='0' or cpid=?) and type=0 AND (STATUS is null or STATUS = 0)";
  38. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, cpid), 0) > 0;
  39. }
  40. /**
  41. * 检查用户是否为黑名单用户
  42. * @param userid
  43. * @param cpid 为0时,表示所有CP有效
  44. * @param spid 为null时,表示所有SP有效
  45. * @return
  46. * @throws SQLException
  47. */
  48. @Cacheable(value="BlackWhite", key="#userid.concat(#spid) + 'Black'")
  49. public boolean isBlackUserBySpid(String userid,String cpid, String spid) throws SQLException {
  50. String sql = "select count(userid) from TB_BLACKWHITE_LIST where userid=? and (cpid='0' or cpid=?) AND (SPID IS NULL OR SPID = '0' OR SPID = ?) and type=1 AND (STATUS is null or STATUS = 0) ";
  51. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, cpid, spid), 0) > 0;
  52. }
  53. /**
  54. * 检查用户是否为白名单用户
  55. * @param userid
  56. * @param cpid 为0时,表示所有CP有效
  57. * @param spid 为null时,表示所有SP有效
  58. * @return
  59. * @throws SQLException
  60. */
  61. @Cacheable(value="BlackWhite", key="#userid.concat(#spid) + 'White'")
  62. public boolean isWhiteUserBySpid(String userid, String cpid, String spid) throws SQLException {
  63. String sql = "select count(userid) from TB_BLACKWHITE_LIST where userid=? and (cpid='0' or cpid=?) AND (SPID IS NULL OR SPID = '0' OR SPID = ?) and type=0 AND (STATUS is null or STATUS = 0)";
  64. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, cpid, spid), 0) > 0;
  65. }
  66. }