Browse Source

微信离线消息

qzyReal 2 years ago
parent
commit
1a33a4fa89

+ 1 - 9
sp-admin/sa-view/tb-business/tb-business-car-business.html

@@ -49,15 +49,7 @@
 							<label v-else>-</label>
 						</template>
 					</el-table-column>
-					<sa-td name="支付状态" prop="payType">
-						<template slot-scope="s">
-							<label v-if="s.row.payType.indexOf('免')!==-1">{{s.row.payType}}</label>
-							<label v-else>
-								<label v-if="s.row.money">已支付</label>
-								<label v-else>未支付</label>
-							</label>
-						</template>
-					</sa-td>
+					<sa-td name="支付状态" prop="payType"></sa-td>
 					<!-- <el-table-column label="操作"  fixed="right">
 						<template slot-scope="s">
 							<el-button class="c-btn" type="primary" @click="sureFn(s.row)">选择

+ 1 - 1
sp-admin/sa-view/tb-business/tb-car-disincle-info.html

@@ -49,7 +49,7 @@
                                         <sa-info name="录入时间" br>{{m.createTime}}</sa-info>
                                         <sa-info name="录入人" br>{{m.createBy}}</sa-info>
                                         <sa-info type="enum" style="margin-top: 0px;" name="支付状态" :value="m.payStatus"
-                                                 :jv="{1: '未支付', 2: '已支付未确认', 3: '已支付已确认'}" br></sa-info>
+                                                 :jv="{1: '未支付', 2: '已支付未确认', 3: '已支付'}" br></sa-info>
                                     </el-col>
                                 </el-row>
                             </div>

+ 29 - 4
sp-server/src/main/java/com/pj/api/wx/service/WxService.java

@@ -2,6 +2,7 @@ package com.pj.api.wx.service;
 
 import cn.hutool.cache.CacheUtil;
 import cn.hutool.cache.impl.TimedCache;
+import cn.hutool.core.codec.Base64;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.net.URLDecoder;
 import cn.hutool.core.util.NumberUtil;
@@ -38,6 +39,8 @@ import com.pj.project.tb_order.TbOrder;
 import com.pj.project.tb_order.TbOrderService;
 import com.pj.project.tb_pay_record.TbPayRecord;
 import com.pj.project.tb_pay_record.TbPayRecordService;
+import com.pj.project.wx_send_msg.WxSendMsg;
+import com.pj.project.wx_send_msg.WxSendMsgService;
 import com.pj.project4sp.global.BusinessException;
 import com.pj.utils.cache.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -85,6 +88,9 @@ public class WxService {
     @Resource
     private TbGoodsService tbGoodsService;
 
+    @Resource
+    private WxSendMsgService wxSendMsgService;
+
 
     /**
      * 统一下单接口
@@ -253,10 +259,10 @@ public class WxService {
                     TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
                     List<TbBusinessCar> carList = tbBusinessCarService.findOtherBusinessCar(businessId);
                     carList.forEach(tbBusinessCar -> {
-                        String carType=tbBusinessCar.getCarType();
+                        String carType = tbBusinessCar.getCarType();
                         //
-                        if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType)&&tbGoods.getChinaCarPay()==0
-                                ||TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType)&&tbGoods.getVietnamCarPay()==0){
+                        if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && tbGoods.getChinaCarPay() == 0
+                                || TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && tbGoods.getVietnamCarPay() == 0) {
                             tbBusinessCar.setPay(1).setPayTime(now);
                             tbBusinessCarService.updateById(tbBusinessCar);
                         }
@@ -327,12 +333,31 @@ public class WxService {
     }
 
     @Async
-    public void sendTemplateMsg(String templateId, String openid, MsgDataBO data, String detailUrl) {
+    public void sendTemplateMsg(String templateId, String openid, Object data, String detailUrl) {
+        if (StrUtil.isEmpty(openid)){
+            return;
+        }
         String accessToken = RedisUtil.get(wxConfig.getAccessTokenKey());
         BaseTemplate baseTemplate = new BaseTemplate(openid, templateId, detailUrl, data);
         String json = JSON.toJSONString(baseTemplate);
         String url = wxConfig.getSendMsgUrl().replace("ACCESS_TOKEN", accessToken);
         String resp = HttpUtil.post(url, json);
+        JSONObject result = JSONUtil.parseObj(resp);
+        int code = result.getInt("errcode");
         log.info("send wx msg{},{},{};return :{}", templateId, openid, JSONUtil.toJsonStr(data), resp);
+        WxSendMsg wxSendMsg = wxSendMsgService.findByOpenidAndDetailUrl(openid, detailUrl);
+        if (code != 0) {
+            if (wxSendMsg == null) {
+                wxSendMsg = new WxSendMsg();
+                wxSendMsg.setCreateTime(DateUtil.now());
+            }
+            wxSendMsg.setCode(code).setDetailUrl(detailUrl)
+                    .setMsgData(JSONUtil.toJsonStr(data)).setOpenid(openid).setTemplateId(templateId)
+                    .setReturnMsg(result.getStr("errmsg"));
+            wxSendMsgService.saveOrUpdate(wxSendMsg);
+        }else if (wxSendMsg != null){
+           wxSendMsgService.delete(wxSendMsg.getId());
+        }
     }
+
 }

+ 1 - 1
sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java

@@ -395,7 +395,7 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                         MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), item.getItemTypeName(),
                                 item.getItemName(), business.getGoodsName(), DateUtil.now(), remark);
                         List<String> openidList = tbCostomerService.findByMessageTypeOpenid(businessType, messageType);
-                        openidList.forEach(openid -> {
+                        openidList.stream().filter(StrUtil::isNotEmpty).forEach(openid -> {
                             String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
                             wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
                         });

+ 3 - 5
sp-server/src/main/java/com/pj/project/tb_business_car/TbBusinessCarMapper.xml

@@ -33,9 +33,7 @@
             <if test=' this.has("id") '>and id = #{id}</if>
             <if test=' this.has("businessId") '>and business_id = #{businessId}</if>
             <if test=' this.has("customerId") '>and customer_id = #{customerId}</if>
-            <if test=' this.has("carNo")'>
-                and car_no like concat('%',#{carNo},'%')
-            </if>
+
             <if test=' this.has("carNoList") and carNoList.size>0'>
                 and (car_no like concat('%',#{carNo},'%') or car_no in
                 <foreach collection="carNoList" open="(" close=")" item="carNo" separator=",">
@@ -53,10 +51,10 @@
             <if test=' this.has("endDay") '>and date_format(time_update,'%Y-%m-%d') &lt;= #{endDay}</if>
             <if test=' this.has("pay") '>and pay = #{pay}</if>
             <if test='leave==2 '>
-              and   real_out_time is not null
+              and   real_out_time is not null and real_in_time is not null
             </if>
             <if test='leave==3 '>
-                and   real_out_time is  null
+                and   real_out_time is  null and real_in_time is not null
             </if>
             <if test="leaveStart!=null and leaveStart !=''">
               and  date_format(real_out_time,'%Y-%m-%d %H:%i:%s') &gt;=#{leaveStart}

+ 32 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxMsgTask.java

@@ -0,0 +1,32 @@
+package com.pj.project.wx_send_msg;
+
+import cn.hutool.json.JSONUtil;
+import com.pj.api.wx.bo.MsgDataBO;
+import com.pj.api.wx.service.WxService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Component
+@Slf4j
+public class WxMsgTask {
+    @Resource
+    private WxSendMsgService wxSendMsgService;
+    @Resource
+    WxService wxService;
+
+    /**
+     * 3分钟执行一次
+     */
+    @Scheduled(fixedRate = 180000)
+    public void check() {
+        List<WxSendMsg> list = wxSendMsgService.list();
+        list.forEach(wxSendMsg -> {
+            log.info("重新发送离线消息:{}", JSONUtil.toJsonStr(wxSendMsg));
+            wxService.sendTemplateMsg(wxSendMsg.getTemplateId(), wxSendMsg.getOpenid(), JSONUtil.toBean(wxSendMsg.getMsgData(), MsgDataBO.class), wxSendMsg.getDetailUrl());
+        });
+    }
+}

+ 85 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxSendMsg.java

@@ -0,0 +1,85 @@
+package com.pj.project.wx_send_msg;
+
+import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.EqualsAndHashCode;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * Model: wx_send_msg -- 微信发送记录
+ * @author qzy 
+ */
+@Data
+@Accessors(chain = true)
+@TableName(WxSendMsg.TABLE_NAME)
+@EqualsAndHashCode(callSuper = false)
+public class WxSendMsg extends Model<WxSendMsg> implements Serializable {
+
+	// ---------- 模块常量 ----------
+	/**
+	 * 序列化版本id 
+	 */
+	private static final long serialVersionUID = 1L;	
+	/**
+	 * 此模块对应的表名 
+	 */
+	public static final String TABLE_NAME = "wx_send_msg";	
+	/**
+	 * 此模块对应的权限码 
+	 */
+	public static final String PERMISSION_CODE = "wx-send-msg";	
+
+
+	// ---------- 表中字段 ----------
+	/**
+	 *  
+	 */
+	@TableId(type = IdType.AUTO)
+	private Long id;	
+
+	/**
+	 *  
+	 */
+	private String openid;	
+
+	/**
+	 * 状态码 
+	 */
+	private Integer code;	
+
+	/**
+	 * 消息内容 
+	 */
+	private String msgData;	
+
+	/**
+	 * 内容详情url 
+	 */
+	private String detailUrl;	
+
+	/**
+	 * 模板ID 
+	 */
+	private String templateId;	
+
+	/**
+	 * 创建时间 
+	 */
+	private String createTime;	
+
+	/**
+	 * 微信返回提示 
+	 */
+	private String returnMsg;	
+
+
+
+
+
+	
+
+
+}

+ 105 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxSendMsgController.java

@@ -0,0 +1,105 @@
+package com.pj.project.wx_send_msg;
+
+import java.util.List;
+
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import com.pj.utils.sg.*;
+import com.pj.project4sp.SP;
+
+import com.pj.current.satoken.StpUserUtil;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+
+
+/**
+ * Controller: wx_send_msg -- 微信发送记录
+ * @author qzy 
+ */
+@RestController
+@RequestMapping("/WxSendMsg/")
+public class WxSendMsgController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	WxSendMsgService wxSendMsgService;
+
+	/** 增 */  
+	@RequestMapping("add")
+	@SaCheckPermission(WxSendMsg.PERMISSION_CODE)
+	@Transactional(rollbackFor = Exception.class)
+	public AjaxJson add(WxSendMsg w){
+		wxSendMsgService.add(w);
+		w = wxSendMsgService.getById(SP.publicMapper.getPrimarykey());
+		return AjaxJson.getSuccessData(w);
+	}
+
+	/** 删 */  
+	@RequestMapping("delete")
+	@SaCheckPermission(WxSendMsg.PERMISSION_CODE)
+	public AjaxJson delete(Long id){
+		int line = wxSendMsgService.delete(id);
+		return AjaxJson.getByLine(line);
+	}
+	
+	/** 删 - 根据id列表 */  
+	@RequestMapping("deleteByIds")
+	@SaCheckPermission(WxSendMsg.PERMISSION_CODE)
+	public AjaxJson deleteByIds(){
+		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
+		int line = SP.publicMapper.deleteByIds(WxSendMsg.TABLE_NAME, ids);
+		return AjaxJson.getByLine(line);
+	}
+	
+	/** 改 */  
+	@RequestMapping("update")
+	@SaCheckPermission(WxSendMsg.PERMISSION_CODE)
+	public AjaxJson update(WxSendMsg w){
+		int line = wxSendMsgService.update(w);
+		return AjaxJson.getByLine(line);
+	}
+
+	/** 查 - 根据id */  
+	@RequestMapping("getById")
+	public AjaxJson getById(Long id){
+		WxSendMsg w = wxSendMsgService.getById(id);
+		return AjaxJson.getSuccessData(w);
+	}
+
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
+	@RequestMapping("getList")
+	public AjaxJson getList() { 
+		SoMap so = SoMap.getRequestSoMap();
+		List<WxSendMsg> list = wxSendMsgService.getList(so.startPage());
+		return AjaxJson.getPageData(so.getDataCount(), list);
+	}
+	
+	
+	
+	
+	// ------------------------- 前端接口 -------------------------
+	
+	
+	/** 改 - 不传不改 [G] */
+	@RequestMapping("updateByNotNull")
+	public AjaxJson updateByNotNull(Long id){
+		AjaxError.throwBy(true, "如需正常调用此接口,请删除此行代码");
+		// 鉴别身份,是否为数据创建者 
+		long userId = SP.publicMapper.getColumnByIdToLong(WxSendMsg.TABLE_NAME, "user_id", id);
+		AjaxError.throwBy(userId != StpUserUtil.getLoginIdAsLong(), "此数据您无权限修改");
+		// 开始修改 (请只保留需要修改的字段)
+		SoMap so = SoMap.getRequestSoMap();
+		so.clearNotIn("id", "openid", "code", "msgData", "detailUrl", "templateId", "createTime", "returnMsg").clearNull().humpToLineCase();	
+		int line = SP.publicMapper.updateBySoMapById(WxSendMsg.TABLE_NAME, so, id);
+		return AjaxJson.getByLine(line);
+	}
+	
+	
+	
+	
+	
+	
+
+}

+ 56 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxSendMsgMapper.java

@@ -0,0 +1,56 @@
+package com.pj.project.wx_send_msg;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import com.pj.utils.so.*;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Mapper: wx_send_msg -- 微信发送记录
+ * @author qzy 
+ */
+
+@Mapper
+@Repository
+public interface WxSendMsgMapper extends BaseMapper <WxSendMsg> {
+
+	/**
+	 * 增  
+	 * @param w 实体对象 
+	 * @return 受影响行数 
+	 */
+	int add(WxSendMsg w);
+
+	/**
+	 * 删  
+	 * @param id 要删除的数据id  
+	 * @return 受影响行数 
+	 */
+	int delete(Long id);	 
+
+	/** 
+	 * 改  
+	 * @param w 实体对象 
+	 * @return 受影响行数 
+	 */
+	int update(WxSendMsg w);
+
+	/** 
+	 * 查 - 根据id  
+	 * @param id 要查询的数据id 
+	 * @return 实体对象 
+	 */
+	WxSendMsg getById(Long id);	 
+
+	/**
+	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+	 * @param so 参数集合 
+	 * @return 数据列表 
+	 */
+	List<WxSendMsg> getList(SoMap so);
+
+
+}

+ 96 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxSendMsgMapper.xml

@@ -0,0 +1,96 @@
+<?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.pj.project.wx_send_msg.WxSendMsgMapper">
+
+	<!-- 增 [G] -->
+	<insert id="add">
+		insert into 
+		wx_send_msg (id, openid, code, msg_data, detail_url, template_id, create_time, return_msg) 
+		values (#{id}, #{openid}, #{code}, #{msgData}, #{detailUrl}, #{templateId}, #{createTime}, #{returnMsg}) 
+	</insert>
+
+	<!-- 删 -->
+	<delete id="delete">
+		delete from wx_send_msg 
+		where id = #{id}
+	</delete>
+
+	<!-- 改 [G] -->
+	<update id="update">
+		update wx_send_msg set
+		id = #{id}, 
+		openid = #{openid}, 
+		code = #{code}, 
+		msg_data = #{msgData}, 
+		detail_url = #{detailUrl}, 
+		template_id = #{templateId}, 
+		create_time = #{createTime}, 
+		return_msg = #{returnMsg}
+		where id = #{id}
+	</update>
+
+
+	<!-- ================================== 查询相关 ================================== -->
+	<!-- select id, openid, code, msg_data, detail_url, template_id, create_time, return_msg from wx_send_msg  -->
+	
+	<!-- 通用映射:手动模式 -->
+	<resultMap id="model" type="com.pj.project.wx_send_msg.WxSendMsg">
+		<result property="id" column="id" />
+		<result property="openid" column="openid" />
+		<result property="code" column="code" />
+		<result property="msgData" column="msg_data" />
+		<result property="detailUrl" column="detail_url" />
+		<result property="templateId" column="template_id" />
+		<result property="createTime" column="create_time" />
+		<result property="returnMsg" column="return_msg" />
+	</resultMap>
+	
+	<!-- 公共查询sql片段 -->
+	<sql id="select_sql">
+		select * 
+		from wx_send_msg 
+	</sql>
+	
+	<!-- 查 - 根据id -->
+	<select id="getById" resultMap="model">
+		<include refid="select_sql"></include>
+		where id = #{id}
+	</select>
+	
+	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
+	<select id="getList" resultMap="model">
+		<include refid="select_sql"></include>
+		<where>
+			<if test=' this.has("id") '> and id = #{id} </if>
+			<if test=' this.has("openid") '> and openid = #{openid} </if>
+			<if test=' this.has("code") '> and code = #{code} </if>
+			<if test=' this.has("msgData") '> and msg_data = #{msgData} </if>
+			<if test=' this.has("detailUrl") '> and detail_url = #{detailUrl} </if>
+			<if test=' this.has("templateId") '> and template_id = #{templateId} </if>
+			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
+			<if test=' this.has("returnMsg") '> and return_msg = #{returnMsg} </if>
+		</where>
+		order by
+		<choose>
+			<when test='sortType == 1'> id desc </when>
+			<when test='sortType == 2'> openid desc </when>
+			<when test='sortType == 3'> code desc </when>
+			<when test='sortType == 4'> msg_data desc </when>
+			<when test='sortType == 5'> detail_url desc </when>
+			<when test='sortType == 6'> template_id desc </when>
+			<when test='sortType == 7'> create_time desc </when>
+			<when test='sortType == 8'> return_msg desc </when>
+			<otherwise> id desc </otherwise>
+		</choose>
+	</select>
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+</mapper>

+ 73 - 0
sp-server/src/main/java/com/pj/project/wx_send_msg/WxSendMsgService.java

@@ -0,0 +1,73 @@
+package com.pj.project.wx_send_msg;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pj.project.tb_order.TbOrder;
+import com.pj.project.tb_order.TbOrderMapper;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.pj.utils.sg.*;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Service: wx_send_msg -- 微信发送记录
+ *
+ * @author qzy
+ */
+@Service
+@Transactional
+public class WxSendMsgService extends ServiceImpl<WxSendMsgMapper, WxSendMsg> implements IService<WxSendMsg> {
+
+    /**
+     * 底层 Mapper 对象
+     */
+    @Autowired
+    WxSendMsgMapper wxSendMsgMapper;
+
+    /**
+     * 增
+     */
+    int add(WxSendMsg w) {
+        return wxSendMsgMapper.add(w);
+    }
+
+    /**
+     * 删
+     */
+    public int delete(Long id) {
+        return wxSendMsgMapper.delete(id);
+    }
+
+    /**
+     * 改
+     */
+    int update(WxSendMsg w) {
+        return wxSendMsgMapper.update(w);
+    }
+
+    /**
+     * 查
+     */
+    WxSendMsg getById(Long id) {
+        return wxSendMsgMapper.getById(id);
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    List<WxSendMsg> getList(SoMap so) {
+        return wxSendMsgMapper.getList(so);
+    }
+
+
+    public WxSendMsg findByOpenidAndDetailUrl(String openid, String detailUrl) {
+        QueryWrapper<WxSendMsg> ew = new QueryWrapper<>();
+        ew.eq("openid", openid).eq("detail_url", detailUrl);
+        return getOne(ew);
+    }
+}