Product.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package com.mall.model.product;
  2. import com.jfinal.plugin.activerecord.Db;
  3. import com.jfinal.plugin.activerecord.Model;
  4. import com.jfinal.plugin.activerecord.Page;
  5. import com.jfinal.plugin.activerecord.Record;
  6. import com.mall.util.DateUtil;
  7. import com.mall.util.Utility;
  8. import org.apache.commons.lang.ObjectUtils;
  9. import org.apache.commons.lang.StringUtils;
  10. import java.util.ArrayList;
  11. import java.util.Date;
  12. import java.util.List;
  13. import java.util.Map;
  14. @SuppressWarnings("serial")
  15. public class Product extends Model<Product>
  16. {
  17. public static final Product dao = new Product();
  18. /**
  19. *
  20. * @Description 查询
  21. * @author zhengwei
  22. * @date 2017年8月25日 下午3:27:34
  23. * @param pageNumber
  24. * @param pageSize
  25. * @return Page<Product>
  26. */
  27. public Page<Product> query(Integer merchantId, Map<String,Object> params, int pageNumber, int pageSize){
  28. StringBuffer sql = new StringBuffer();
  29. StringBuffer select = new StringBuffer();
  30. List<String> param=new ArrayList<String>();
  31. select.append(" select t.*");
  32. sql.append(" from product t where 1=1 ");
  33. if(Utility.isNotEmpty(params.get("productName"))){
  34. sql.append(" and product_name like ?");
  35. param.add("%"+ObjectUtils.toString(params.get("productName"))+"%");
  36. }
  37. if(Utility.isNotEmpty(params.get("merchantName"))){
  38. sql.append(" and merchant_name like ?");
  39. param.add("%"+ObjectUtils.toString(params.get("merchantName"))+"%");
  40. }
  41. if(Utility.isNotEmpty(params.get("productType"))){
  42. sql.append(" and product_type = ?");
  43. param.add(ObjectUtils.toString(params.get("productType")));
  44. }
  45. if(Utility.isNotEmpty(params.get("productOwner"))){
  46. sql.append(" and product_owner = ?");
  47. param.add(ObjectUtils.toString(params.get("productOwner")));
  48. }
  49. if(merchantId!=null) {
  50. sql.append(" and merchant_id = ?");
  51. param.add(""+merchantId+"");
  52. }
  53. sql.append(" order by create_time desc");
  54. if(param.isEmpty()){
  55. return paginate(pageNumber, pageSize, select.toString(), sql.toString());
  56. }else{
  57. return paginate(pageNumber, pageSize, select.toString(), sql.toString(),param.toArray());
  58. }
  59. }
  60. /**
  61. *
  62. * @Description 查询
  63. * @author zhengwei
  64. * @date 2017年8月25日 下午3:27:34
  65. * @param pageNumber
  66. * @param pageSize
  67. * @return Page<Product>
  68. */
  69. public Page<Product> getList(String type, int pageNumber, int pageSize){
  70. StringBuffer sql = new StringBuffer();
  71. StringBuffer select = new StringBuffer();
  72. select.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
  73. select.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.share_price");
  74. sql.append(" from product t where product_type='10' and product_owner='10' and t.status='1' ");
  75. sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
  76. if(StringUtils.isNotEmpty(type)){
  77. sql.append(" and t.merchant_id in (select id from merchant where merchant_category="+type+")");
  78. }
  79. sql.append(" order by t.time_status, t.is_hot desc, t.sort desc");
  80. return paginate(pageNumber, pageSize, select.toString(), sql.toString());
  81. }
  82. /**
  83. *
  84. * @Description 查询
  85. * @author zhengwei
  86. * @date 2017年8月25日 下午3:27:34
  87. * @param pageNumber
  88. * @param pageSize
  89. * @return Page<Product>
  90. */
  91. public Page<Product> getCutList(String type, int pageNumber, int pageSize){
  92. StringBuffer sql = new StringBuffer();
  93. StringBuffer select = new StringBuffer();
  94. select.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
  95. select.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.share_price");
  96. sql.append(" from product t where product_type='20' and t.status='1' ");
  97. sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
  98. // if("0".equals(type)){
  99. // sql.append(" and t.use_time>'"+DateUtil.formatDateTime(new Date())+"'");
  100. // }else {
  101. // sql.append(" and t.use_time<'"+DateUtil.formatDateTime(new Date())+"'");
  102. // }
  103. sql.append(" order by t.time_status , t.is_hot desc, t.sort desc");
  104. return paginate(pageNumber, pageSize, select.toString(), sql.toString());
  105. }
  106. /**
  107. *
  108. * @Description 查询
  109. * @author zhengwei
  110. * @date 2017年8月25日 下午3:27:34
  111. * @return Page<Product>
  112. */
  113. public List<Product> getAll(String type){
  114. StringBuffer sql = new StringBuffer();
  115. sql.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
  116. sql.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.product_img_1");
  117. sql.append(" from product t where t.status='1' ");
  118. sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
  119. if(StringUtils.isNotEmpty(type)) {
  120. if("0".equals(type)){
  121. sql.append(" and t.use_time>'"+DateUtil.formatDateTime(new Date())+"'");
  122. }else {
  123. sql.append(" and t.use_time<'"+DateUtil.formatDateTime(new Date())+"'");
  124. }
  125. }
  126. sql.append(" order by t.time_status , t.is_hot desc, t.sort desc");
  127. return find(sql.toString());
  128. }
  129. /**
  130. *
  131. * @Description: 批量删除 
  132. * @author zhengwei  
  133. * @date 2016年8月10日 下午10:33:53      
  134. * @return void    
  135. */
  136. public void deleteAll(Object[][] paras){
  137. Db.batch("delete from product where id = ?", paras,1000);
  138. }
  139. /**
  140. *
  141. * @Description: 修改状态 
  142. * @author zhengwei  
  143. * @date 2016年8月10日 下午10:33:53      
  144. * @return void    
  145. */
  146. public void updateStatus(Object[][] paras){
  147. Db.batch("update product set status=? where id = ?", paras,1000);
  148. }
  149. /**
  150. *
  151. * @Description 根据分类获取
  152. * @author zhengwei
  153. * @date 2017年8月30日 下午3:36:28
  154. * @return List<Record>
  155. */
  156. public List<Record> getByCategory(int categoryId){
  157. return Db.find("select t.*,"
  158. + " (select ifnull(sum(product_qty),0) from user_order_detail where product_id=t.id) sale_num"
  159. + " from product t"
  160. + " where t.status='1' and t.product_category=? order by is_hot desc,t.create_time desc ",categoryId);
  161. }
  162. /**
  163. *
  164. * @Description 根据ID获取
  165. * @author zhengwei
  166. * @date 2017年8月31日 上午12:15:06
  167. * @param id
  168. * @return Product
  169. */
  170. public Product getById(int id){
  171. return findFirst("select t.*,"
  172. + " (select ifnull(sum(a.product_qty),0) from user_order a,user_order_detail b where "
  173. + " a.id =b.order_id and b.product_id = t.id and (order_status='20' or order_status='30'))sale_num"
  174. + " from product t"
  175. + " where t.id=?",id);
  176. }
  177. public List<Product> getByMerchant(int merchantId, String isShop){
  178. if("1".equals(isShop)){
  179. return find("select t.*"
  180. + " from product t"
  181. + " where t.merchant_id=? and t.product_owner='20' and t.time_status in ('0','1','2') order by t.time_status",merchantId);
  182. }else{
  183. return find("select t.*"
  184. + " from product t"
  185. + " where t.merchant_id=? and t.product_owner='10' order by t.time_status limit 5",merchantId);
  186. }
  187. }
  188. public int getMaxSort() {
  189. Record record = Db.findFirst("select max(sort) sort from product");
  190. if(record.get("sort")!=null) {
  191. return record.getInt("sort")+1;
  192. }else {
  193. return 1;
  194. }
  195. }
  196. public List<Product> getForTask(){
  197. return find("select t.*,"
  198. + " (select ifnull(sum(a.product_qty),0) from user_order a,user_order_detail b where "
  199. + " a.id =b.order_id and b.product_id = t.id and (order_status='20' or order_status='30'))sale_num"
  200. + " from product t");
  201. }
  202. }