Przeglądaj źródła

Merge branch 'dev' into feature-201813-liusw

liusw 7 lat temu
rodzic
commit
344a5e4d03

+ 6 - 0
pom.xml

@@ -101,6 +101,12 @@
             <artifactId>junit-jupiter-api</artifactId>
             <version>RELEASE</version>
         </dependency>
+        <dependency>
+            <groupId>org.quartz-scheduler</groupId>
+            <artifactId>quartz</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 80 - 0
src/main/java/com/uas/ps/inquiry/SchedulingConfig.java

@@ -0,0 +1,80 @@
+package com.uas.ps.inquiry;
+
+import com.uas.ps.core.util.CollectionUtils;
+import com.uas.ps.inquiry.dao.CronDao;
+import com.uas.ps.inquiry.model.Cron;
+import com.uas.ps.inquiry.model.InquiryRemind;
+import com.uas.ps.inquiry.service.impl.InquiryServiceImpl;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.Trigger;
+import org.springframework.scheduling.TriggerContext;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.util.StringUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * created by shicr on 2018/6/8
+ **/
+@Configuration
+@EnableScheduling
+public class SchedulingConfig implements SchedulingConfigurer {
+
+    private final Logger logger = Logger.getLogger(Logger.class);
+
+    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");
+
+    @Autowired
+    private CronDao cronDao;
+
+    private String cornStr = "";
+
+    @Autowired
+    private InquiryServiceImpl service;
+
+    @Override
+    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
+
+
+        scheduledTaskRegistrar.addTriggerTask(new Runnable() {
+
+
+            @Override
+            public void run() {
+                Cron cron = cronDao.findOne(1L);
+                List<InquiryRemind> reminds = new ArrayList<>();
+                logger.info("动态修改定时任务cron参数,当前时间:" + DATE_FORMAT.format(new Date()));
+                if(null != cron.getCron() && cron.getStartTime() != null && cron.getEndTime() != null && cron.getEnuu() != null && cron.getUseruu() != null){
+                    reminds = service.testMessage(cron.getStartTime(), cron.getEndTime(), cron.getUseruu(),cron.getEnuu());
+//                    reminds = service.findInquiryRemindGroupByVendUUAndVendUserUU(5);
+                }
+
+                if(!CollectionUtils.isEmpty(reminds)){
+                    service.sendMessage(reminds.size(), reminds);
+                }
+            }
+        }, new Trigger() {
+            @Override
+            public Date nextExecutionTime(TriggerContext triggerContext) {
+                Cron cron = cronDao.findOne(1L);
+                if (cron != null && !StringUtils.isEmpty(cron.getCron())) {
+                    cornStr = cron.getCron();
+                }
+                CronTrigger trigger = new CronTrigger(cron.getCron());
+                Date nextExecDate = trigger.nextExecutionTime(triggerContext);
+                logger.info("下次执行自动推送时间: " + DATE_FORMAT.format(nextExecDate));
+                return nextExecDate;
+            }
+        });
+    }
+
+
+}

+ 84 - 13
src/main/java/com/uas/ps/inquiry/controller/DeadlineTask.java

@@ -7,8 +7,9 @@ import com.uas.ps.inquiry.dao.EnterpriseDao;
 import com.uas.ps.inquiry.dao.PurcInquiryItemDao;
 import com.uas.ps.inquiry.entity.MessageModel;
 import com.uas.ps.inquiry.model.Enterprise;
+import com.uas.ps.inquiry.model.InquiryRemind;
 import com.uas.ps.inquiry.model.PublicInquiryItem;
-import com.uas.ps.inquiry.model.PurcInquiryItem;
+import com.uas.ps.inquiry.service.InquiryService;
 import com.uas.ps.inquiry.util.FlexJsonUtils;
 import com.uas.ps.inquiry.util.HttpUtil;
 import com.uas.ps.inquiry.util.ThreadUtils;
@@ -20,15 +21,14 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
+import java.util.Calendar;
 import java.util.List;
 
 /**
  * 求购截止,每日晚上轮询一次
  *
- * @param
+ * @version 2018年6月12日 15:00  询价短信定时发送的任务移到这里  dongbw
 
  */
 @Component
@@ -41,17 +41,41 @@ public class DeadlineTask {
     @Autowired
     private EnterpriseDao enterpriseDao;
 
+    @Autowired
+    private InquiryService inquiryService;
+
     private static final Logger log = Logger.getLogger(Logger.class);
 
-    /**
-     * 公共消息访问地址
-     */
-    private final String PS_MESSAGE_URL = ContextUtils.getBean(AccessConfiguration.class).getPsMessageUrl();
     /**
      * 消息类型,公共询价的采纳结果
      */
     private final String INQUIRY_DECIDE_TYPE_MALL = "商城公共询价采纳结果";
 
+    /**
+     * 接收应用
+     */
+    private final String CONSUMERAPP_B2B_MALL = "B2B,MALL";
+
+    /**
+     * 应用来源,主要是为了平台公共询价做处理
+     */
+    private String SOURCEAPP_MALL = "MALL";
+
+    /**
+     * 消息类型 (在B2B消息中拼接跳转单据详情url请求时需要)
+     */
+    private final String INQUIRY_TYPE = "公共询价";
+
+    /**
+     * 消息推送短信模板id
+     */
+    private final String SMS_TEMP_ID = "e6320a3c-89ac-4c77-a75f-62a727bce654";
+
+    /**
+     * 消息推送方式:邮件、短信、im
+     */
+    private final String SMS_TYPE = "MAIL_AND_SM_AND_IM";
+
     /**
      * 消费类型: 多个,MULTI
      */
@@ -60,12 +84,27 @@ public class DeadlineTask {
     /**
      * 接收应用
      */
-    private final String CONSUMERAPP = "B2B,MALL";
+    private final String CONSUMERAPP_HIDE = "HIDE";
 
     /**
-     * 应用来源,主要是为了平台公共询价做处理
+     * 消息类型 (在MALL消息中拼接求购询价待报价)
+     */
+    private final String INQUIRY_TYPE_SELLER_MALL = "MALL跳转卖家待报价页面";
+
+    /**
+     * 公共消息访问地址
+     */
+    private final String PS_MESSAGE_URL = ContextUtils.getBean(AccessConfiguration.class).getPsMessageUrl();
+
+    /**
+     * 询价统计通知发送人UU
+     */
+    private final Long MESSAGE_SENDERUU = ContextUtils.getBean(AccessConfiguration.class).getSenderuu();
+
+    /**
+     * 询价统计通知发送企业UU
      */
-    private String sourceApp = "MALL";
+    private final Long MESSAGE_SENDERENUU = ContextUtils.getBean(AccessConfiguration.class).getSenderEnuu();
 
     @Scheduled(cron =  "0 30 23 ? * *" )//每天23:30分执行
     public void execute(){
@@ -78,9 +117,9 @@ public class DeadlineTask {
                 String content= param.getInquiry().getEnName()+"关于“型号:"+ cmp +"“的求购【已截止】,您的报价尚未被采纳。";
                 MessageModel model = new MessageModel();
                 model.setType(INQUIRY_DECIDE_TYPE_MALL);
-                model.setProducerApp(sourceApp);
+                model.setProducerApp(SOURCEAPP_MALL);
                 model.setConsumerType(CUST_TYPE);
-                model.setConsumerApp(CONSUMERAPP);
+                model.setConsumerApp(CONSUMERAPP_B2B_MALL);
                 model.setContent(content);
                 model.setRemark(String.valueOf(param.getInquiry().getId()));
                 model.setSourceId(param.getId());
@@ -101,6 +140,7 @@ public class DeadlineTask {
 
         }
     }
+
     /**
      * 发送消息推送
      *
@@ -120,4 +160,35 @@ public class DeadlineTask {
             }
         }).run();
     }
+
+    /**
+     * 每早9点、14点、17点发送询价通知短信
+     */
+    @Scheduled(cron = "0 0 9,14,17 * * ?" )
+    private void sendMessageTiming() throws Exception {
+        Calendar now = Calendar.getInstance();
+        Integer hour = now.get(Calendar.HOUR_OF_DAY);
+        log.info(hour + "点定时统计询价单总数服务开启");
+        List<InquiryRemind> reminds = new ArrayList<>();
+        switch (hour) {
+            case 9 :
+                reminds = inquiryService. findInquiryRemindGroupByVendUUAndVendUserUU(16);
+                break;
+            case 14 :
+                reminds = inquiryService.findInquiryRemindGroupByVendUUAndVendUserUU(5);
+                break;
+            case 17 :
+                reminds = inquiryService.findInquiryRemindGroupByVendUUAndVendUserUU(3);
+                break;
+            default:
+                reminds = inquiryService.findInquiryRemindGroupByVendUUAndVendUserUU(5);
+                break;
+        }
+
+        if(!CollectionUtils.isEmpty(reminds)){
+            inquiryService.sendMessage(reminds);
+        }
+        log.info(hour + "点定时统计询价单总数服务结束");
+    }
+
 }

+ 15 - 0
src/main/java/com/uas/ps/inquiry/dao/CronDao.java

@@ -0,0 +1,15 @@
+package com.uas.ps.inquiry.dao;
+
+import com.uas.ps.inquiry.model.Cron;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+
+/**
+ * created by shicr on 2018/6/8
+ **/
+@Repository
+public interface CronDao extends JpaRepository<Cron,Long>,JpaSpecificationExecutor<Cron> {
+
+}

+ 34 - 19
src/main/java/com/uas/ps/inquiry/dao/InquiryRemindDao.java

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository;
 
 import javax.transaction.Transactional;
 import java.math.BigInteger;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -24,15 +25,15 @@ public interface InquiryRemindDao extends JpaRepository<InquiryRemind, Long>, Jp
      * 通过vendUU和公共询价明细id更新该单据的状态
      *
      * @param sourceId 公共询价明细id
-     * @param value 单据状态
-     *              <note>
-     *                  {@code 100 在录入}
-     *                  {@code 101 已提交}
-     *                  {@code 102 已审核}
-     *                  {@code 103 未通过}
-     *                  {@code 104 已通过}
-     *              </note>
-     * @param vendUU 被推荐的企业
+     * @param value    单据状态
+     *                 <note>
+     *                 {@code 100 在录入}
+     *                 {@code 101 已提交}
+     *                 {@code 102 已审核}
+     *                 {@code 103 未通过}
+     *                 {@code 104 已通过}
+     *                 </note>
+     * @param vendUU   被推荐的企业
      */
     @Transactional
     @Modifying
@@ -62,45 +63,59 @@ public interface InquiryRemindDao extends JpaRepository<InquiryRemind, Long>, Jp
      * 通过被推荐的企业UU,个人UU,来源id判断单据是否存在
      *
      * @param vendUserUU 推荐的企业UU
-     * @param vendUU 个人UU
-     * @param itemId 来源id
+     * @param vendUU     个人UU
+     * @param itemId     来源id
      */
     List<InquiryRemind> findByVendUserUUAndVendUUAndItemId(Long vendUserUU, Long vendUU, Long itemId);
 
     /**
      * 查出昨晚17点到今早九点的询价信息
+     *
      * @param venduseruu
      * @param venduu
      */
-    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -16 HOUR) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2 and ir_enuu != ir_venduu",nativeQuery = true)
-    List<InquiryRemind> findInquiryRemind(BigInteger venduseruu,BigInteger venduu);
+    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -16 HOUR) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2 and ir_enuu != ir_venduu", nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind(BigInteger venduseruu, BigInteger venduu);
 
     /**
      * 查出今早9点到14点的询价信息
+     *
      * @param venduseruu
      * @param venduu
      */
-    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -5 hour) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2  and ir_enuu != ir_venduu ",nativeQuery = true)
-    List<InquiryRemind> findInquiryRemind1(BigInteger venduseruu,BigInteger venduu);
+    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -5 hour) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2  and ir_enuu != ir_venduu ", nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind1(BigInteger venduseruu, BigInteger venduu);
 
     /**
      * 查出14点到17点的询价信息
+     *
      * @param venduseruu
      * @param venduu
      */
-    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -3 hour) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2 and ir_enuu != ir_venduu",nativeQuery = true)
-    List<InquiryRemind> findInquiryRemind2(BigInteger venduseruu,BigInteger venduu);
+    @Query(value = "select * from purc$inquiry$remind where ir_date > date_add(now(),interval -3 hour) and ir_date < now() and ir_venduseruu =?1 and ir_venduu = ?2 and ir_enuu != ir_venduu", nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind2(BigInteger venduseruu, BigInteger venduu);
 
     /**
      * 找到询价推荐表中所有的用户
      */
-    @Query(value = "select ir_venduseruu from purc$inquiry$remind group by ir_venduseruu",nativeQuery = true)
+    @Query(value = "select ir_venduseruu from purc$inquiry$remind group by ir_venduseruu", nativeQuery = true)
     List<BigInteger> findvenduseruu();
 
     /**
      * 找到询价推荐表中的所有公司
      */
-    @Query(value = "select ir_venduu from purc$inquiry$remind group by ir_venduu",nativeQuery = true)
+    @Query(value = "select ir_venduu from purc$inquiry$remind group by ir_venduu", nativeQuery = true)
     List<BigInteger> findvenduu();
 
+    /**
+     * 可配置测试接口
+     * @param startTime
+     * @param endTime
+     * @param useruu
+     * @param enuu
+     * @return
+     */
+    @Query(value = "select * from purc$inquiry$remind where ir_date between ?1 and ?2 and ir_venduseruu =?3 and ir_venduu = ?4",nativeQuery = true)
+    List<InquiryRemind> findTestInfo(Date startTime, Date endTime, Long useruu, Long enuu);
+
 }

+ 110 - 0
src/main/java/com/uas/ps/inquiry/model/Cron.java

@@ -0,0 +1,110 @@
+package com.uas.ps.inquiry.model;
+
+
+import javax.persistence.*;
+import java.util.Date;
+
+/**
+ * created by shicr on 2018/6/8
+ **/
+@Entity
+@Table(name = "cron")
+public class Cron {
+
+    @Id
+    @Column(name = "cr_id")
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+
+    /**
+     * 任务定时
+     */
+    @Column(name = "cr_cron")
+    private String cron;
+
+    /**
+     * 备注
+     */
+    @Column(name = "cr_remark")
+    private String remark;
+
+    /**
+     * 用户UU
+     */
+    @Column(name = "useruu")
+    private Long useruu;
+
+    /**
+     * 企业UU
+     */
+    @Column(name = "enuu")
+    private Long enuu;
+
+    /**
+     * 开始时间
+     */
+    @Column(name = "startTime")
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @Column(name = "endTime")
+    private Date endTime;
+
+    public Long getUseruu() {
+        return useruu;
+    }
+
+    public void setUseruu(Long useruu) {
+        this.useruu = useruu;
+    }
+
+    public Long getEnuu() {
+        return enuu;
+    }
+
+    public void setEnuu(Long enuu) {
+        this.enuu = enuu;
+    }
+
+    public Date getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Date startTime) {
+        this.startTime = startTime;
+    }
+
+    public Date getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCron() {
+        return cron;
+    }
+
+    public void setCron(String cron) {
+        this.cron = cron;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 5 - 0
src/main/java/com/uas/ps/inquiry/model/InquiryLog.java

@@ -195,4 +195,9 @@ public class InquiryLog extends BufferedLogable implements Serializable {
         this.date = System.currentTimeMillis();
         this.source = source;
     }
+
+    public InquiryLog(String title, String message){
+        this.title = title;
+        this.message = message;
+    }
 }

+ 14 - 0
src/main/java/com/uas/ps/inquiry/model/InquiryRemind.java

@@ -180,6 +180,12 @@ public class InquiryRemind implements Serializable {
     @Transient
     private PublicInquiryItem quotation;
 
+    /**
+     * 发送消息时,记录条数
+     */
+    @Transient
+    private Integer counts;
+
     public String getInbrand() {
         return inbrand;
     }
@@ -374,4 +380,12 @@ public class InquiryRemind implements Serializable {
     public void setQuotation(PublicInquiryItem quotation) {
         this.quotation = quotation;
     }
+
+    public Integer getCounts() {
+        return counts;
+    }
+
+    public void setCounts(Integer counts) {
+        this.counts = counts;
+    }
 }

+ 26 - 0
src/main/java/com/uas/ps/inquiry/service/InquiryService.java

@@ -8,6 +8,9 @@ import com.uas.ps.inquiry.page.SearchFilter;
 import javassist.NotFoundException;
 import org.springframework.data.domain.Page;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * 转询价报价后的数据查询
  *
@@ -99,4 +102,27 @@ public interface InquiryService {
      * @return
      */
     PurcInquiryItemInfo findQuotationById(Long id);
+
+    /**
+     * 测试消息
+     * @param startTime
+     * @param endTime
+     * @param useruu
+     * @param enuu
+     * @return
+     */
+    List<InquiryRemind> testMessage(Date startTime, Date endTime, Long useruu, Long enuu);
+
+    /**
+     * 根据商机发送消息
+     * @param reminds 商机List
+     */
+    void sendMessage(List<InquiryRemind> reminds);
+
+    /**
+     * 以供应商企业UU和用户UU分组查询商机
+     * @param hours  查之前多少小时内的单据
+     * @return 商机List
+     */
+    List<InquiryRemind> findInquiryRemindGroupByVendUUAndVendUserUU(int hours);
 }

+ 128 - 123
src/main/java/com/uas/ps/inquiry/service/impl/InquiryServiceImpl.java

@@ -43,12 +43,13 @@ import com.uas.ps.inquiry.util.FlexJsonUtils;
 import com.uas.ps.inquiry.util.HttpUtil;
 import com.uas.ps.inquiry.util.ThreadUtils;
 import javassist.NotFoundException;
+import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -56,7 +57,6 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
@@ -77,22 +77,6 @@ public class InquiryServiceImpl implements InquiryService {
      */
     private final String INQUIRY_TYPE = "公共询价";
 
-    /**
-     * 应用来源
-     */
-    private final String SOURCERAPP = "MALL";
-
-    /**
-     * 消息类型,公共询价的采纳结果
-     */
-    private final String INQUIRY_DECIDE_TYPE = "公共询价采纳结果";
-
-    /**
-     * 询价种类
-     */
-    private final String INQUIRYKIND = "publicInquiry";
-
-
     /**
      * 消息推送短信模板id
      */
@@ -104,19 +88,19 @@ public class InquiryServiceImpl implements InquiryService {
     private final String SMS_TYPE = "MAIL_AND_SM_AND_IM";
 
     /**
-     * 来源应用,ERP
+     * 消费类型: 多个,MULTI
      */
-    private final String PRODUCERAPP = "ERP";
+    private final String CUST_TYPE = "MULTI";
 
     /**
-     * 消费类型: 多个,MULTI
+     * 应用来源,主要是为了平台公共询价做处理
      */
-    private final String CUST_TYPE = "MULTI";
+    private String SOURCEAPP_MALL = "MALL";
 
     /**
      * 接收应用
      */
-    private final String CONSUMERAPP = "HIDE";
+    private final String CONSUMERAPP_HIDE = "HIDE";
 
     /**
      * 消息类型 (在MALL消息中拼接求购询价待报价)
@@ -185,6 +169,8 @@ public class InquiryServiceImpl implements InquiryService {
      */
     private final static InquiryBufferedLogger logger = BufferedLoggerManager.getLogger(InquiryBufferedLogger.class);
 
+    private static final Logger log = Logger.getLogger(Logger.class);
+
     /**
      * 查询公共询价列表信息
      *
@@ -343,107 +329,14 @@ public class InquiryServiceImpl implements InquiryService {
     }
 
     /**
-     * 每早9点发送询价通知短信
-     */
-    @Scheduled(cron = "0 0 9 * * ?" )
-    private void sendMessage() throws Exception {
-
-            List<BigInteger> list1 = inquiryRemindDao.findvenduseruu();
-            //找到询价推荐表中的所有公司
-            List<BigInteger> list2 = inquiryRemindDao.findvenduu();
-            for(BigInteger vendUserUU : list1){
-                for(BigInteger enuu : list2){
-                    //查出昨晚17点到今早九点的询价信息
-                    List<InquiryRemind> reminds = inquiryRemindDao.findInquiryRemind(vendUserUU,enuu);
-                    if(!CollectionUtils.isEmpty(reminds)){
-                            sendMessage(reminds.size(),reminds);
-                    }
-                }
-            }
-    }
-
-
-    /**
-     * 发送消息推送
-     *
-     */
-    private void sendMessage(final Integer count, final List<InquiryRemind> reminds) {
-        ThreadUtils.task(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    List<MessageModel> models = new ArrayList<>();
-                    MessageModel model = new MessageModel();
-                    model.setType(INQUIRY_TYPE);
-                    model.setType(INQUIRY_TYPE_SELLER_MALL);
-                    model.setProducerApp("MALl");
-                    model.setConsumerType(CUST_TYPE);
-                    model.setConsumerApp(CONSUMERAPP);
-                    model.setRemark(String.valueOf(count));
-                    for(InquiryRemind remind : reminds){
-                        model.setReceiverEnuu(remind.getVendUU());
-                        model.setReceiverUu(remind.getVendUserUU());
-                        model.setSenderEnuu(MESSAGE_SENDERENUU);
-                        model.setSenderUu(MESSAGE_SENDERUU);
-                    }
-                    String company = "";
-                    Enterprise enterprise = enterpriseDao.findOne(reminds.get(0).getVendUU());
-                    if(null != enterprise){
-                        company = enterprise.getEnName();
-                    }
-                    String content = company + "新增了"+ count +"张公共询价单,快登录优软商城查看详情吧!https://www.usoftmall.com/vendor#/seekPurchase";
-                    model.setContent(content);
-                    model.setSmsType(SMS_TYPE);
-                    model.setSmTemplate(SMS_TEMP_ID);
-                    models.add(model);
-                    String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
-                    System.out.println(res);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }).run();
-    }
-
-
-    /**
-     *  每天下午2点发送询价通知短信
-     */
-    @Scheduled(cron = "0 0 14 * * ?" )
-    private void sendMessage2(){
-
-        List<BigInteger> list1 = inquiryRemindDao.findvenduseruu();
-        //找到询价推荐表中的所有公司
-        List<BigInteger> list2 = inquiryRemindDao.findvenduu();
-        for(BigInteger vendUserUU : list1){
-            for(BigInteger enuu : list2){
-                //查出昨晚17点到今早九点的询价信息
-                List<InquiryRemind> reminds = inquiryRemindDao.findInquiryRemind1(vendUserUU,enuu);
-                if(!CollectionUtils.isEmpty(reminds)){
-                    sendMessage(reminds.size(),reminds);
-                }
-            }
-        }
-    }
-
-    /**
-     * 每天下午5点发送询价通知短信
+     * 可配置的定时任务
      */
-    @Scheduled(cron = "0 0 17 * * ?" )
-    private void sendMessage3(){
-
-        List<BigInteger> list1 = inquiryRemindDao.findvenduseruu();
-        //找到询价推荐表中的所有公司
-        List<BigInteger> list2 = inquiryRemindDao.findvenduu();
-        for(BigInteger vendUserUU : list1){
-            for(BigInteger enuu : list2){
-                //查出昨晚17点到今早九点的询价信息
-                List<InquiryRemind> reminds = inquiryRemindDao.findInquiryRemind2(vendUserUU,enuu);
-                if(!CollectionUtils.isEmpty(reminds)){
-                    sendMessage(reminds.size(),reminds);
-                }
-            }
-        }
+    @Override
+    public List<InquiryRemind> testMessage(Date startTime, Date endTime, Long useruu, Long enuu){
+        logger.log("公共询价","9点定时统计询价单总数服务开启");
+        List<InquiryRemind> list = inquiryRemindDao.findTestInfo(startTime,endTime,useruu,enuu);
+        logger.log("公共询价","9点定时统计询价单总数服务结束");
+        return list;
     }
 
     /**
@@ -874,4 +767,116 @@ public class InquiryServiceImpl implements InquiryService {
         }
         return itemInfo;
     }
+
+    /**
+     * 发送消息推送
+     *
+     */
+    public void sendMessage(final Integer count, final List<InquiryRemind> reminds) {
+        ThreadUtils.task(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    List<MessageModel> models = new ArrayList<>();
+                    MessageModel model = new MessageModel();
+                    model.setType(INQUIRY_TYPE);
+                    model.setType(INQUIRY_TYPE_SELLER_MALL);
+                    model.setProducerApp("MALl");
+                    model.setConsumerType(CUST_TYPE);
+                    model.setConsumerApp(CONSUMERAPP_HIDE);
+                    model.setRemark(String.valueOf(count));
+                    for(InquiryRemind remind : reminds){
+                        model.setReceiverEnuu(remind.getVendUU());
+                        model.setReceiverUu(remind.getVendUserUU());
+                        model.setSenderEnuu(MESSAGE_SENDERENUU);
+                        model.setSenderUu(MESSAGE_SENDERUU);
+                    }
+                    String company = "";
+                    Enterprise enterprise = enterpriseDao.findOne(reminds.get(0).getVendUU());
+                    if(null != enterprise){
+                        company = enterprise.getEnName();
+                    }
+                    String content = company + "新增了"+ count +"张公共询价单,快登录优软商城查看详情吧!https://www.usoftmall.com/vendor#/seekPurchase";
+                    model.setContent(content);
+                    model.setSmsType(SMS_TYPE);
+                    model.setSmTemplate(SMS_TEMP_ID);
+                    models.add(model);
+                    String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
+                    System.out.println(FlexJsonUtils.toJsonDeep(models));
+                    System.out.println(res);
+                    logger.log("公共询价", "此次"+company+"公司新增"+count+"张公共询价");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }).run();
+    }
+
+    /**
+     * 发送消息推送
+     *
+     */
+    @Override
+    public void sendMessage(final List<InquiryRemind> reminds) {
+        ThreadUtils.task(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    log.info("发送消息开始");
+                    List<MessageModel> models = new ArrayList<>();
+                    for (InquiryRemind remind : reminds) {
+                        if (null != remind.getVendUU() && null != remind.getVendUserUU()) {
+                            Integer count = remind.getCounts();
+                            MessageModel model = new MessageModel();
+                            model.setType(INQUIRY_TYPE);
+                            model.setType(INQUIRY_TYPE_SELLER_MALL);
+                            model.setProducerApp(SOURCEAPP_MALL);
+                            model.setConsumerType(CUST_TYPE);
+                            model.setConsumerApp(CONSUMERAPP_HIDE);
+                            model.setRemark(String.valueOf(count));
+                            model.setReceiverEnuu(remind.getVendUU());
+                            model.setReceiverUu(remind.getVendUserUU());
+                            model.setSenderEnuu(MESSAGE_SENDERENUU);
+                            model.setSenderUu(MESSAGE_SENDERUU);
+                            String company = "";
+                            Enterprise enterprise = enterpriseDao.findOne(remind.getVendUU());
+                            if(null != enterprise){
+                                company = enterprise.getEnName();
+                            }
+                            String content = company + "新增了"+ count +"张公共询价单,快登录优软商城查看详情吧!https://www.usoftmall.com/vendor#/seekPurchase";
+                            model.setContent(content);
+                            model.setSmsType(SMS_TYPE);
+                            model.setSmTemplate(SMS_TEMP_ID);
+                            models.add(model);
+                            log.info("此次" + company + "公司新增" + remind.getCounts() + "张公共询价(发送信息前)");
+                        }
+                        if (models.size() >= 500) {
+                            String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
+                            log.info("发送消息" + models.size());
+                            models = new ArrayList<>();
+                        }
+                    }
+                    if (!CollectionUtils.isEmpty(models)) {
+                        String res = HttpUtil.doPost(PS_MESSAGE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
+                        log.info("发送消息" + models.size());
+                    }
+                    log.info("发送消息全部完成");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }).run();
+    }
+
+    /**
+     * 以供应商企业UU和用户UU分组查询商机
+     * @param hours  查之前多少小时内的单据
+     * @return 商机List
+     */
+    @Override
+    public List<InquiryRemind> findInquiryRemindGroupByVendUUAndVendUserUU(int hours) {
+        String sql = "select ir_venduu vendUU,ir_venduseruu vendUserUU, count(1) counts from purc$inquiry$remind where ir_date between date_sub(now(), interval "
+                + hours + " hour) and now() group by ir_venduu,ir_venduseruu";
+        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<InquiryRemind>(InquiryRemind.class));
+    }
 }

+ 0 - 1
src/main/java/com/uas/ps/inquiry/service/impl/readme.md

@@ -1 +0,0 @@
-#公共询价服务实现层

+ 9 - 0
src/main/java/com/uas/ps/inquiry/support/InquiryBufferedLogger.java

@@ -29,4 +29,13 @@ public class InquiryBufferedLogger extends BufferedLogger<InquiryLog> {
     public void log(String title, String message, String detail, Long userUU, Long enUU, String source) {
         log(new InquiryLog(title, message, detail, userUU, enUU, source));
     }
+
+    /**
+     * 用户操作日志
+     * @param title
+     * @param message
+     */
+    public void log(String title, String message){
+        log(new InquiryLog(title,message));
+    }
 }

+ 93 - 0
src/main/java/com/uas/ps/inquiry/util/MessageUtils.java

@@ -0,0 +1,93 @@
+package com.uas.ps.inquiry.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.ps.core.util.ContextUtils;
+import com.uas.ps.inquiry.AccessConfiguration;
+import com.uas.ps.inquiry.entity.MessageModel;
+import org.apache.log4j.Logger;
+import org.springframework.http.HttpStatus;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * 对接公共消息服务的接口
+ *
+ * @author dongbw
+ * 2018-01-22 15:43:41
+ * @version 2018年6月13日 11:28:50 从B2B dongbw
+ */
+public class MessageUtils {
+
+
+    private static final String MESSAGE_PUBLIC_SERVICE_URL = ContextUtils.getBean(AccessConfiguration.class).getPsMessageUrl();
+
+    private static final Logger log = Logger.getLogger(Logger.class);
+
+    /**
+     * 单次请求数据量大小
+     */
+    private static final int ONE_TIME_DATA_SIZE = 500;
+
+    /**
+     * 产生消息
+     * @param models  消息实体List
+     * @return 返回信息
+     */
+    public static String paginationProduceMessage(List<MessageModel> models) throws Exception {
+        if (models.size() < ONE_TIME_DATA_SIZE) {
+            return produceMessage(models);
+        } else {
+            String res = "";
+            for (int i = 0; i < models.size(); i = i + ONE_TIME_DATA_SIZE) {
+                if (i + ONE_TIME_DATA_SIZE < models.size()) {
+                    res = produceMessage(models.subList(i, i + ONE_TIME_DATA_SIZE));
+                } else {
+                    res = produceMessage(models.subList(i, models.size()));
+                }
+            }
+            return res;
+        }
+    }
+
+    /**
+     * 获取当前企业当前用户未读消息数量
+     *
+     * @author dongbw
+     * @param enUU 企业UU
+     * @param userUU 用户UU
+     * @return
+     * @throws Exception
+     */
+    public static Integer getMessageNotReadNum(Long enUU, Long userUU) throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("receiverUu", userUU);
+        params.put("receiverEnuu", enUU);
+        params.put("consumerApp", "B2B");
+        HttpUtil.Response res = HttpUtil.sendGetRequest(MESSAGE_PUBLIC_SERVICE_URL + "/messages/count/unread", params);
+        if (res.getStatusCode() == HttpStatus.OK.value() && null != res.getResponseText()) {
+            JSONObject jsonObject = JSON.parseObject(res.getResponseText());
+            return (Integer) jsonObject.get("count");
+        } else {
+            throw new RuntimeException("获取消息失败");
+        }
+    }
+
+    /**
+     * 产生消息
+     * @param models  消息实体List
+     * @return 返回信息
+     */
+    public static String produceMessage(List<MessageModel> models) throws Exception {
+        try {
+            String res = HttpUtil.doPost(MESSAGE_PUBLIC_SERVICE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
+            log.info("发送消息" + models.size());
+            return res;
+        } catch (Exception e) {
+            throw  new RuntimeException("本次产生消息失败");
+        }
+    }
+
+    //TODO 调用消息服务的方法都迁移到工具类中
+}

+ 2 - 2
src/main/resources/config/application-cloud.properties

@@ -24,5 +24,5 @@ ps.message.url=http://api-message.ubtob.com/
 mall.url = https://www.usoftmall.com/
 
 #message
-message.senderuu=2000002849
-message.senderEnuu=20000682
+message.senderuu=1000010022
+message.senderEnuu=10042875

+ 3 - 3
src/main/resources/config/application-dev.properties

@@ -19,7 +19,7 @@ datasource.filters=stat,slf4j
 datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMillis=5000
 
 # Access path
-#ps.product.url=http://192.168.253.12:24000/product/
+#ps.product.url=http://192.168.253.12:24000/
 #dong localhost
 ps.product.url=http://192.168.253.12:24000/
 ps.message.url=http://192.168.253.12:24000/message/
@@ -28,5 +28,5 @@ ps.message.url=http://192.168.253.12:24000/message/
 mall.url = http://192.168.253.12:23400/
 
 #message
-message.senderuu=2000002849
-message.senderEnuu=20000682
+message.senderuu=1000010022
+message.senderEnuu=10043516

+ 2 - 2
src/main/resources/config/application-test.properties

@@ -24,5 +24,5 @@ ps.message.url=http://218.17.158.219:24000/message/
 mall.url = http://192.168.253.12:23400/
 
 #message
-message.senderuu=2000002849
-message.senderEnuu=20000682
+message.senderuu=1000010022
+message.senderEnuu=10043516