Browse Source

询价统计,短信推送功能

scr 7 years ago
parent
commit
164b8e0694

+ 28 - 0
src/main/java/com/uas/ps/inquiry/AccessConfiguration.java

@@ -29,6 +29,34 @@ public class AccessConfiguration {
     @Value("${mall.url}")
     private String mallUrl;
 
+    /**
+     * 短信推送人UU
+     */
+    @Value("${message.senderuu}")
+    private Long senderuu;
+
+    /**
+     * 短信推送人企业uU
+     */
+    @Value("${message.senderEnuu}")
+    private Long senderEnuu;
+
+    public Long getSenderuu() {
+        return senderuu;
+    }
+
+    public void setSenderuu(Long senderuu) {
+        this.senderuu = senderuu;
+    }
+
+    public Long getSenderEnuu() {
+        return senderEnuu;
+    }
+
+    public void setSenderEnuu(Long senderEnuu) {
+        this.senderEnuu = senderEnuu;
+    }
+
     public String getMallUrl() {
         return mallUrl;
     }

+ 22 - 0
src/main/java/com/uas/ps/inquiry/dao/InquiryRemindDao.java

@@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
 import javax.transaction.Transactional;
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -47,4 +48,25 @@ public interface InquiryRemindDao extends JpaRepository<InquiryRemind, Long>, Jp
      * @return
      */
     List<InquiryRemind> findByVendUserUUAndVendUUAndItemId(Long vendUserUU, Long vendUU, Long itemId);
+
+    //查出昨晚17点到今早九点的询价信息
+    @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",nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind(BigInteger venduseruu,BigInteger venduu);
+
+    //查出今早9点到14点的询价信息
+    @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",nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind1(BigInteger venduseruu,BigInteger venduu);
+
+    //查出14点到17点的询价信息
+    @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",nativeQuery = true)
+    List<InquiryRemind> findInquiryRemind2(BigInteger venduseruu,BigInteger venduu);
+
+    //找到询价推荐表中所有的用户
+    @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)
+    List<BigInteger> findvenduu();
+
 }

+ 203 - 17
src/main/java/com/uas/ps/inquiry/service/impl/InquiryServiceImpl.java

@@ -20,6 +20,7 @@ import com.uas.ps.inquiry.page.exception.IllegalOperatorException;
 import com.uas.ps.inquiry.service.InquiryService;
 import com.uas.ps.inquiry.service.PublicInquiryService;
 
+import java.math.BigInteger;
 import java.util.*;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -34,7 +35,9 @@ import javassist.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 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;
 
@@ -46,6 +49,72 @@ import org.springframework.util.StringUtils;
 @Service
 public class InquiryServiceImpl implements InquiryService {
 
+    /**
+     * 消息类型 (在B2B消息中拼接跳转单据详情url请求时需要)
+     */
+    private final String INQUIRY_TYPE = "公共询价";
+
+    /**
+     * 应用来源
+     */
+    private final String SOURCERAPP = "MALL";
+
+    /**
+     * 消息类型,公共询价的采纳结果
+     */
+    private final String INQUIRY_DECIDE_TYPE = "公共询价采纳结果";
+
+    /**
+     * 询价种类
+     */
+    private final String INQUIRYKIND = "publicInquiry";
+
+
+    /**
+     * 消息推送短信模板id
+     */
+    private final String SMS_TEMP_ID = "e6320a3c-89ac-4c77-a75f-62a727bce654";
+
+    /**
+     * 消息推送方式:邮件、短信、im
+     */
+    private final String SMS_TYPE = "MAIL_AND_SM_AND_IM";
+
+    /**
+     * 来源应用,ERP
+     */
+    private final String PRODUCERAPP = "ERP";
+
+    /**
+     * 消费类型: 多个,MULTI
+     */
+    private final String CUST_TYPE = "MULTI";
+
+    /**
+     * 接收应用
+     */
+    private final String CONSUMERAPP = "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 final Long MESSAGE_SENDERENUU = ContextUtils.getBean(AccessConfiguration.class).getSenderEnuu();
+
     @Autowired
     private PublicInquiryItemDao itemDao;
 
@@ -76,6 +145,10 @@ public class InquiryServiceImpl implements InquiryService {
     @Autowired
     private EnterpriseDao enterpriseDao;
 
+    @Autowired
+    private PublicInquiryServiceImpl service;
+
+
     /**
      * 公共物料访问地址
      */
@@ -89,9 +162,9 @@ public class InquiryServiceImpl implements InquiryService {
     /**
      * 查询公共询价列表信息
      *
-     * @param info 分页新
-     * @param filter 过滤条件
-     * @param state 过滤状态
+     * @param info    分页新
+     * @param filter  过滤条件
+     * @param state   过滤状态
      * @param overdue 是否过期 1、已过期;0、未过期
      * @return
      */
@@ -159,6 +232,7 @@ public class InquiryServiceImpl implements InquiryService {
      */
     @Override
     public PurcInquiry saveInquiry(PurcInquiry currentInquiry) throws NotFoundException {
+        //通过流水号和企业号找到公共询价单
         PurcInquiry existInquiry = purcInquiryDao.findByCodeAndEnUU(currentInquiry.getCode(), currentInquiry.getEnUU());
         if (null != existInquiry) {
             throw new IllegalOperatorException("单号重复");
@@ -171,15 +245,19 @@ public class InquiryServiceImpl implements InquiryService {
                     throw new NotFoundException("询价企业不存在");
                 }
             }
+            //保存询价单
             PurcInquiry inquiry = purcInquiryDao.save(currentInquiry);
+            //判断询价明细单是否为空
             if (!CollectionUtils.isEmpty(currentInquiry.getInquiryItems())) {
                 List<PurcInquiryItem> items = new ArrayList<PurcInquiryItem>();
+                //给询价明细单属性设置初始值
                 for (PurcInquiryItem item : currentInquiry.getInquiryItems()) {
                     item.setInquiry(inquiry);
                     item.setOfferAmount(0);
                     item.setStatus((short) Status.NOT_REPLY.value());
                     item.setIsOpen(Constant.YES);
                     if (null == item.getDate()) {
+                        //设置提交时间
                         item.setDate(new Date(System.currentTimeMillis()));
                     }
                     // 这里设置物料信息的冗余字段
@@ -198,8 +276,9 @@ public class InquiryServiceImpl implements InquiryService {
                     }
                     items.add(item);
                 }
+                //保存询价单明细表
                 items = purcInquiryItemDao.save(items);
-                // 消息推送
+
                 final List<PurcInquiryItem> purcInquiryItems = items;
                 final String sourceapp = inquiry.getSourceapp();
                 final Long enuu = inquiry.getEnUU();
@@ -208,6 +287,7 @@ public class InquiryServiceImpl implements InquiryService {
                         @Override
                         public void run() {
                             try {
+                                //生成推荐询价表
                                 inquiryService.notifyMessage(purcInquiryItems, sourceapp);
                                 if (!StringUtils.isEmpty(enuu)) {
                                     saveProduct(purcInquiryItems, sourceapp);
@@ -223,6 +303,110 @@ public class InquiryServiceImpl implements InquiryService {
         }
     }
 
+    /**
+     * 每早9点发送询价通知短信
+     */
+    @Scheduled(cron = "0 46 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);
+                }
+            }
+        }
+    }
+
     /**
      * 发布询价成功后加入当前用户的个人物料库
      * @param inquiryItems
@@ -266,7 +450,7 @@ public class InquiryServiceImpl implements InquiryService {
     /**
      * 通过报价明细id对供应商报价进行相关审核操作
      *
-     * @param id 报价明细id
+     * @param id     报价明细id
      * @param status 状态
      */
     @Override
@@ -382,15 +566,15 @@ public class InquiryServiceImpl implements InquiryService {
                         productInfo.setCmpCode(item.getCmpCode());
                         products.add(productInfo);
                         for (PublicInquiryItem item1 : inquiry.getInquiryItems()) {
-                             if (item1.getCmpCode() != null && item1.getCmpCode().equals(productInfo.getCmpCode())) {
-                                 String sql = "select at_path,at_name from attachs a left join public$inquiryitems$attach p on a.at_id = p.at_id " +
-                                         "left join public$inquiryitems i on p.id_id = i.id_id where i.id_id = " + item1.getId();
-                                 List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
-                                 if (!org.springframework.util.CollectionUtils.isEmpty(maps)) {
-                                     Map<String, Object> map = maps.get(0);
-                                     item1.setAttachUrl(map.get("at_path").toString());
-                                     item1.setAttachName(map.get("at_name").toString());
-                                 }
+                            if (item1.getCmpCode() != null && item1.getCmpCode().equals(productInfo.getCmpCode())) {
+                                String sql = "select at_path,at_name from attachs a left join public$inquiryitems$attach p on a.at_id = p.at_id " +
+                                        "left join public$inquiryitems i on p.id_id = i.id_id where i.id_id = " + item1.getId();
+                                List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
+                                if (!org.springframework.util.CollectionUtils.isEmpty(maps)) {
+                                    Map<String, Object> map = maps.get(0);
+                                    item1.setAttachUrl(map.get("at_path").toString());
+                                    item1.setAttachName(map.get("at_name").toString());
+                                }
                                 items.add(item1);
                             }
                         }
@@ -436,7 +620,7 @@ public class InquiryServiceImpl implements InquiryService {
     /**
      * 通过企业UU和分页信息等查询已发布信息
      *
-     * @param info     分页信息
+     * @param info   分页信息
      * @param filter 过滤条件
      * @return
      */
@@ -501,8 +685,8 @@ public class InquiryServiceImpl implements InquiryService {
     /**
      * 针对客户查询供应商报价信息
      *
-     * @param pageInfo     分页信息
-     * @param filter 过滤条件
+     * @param pageInfo 分页信息
+     * @param filter   过滤条件
      * @return
      */
     @Override
@@ -558,6 +742,7 @@ public class InquiryServiceImpl implements InquiryService {
 
     /**
      * 针对客户单个公共询价,查询供应商报价信息
+     *
      * @param id
      * @return
      */
@@ -566,6 +751,7 @@ public class InquiryServiceImpl implements InquiryService {
         PurcInquiryItemInfo itemInfo = inquiryItemDao.findOne(id);
         List<PublicInquiryItem> itemList = itemDao.findBySourceId(itemInfo.getId());
         itemInfo.setQutations(itemList);
+
         itemInfo.setAgreed(Constant.NO);
         if (!CollectionUtils.isEmpty(itemList)) {
             for (PublicInquiryItem i : itemList) {

+ 4 - 0
src/main/resources/config/application-cloud.properties

@@ -22,3 +22,7 @@ datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMill
 ps.product.url=https://api-product.usoftmall.com/
 ps.message.url=http://api-message.ubtob.com/
 mall.url = https://www.usoftmall.com/
+
+#message
+message.senderuu=1000010022
+message.senderEnuu=10043516

+ 5 - 1
src/main/resources/config/application-dev.properties

@@ -25,4 +25,8 @@ ps.product.url=http://192.168.253.102:8080/
 ps.message.url=http://192.168.253.12:24000/message/
 # wang localhost
 #ps.message.url=http://192.168.253.131:20000/
-mall.url = http://192.168.253.12:23400/
+mall.url = http://192.168.253.12:23400/
+
+#message
+message.senderuu=1000010022
+message.senderEnuu=10043516

+ 5 - 1
src/main/resources/config/application-test.properties

@@ -21,4 +21,8 @@ datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMill
 # Access path
 ps.product.url=http://218.17.158.219:24000/
 ps.message.url=http://218.17.158.219:24000/message/
-mall.url = http://192.168.253.12:23400/
+mall.url = http://192.168.253.12:23400/
+
+#message
+message.senderuu=1000010022
+message.senderEnuu=10043516