浏览代码

优惠券的异步推送

zhijiezhao 2 年之前
父节点
当前提交
2e97309b99

+ 6 - 0
pom.xml

@@ -105,6 +105,12 @@
 	</pluginRepositories>
 	<!-- 依赖项定义 -->
 	<dependencies>
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+			<version>1.18.18</version>
+		</dependency>
+
 		<dependency>
 			<groupId>commons-httpclient</groupId>
 			<artifactId>commons-httpclient</artifactId>

+ 0 - 47
src/main/java/com/caimei/modules/coupon/redis/RedisLearn.java

@@ -1,47 +0,0 @@
-package com.caimei.modules.coupon.redis;
-
-import com.caimei.modules.coupon.entity.CmCoupon;
-import com.caimei.modules.user.dao.MessageCenterDao;
-import com.caimei.modules.user.entity.CmUser;
-import com.caimei.modules.user.entity.MessageCenter;
-import com.cmme.modules.product.entity.CmmeProductImage;
-import com.thinkgem.jeesite.common.web.BaseController;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import redis.clients.jedis.Jedis;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2022/7/14
- */
-public class RedisLearn {
-
-
-    public static void producer( List<Integer> clubIds) {
-
-        clubIds.forEach(clubId -> {
-            Jedis jedis=null;
-            String constraint="";
-
-//                jedis=new Jedis("172.31.165.27", 6379);
-//                jedis.auth("6#xsI%b4o@5c3RoE");
-
-                jedis=new Jedis("192.168.2.100", 6379);
-
-//                jedis=new Jedis("172.31.165.23", 6379);
-
-            // 记录机构ID
-            jedis.lpush("mess"+clubId.toString(),clubId.toString());
-        });
-    }
-
-}
-

+ 90 - 0
src/main/java/com/caimei/modules/coupon/service/AsyncService.java

@@ -0,0 +1,90 @@
+package com.caimei.modules.coupon.service;
+
+import com.caimei.modules.coupon.entity.CmCoupon;
+import com.caimei.modules.sys.utils.SMSUtils;
+import com.caimei.modules.user.dao.MessageCenterDao;
+import com.caimei.modules.user.entity.CmUser;
+import com.caimei.modules.user.entity.MessageCenter;
+import com.caimei.po.User;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+@EnableAsync
+@Transactional(readOnly = false)
+public class AsyncService {
+
+    @Resource
+    private MessageCenterDao messageCenterDao;
+
+    //优惠券站内消息推送
+    @Async("mytask")
+    public void consumer(CmCoupon cmCoupon) {
+        String smsContent = "采美平台送您" + cmCoupon.getCouponAmount() + "元优惠券,众多大牌正品等着您,快戳采美网站链接www.caimei365.com" +
+                "或微信搜索“采美采购商城”小程序登录采美平台领取下单吧。关注公众号“采美网”获取更多优惠和精彩资讯。";
+        MessageCenter messageCenter = new MessageCenter();
+        Date date = new Date();
+        String now = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+        messageCenter.userType(1).couponType(cmCoupon.getCouponType()).messageType(4).time(now).couponMessageType(1).
+                couponFee(cmCoupon.getCouponAmount().doubleValue());
+        List<Integer> clubIds = messageCenterDao.ClubIds();
+        List<User> users = new ArrayList<>();
+        switch (cmCoupon.getCouponType()) {
+            // 劵类型 0活动券 1品类券 2用户专享券 3店铺券 4新用户券
+            case 0:
+                setCouponMessage(messageCenter, clubIds, smsContent, null);
+                break;
+            case 1:
+                String type = "1".equals(cmCoupon.getCategoryType()) ? "产品" : "仪器";
+                smsContent = "采美平台" + type + "类商品大优惠,采美平台送您" + cmCoupon.getCouponAmount() + "元优惠券,快戳采美网站链接www.caimei365.com" +
+                        "或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。";
+                setCouponMessage(messageCenter, clubIds, smsContent, null);
+                break;
+            case 2:
+                users = messageCenterDao.getUserInfo(cmCoupon.getUserId());
+                setCouponMessage(messageCenter, null, smsContent, users);
+                break;
+            case 3:
+                String shopName = messageCenterDao.shopName(cmCoupon.getShopId());
+                smsContent = "采美平台为了回馈客户,赠送您" + cmCoupon.getCouponAmount() + "元的店铺专属优惠券,快戳采美网站链接www.caimei365.com" +
+                        "或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。";
+                messageCenter.content(shopName);
+                setCouponMessage(messageCenter, clubIds, smsContent, null);
+                break;
+            case 4:
+                smsContent = "恭喜成功注册采美平台。采美平台赠送您" + cmCoupon.getCouponAmount() + "元新用户优惠券,快戳采美网站链接www.caimei365.com" +
+                        "或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。";
+                users = messageCenterDao.getNewUsers();
+                setCouponMessage(messageCenter, null, smsContent, users);
+                break;
+            default:
+                throw new IllegalStateException("Unexpected value: " + cmCoupon.getCouponType());
+        }
+    }
+
+    public void setCouponMessage(MessageCenter messageCenter, List<Integer> clubIds, String sms, List<User> users) {
+        if (null != clubIds && clubIds.size() > 0) {
+            clubIds.forEach(c -> {
+                CmUser user = messageCenterDao.clubList(c);
+                messageCenter.clubId(c);
+                messageCenterDao.addMessageCenter(messageCenter);
+                SMSUtils.sendSms(3, user.getBindMobile(), sms);
+            });
+        } else if (null != users && users.size() > 0) {
+            messageCenterDao.addMessageCenter(messageCenter);
+            users.forEach(u -> {
+                messageCenter.clubId(u.getClubID());
+                messageCenterDao.addMessageCenter(messageCenter);
+                SMSUtils.sendSms(3, u.getBindMobile(), sms);
+            });
+        }
+    }
+}

+ 1 - 1
src/main/java/com/caimei/modules/coupon/web/CmCouponClubTask.java

@@ -17,7 +17,7 @@ import java.util.concurrent.ThreadPoolExecutor;
 @Configuration
 @EnableAsync
 public class CmCouponClubTask {
-    @Bean(name="new_coupn")
+    @Bean(name="mytask")
     public Executor taskExecutor(){
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
         executor.setCorePoolSize(10);

+ 11 - 240
src/main/java/com/caimei/modules/coupon/web/CmCouponController.java

@@ -3,7 +3,7 @@ package com.caimei.modules.coupon.web;
 import com.caimei.modules.coupon.entity.CmCoupon;
 import com.caimei.modules.coupon.entity.CmCouponAssociate;
 import com.caimei.modules.coupon.entity.CmCouponRedemptionCode;
-import com.caimei.modules.coupon.redis.RedisLearn;
+import com.caimei.modules.coupon.service.AsyncService;
 import com.caimei.modules.coupon.service.CmCouponService;
 import com.caimei.modules.order.dao.NewShopOrderDao;
 import com.caimei.modules.order.service.NewOrderService;
@@ -18,36 +18,31 @@ import com.caimei.modules.user.entity.CmUser;
 import com.caimei.modules.user.entity.MessageCenter;
 import com.caimei.modules.user.entity.NewCmClub;
 import com.caimei.modules.user.entity.NewCmShop;
+import com.caimei.po.User;
 import com.caimei.utils.AppUtils;
 import com.thinkgem.jeesite.common.config.Global;
 import com.thinkgem.jeesite.common.persistence.Page;
-import com.thinkgem.jeesite.common.utils.JedisUtils;
 import com.thinkgem.jeesite.common.utils.StringUtils;
 import com.thinkgem.jeesite.common.web.BaseController;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
-import redis.clients.jedis.Jedis;
 
+import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.*;
+
 
 /**
  * 优惠券管理Controller
@@ -77,6 +72,8 @@ public class CmCouponController extends BaseController {
     private WeChatService weChatService;
     @Value("${wwwServer}")
     private String domain;
+    @Autowired
+    private AsyncService asyncService;
 
     @ModelAttribute
     public CmCoupon get(@RequestParam(required = false) String id) {
@@ -91,8 +88,6 @@ public class CmCouponController extends BaseController {
     }
 
 
-
-
     @RequiresPermissions("coupon:cmCoupon:view")
     @RequestMapping(value = {"list", ""})
     public String list(CmCoupon cmCoupon, HttpServletRequest request, HttpServletResponse response, Model model) {
@@ -156,238 +151,14 @@ public class CmCouponController extends BaseController {
         }
     }
 
-
-
-
-
-    //优惠券站内消息推送
-    private void consumer(CmCoupon cmCoupon, List<Integer> clubIds) {
-        // 消费消息
-            clubIds.forEach(clubIdb -> {
-                        Jedis jedis = null;
-                        String constraint = "";
-                        if (domain.contains("-b")) {
-                            jedis = new Jedis("172.31.165.27", 6379);
-                            jedis.auth("6#xsI%b4o@5c3RoE");
-                        } else if (domain.contains("localhost")) {
-                            jedis = new Jedis("192.168.2.100", 6379);
-                        } else {
-                            jedis = new Jedis("172.31.165.23", 6379);
-                        }
-                        // 获取消息
-                        String clubIdc = jedis.rpop("mess" + clubIdb.toString());
-                        Integer clubId = clubIdb;
-                        if (clubId != null) {
-                            Date date = new Date();
-                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-                            CmUser user = messageCenterDao.clubList(clubId);
-                            int coumt = 0;//计数五种消息只推送一条
-                            String catego = "";
-                            Integer ts = (date.compareTo(cmCoupon.getStartDate()));
-                            if (ts >= 0) {
-                                if ("90".equals(user.getClubStatus()) && 0 == cmCoupon.getCouponType()) {
-                                    CmCoupon coupon = messageCenterDao.CouponList(0);//查询活动优惠券信息
-                                    if (coupon != null) {
-                                        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-                                        MessageCenter messageCenter = new MessageCenter();
-                                        messageCenter.setShopId(null);
-                                        messageCenter.setClubId(clubIdb);
-                                        messageCenter.setUserType(1);
-                                        messageCenter.setMessageType(4);
-                                        messageCenter.setContent(null);
-                                        messageCenter.setTime(curDateStr);
-                                        messageCenter.setCouponType(0);
-                                        messageCenter.setCouponMessageType(1);
-                                        messageCenter.setCouponFee(cmCoupon.getCouponAmount().doubleValue());
-                                        messageCenterDao.addMessageCenter(messageCenter);
-                                        String content = "采美平台送您" + cmCoupon.getCouponAmount() + "元优惠券,众多大牌正品等着您,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台领取下单吧。关注公众号“采美网”获取更多优惠和精彩资讯。退订回T";
-                                        boolean sendSms = false;
-                                        try {
-                                            sendSms = SMSUtils.sendSms(3,user.getBindMobile(), content);
-                                        } catch (Exception e) {
-                                            e.printStackTrace();
-                                        }
-                                        if (sendSms) {
-                                            logger.info(">>>>>>>发送成功");
-                                        }
-                                        jedis.del("mess" + clubIdc);
-                                        coumt++;
-                                    }
-                                }
-                                if ("90".equals(user.getClubStatus()) && coumt == 0 && 1 == cmCoupon.getCouponType()) {
-                                    CmCoupon coupon = messageCenterDao.CouponList(1);//查询品类优惠券信息
-                                    if (coupon != null) {
-                                        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-                                        MessageCenter messageCenter = new MessageCenter();
-                                        messageCenter.setShopId(null);
-                                        messageCenter.setClubId(clubIdb);
-                                        messageCenter.setUserType(1);
-                                        messageCenter.setMessageType(4);
-                                        if (cmCoupon != null && "1".equals(cmCoupon.getCategoryType())) {
-                                            catego = "产品";
-                                        }
-                                        if (cmCoupon != null && "2".equals(cmCoupon.getCategoryType())) {
-                                            catego = "仪器";
-                                        }
-                                        messageCenter.setContent(catego);
-                                        messageCenter.setTime(curDateStr);
-                                        messageCenter.setCouponType(1);
-                                        messageCenter.setCouponMessageType(1);
-                                        messageCenter.setCouponFee(cmCoupon.getCouponAmount().doubleValue());
-                                        messageCenterDao.addMessageCenter(messageCenter);
-                                        String content = "采美平台" + catego + "类商品大优惠,采美平台送您" + cmCoupon.getCouponAmount() + "元优惠券,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。退订回T";
-                                        boolean sendSms = false;
-                                        try {
-                                            sendSms = SMSUtils.sendSms(3,user.getBindMobile(), content);
-                                        } catch (Exception e) {
-                                            e.printStackTrace();
-                                        }
-                                        if (sendSms) {
-                                            logger.info(">>>>>>>发送成功");
-                                        }
-
-                                        jedis.del("mess" + clubIdc);
-                                        coumt++;
-                                    }
-                                }
-                                if (coumt == 0 && 2 == cmCoupon.getCouponType()) {
-                                    CmCoupon coupon = messageCenterDao.CouponList(2);//查询用户专享优惠券信息
-                                    if (coupon != null && cmCoupon.getUserId() != null) {
-                                        if (coupon.getUserId().equals(cmCoupon.getUserId())) {
-                                            Integer clubc = messageCenterDao.clubIdCule(cmCoupon.getUserId());
-                                            String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-
-
-                                            jedis.del("mess" + clubIdc);
-                                            coumt++;
-                                        }
-                                    }
-                                }
-                                if ("90".equals(user.getClubStatus()) && coumt == 0 && 3 == cmCoupon.getCouponType()) {
-                                    CmCoupon coupon = messageCenterDao.CouponList(3);//查询店铺优惠券信息
-                                        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-                                        String shopName = messageCenterDao.shopName(cmCoupon.getShopId());
-                                        Integer userID = messageCenterDao.userID(cmCoupon.getShopId());
-                                        Integer clubID = messageCenterDao.clubIdCule(userID);
-                                        MessageCenter messageCenter = new MessageCenter();
-                                        messageCenter.setShopId(null);
-                                        messageCenter.setClubId(clubIdb);
-                                        messageCenter.setUserType(1);
-                                        messageCenter.setMessageType(4);
-                                        messageCenter.setContent(shopName);
-                                        messageCenter.setTime(curDateStr);
-                                        messageCenter.setCouponType(3);
-                                        messageCenter.setCouponMessageType(1);
-                                        messageCenter.setCouponFee(cmCoupon.getCouponAmount().doubleValue());
-                                        messageCenterDao.addMessageCenter(messageCenter);
-                                        String content = "采美平台为了回馈客户,赠送您" + cmCoupon.getCouponAmount() + "元的店铺专属优惠券,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。退订回T";
-                                        boolean sendSms = false;
-                                        try {
-                                            sendSms = SMSUtils.sendSms(3,user.getBindMobile(), content);
-                                        } catch (Exception e) {
-                                            e.printStackTrace();
-                                        }
-                                        if (sendSms) {
-                                            logger.info(">>>>>>>发送成功");
-                                        }
-                                    jedis.del("mess" + clubIdc);
-                                    coumt++;
-                                }
-                            if (coumt == 0 && 4 == cmCoupon.getCouponType()) {
-                                CmCoupon coupon = messageCenterDao.CouponList(4);//查询优惠券信息
-                                if (coupon != null) {
-                                    String startDate = sdf.format(coupon.getStartDate());
-                                    Calendar calendars = Calendar.getInstance();
-                                    Date receiptime = new Date();
-                                    try {
-                                        receiptime = sdf.parse(user.getRegisterTime());
-                                    } catch (ParseException e) {
-                                        e.printStackTrace();
-                                    }
-                                    calendars.setTime(receiptime);
-                                    calendars.add(Calendar.HOUR, -6);
-                                    String hTimes=sdf.format(calendars.getTime());
-                                    int num = startDate.compareTo(hTimes);
-                                    if (num >= 0) {
-                                        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-                                        MessageCenter messageCenter = new MessageCenter();
-                                        if (coupon != null && coupon.getUserId() != null) {
-                                            messageCenter.setShopId(null);
-                                            messageCenter.setClubId(clubIdb);
-                                            messageCenter.setUserType(1);
-                                            messageCenter.setMessageType(4);
-                                            messageCenter.setContent(null);
-                                            messageCenter.setTime(curDateStr);
-                                            messageCenter.setCouponType(4);
-                                            messageCenter.setCouponMessageType(1);
-                                            messageCenter.setCouponFee(cmCoupon.getCouponAmount().doubleValue());
-                                            messageCenterDao.addMessageCenter(messageCenter);
-
-                                            String content = "恭喜成功注册采美平台。采美平台赠送您" + cmCoupon.getCouponAmount() + "元新用户优惠券,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。退订回T";
-                                            boolean sendSms = false;
-                                            try {
-                                                sendSms = SMSUtils.sendSms(3,user.getBindMobile(), content);
-                                            } catch (Exception e) {
-                                                e.printStackTrace();
-                                            }
-                                            if (sendSms) {
-                                                logger.info(">>>>>>>发送成功");
-                                            }
-                                            jedis.del("mess" + clubIdc);
-                                            coumt++;
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                jedis.del("mess" + clubIdc);
-                System.out.println(jedis.rpop("mess" + clubIdc));
-            });
-
-        }
-
     @RequestMapping(value = "save")
-    public String save(CmCoupon cmCoupon, Model model, RedirectAttributes redirectAttributes) throws ParseException {
+    public String save(CmCoupon cmCoupon, Model model, RedirectAttributes redirectAttributes) {
         if (!beanValidator(model, cmCoupon)) {
             return form(cmCoupon, model);
         }
-        Date date=new Date();
-        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-//        ExecutorService pool = Executors.newFixedThreadPool(3);
-        List<Integer> clubIds = messageCenterDao.ClubIds();
-
-//        new Thread(() -> consumer(cmCoupon, clubIds)).start();
         //等于空就是添加否则是修改
-        if("".equals(cmCoupon.getId())){
-//        consumer(cmCoupon, clubIds);
-//        RedisLearn.producer(clubIds);
-        MessageCenter messageCenter = new MessageCenter();
-        if (cmCoupon.getUserId() != null) {
-            Integer clubc = messageCenterDao.clubIdCule(cmCoupon.getUserId());
-            CmUser user = messageCenterDao.clubList(clubc);
-            messageCenter.setShopId(null);
-            messageCenter.setClubId(clubc);
-            messageCenter.setUserType(1);
-            messageCenter.setMessageType(4);
-            messageCenter.setContent(null);
-            messageCenter.setTime(curDateStr);
-            messageCenter.setCouponType(2);
-            messageCenter.setCouponMessageType(1);
-            messageCenter.setCouponFee(cmCoupon.getCouponAmount().doubleValue());
-            messageCenterDao.addMessageCenter(messageCenter);
-            String content = "为了答谢您对采美平台的支持,采美平台送您" + cmCoupon.getCouponAmount() + "元优惠券,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台领取吧。关注公众号“采美网”获取更多优惠和精彩资讯。退订回T";
-            boolean sendSms = false;
-            try {
-                sendSms = SMSUtils.sendSms(3,user.getBindMobile(), content);
-//                sendSms =  SMSUtils.sendSms( user.getBindMobile(), content);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            if (sendSms) {
-                logger.info(">>>>>>>发送成功");
-            }
-        }
+        if ("".equals(cmCoupon.getId())) {
+            asyncService.consumer(cmCoupon);
         }
         cmCouponService.save(cmCoupon);
         addMessage(redirectAttributes, "保存优惠券成功");

+ 69 - 86
src/main/java/com/caimei/modules/sys/utils/SMSUtils.java

@@ -11,90 +11,73 @@ import java.util.List;
 
 public class SMSUtils {
 
-	/**
-	 * key
-	 */
-	private static final String ACCOUNT = "account";
-	private static final String PASSWORD = "password";
-	/**
-	 * 通知短信 账户
-	 */
-	private static final String ACCOUNT_NOTICE = "N2532063";
-	private static final String PASSWORD_NOTICE = "jzVvYmuP4D7f1b";
-	/**
-	 * 验证码短信 账户
-	 */
-	private static final String ACCOUNT_YZM = "YZM6372171";
-	private static final String PASSWORD_YZM = "1L8ZaIEW7fa3ca";
-	/**
-	 * 营销短信 账户
-	 */
-	private static final String ACCOUNT_ADS = "M1666161";
-	private static final String PASSWORD_ADS = "TO3xSGvEUk6ddc";
-	/**
-	 * 请求地址
-	 */
-	private static final String SMS_URL = "http://smssh1.253.com/msg/send/json";
+    /**
+     * key
+     */
+    private static final String ACCOUNT = "account";
+    private static final String PASSWORD = "password";
+    /**
+     * 通知短信 账户
+     */
+    private static final String ACCOUNT_NOTICE = "N2532063";
+    private static final String PASSWORD_NOTICE = "jzVvYmuP4D7f1b";
+    /**
+     * 验证码短信 账户
+     */
+    private static final String ACCOUNT_YZM = "YZM6372171";
+    private static final String PASSWORD_YZM = "1L8ZaIEW7fa3ca";
+    /**
+     * 营销短信 账户
+     */
+    private static final String ACCOUNT_ADS = "M1666161";
+    private static final String PASSWORD_ADS = "TO3xSGvEUk6ddc";
+    /**
+     * 请求地址
+     */
+    private static final String SMS_URL = "http://smssh1.253.com/msg/send/json";
 
-
-//	private static String url = "http://47.96.109.82:9999/sms.aspx";
-//	private static String userid = "321";
-//	private static String account = "0755cmxx";
-//	private static String password = "CaimeiSMS999";
-
-	public static boolean sendSms(Integer type, String mobile, String content) {
-
-//		String res = SmsClientSend.sendSms(url, userid, account, password, mobile, content);
-//		return res.indexOf("Success") != -1;
-
-//		JSONObject params = new JSONObject();
-//		if (null != type && 2 == type) {
-//			// 验证码短信
-//			params.put(ACCOUNT, ACCOUNT_YZM);
-//			params.put(PASSWORD, PASSWORD_YZM);
-//		} else if (null != type && 3 == type) {
-//			// 营销短信
-//			params.put(ACCOUNT, ACCOUNT_ADS);
-//			params.put(PASSWORD, PASSWORD_ADS);
-//		} else {
-//			// 通知短信
-//			params.put(ACCOUNT, ACCOUNT_NOTICE);
-//			params.put(PASSWORD, PASSWORD_NOTICE);
-//		}
-
-		// 获取core服务器地址
-		List<String> list = new ArrayList<>();
-		list.add("15917362709");
-		list.add("15814011616");
-		list.add("13100721916");
-		list.add("15113936829");
-		list.add("15827317748");
-		list.add("18476937515");
-		list.add("18175515644");
-		if (list.contains(mobile)) {
-			String coreServer = Global.getConfig("caimei.core");
-			RestTemplate restTemplate = new RestTemplate();
-			String uri = coreServer + "/tools/sms/send";
-			// 发起Post请求
-			MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<>();
-			paramMap.add("type", type.toString());
-			paramMap.add("mobile", mobile);
-			paramMap.add("content", content);
-			String result = restTemplate.postForObject(uri, paramMap, String.class);
-
-			System.out.println(result);
-			JSONObject json = (JSONObject) JSONObject.parse(result);
-			if (null != json && json.getInteger("code") == 0) {
-				return true;
-			} else {
-				return false;
-			}
-		}
-		return false;
-	}
-//		public static void main (String[]args){
-////		String e="abc";
-////		System.out.println(sendSms(3,"1817515644", "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“" + e + "”资质证书将于3个月后失效,请及时登录采美网站上传新证书。"));
-////		 System.out.println(sendSms("18175515644", "您短信验证码是:7895"));
-//		}
-	}
+    public static boolean sendSms(Integer type, String mobile, String content) {
+        String wwwServer = Global.getConfig("wwwServer");
+        JSONObject params = new JSONObject();
+        if (null != type && 2 == type) {
+            // 验证码短信
+            params.put(ACCOUNT, ACCOUNT_YZM);
+            params.put(PASSWORD, PASSWORD_YZM);
+        } else if (null != type && 3 == type) {
+            // 营销短信
+            params.put(ACCOUNT, ACCOUNT_ADS);
+            params.put(PASSWORD, PASSWORD_ADS);
+        } else {
+            // 通知短信
+            params.put(ACCOUNT, ACCOUNT_NOTICE);
+            params.put(PASSWORD, PASSWORD_NOTICE);
+        }
+        // 获取core服务器地址
+        List<String> list = new ArrayList<>();
+        list.add("15917362709");
+        list.add("15814011616");
+        list.add("13100721916");
+        list.add("15113936829");
+        list.add("15827317748");
+        list.add("18476937515");
+        list.add("18175515644");
+        if (list.contains(mobile) || wwwServer.contains("www.caimei365.com")) {
+            String coreServer = Global.getConfig("caimei.core");
+            RestTemplate restTemplate = new RestTemplate();
+            String uri = coreServer + "/tools/sms/send";
+            // 发起Post请求
+            MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<>();
+            paramMap.add("type", type.toString());
+            paramMap.add("mobile", mobile);
+            paramMap.add("content", content);
+            String result = restTemplate.postForObject(uri, paramMap, String.class);
+            JSONObject json = (JSONObject) JSONObject.parse(result);
+            if (null != json && json.getInteger("code") == 0) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        return false;
+    }
+}

+ 300 - 300
src/main/java/com/caimei/modules/sys/web/NotificationController.java

@@ -48,37 +48,42 @@ import java.util.List;
 public class NotificationController extends BaseController {
 
     @Autowired
-    NotificationDao notificationDao;
+    private NotificationDao notificationDao;
     @Autowired
-    NotificationService notificationService;
+    private NotificationService notificationService;
     @Autowired
-    MessageCenterDao messageCenterDao;
+    private MessageCenterDao messageCenterDao;
     @Autowired
-    NewOrderService newOrderService;
+    private NewOrderService newOrderService;
     @Autowired
-    NewShopOrderDao newShopOrderDao;
+    private NewShopOrderDao newShopOrderDao;
     @Autowired
-    WeChatService weChatService;
+    private WeChatService weChatService;
     @Value("${wwwServer}")
     private String domain;
+
     @RequestMapping(value = {"list", ""})
-    public String list( Notification notifi,HttpServletRequest request, HttpServletResponse response, Model model) {
+    public String list(Notification notifi, HttpServletRequest request, HttpServletResponse response, Model model) {
 
-      List<String> content=new ArrayList<>();
+        List<String> content = new ArrayList<>();
         Page<Notification> page = notificationService.notificationPagen(new Page<Notification>(request, response), notifi);
 
-            String[] IdArr=null;
-            String[] porductIDs=null;
-            String[] shopIDs=null;
-             for (int i = 0; i < page.getList().size(); i++) {
-                IdArr =page.getList().get(i).getShopContent().split(",");
-                if(page.getList().get(i).getPorductID()!=null){porductIDs=page.getList().get(i).getPorductID().split(",");}
-                 if(page.getList().get(i).getShopID()!=null){shopIDs=page.getList().get(i).getShopID().split(",");}
-
-                page.getList().get(i).setContents(IdArr);
-                page.getList().get(i).setPorductIDs(porductIDs);
-                 page.getList().get(i).setShopIDs(shopIDs);
+        String[] IdArr = null;
+        String[] porductIDs = null;
+        String[] shopIDs = null;
+        for (int i = 0; i < page.getList().size(); i++) {
+            IdArr = page.getList().get(i).getShopContent().split(",");
+            if (page.getList().get(i).getPorductID() != null) {
+                porductIDs = page.getList().get(i).getPorductID().split(",");
+            }
+            if (page.getList().get(i).getShopID() != null) {
+                shopIDs = page.getList().get(i).getShopID().split(",");
             }
+
+            page.getList().get(i).setContents(IdArr);
+            page.getList().get(i).setPorductIDs(porductIDs);
+            page.getList().get(i).setShopIDs(shopIDs);
+        }
         notificationDao.hides();
         model.addAttribute("Notification", notifi);
         model.addAttribute("page", page);
@@ -87,62 +92,68 @@ public class NotificationController extends BaseController {
 
 
     /**
-     *constraint加入缓存
+     * constraint加入缓存
      */
     @Scheduled(cron = "0 0 23 * * ?")
     public void Open() {
-//        Jedis jedis=new Jedis("172.31.165.27", 6379);
-//        jedis.auth("6#xsI%b4o@5c3RoE");
-        Jedis jedis=new Jedis("192.168.2.100", 6379);
-        jedis.lpush("constraint","0");
+        Jedis jedis = new Jedis("192.168.2.100", 6379);
+        if(domain.contains("-b")){
+            jedis=new Jedis("47.119.112.46", 6379);
+            jedis.auth("6#xsI%b4o@5c3RoE");
+        }else if(domain.contains("localhost")){
+            jedis=new Jedis("192.168.2.100", 6379);
+        }else {
+            jedis=new Jedis("172.31.165.23", 6379);
+        }
+        jedis.lpush("constraint", "0");
     }
 
     @Scheduled(cron = "0 0 11 * * ?")
 //@Scheduled(cron = "0 0/10 * * * ?")
     public void mess() throws Exception {
-        Date date=new Date();
-        String name="";
-        Integer count=0;
-        List<Product>pro=notificationDao.productTypeCount(3);
-        List<Product>pro1=notificationDao.productTypeCount(1);
-        List<Product>pro2=notificationDao.productTypeCount1(7);
-        List<Product>pro3=notificationDao.productTypeCount1(1);
-        for (int i=0;i<pro.size();i++){
-            name=pro.get(i).getName();
+        Date date = new Date();
+        String name = "";
+        Integer count = 0;
+        List<Product> pro = notificationDao.productTypeCount(3);
+        List<Product> pro1 = notificationDao.productTypeCount(1);
+        List<Product> pro2 = notificationDao.productTypeCount1(7);
+        List<Product> pro3 = notificationDao.productTypeCount1(1);
+        for (int i = 0; i < pro.size(); i++) {
+            name = pro.get(i).getName();
             if (name.length() > 10) {
                 name = StringUtils.strip(name.substring(0, 11));
                 name += "...";
             }
 
             logger.info("**************************质证书失效消息推送************************************");
-                try {
-                    Integer userID = messageCenterDao.userID(pro.get(i).getShopID());
-                   String shopName= messageCenterDao.shopName(pro.get(i).getShopID());
-                    String unionid = newShopOrderDao.UnionId(userID);
-                    List<String> openidList = newShopOrderDao.getOpenidListByPermission(unionid);
-                    String accessToken = weChatService.getAccessToken();
-                    String qualificationNo = pro.get(i).getQualificationNo();
-                    String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
-                    String pagePath = "";
-                    for (String openid : openidList) {
-                        weChatService.messteme(accessToken, openid,shopName , qualificationNo, time, name, pagePath);
-                        count++;
-                    }
-                } catch (Exception e) {
-                    logger.error("【质证书失效消息推送】获取微信公众号access_token异常!", e);
+            try {
+                Integer userID = messageCenterDao.userID(pro.get(i).getShopID());
+                String shopName = messageCenterDao.shopName(pro.get(i).getShopID());
+                String unionid = newShopOrderDao.UnionId(userID);
+                List<String> openidList = newShopOrderDao.getOpenidListByPermission(unionid);
+                String accessToken = weChatService.getAccessToken();
+                String qualificationNo = pro.get(i).getQualificationNo();
+                String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+                String pagePath = "";
+                for (String openid : openidList) {
+                    weChatService.messteme(accessToken, openid, shopName, qualificationNo, time, name, pagePath);
+                    count++;
                 }
-            if(count<=0) {
+            } catch (Exception e) {
+                logger.error("【质证书失效消息推送】获取微信公众号access_token异常!", e);
+            }
+            if (count <= 0) {
                 String bindMobile = messageCenterDao.Mobile(pro.get(i).getShopID());
                 String content = "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“" + name + "”资质证书将于3个月后失效,请及时登录采美网站上传新证书。";
-                boolean sendSms = SMSUtils.sendSms(1,bindMobile, content);
+                boolean sendSms = SMSUtils.sendSms(1, bindMobile, content);
                 if (sendSms) {
                     logger.info(">>>>>>>资质证书将于3个月后失效短信推送成功");
                 }
             }
         }
 
-        for (int i=0;i<pro1.size();i++){
-            name=pro1.get(i).getName();
+        for (int i = 0; i < pro1.size(); i++) {
+            name = pro1.get(i).getName();
             if (name.length() > 10) {
                 name = StringUtils.strip(name.substring(0, 11));
                 name += "...";
@@ -151,7 +162,7 @@ public class NotificationController extends BaseController {
             logger.info("**************************质证书失效消息推送************************************");
             try {
                 Integer userID = messageCenterDao.userID(pro1.get(i).getShopID());
-                String shopName= messageCenterDao.shopName(pro1.get(i).getShopID());
+                String shopName = messageCenterDao.shopName(pro1.get(i).getShopID());
                 String unionid = newShopOrderDao.UnionId(userID);
                 List<String> openidList = newShopOrderDao.getOpenidListByPermission(unionid);
                 String accessToken = weChatService.getAccessToken();
@@ -159,24 +170,24 @@ public class NotificationController extends BaseController {
                 String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
                 String pagePath = "";
                 for (String openid : openidList) {
-                    weChatService.messteme(accessToken, openid,shopName , qualificationNo, time, name, pagePath);
+                    weChatService.messteme(accessToken, openid, shopName, qualificationNo, time, name, pagePath);
                     count++;
                 }
             } catch (Exception e) {
                 logger.error("【质证书失效消息推送】获取微信公众号access_token异常!", e);
             }
-            if(count<=0) {
+            if (count <= 0) {
                 String bindMobile = messageCenterDao.Mobile(pro1.get(i).getShopID());
                 String content = "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“" + name + "”资质证书将于1个月后失效,请及时登录采美网站上传新证书。";
-                boolean sendSms = SMSUtils.sendSms(1,bindMobile, content);
+                boolean sendSms = SMSUtils.sendSms(1, bindMobile, content);
                 if (sendSms) {
                     logger.info(">>>>>>>资质证书将于1个月后失效短信推送成功");
                 }
             }
         }
 
-        for (int i=0;i<pro2.size();i++){
-            name=pro2.get(i).getName();
+        for (int i = 0; i < pro2.size(); i++) {
+            name = pro2.get(i).getName();
             if (name.length() > 10) {
                 name = StringUtils.strip(name.substring(0, 11));
                 name += "...";
@@ -185,7 +196,7 @@ public class NotificationController extends BaseController {
             logger.info("**************************质证书失效消息推送************************************");
             try {
                 Integer userID = messageCenterDao.userID(pro2.get(i).getShopID());
-                String shopName= messageCenterDao.shopName(pro2.get(i).getShopID());
+                String shopName = messageCenterDao.shopName(pro2.get(i).getShopID());
                 String unionid = newShopOrderDao.UnionId(userID);
                 List<String> openidList = newShopOrderDao.getOpenidListByPermission(unionid);
                 String accessToken = weChatService.getAccessToken();
@@ -193,33 +204,32 @@ public class NotificationController extends BaseController {
                 String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
                 String pagePath = "";
                 for (String openid : openidList) {
-                    weChatService.messteme(accessToken, openid,shopName, qualificationNo, time, name, pagePath);
+                    weChatService.messteme(accessToken, openid, shopName, qualificationNo, time, name, pagePath);
                     count++;
                 }
             } catch (Exception e) {
                 logger.error("【质证书失效消息推送】获取微信公众号access_token异常!", e);
             }
-            if(count<=0) {
+            if (count <= 0) {
                 String bindMobile = messageCenterDao.Mobile(pro2.get(i).getShopID());
                 String content = "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“" + name + "”资质证书将于7天后失效,请及时登录采美网站上传新证书。";
-                boolean sendSms = SMSUtils.sendSms(1,bindMobile, content);
+                boolean sendSms = SMSUtils.sendSms(1, bindMobile, content);
                 if (sendSms) {
                     logger.info(">>>>>>>资质证书将于7天后失效短信推送成功");
                 }
             }
         }
 
-        for (int i=0;i<pro3.size();i++){
-            name=pro3.get(i).getName();
+        for (int i = 0; i < pro3.size(); i++) {
+            name = pro3.get(i).getName();
             if (name.length() > 10) {
                 name = StringUtils.strip(name.substring(0, 11));
                 name += "...";
             }
-
             logger.info("**************************质证书失效消息推送************************************");
             try {
                 Integer userID = messageCenterDao.userID(pro3.get(i).getShopID());
-                String shopName= messageCenterDao.shopName(pro3.get(i).getShopID());
+                String shopName = messageCenterDao.shopName(pro3.get(i).getShopID());
                 String unionid = newShopOrderDao.UnionId(userID);
                 List<String> openidList = newShopOrderDao.getOpenidListByPermission(unionid);
                 String accessToken = weChatService.getAccessToken();
@@ -227,290 +237,280 @@ public class NotificationController extends BaseController {
                 String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
                 String pagePath = "";
                 for (String openid : openidList) {
-                    weChatService.messteme(accessToken, openid,shopName , qualificationNo, time, name, pagePath);
+                    weChatService.messteme(accessToken, openid, shopName, qualificationNo, time, name, pagePath);
                     count++;
                 }
             } catch (Exception e) {
                 logger.error("【质证书失效消息推送】获取微信公众号access_token异常!", e);
             }
-if(count<=0){
-            String bindMobile= messageCenterDao.Mobile(pro3.get(i).getShopID());
-            String content = "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“"+name+"”资质证书将于今天后失效,请及时登录采美网站上传新证书。";
-            boolean sendSms = SMSUtils.sendSms(1,bindMobile, content);
-            if(sendSms){
-                logger.info(">>>>>>>资质证书将于今天后后失效短信推送成功");
+            if (count <= 0) {
+                String bindMobile = messageCenterDao.Mobile(pro3.get(i).getShopID());
+                String content = "【采美365】 尊敬的采美供应商用户,您在采美上架的商品“" + name + "”资质证书将于今天后失效,请及时登录采美网站上传新证书。";
+                boolean sendSms = SMSUtils.sendSms(1, bindMobile, content);
+                if (sendSms) {
+                    logger.info(">>>>>>>资质证书将于今天后后失效短信推送成功");
+                }
             }
         }
-        }
-
     }
 
 
     @RequestMapping(value = {"update"})
-    public String update( Notification notification,HttpServletRequest request, HttpServletResponse response, Model model) {
+    public String update(Notification notification, HttpServletRequest request, HttpServletResponse response, Model model) {
         notificationDao.Upnotification(notification);
-        return "redirect:"+Global.getAdminPath()+"/sys/Notification/list";
+        return "redirect:" + Global.getAdminPath() + "/sys/Notification/list";
     }
 
     @RequestMapping(value = {"updates"})
-    public void updates( Notification notification,HttpServletRequest request, HttpServletResponse response, Model model) {
+    public void updates(Notification notification, HttpServletRequest request, HttpServletResponse response, Model model) {
         notificationDao.Upnotification(notification);
     }
 
     @RequestMapping(value = {"Idques"})
-    public String Idques( Notification notification,HttpServletRequest request, HttpServletResponse response, Model model){
-         String c= notificationDao.notificationId(notification);
-
+    public String Idques(Notification notification, HttpServletRequest request, HttpServletResponse response, Model model) {
+        String c = notificationDao.notificationId(notification);
         model.addAttribute("shopContent", c);
-        return "redirect:"+Global.getAdminPath()+"/sys/Notification/list?shopContent="+c;
+        return "redirect:" + Global.getAdminPath() + "/sys/Notification/list?shopContent=" + c;
     }
 
     @RequestMapping(value = {"hide"})
-    public String hide( Notification notification,HttpServletRequest request, HttpServletResponse response, Model model){
-        Integer hide=null;
-        if(notification.getHide() == 0){
-            hide=1;
-        }else{
-            hide=0;
+    public String hide(Notification notification, HttpServletRequest request, HttpServletResponse response, Model model) {
+        Integer hide = null;
+        if (notification.getHide() == 0) {
+            hide = 1;
+        } else {
+            hide = 0;
         }
-        notificationDao.hide(hide,Integer.parseInt(notification.getId()));
-        return "redirect:"+Global.getAdminPath()+"/sys/Notification/list";
+        notificationDao.hide(hide, Integer.parseInt(notification.getId()));
+        return "redirect:" + Global.getAdminPath() + "/sys/Notification/list";
     }
 
     @RequestMapping(value = {"hides"})
-    public String hides( Notification notification,HttpServletRequest request, HttpServletResponse response, Model model){
+    public String hides(Notification notification, HttpServletRequest request, HttpServletResponse response, Model model) {
 
         notificationDao.hides();
-        return "redirect:"+Global.getAdminPath()+"/sys/Notification/list";
+        return "redirect:" + Global.getAdminPath() + "/sys/Notification/list";
     }
+
     @Scheduled(cron = "0 0 11 * * ?")
 //@Scheduled(cron = "0 0/1 * * * ?")
-    public void nottime(){
+    public void nottime() {
         logger.info("》》》》》》》》》》》开始检测商品资质证书和上架费是否过期");
 
         //械字号资质证书3个月后过期
-        Integer count=0;
-        String name="";
-        String productID="";
-        String shopID="";
-        Date date=new Date();
+        Integer count = 0;
+        String name = "";
+        String productID = "";
+        String shopID = "";
+        Date date = new Date();
         String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
         //资质证书
-        List<Product>pro=notificationDao.productTypeCount(3);
-        List<Product>pro1=notificationDao.productTypeCount(1);
-        List<Product>pro2=notificationDao.productTypeCount1(7);
-        List<Product>pro3=notificationDao.productTypeCount1(1);
+        List<Product> pro = notificationDao.productTypeCount(3);
+        List<Product> pro1 = notificationDao.productTypeCount(1);
+        List<Product> pro2 = notificationDao.productTypeCount1(7);
+        List<Product> pro3 = notificationDao.productTypeCount1(1);
         //上架费
-        List<Product>product=notificationDao.productTypeCount2(3);
-        List<Product>product1=notificationDao.productTypeCount2(1);
-        List<Product>product2=notificationDao.productTypeCount3(7);
-        List<Product>product3=notificationDao.productTypeCount3(1);
-//
-        Jedis jedis=null;
-        String constraint="";
-        if(domain.contains("-b")){
-            jedis=new Jedis("172.31.165.27", 6379);
+        List<Product> product = notificationDao.productTypeCount2(3);
+        List<Product> product1 = notificationDao.productTypeCount2(1);
+        List<Product> product2 = notificationDao.productTypeCount3(7);
+        List<Product> product3 = notificationDao.productTypeCount3(1);
+        Jedis jedis = null;
+        String constraint = "";
+        if (domain.contains("-b")) {
+            jedis = new Jedis("47.119.112.46", 6379);
             jedis.auth("6#xsI%b4o@5c3RoE");
-        }else if(domain.contains("localhost")){
-            jedis=new Jedis("192.168.2.100", 6379);
-        }else {
-            jedis=new Jedis("172.31.165.23", 6379);
+        } else if (domain.contains("localhost")) {
+            jedis = new Jedis("192.168.2.100", 6379);
+        } else {
+            jedis = new Jedis("172.31.165.23", 6379);
         }
-
-        if(!"1".equals(jedis.rpop("constraint"))){
-            jedis.lpush("constraint","0");
-
+        if (!"1".equals(jedis.rpop("constraint"))) {
+            jedis.lpush("constraint", "0");
         }
-        constraint=jedis.rpop("constraint");
+        constraint = jedis.rpop("constraint");
         System.out.println(jedis.rpop("constraint"));
-//        if("0".equals(constraint)){
-            for (int i=0;i<pro.size();i++){
-                MessageCenter messageCenter = new MessageCenter();
-                messageCenter.setShopId(pro.get(i).getShopID());
-                messageCenter.setClubId(null);
-                messageCenter.setUserType(2);
-                messageCenter.setMessageType(2);
-                messageCenter.setShopMessType(5);
-                messageCenter.setProductId(pro.get(i).getProductID());
-                messageCenter.setContent("该商品的资质证书将于3个月后失效,请及时登录采美网站上传新证书。");
-                messageCenter.setTime(curDateStr);
-                messageCenterDao.addMessageCenter(messageCenter);
-
-                if(i!=0){
-                    name+=",";
-                    productID+=",";
-                }
-                name +="("+pro.get(i).getProductID().toString()+")"+pro.get(i).getName();
-                productID+=pro.get(i).getProductID().toString();
-            }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下械字号商品的资质证书将于3个月后失效,请及时提醒供应商更换证书。");
-                notification.setShopContent(name);
-                notification.setPorductID(productID);
-                notificationDao.addNotification(notification);
-                name="";
-                productID="";
-            }
-            //械字号资质证书1个月后过期
-            for (int i=0;i<pro1.size();i++){
-                MessageCenter messageCenter = new MessageCenter();
-                messageCenter.setShopId(pro1.get(i).getShopID());
-                messageCenter.setClubId(null);
-                messageCenter.setUserType(2);
-                messageCenter.setMessageType(2);
-                messageCenter.setShopMessType(5);
-                messageCenter.setProductId(pro1.get(i).getProductID());
-                messageCenter.setContent("该商品的资质证书将于1个月后失效,请及时登录采美网站上传新证书。");
-                messageCenter.setTime(curDateStr);
-                messageCenterDao.addMessageCenter(messageCenter);
-                if(i!=0){
-                    name+=",";
-                    productID+=",";
-                }
-                name +="("+pro1.get(i).getProductID().toString()+")"+pro1.get(i).getName();
-                productID+=pro1.get(i).getProductID().toString();
-            }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下械字号商品的资质证书将于1个月后失效,请及时提醒供应商更换证书。");
-                notification.setShopContent(name);
-                notification.setPorductID(productID);
-                notificationDao.addNotification(notification);
-                name="";
-                productID="";
-            }
-//械字号资质证书7日后过期
-            for (int i=0;i<pro2.size();i++){
-                MessageCenter messageCenter = new MessageCenter();
-                messageCenter.setShopId(pro2.get(i).getShopID());
-                messageCenter.setClubId(null);
-                messageCenter.setUserType(2);
-                messageCenter.setMessageType(2);
-                messageCenter.setShopMessType(5);
-                messageCenter.setProductId(pro2.get(i).getProductID());
-                messageCenter.setContent("该商品的资质证书将于7天后失效,请及时登录采美网站上传新证书。");
-                messageCenter.setTime(curDateStr);
-                messageCenterDao.addMessageCenter(messageCenter);
-                if(i!=0){
-                    name+=",";
-                    productID+=",";
-                }
-                name +="("+pro2.get(i).getProductID().toString()+")"+pro2.get(i).getName();
-                productID+=pro2.get(i).getProductID().toString();
+        for (int i = 0; i < pro.size(); i++) {
+            MessageCenter messageCenter = new MessageCenter();
+            messageCenter.setShopId(pro.get(i).getShopID());
+            messageCenter.setClubId(null);
+            messageCenter.setUserType(2);
+            messageCenter.setMessageType(2);
+            messageCenter.setShopMessType(5);
+            messageCenter.setProductId(pro.get(i).getProductID());
+            messageCenter.setContent("该商品的资质证书将于3个月后失效,请及时登录采美网站上传新证书。");
+            messageCenter.setTime(curDateStr);
+            messageCenterDao.addMessageCenter(messageCenter);
+            if (i != 0) {
+                name += ",";
+                productID += ",";
             }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下械字号商品的资质证书将于7天后失效,请及时提醒供应商更换证书。");
-                notification.setShopContent(name);
-                notification.setPorductID(productID);
-                notificationDao.addNotification(notification);
-                name="";
-                productID="";
-            }
-//械字号资质证书今日后过期
-            for (int i=0;i<pro3.size();i++){
-                MessageCenter messageCenter = new MessageCenter();
-                messageCenter.setShopId(pro3.get(i).getShopID());
-                messageCenter.setClubId(null);
-                messageCenter.setUserType(2);
-                messageCenter.setMessageType(2);
-                messageCenter.setShopMessType(5);
-                messageCenter.setProductId(pro3.get(i).getProductID());
-                messageCenter.setContent("该商品的资质证书将于今天后失效,请及时登录采美网站上传新证书。");
-                messageCenter.setTime(curDateStr);
-                messageCenterDao.addMessageCenter(messageCenter);
-                if(i!=0){
-                    name+=",";
-                    productID+=",";
-                }
-                name +="("+pro3.get(i).getProductID().toString()+")"+pro3.get(i).getName();
-                productID+=pro3.get(i).getProductID().toString();
-            }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下械字号商品的资质证书将于今天后失效,请及时提醒供应商更换证书。");
-                notification.setShopContent(name);
-                notification.setPorductID(productID);
-                notificationDao.addNotification(notification);
-                name="";
-                productID="";
-            }
-            //上架费
-            for (int i=0;i<product.size();i++){
-                if(i!=0){
-                    name+=",";
-                    shopID+=",";
-                }
-                name +=product.get(i).getName();
-                shopID+=product.get(i).getShopID();
-            }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下供应商的上架费将于3个月后到期,请及时提醒供应商续费。");
-                notification.setShopContent(name);
-                notification.setShopID(shopID);
-                notificationDao.addNotification(notification);
-                name="";
-                shopID="";
+            name += "(" + pro.get(i).getProductID().toString() + ")" + pro.get(i).getName();
+            productID += pro.get(i).getProductID().toString();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下械字号商品的资质证书将于3个月后失效,请及时提醒供应商更换证书。");
+            notification.setShopContent(name);
+            notification.setPorductID(productID);
+            notificationDao.addNotification(notification);
+            name = "";
+            productID = "";
+        }
+        //械字号资质证书1个月后过期
+        for (int i = 0; i < pro1.size(); i++) {
+            MessageCenter messageCenter = new MessageCenter();
+            messageCenter.setShopId(pro1.get(i).getShopID());
+            messageCenter.setClubId(null);
+            messageCenter.setUserType(2);
+            messageCenter.setMessageType(2);
+            messageCenter.setShopMessType(5);
+            messageCenter.setProductId(pro1.get(i).getProductID());
+            messageCenter.setContent("该商品的资质证书将于1个月后失效,请及时登录采美网站上传新证书。");
+            messageCenter.setTime(curDateStr);
+            messageCenterDao.addMessageCenter(messageCenter);
+            if (i != 0) {
+                name += ",";
+                productID += ",";
             }
-            //上架费1个月后过期
-            for (int i=0;i<product1.size();i++){
-                if(i!=0){
-                    name+=",";
-                    shopID+=",";
-                }
-                name +=product1.get(i).getName();
-                shopID+=product1.get(i).getShopID();
+            name += "(" + pro1.get(i).getProductID().toString() + ")" + pro1.get(i).getName();
+            productID += pro1.get(i).getProductID().toString();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下械字号商品的资质证书将于1个月后失效,请及时提醒供应商更换证书。");
+            notification.setShopContent(name);
+            notification.setPorductID(productID);
+            notificationDao.addNotification(notification);
+            name = "";
+            productID = "";
+        }
+        //械字号资质证书7日后过期
+        for (int i = 0; i < pro2.size(); i++) {
+            MessageCenter messageCenter = new MessageCenter();
+            messageCenter.setShopId(pro2.get(i).getShopID());
+            messageCenter.setClubId(null);
+            messageCenter.setUserType(2);
+            messageCenter.setMessageType(2);
+            messageCenter.setShopMessType(5);
+            messageCenter.setProductId(pro2.get(i).getProductID());
+            messageCenter.setContent("该商品的资质证书将于7天后失效,请及时登录采美网站上传新证书。");
+            messageCenter.setTime(curDateStr);
+            messageCenterDao.addMessageCenter(messageCenter);
+            if (i != 0) {
+                name += ",";
+                productID += ",";
             }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下供应商的上架费将于1个月后到期,请及时提醒供应商续费。");
-                notification.setShopContent(name);
-                notification.setShopID(shopID);
-                notificationDao.addNotification(notification);
-                name="";
-                shopID="";
+            name += "(" + pro2.get(i).getProductID().toString() + ")" + pro2.get(i).getName();
+            productID += pro2.get(i).getProductID().toString();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下械字号商品的资质证书将于7天后失效,请及时提醒供应商更换证书。");
+            notification.setShopContent(name);
+            notification.setPorductID(productID);
+            notificationDao.addNotification(notification);
+            name = "";
+            productID = "";
+        }
+        //械字号资质证书今日后过期
+        for (int i = 0; i < pro3.size(); i++) {
+            MessageCenter messageCenter = new MessageCenter();
+            messageCenter.setShopId(pro3.get(i).getShopID());
+            messageCenter.setClubId(null);
+            messageCenter.setUserType(2);
+            messageCenter.setMessageType(2);
+            messageCenter.setShopMessType(5);
+            messageCenter.setProductId(pro3.get(i).getProductID());
+            messageCenter.setContent("该商品的资质证书将于今天后失效,请及时登录采美网站上传新证书。");
+            messageCenter.setTime(curDateStr);
+            messageCenterDao.addMessageCenter(messageCenter);
+            if (i != 0) {
+                name += ",";
+                productID += ",";
             }
-//上架费7日后过期
-            for (int i=0;i<product2.size();i++){
-                if(i!=0){
-                    name+=",";
-                    shopID+=",";
-                }
-                name +=product2.get(i).getName();
-                shopID+=product2.get(i).getShopID();
+            name += "(" + pro3.get(i).getProductID().toString() + ")" + pro3.get(i).getName();
+            productID += pro3.get(i).getProductID().toString();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下械字号商品的资质证书将于今天后失效,请及时提醒供应商更换证书。");
+            notification.setShopContent(name);
+            notification.setPorductID(productID);
+            notificationDao.addNotification(notification);
+            name = "";
+            productID = "";
+        }
+        //上架费
+        for (int i = 0; i < product.size(); i++) {
+            if (i != 0) {
+                name += ",";
+                shopID += ",";
             }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下供应商的上架费将于7天后到期,请及时提醒供应商续费。");
-                notification.setShopContent(name);
-                notification.setShopID(shopID);
-                notificationDao.addNotification(notification);
-                name="";
-                shopID="";
+            name += product.get(i).getName();
+            shopID += product.get(i).getShopID();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下供应商的上架费将于3个月后到期,请及时提醒供应商续费。");
+            notification.setShopContent(name);
+            notification.setShopID(shopID);
+            notificationDao.addNotification(notification);
+            name = "";
+            shopID = "";
+        }
+        //上架费1个月后过期
+        for (int i = 0; i < product1.size(); i++) {
+            if (i != 0) {
+                name += ",";
+                shopID += ",";
             }
-//上架费今日后过期
-            for (int i=0;i<product3.size();i++){
-                if(i!=0){
-                    name+=",";
-                    shopID+=",";
-                }
-                name +=product3.get(i).getName();
-                shopID+=product3.get(i).getShopID();
+            name += product1.get(i).getName();
+            shopID += product1.get(i).getShopID();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下供应商的上架费将于1个月后到期,请及时提醒供应商续费。");
+            notification.setShopContent(name);
+            notification.setShopID(shopID);
+            notificationDao.addNotification(notification);
+            name = "";
+            shopID = "";
+        }
+        //上架费7日后过期
+        for (int i = 0; i < product2.size(); i++) {
+            if (i != 0) {
+                name += ",";
+                shopID += ",";
             }
-            if(!"".equals(name)){
-                Notification notification=new Notification();
-                notification.setTheme("以下供应商的上架费将于今天后到期,请及时提醒供应商续费。");
-                notification.setShopContent(name);
-                notification.setShopID(shopID);
-                notificationDao.addNotification(notification);
-                name="";
-                shopID="";
+            name += product2.get(i).getName();
+            shopID += product2.get(i).getShopID();
+        }
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下供应商的上架费将于7天后到期,请及时提醒供应商续费。");
+            notification.setShopContent(name);
+            notification.setShopID(shopID);
+            notificationDao.addNotification(notification);
+            name = "";
+            shopID = "";
+        }
+        //上架费今日后过期
+        for (int i = 0; i < product3.size(); i++) {
+            if (i != 0) {
+                name += ",";
+                shopID += ",";
             }
-//        }
-        jedis.lpush("constraint","1");
+            name += product3.get(i).getName();
+            shopID += product3.get(i).getShopID();
         }
-
+        if (!"".equals(name)) {
+            Notification notification = new Notification();
+            notification.setTheme("以下供应商的上架费将于今天后到期,请及时提醒供应商续费。");
+            notification.setShopContent(name);
+            notification.setShopID(shopID);
+            notificationDao.addNotification(notification);
+        }
+        jedis.lpush("constraint", "1");
     }
+}
 

+ 4 - 1
src/main/java/com/caimei/modules/user/dao/MessageCenterDao.java

@@ -5,9 +5,9 @@ import com.caimei.modules.user.entity.ClubChangeSp;
 import com.caimei.modules.user.entity.ClubTemporary;
 import com.caimei.modules.user.entity.CmUser;
 import com.caimei.modules.user.entity.MessageCenter;
+import com.caimei.po.User;
 import com.thinkgem.jeesite.common.persistence.CrudDao;
 import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
-import com.thinkgem.jeesite.modules.sys.entity.User;
 import com.caimei.modules.user.entity.MessageCenter;
 import com.thinkgem.jeesite.common.persistence.CrudDao;
 import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
@@ -47,4 +47,7 @@ public interface MessageCenterDao extends CrudDao<MessageCenter> {
 
     Integer count();
 
+    List<User> getNewUsers();
+
+    List<User> getUserInfo(Integer userId);
 }

+ 4 - 1
src/main/java/com/caimei/modules/user/entity/MessageCenter.java

@@ -1,8 +1,11 @@
 package com.caimei.modules.user.entity;
 
 import com.thinkgem.jeesite.common.persistence.DataEntity;
+import lombok.Data;
+import lombok.experimental.Accessors;
 
-
+@Accessors(fluent = true)
+@Data
 public class MessageCenter extends DataEntity<MessageCenter> {
 
 

+ 62 - 26
src/main/resources/mappings/modules/user/MessageCenter.xml

@@ -1,68 +1,104 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.modules.user.dao.MessageCenterDao">
-<!--    <insert id="addMessageCenter">-->
-<!--        INSERT INTO message_center (shopID, clubID, userType, messageType,content,time,accountType,orderID,orderMessageType,shopMessType)-->
-<!--        VALUES (#{shopId}, #{clubId}, #{userType}, #{messageType},#{content},#{time},#{accountType},#{orderID},#{orderMessageType},#{shopMessType})-->
-<!--    </insert>-->
+    <!--    <insert id="addMessageCenter">-->
+    <!--        INSERT INTO message_center (shopID, clubID, userType, messageType,content,time,accountType,orderID,orderMessageType,shopMessType)-->
+    <!--        VALUES (#{shopId}, #{clubId}, #{userType}, #{messageType},#{content},#{time},#{accountType},#{orderID},#{orderMessageType},#{shopMessType})-->
+    <!--    </insert>-->
     <insert id="addMessageCenter">
-        INSERT INTO message_center (shopID, clubID, userType, messageType, content,time,accountType,couponType,couponFee,couponMessageType,orderID,orderMessageType,shopMessType,productId)
-        VALUES (#{shopId}, #{clubId}, #{userType}, #{messageType}, #{content},#{time},#{accountType},#{couponType},#{couponFee},#{couponMessageType},#{orderId},#{orderMessageType},#{shopMessType},#{productId})
+        INSERT INTO message_center (shopID, clubID, userType, messageType, content, time, accountType, couponType,
+                                    couponFee, couponMessageType, orderID, orderMessageType, shopMessType, productId)
+        VALUES (#{shopId}, #{clubId}, #{userType}, #{messageType}, #{content}, #{time}, #{accountType}, #{couponType},
+                #{couponFee}, #{couponMessageType}, #{orderId}, #{orderMessageType}, #{shopMessType}, #{productId})
     </insert>
 
     <select id="clubIdCule" resultType="java.lang.Integer">
-        SELECT clubID FROM `club` WHERE userId=#{userId}
+        SELECT clubID
+        FROM `club`
+        WHERE userId = #{userId}
     </select>
 
     <select id="contractMobile" resultType="java.lang.String">
-        SELECT contractMobile FROM club WHERE userID=#{UserID}
+        SELECT contractMobile
+        FROM club
+        WHERE userID = #{UserID}
     </select>
 
     <select id="Mobile" resultType="java.lang.String">
-        SELECT contractMobile FROM shop WHERE shopID=#{shopID}
+        SELECT contractMobile
+        FROM shop
+        WHERE shopID = #{shopID}
     </select>
 
 
     <select id="clubList" resultType="com.caimei.modules.user.entity.CmUser">
-        SELECT * FROM `user` WHERE clubId=#{clubId}  LIMIT 1
+        SELECT *
+        FROM `user`
+        WHERE clubId = #{clubId}
+        LIMIT 1
     </select>
     <select id="shopID" resultType="java.lang.Integer">
-        SELECT shopID FROM `product` WHERE productID=#{productID}
+        SELECT shopID
+        FROM `product`
+        WHERE productID = #{productID}
     </select>
 
     <select id="shopName" resultType="java.lang.String">
-        SELECT name FROM shop where shopID=#{shopID}
+        SELECT name
+        FROM shop
+        where shopID = #{shopID}
     </select>
 
     <select id="ClubIds" resultType="java.lang.Integer">
-        SELECT DISTINCT clubID FROM `user` WHERE YEAR(loginTime)>YEAR(NOW())-3 AND clubID IS NOT NULL
-        ORDER BY clubID DESC
+        SELECT DISTINCT clubid, loginTime
+        FROM user
+        WHERE DATE_ADD(loginTime, INTERVAL 3 YEAR) > NOW()
+          AND clubstatus = 90
+          AND clubId IS NOT NULL
+        ORDER BY logintime DESC
     </select>
 
     <select id="userID" resultType="java.lang.Integer">
-        select userID from shop where shopID=#{shopID}
+        select userID
+        from shop
+        where shopID = #{shopID}
     </select>
 
     <select id="CouponList" resultType="com.caimei.modules.coupon.entity.CmCoupon">
-        SELECT * FROM cm_coupon WHERE couponType=#{couponType}
-                                  AND NOW() >= startDate
-                                  AND endDate >= NOW()
-                                  AND status=1
-                                  AND delFlag=0
+        SELECT *
+        FROM cm_coupon
+        WHERE couponType = #{couponType}
+          AND NOW() >= startDate
+          AND endDate >= NOW()
+          AND status = 1
+          AND delFlag = 0
         ORDER BY id DESC
         LIMIT 1
     </select>
 
     <select id="couponTime" resultType="com.caimei.modules.coupon.entity.CmCoupon">
-        SELECT * FROM `cm_coupon` WHERE
-            NOW() >= startDate
-            AND endDate >= NOW()
-            AND STATUS = 1
-            AND delFlag=0
+        SELECT *
+        FROM `cm_coupon`
+        WHERE NOW() >= startDate
+          AND endDate >= NOW()
+          AND STATUS = 1
+          AND delFlag = 0
     </select>
 
     <select id="count" resultType="integer">
-        SELECT COUNT(*) FROM `notification` WHERE saved=0
+        SELECT COUNT(*)
+        FROM `notification`
+        WHERE saved = 0
+    </select>
+    <select id="getNewUsers" resultType="com.caimei.po.User">
+        select userID, clubID, bindMobile
+        from user
+        where DATE_ADD(registerTime, INTERVAL 6 MONTH) > NOW()
+    </select>
+    <select id="getUserInfo" resultType="com.caimei.po.User">
+        select userId, clubId, bindMobile
+        from user
+        where userId = #{userId}
     </select>