yujian
2019-04-22 5953f70fd53c8bbdf4fdf0c6b9307eff68d6fcaf
新增定时推送:站内信、网页、百川、今日推荐
7个文件已修改
8个文件已添加
1407 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushGoodsController.java 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushInfoController.java 179 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/push/PushGoodsMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/push/PushInfoMapper.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/push/PushGoods.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/push/PushInfo.java 234 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/push/PushInfoException.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/PushJob.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushGoodsMapper.xml 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushInfoMapper.xml 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushGoodsServiceImpl.java 105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushInfoServiceImpl.java 377 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushGoodsService.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushInfoService.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/mybatishandler/PushTypeEnumHandler.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushGoodsController.java
@@ -1,8 +1,10 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -76,7 +78,8 @@
            pushGoodsService.save(pushGoods, list);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
        } catch (PushGoodsException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
@@ -143,13 +146,24 @@
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("数据信息已不存在"));
                return;
            }
            Date controlTime = pushGoods.getControlTime();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            if (controlTime == null) {
                pushGoods.setTimeTask(false);
                pushGoods.setControlTime_str("");
            } else {
                pushGoods.setTimeTask(true);
                pushGoods.setControlTime_str(sdf.format(controlTime));
            }
            // 版本处理
            convertVersionList(pushGoods);
            
            List<TaoBaoGoodsBrief> listgoods = new ArrayList<TaoBaoGoodsBrief>();
            
            List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(pushGoods.getId());
            List<PushGoodsGroup> listGroup = pushGoodsGroupService.getAllInfoByPushId(id);
            if (listGroup == null) {
                listGroup = new ArrayList<PushGoodsGroup>();
            } else {
@@ -162,8 +176,12 @@
                }
            }
            
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.serializeNulls();
            Gson gson = gsonBuilder.create();
            JSONObject data = new JSONObject();
            data.put("pushGoods", pushGoods);
            data.put("pushGoods", gson.toJson(pushGoods));
            data.put("listGroup", listgoods);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
@@ -205,6 +223,17 @@
            }
            for (PushGoods pushGoods : list) {
                Date controlTime = pushGoods.getControlTime();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
                if (controlTime == null) {
                    pushGoods.setTimeTask(false);
                    pushGoods.setControlTime_str("");
                } else {
                    pushGoods.setTimeTask(true);
                    pushGoods.setControlTime_str(sdf.format(controlTime));
                }
                long countGoods = pushGoodsGroupService.countByPushId(pushGoods.getId());
                pushGoods.setCountGoods(countGoods);
                
@@ -260,7 +289,7 @@
            }
                
            for (Long id: list) {
                pushGoodsService.executePush(id);
                pushGoodsService.handPush(id);
            }
            
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushInfoController.java
New file
@@ -0,0 +1,179 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.exception.push.PushInfoException;
import com.yeshi.fanli.service.inter.push.PushInfoService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("admin/new/api/v1/pushInfo")
public class PushInfoController {
    @Resource
    private PushInfoService pushInfoService;
    /**
     * 新增/修改
     *
     * @param callback
     * @param out
     */
    @RequestMapping(value = "save")
    public void save(String callback, PushInfo pushInfo,PrintWriter out) {
        try {
            pushInfoService.save(pushInfo);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
        } catch (PushInfoException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    /**
     * 查询
     *
     * @param callback
     * @param pageIndex
     * @param pageSize
     * @param key
     *            模糊查询:说明、标识
     * @param out
     */
    @RequestMapping(value = "query")
    public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer keyType,
            Integer state, String type, PrintWriter out) {
        if (pageIndex == null || pageIndex < 1) {
            pageIndex = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = Constant.PAGE_SIZE;
        }
        try {
            List<PushInfo> list = pushInfoService.listQuery((pageIndex-1) * pageSize, pageSize, key, keyType, state, type);
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
                return;
            }
            long count = pushInfoService.countQuery(key, keyType, state, type);
            int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
            PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.serializeNulls();
            Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd").create();
            JSONObject data = new JSONObject();
            data.put("pe", pe);
            data.put("result_list", gson.toJson(list));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    /**
     * 删除
     *
     * @param callback
     * @param idArray
     * @param out
     */
    @RequestMapping(value = "delete")
    public void delete(String callback, String idArray, PrintWriter out) {
        try {
            if (StringUtil.isNullOrEmpty(idArray)) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择操作的数据"));
                return;
            }
            Gson gson = new Gson();
            List<Long> list = gson.fromJson(idArray, new TypeToken<ArrayList<Long>>() {
            }.getType());
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检测到删除的数据"));
                return;
            }
            pushInfoService.deleteBatchByPrimaryKey(list);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败"));
            e.printStackTrace();
        }
    }
    /**
     * 推送
     * @param id 推送id
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "push")
    public void push(String callback, String idArray, PrintWriter out) throws Exception {
        if (idArray == null || idArray.trim().length() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不能为空"));
            return;
        }
        try {
            Gson gson = new Gson();
            List<Long> list = gson.fromJson(idArray, new TypeToken<ArrayList<Long>>() {}.getType());
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不能为空"));
                return;
            }
            for (Long id: list) {
                pushInfoService.handPush(id);
            }
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
        } catch (PushException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (PushInfoException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            e.printStackTrace();
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/push/PushGoodsMapper.java
@@ -68,4 +68,10 @@
    List<PushGoods>  listByPushState(List<Long> list);
    
    
    /**
     * 需要执行推送的任务
     * @return
     */
    List<PushGoods> listTask();
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/push/PushInfoMapper.java
New file
@@ -0,0 +1,36 @@
package com.yeshi.fanli.dao.mybatis.push;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.push.PushInfo;
public interface PushInfoMapper extends BaseMapper<PushInfo> {
    int deleteBatchByPrimaryKey(List<Long> list);
    /**
     * 后端查询列表
     * @param start
     * @param count
     * @param key
     * @param keyType
     * @param state
     * @return
     */
    List<PushInfo> listQuery(@Param("start") long start, @Param("count") int count,
             @Param("key") String key, @Param("keyType") Integer keyType, @Param("state") Integer state
             ,  @Param("type")String type);
    long countQuery(@Param("key") String key, @Param("keyType") Integer keyType,
            @Param("state") Integer state,  @Param("type")String type);
    /**
     * 需要执行推送的任务
     * @return
     */
    List<PushInfo> listTask();
}
fanli/src/main/java/com/yeshi/fanli/entity/push/PushGoods.java
@@ -8,6 +8,11 @@
@Table("yeshi_ec_push_goods")
public class PushGoods {
    // 推送状态: 0未推送 1推送成功 2推送失败
    public final static int STATE_INIT = 0;
    public final static int STATE_SUCCESS = 1;
    public final static int STATE_FAIL = 2;
    @Column(name = "pg_id")
    private Long id;
@@ -39,9 +44,17 @@
    @Column(name = "pg_versions")
    private String versions;
    
    // 预设推送时间
    @Column(name = "pg_control_time")
    private Date controlTime;
    // 备注
    @Column(name = "pg_remark")
    private String remark;
    // 是否已推送
    @Column(name = "pg_is_push")
    private boolean isPush;
    private Integer isPush;
    
    // 推送时间
    @Column(name = "pg_push_time")
@@ -53,6 +66,10 @@
    @Column(name = "pg_updatetime")
    private Date updateTime;
    // 是否定时
    private Boolean timeTask;
    // 定时时间
    private String controlTime_str;
    
    // 统计商品数量
    private Long countGoods; 
@@ -109,11 +126,11 @@
        this.content = content;
    }
    public boolean isPush() {
    public Integer getIsPush() {
        return isPush;
    }
    public void setPush(boolean isPush) {
    public void setIsPush(Integer isPush) {
        this.isPush = isPush;
    }
@@ -188,4 +205,37 @@
    public void setListAndroid(List<String> listAndroid) {
        this.listAndroid = listAndroid;
    }
    public Date getControlTime() {
        return controlTime;
    }
    public void setControlTime(Date controlTime) {
        this.controlTime = controlTime;
    }
    public Boolean isTimeTask() {
        return timeTask;
    }
    public void setTimeTask(Boolean timeTask) {
        this.timeTask = timeTask;
    }
    public String getControlTime_str() {
        return controlTime_str;
    }
    public void setControlTime_str(String controlTime_str) {
        this.controlTime_str = controlTime_str;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/push/PushInfo.java
New file
@@ -0,0 +1,234 @@
package com.yeshi.fanli.entity.push;
import java.util.Date;
import java.util.List;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
@Table("yeshi_ec_push_info")
public class PushInfo {
    public enum PushTypeEnum {
        ZNX("站内信"), URL("网页"), BAICHUAN("百川");
        private final String desc;
        private PushTypeEnum(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return desc;
        }
    }
    // 推送状态: 0未推送 1推送成功 2推送失败
    public final static int STATE_INIT = 0;
    public final static int STATE_SUCCESS = 1;
    public final static int STATE_FAIL = 2;
    @Column(name = "pi_id")
    private Long id;
    // 显示标题
    @Column(name = "pi_title")
    private String title;
    // 显示内容
    @Column(name = "pi_content")
    private String content;
    // 显示内容
    @Column(name = "pi_uids")
    private String uids;
    // json数据
    @Column(name = "pi_json_data")
    private String jsonData;
    // 推送类型
    @Column(name = "pi_type")
    private PushTypeEnum type;
    // 预设推送时间
    @Column(name = "pi_control_time")
    private Date controlTime;
    // 备注
    @Column(name = "pi_remark")
    private String remark;
    // 状态:0未推送 1推送成功 2 推送失败
    @Column(name = "pi_state")
    private Integer state;
    // 推送时间
    @Column(name = "pi_push_time")
    private Date pushTime;
    @Column(name = "pi_create_time")
    private Date createTime;
    @Column(name = "pi_update_time")
    private Date updateTime;
    // 推送URL
    private String url;
    // 是否定时
    private Boolean timeTask;
    // 定时时间
    private String controlTime_str;
    private String arrayIOS;
    private String arrayAndroid;
    // ios推送版本
    private List<String> listIOS;
    // Android推送版本
    private List<String> listAndroid;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getUids() {
        return uids;
    }
    public void setUids(String uids) {
        this.uids = uids;
    }
    public String getJsonData() {
        return jsonData;
    }
    public void setJsonData(String jsonData) {
        this.jsonData = jsonData;
    }
    public PushTypeEnum getType() {
        return type;
    }
    public void setType(PushTypeEnum type) {
        this.type = type;
    }
    public Date getControlTime() {
        return controlTime;
    }
    public void setControlTime(Date controlTime) {
        this.controlTime = controlTime;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    public Date getPushTime() {
        return pushTime;
    }
    public void setPushTime(Date pushTime) {
        this.pushTime = pushTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Boolean isTimeTask() {
        return timeTask;
    }
    public void setTimeTask(Boolean timeTask) {
        this.timeTask = timeTask;
    }
    public String getControlTime_str() {
        return controlTime_str;
    }
    public void setControlTime_str(String controlTime_str) {
        this.controlTime_str = controlTime_str;
    }
    public List<String> getListIOS() {
        return listIOS;
    }
    public void setListIOS(List<String> listIOS) {
        this.listIOS = listIOS;
    }
    public List<String> getListAndroid() {
        return listAndroid;
    }
    public void setListAndroid(List<String> listAndroid) {
        this.listAndroid = listAndroid;
    }
    public String getArrayIOS() {
        return arrayIOS;
    }
    public void setArrayIOS(String arrayIOS) {
        this.arrayIOS = arrayIOS;
    }
    public String getArrayAndroid() {
        return arrayAndroid;
    }
    public void setArrayAndroid(String arrayAndroid) {
        this.arrayAndroid = arrayAndroid;
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/push/PushInfoException.java
New file
@@ -0,0 +1,30 @@
package com.yeshi.fanli.exception.push;
public class PushInfoException extends Exception {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public PushInfoException() {}
    public PushInfoException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli/src/main/java/com/yeshi/fanli/job/PushJob.java
@@ -5,9 +5,16 @@
import java.util.List;
import java.util.Scanner;
import javax.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.yeshi.fanli.entity.push.PushGoods;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.push.PushGoodsService;
import com.yeshi.fanli.service.inter.push.PushInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.factory.IOSPushFactory;
import com.yeshi.fanli.util.push.IOSPushUtil;
@@ -16,7 +23,14 @@
@Component
public class PushJob {
    @Resource
    private PushInfoService pushInfoService;
    @Resource
    private PushGoodsService pushGoodsService;
    /**
     * 推送老版本IOS(每晚8点推送)
     */
@@ -49,4 +63,51 @@
        }
    }
    /**
     *  定时消息推送任务 每个30秒爬取
     */
    @Scheduled(cron = "30 * * * * ? ")
    public void pushInfo() {
        if (!Constant.IS_TASK) {
            return;
        }
        // 站内信、网页、百川
        try {
            List<PushInfo> listTask = pushInfoService.listTask();
            if (listTask != null && listTask.size() > 0) {
                for (PushInfo pushInfo: listTask) {
                    pushInfoService.taskPush(pushInfo);
                }
            }
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        //    今日推荐
        try {
            List<PushGoods> listTask = pushGoodsService.listTask();
            if (listTask != null && listTask.size() > 0) {
                for (PushGoods pushGoods: listTask) {
                    pushGoodsService.taskPush(pushGoods);
                }
            }
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushGoodsMapper.xml
@@ -11,17 +11,19 @@
    <result column="pg_picture" property="picture" jdbcType="VARCHAR"/>
    <result column="pg_uid" property="uid" jdbcType="BIGINT"/>
    <result column="pg_versions" property="versions" jdbcType="VARCHAR"/>
    <result column="pg_is_push" property="isPush" jdbcType="VARCHAR"/>
    <result column="pg_remark" property="remark" jdbcType="VARCHAR"/>
    <result column="pg_is_push" property="isPush" jdbcType="INTEGER"/>
    <result column="pg_control_time" property="controlTime" jdbcType="TIMESTAMP"/>
    <result column="pg_push_time" property="pushTime" jdbcType="TIMESTAMP"/>
    <result column="pg_createtime" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="pg_updatetime" property="updateTime" jdbcType="TIMESTAMP"/>
  </resultMap>
  <sql id="Base_Column_List">pg_id,pg_alert_title,pg_alert_content,pg_title,pg_content,pg_picture,pg_uid,pg_versions,pg_is_push,pg_push_time,pg_createtime,pg_updatetime</sql>
  <sql id="Base_Column_List">pg_id,pg_alert_title,pg_alert_content,pg_title,pg_content,pg_picture,pg_uid,pg_versions,pg_remark,pg_is_push,pg_control_time,pg_push_time,pg_createtime,pg_updatetime</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_push_goods where pg_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_push_goods where pg_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.push.PushGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_push_goods (pg_id,pg_alert_title,pg_alert_content,pg_title,pg_content,pg_picture,pg_uid,pg_versions,pg_is_push,pg_push_time,pg_createtime,pg_updatetime) values (#{id,jdbcType=BIGINT},#{alertTitle,jdbcType=VARCHAR},#{alertContent,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{uid,jdbcType=BIGINT},#{versions,jdbcType=VARCHAR},#{isPush,jdbcType=VARCHAR},#{pushTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.push.PushGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_push_goods (pg_id,pg_alert_title,pg_alert_content,pg_title,pg_content,pg_picture,pg_uid,pg_versions,pg_remark,pg_is_push,pg_control_time,pg_push_time,pg_createtime,pg_updatetime) values (#{id,jdbcType=BIGINT},#{alertTitle,jdbcType=VARCHAR},#{alertContent,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{uid,jdbcType=BIGINT},#{versions,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR},#{isPush,jdbcType=INTEGER},#{controlTime,jdbcType=TIMESTAMP},#{pushTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.push.PushGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_push_goods
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">pg_id,</if>
@@ -32,7 +34,9 @@
      <if test="picture != null">pg_picture,</if>
      <if test="uid != null">pg_uid,</if>
      <if test="versions != null">pg_versions,</if>
      <if test="remark != null">pg_remark,</if>
      <if test="isPush != null">pg_is_push,</if>
      <if test="controlTime != null">pg_control_time,</if>
      <if test="pushTime != null">pg_push_time,</if>
      <if test="createTime != null">pg_createtime,</if>
      <if test="updateTime != null">pg_updatetime,</if>
@@ -46,13 +50,15 @@
      <if test="picture != null">#{picture,jdbcType=VARCHAR},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="versions != null">#{versions,jdbcType=VARCHAR},</if>
      <if test="isPush != null">#{isPush,jdbcType=VARCHAR},</if>
      <if test="remark != null">#{remark,jdbcType=VARCHAR},</if>
      <if test="isPush != null">#{isPush,jdbcType=INTEGER},</if>
      <if test="controlTime != null">#{controlTime,jdbcType=TIMESTAMP},</if>
      <if test="pushTime != null">#{pushTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.push.PushGoods">update yeshi_ec_push_goods set pg_alert_title = #{alertTitle,jdbcType=VARCHAR},pg_alert_content = #{alertContent,jdbcType=VARCHAR},pg_title = #{title,jdbcType=VARCHAR},pg_content = #{content,jdbcType=VARCHAR},pg_picture = #{picture,jdbcType=VARCHAR},pg_uid = #{uid,jdbcType=BIGINT},pg_versions = #{versions,jdbcType=VARCHAR},pg_is_push = #{isPush,jdbcType=VARCHAR},pg_push_time = #{pushTime,jdbcType=TIMESTAMP},pg_createtime = #{createTime,jdbcType=TIMESTAMP},pg_updatetime = #{updateTime,jdbcType=TIMESTAMP} where pg_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.push.PushGoods">update yeshi_ec_push_goods set pg_alert_title = #{alertTitle,jdbcType=VARCHAR},pg_alert_content = #{alertContent,jdbcType=VARCHAR},pg_title = #{title,jdbcType=VARCHAR},pg_content = #{content,jdbcType=VARCHAR},pg_picture = #{picture,jdbcType=VARCHAR},pg_uid = #{uid,jdbcType=BIGINT},pg_versions = #{versions,jdbcType=VARCHAR},pg_remark = #{remark,jdbcType=VARCHAR},pg_is_push = #{isPush,jdbcType=INTEGER},pg_control_time = #{controlTime,jdbcType=TIMESTAMP},pg_push_time = #{pushTime,jdbcType=TIMESTAMP},pg_createtime = #{createTime,jdbcType=TIMESTAMP},pg_updatetime = #{updateTime,jdbcType=TIMESTAMP} where pg_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.push.PushGoods">update yeshi_ec_push_goods
    <set>
      <if test="alertTitle != null">pg_alert_title=#{alertTitle,jdbcType=VARCHAR},</if>
@@ -62,7 +68,9 @@
      <if test="picture != null">pg_picture=#{picture,jdbcType=VARCHAR},</if>
      <if test="uid != null">pg_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="versions != null">pg_versions=#{versions,jdbcType=VARCHAR},</if>
      <if test="isPush != null">pg_is_push=#{isPush,jdbcType=VARCHAR},</if>
      <if test="remark != null">pg_remark=#{remark,jdbcType=VARCHAR},</if>
      <if test="isPush != null">pg_is_push=#{isPush,jdbcType=INTEGER},</if>
      <if test="controlTime != null">pg_control_time=#{controlTime,jdbcType=TIMESTAMP},</if>
      <if test="pushTime != null">pg_push_time=#{pushTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">pg_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">pg_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
@@ -83,7 +91,7 @@
           <if test='state != null'>
                  AND pg_is_push = #{state}
           </if>
           ORDER BY pg_createtime desc
           ORDER BY pg_is_push,pg_push_time DESC
        LIMIT ${start},${count}
   </select>
   
@@ -118,5 +126,11 @@
        <foreach item="item" collection="list" open="(" separator=","
            close=")">#{item}</foreach>
   </select>
   <select id="listTask" resultMap="BaseResultMap">
          SELECT * FROM `yeshi_ec_push_goods` p
        WHERE p.`pg_is_push` = 0 AND p.`pg_control_time` IS NOT NULL
              AND p.`pg_control_time` <![CDATA[<=]]> NOW()
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/push/PushInfoMapper.xml
New file
@@ -0,0 +1,112 @@
<?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.yeshi.fanli.dao.mybatis.push.PushInfoMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.push.PushInfo">
    <id column="pi_id" property="id" jdbcType="BIGINT"/>
    <result column="pi_title" property="title" jdbcType="VARCHAR"/>
    <result column="pi_content" property="content" jdbcType="VARCHAR"/>
    <result column="pi_uids" property="uids" jdbcType="VARCHAR"/>
    <result column="pi_json_data" property="jsonData" jdbcType="VARCHAR"/>
    <result column="pi_control_time" property="controlTime" jdbcType="TIMESTAMP"/>
    <result column="pi_remark" property="remark" jdbcType="VARCHAR"/>
    <result column="pi_state" property="state" jdbcType="INTEGER"/>
    <result column="pi_push_time" property="pushTime" jdbcType="TIMESTAMP"/>
    <result column="pi_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="pi_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    <result column="pi_type" property="type" typeHandler="com.yeshi.fanli.util.mybatishandler.PushTypeEnumHandler" />
  </resultMap>
  <sql id="Base_Column_List">pi_id,pi_title,pi_content,pi_uids,pi_json_data,pi_type,pi_control_time,pi_remark,pi_state,pi_push_time,pi_create_time,pi_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_push_info where pi_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_push_info where pi_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.push.PushInfo" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_push_info (pi_id,pi_title,pi_content,pi_uids,pi_json_data,pi_type,pi_control_time,pi_remark,pi_state,pi_push_time,pi_create_time,pi_update_time) values (#{id,jdbcType=BIGINT},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{uids,jdbcType=VARCHAR},#{jsonData,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{controlTime,jdbcType=TIMESTAMP},#{remark,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{pushTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.push.PushInfo" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_push_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">pi_id,</if>
      <if test="title != null">pi_title,</if>
      <if test="content != null">pi_content,</if>
      <if test="uids != null">pi_uids,</if>
      <if test="jsonData != null">pi_json_data,</if>
      <if test="type != null">pi_type,</if>
      <if test="controlTime != null">pi_control_time,</if>
      <if test="remark != null">pi_remark,</if>
      <if test="state != null">pi_state,</if>
      <if test="pushTime != null">pi_push_time,</if>
      <if test="createTime != null">pi_create_time,</if>
      <if test="updateTime != null">pi_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="title != null">#{title,jdbcType=VARCHAR},</if>
      <if test="content != null">#{content,jdbcType=VARCHAR},</if>
      <if test="uids != null">#{uids,jdbcType=VARCHAR},</if>
      <if test="jsonData != null">#{jsonData,jdbcType=VARCHAR},</if>
      <if test="type != null">#{type,jdbcType=VARCHAR},</if>
      <if test="controlTime != null">#{controlTime,jdbcType=TIMESTAMP},</if>
      <if test="remark != null">#{remark,jdbcType=VARCHAR},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
      <if test="pushTime != null">#{pushTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.push.PushInfo">update yeshi_ec_push_info set pi_title = #{title,jdbcType=VARCHAR},pi_content = #{content,jdbcType=VARCHAR},pi_uids = #{uids,jdbcType=VARCHAR},pi_json_data = #{jsonData,jdbcType=VARCHAR},pi_type = #{type,jdbcType=VARCHAR},pi_control_time = #{controlTime,jdbcType=TIMESTAMP},pi_remark = #{remark,jdbcType=VARCHAR},pi_state = #{state,jdbcType=INTEGER},pi_push_time = #{pushTime,jdbcType=TIMESTAMP},pi_create_time = #{createTime,jdbcType=TIMESTAMP},pi_update_time = #{updateTime,jdbcType=TIMESTAMP} where pi_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.push.PushInfo">update yeshi_ec_push_info
    <set>
      <if test="title != null">pi_title=#{title,jdbcType=VARCHAR},</if>
      <if test="content != null">pi_content=#{content,jdbcType=VARCHAR},</if>
      <if test="uids != null">pi_uids=#{uids,jdbcType=VARCHAR},</if>
      <if test="jsonData != null">pi_json_data=#{jsonData,jdbcType=VARCHAR},</if>
      <if test="type != null">pi_type=#{type,jdbcType=VARCHAR},</if>
      <if test="controlTime != null">pi_control_time=#{controlTime,jdbcType=TIMESTAMP},</if>
      <if test="remark != null">pi_remark=#{remark,jdbcType=VARCHAR},</if>
      <if test="state != null">pi_state=#{state,jdbcType=INTEGER},</if>
      <if test="pushTime != null">pi_push_time=#{pushTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">pi_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">pi_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where pi_id = #{id,jdbcType=BIGINT}
  </update>
   <delete id="deleteBatchByPrimaryKey"  parameterType="java.util.List">
        delete from yeshi_ec_push_info where pi_push_time is null AND pi_id in
        <foreach item="item" collection="list" open="(" separator=","
            close=")">#{item}</foreach>
   </delete>
  <select id="listQuery" resultMap="BaseResultMap">
      SELECT * FROM  yeshi_ec_push_info
    WHERE pi_type = #{type}
        <if test="key != null and key !='' ">
            <if test="keyType == 1">AND pi_title like '%#{key}%'</if>
            <if test="keyType == 2">AND pi_content like '%#{key}%'</if>
            <if test="keyType == 3">AND pi_uids like '%#{key}%'</if>
        </if>
        <if  test="state != null">
            AND pi_state = #{state}
        </if>
      ORDER BY pi_state,pi_push_time DESC
      LIMIT ${start},${count}
  </select>
  <select id="countQuery" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(pi_id),0) FROM  yeshi_ec_push_info
    WHERE pi_type = #{type}
        <if test="key != null and key !='' ">
            <if test="keyType == 1">AND pi_title like '%#{key}%'</if>
            <if test="keyType == 2">AND pi_content like '%#{key}%'</if>
            <if test="keyType == 3">AND pi_uids like '%#{key}%'</if>
        </if>
        <if test="state != null">
            AND pi_state = #{state}
        </if>
  </select>
  <select id="listTask" resultMap="BaseResultMap">
      SELECT * FROM `yeshi_ec_push_info` p
    WHERE p.`pi_state` = 0 AND p.`pi_control_time` IS NOT NULL
          AND p.`pi_control_time` <![CDATA[<=]]> NOW()
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushGoodsServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.impl.push;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -78,8 +79,25 @@
    @Override
    @Transactional
    public void save(PushGoods record, List<Long> goodsIds) throws Exception {
    public void save(PushGoods record, List<Long> goodsIds) throws PushGoodsException, Exception {
        // 定时时间
        Boolean timeTask = record.isTimeTask();
        if (timeTask != null && timeTask) {
            String controlTime_str = record.getControlTime_str();
            if (controlTime_str == null || controlTime_str.trim().length() == 0) {
                throw new PushGoodsException(1, "预设时间不能为空");
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            controlTime_str = controlTime_str.replaceAll("T", " ");
            record.setControlTime(format.parse(controlTime_str));
        } else {
            record.setControlTime(null);
        }
        record.setIsPush(PushGoods.STATE_INIT);
        boolean isAdd = false;
        // 推送id
        Long pushId = record.getId();
@@ -89,14 +107,20 @@
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            pushGoodsMapper.insertSelective(record);
            pushGoodsMapper.insert(record);
            pushId = record.getId();
        } else {
            // 修改
            PushGoods current = pushGoodsMapper.selectByPrimaryKey(pushId);
            if (current == null) {
                throw new PushGoodsException(1, "该记录已不存在");
            }
            record.setCreateTime(current.getCreateTime());
            record.setUpdateTime(new Date());
            pushGoodsMapper.updateByPrimaryKeySelective(record);
            pushGoodsMapper.updateByPrimaryKey(record);
        }
        // 处理商品信息
@@ -214,28 +238,72 @@
        return pushGoodsMapper.countHistoryByPushTime(uid, pushTime);
    }
    @Override
    public void executePush(Long id) throws Exception, PushGoodsException, PushException {
        PushGoods pushGoods = selectByPrimaryKey(id);
        if (pushGoods == null) {
            throw new PushException(1, "推送信息已不存在");
    public List<PushGoods> listTask() {
        return pushGoodsMapper.listTask();
    }
    @Override
    public void taskPush(PushGoods record) {
        String msg = null;
        int state = PushGoods.STATE_FAIL;
        try {
            // 执行推送
            executePush(record);
            state = PushGoods.STATE_SUCCESS;
        } catch (PushGoodsException e) {
            msg = e.getMsg();
        } catch (PushException e) {
            msg = e.getMsg();
        } catch (Exception e) {
            msg = "系统推送失败";
        }
        record.setIsPush(state);
        record.setPushTime(new Date());
        record.setRemark(msg);
        record.setUpdateTime(new Date());
        pushGoodsMapper.updateByPrimaryKey(record);
    }
    @Override
    public void handPush(Long id) throws Exception, PushGoodsException, PushException {
        PushGoods record = selectByPrimaryKey(id);
        if (record == null) {
            throw new PushGoodsException(1, "推送信息已不存在");
        }
        // 执行推送
        executePush(record);
        record.setIsPush(PushGoods.STATE_SUCCESS);
        record.setPushTime(new Date());
        record.setUpdateTime(new Date());
        pushGoodsMapper.updateByPrimaryKey(record);
    }
    @Override
    public void executePush(PushGoods pushGoods) throws Exception, PushGoodsException, PushException {
        Long id = pushGoods.getId();
        String alertTitle = pushGoods.getAlertTitle();
        String alertContent = pushGoods.getAlertContent();
        if (StringUtil.isNullOrEmpty(alertTitle) || StringUtil.isNullOrEmpty(alertContent)) {
            throw new PushException(1, "推送标题及内容不能为空");
            throw new PushGoodsException(1, "推送标题及内容不能为空");
        }
        List<PushGoodsGroup> goodsList = pushGoodsGroupService.getAllInfoByPushId(id);
        if (goodsList == null || goodsList.size() == 0) {
            throw new PushException(1, "推送无商品,请完善数据");
            throw new PushGoodsException(1, "推送无商品,请完善数据");
        }
        
        String versions = pushGoods.getVersions();
        if (versions == null || versions.trim().length() == 0) {
            throw new PushException(1, "推送版本不能为空");
            throw new PushGoodsException(1, "推送版本不能为空");
        }
        
        List<String> listIOS = new ArrayList<String>();
@@ -264,7 +332,7 @@
            PushGoodsGroup pushGoodsGroup = goodsList.get(0);
            CommonGoods commonGoods = pushGoodsGroup.getCommonGoods();
            if (commonGoods == null) {
                throw new PushException(1, "商品详细信息已不存在");
                throw new PushGoodsException(1, "商品详细信息已不存在");
            }
            Long goodsId = commonGoods.getGoodsId();
@@ -276,22 +344,13 @@
            /*   多个商品推送    */
            String url = configService.get("push_goods_details");
            if (StringUtil.isNullOrEmpty(url)) {
                throw new PushException(1, "推送页面链接不存在");
                throw new PushGoodsException(1, "推送页面链接不存在");
            }
            // 生成链接
            url = url + "?id=" + id;
            pushService.pushUrl(pushGoods.getUid(), alertTitle, alertContent, url, listIOS, listAndroid);
        }
        // 已推送
        pushGoods.setPush(true);
        // 推送时间
        pushGoods.setPushTime(new Date());
        // 更新时间
        pushGoods.setUpdateTime(new Date());
        updateByPrimaryKeySelective(pushGoods);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushInfoServiceImpl.java
New file
@@ -0,0 +1,377 @@
package com.yeshi.fanli.service.impl.push;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.dao.mybatis.push.PushInfoMapper;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.entity.push.PushInfo.PushTypeEnum;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.exception.push.PushInfoException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
import com.yeshi.fanli.service.inter.push.PushInfoService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
@Service
public class PushInfoServiceImpl implements PushInfoService {
    @Resource
    private PushService pushService;
    @Resource
    private UserSystemMsgService userSystemMsgService;
    @Resource
    private ConfigService configService;
    @Resource
    private PushInfoMapper pushInfoMapper;
    @Override
    public void save(PushInfo record) throws PushInfoException, Exception {
        if (record == null) {
            throw new PushInfoException(1, "参数不正确");
        }
        PushTypeEnum type = record.getType();
        if (type == null) {
            throw new PushInfoException(1, "推送类型不能为空");
        }
        String title = record.getTitle();
        if (title == null || title.trim().length() == 0) {
            throw new PushInfoException(1, "标题不能为空");
        }
        String arrayAndroid = record.getArrayAndroid();
        String arrayIOS = record.getArrayIOS();
        if (StringUtil.isNullOrEmpty(arrayIOS) && StringUtil.isNullOrEmpty(arrayAndroid)) {
            throw new PushInfoException(1, "推送版本不能为空");
        }
        // 定时时间
        Boolean timeTask = record.isTimeTask();
        if (timeTask != null && timeTask) {
            String controlTime_str = record.getControlTime_str();
            if (controlTime_str == null || controlTime_str.trim().length() == 0) {
                throw new PushInfoException(1, "预设时间不能为空");
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            controlTime_str = controlTime_str.replaceAll("T", " ");
            record.setControlTime(format.parse(controlTime_str));
        } else {
            record.setControlTime(null);
        }
        String url = record.getUrl();
        String content = record.getContent();
        if (StringUtil.isNullOrEmpty(url) && StringUtil.isNullOrEmpty(content)) {
            throw new PushInfoException(1, "推送内容或URL不能为空");
        }
        if (url != null && (url.trim().length() == 0 || url.equalsIgnoreCase("null"))) {
            record.setUrl(null);
        }
        if (content != null && (content.trim().length() == 0 || content.equalsIgnoreCase("null"))) {
            record.setContent(null);
        }
        String uids = record.getUids();
        if (uids != null && (uids.trim().length() == 0 || uids.equalsIgnoreCase("null"))) {
            record.setUids(null);
        }
        // 数据转换json
        convertJson(record);
        record.setState(PushInfo.STATE_INIT);
        Long id = record.getId();
        if (id == null) {
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            pushInfoMapper.insert(record);
        } else {
            // 修改
            PushInfo current = pushInfoMapper.selectByPrimaryKey(id);
            if (current == null) {
                throw new PushInfoException(1, "该记录已不存在");
            }
            if (PushInfo.STATE_SUCCESS == current.getState()) {
                throw new PushInfoException(1, "已推送成功的信息不能修改");
            }
            record.setCreateTime(current.getCreateTime());
            record.setUpdateTime(new Date());
            pushInfoMapper.updateByPrimaryKey(record);
        }
    }
    /**
     * 转换json
     *
     * @param pushGoods
     */
    public void convertJson(PushInfo record) {
        JSONObject json = new JSONObject();
        String url = record.getUrl();
        if (StringUtil.isNullOrEmpty(url)) {
            url = "";
        }
        json.put("url", url);
        json.put("ios", convertVersion(record.getArrayIOS()));
        json.put("android", convertVersion(record.getArrayAndroid()));
        record.setJsonData(json.toString());
    }
    /**
     * 转换list
     *
     * @param pushGoods
     */
    public String convertVersion(String array) {
        String versions = "";
        if (array != null && array.trim().length() > 0) {
            Gson gson = new Gson();
            List<String> list = gson.fromJson(array, new TypeToken<ArrayList<String>>() {
            }.getType());
            if (list != null && list.size() > 0) {
                for (String version: list) {
                    versions += version + ",";
                }
                if (versions.endsWith(",")) {
                    versions = versions.substring(0, versions.length() - 1);
                }
            }
        }
        return versions;
    }
    @Override
    public void deleteBatchByPrimaryKey(List<Long> list) {
        pushInfoMapper.deleteBatchByPrimaryKey(list);
    }
    @Override
    public List<PushInfo> listQuery(long start, int count, String key, Integer keyType, Integer state, String type) {
        List<PushInfo> list = pushInfoMapper.listQuery(start, count, key, keyType, state, type);
        if (list == null || list.size() == 0) {
            return list;
        }
        for (PushInfo pushInfo: list) {
            Date controlTime = pushInfo.getControlTime();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
            if (controlTime == null) {
                pushInfo.setTimeTask(false);
                pushInfo.setControlTime_str("");
            } else {
                pushInfo.setTimeTask(true);
                pushInfo.setControlTime_str(sdf.format(controlTime));
            }
            String jsonData = pushInfo.getJsonData();
            JSONObject json = JSONObject.fromObject(jsonData);
            String url = json.getString("url");
            pushInfo.setUrl(url);
            List<String> listIOS = new ArrayList<String>();
            String versionsIOS = json.getString("ios");
            if (versionsIOS != null && versionsIOS.trim().length() > 0) {
                listIOS = Arrays.asList(versionsIOS.split(","));
            }
            pushInfo.setListIOS(listIOS);
            List<String> listAndroid = new ArrayList<String>();
            String versionsAndroid = json.getString("android");
            if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
                listAndroid = Arrays.asList(versionsAndroid.split(","));
            }
            pushInfo.setListAndroid(listAndroid);
        }
        return list;
    }
    @Override
    public long countQuery(String key, Integer keyType, Integer state, String type) {
        return pushInfoMapper.countQuery(key, keyType, state, type);
    }
    @Override
    public List<PushInfo> listTask() {
        return pushInfoMapper.listTask();
    }
    @Override
    public void handPush(Long id) throws Exception, PushInfoException, PushException {
        PushInfo record = pushInfoMapper.selectByPrimaryKey(id);
        if (record == null) {
            throw new PushInfoException(1, "推送信息已不存在");
        }
        // 执行推送
        executePush(record);
        record.setState(PushInfo.STATE_SUCCESS);
        record.setPushTime(new Date());
        record.setUpdateTime(new Date());
        pushInfoMapper.updateByPrimaryKey(record);
    }
    @Override
    public void taskPush(PushInfo record) {
        String msg = null;
        int state = PushInfo.STATE_FAIL;
        try {
            // 执行推送
            executePush(record);
            state = PushInfo.STATE_SUCCESS;
        } catch (PushInfoException e) {
            msg = e.getMsg();
        } catch (PushException e) {
            msg = e.getMsg();
        } catch (Exception e) {
            msg = "系统推送失败";
        }
        record.setState(state);
        record.setPushTime(new Date());
        record.setRemark(msg);
        record.setUpdateTime(new Date());
        pushInfoMapper.updateByPrimaryKey(record);
    }
    @Override
    @Transactional
    public void executePush(PushInfo record) throws Exception, PushInfoException, PushException {
        if (PushInfo.STATE_SUCCESS == record.getState()) {
            throw new PushInfoException(1, "该信息不能重复推送");
        }
        String title = record.getTitle();
        if (title == null || title.trim().length() == 0) {
            throw new PushInfoException(1, "标题不能为空");
        }
        String jsonData = record.getJsonData();
        if (StringUtil.isNullOrEmpty(jsonData) && StringUtil.isNullOrEmpty(jsonData)) {
            throw new PushInfoException(1, "推送版本不能为空");
        }
        JSONObject json = JSONObject.fromObject(jsonData);
        String url = json.getString("url");
        String content = record.getContent();
        if (StringUtil.isNullOrEmpty(url) && StringUtil.isNullOrEmpty(content)) {
            throw new PushInfoException(1, "推送内容或URL不能为空");
        }
        List<String> listIOS = new ArrayList<String>();
        String versionsIOS = json.getString("ios");
        if (versionsIOS != null && versionsIOS.trim().length() > 0) {
            if (versionsIOS.contains("全推")) {
                listIOS = null;
            } else {
                listIOS = Arrays.asList(versionsIOS.split(","));
            }
        }
        List<String> listAndroid = new ArrayList<String>();
        String versionsAndroid = json.getString("android");
        if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
            if (versionsAndroid.contains("全推")) {
                listAndroid = null;
            } else {
                listAndroid = Arrays.asList(versionsAndroid.split(","));
            }
        }
        List<String> listuid = null;
        String uids = record.getUids();
        if (uids != null && uids.trim().length() > 0) {
            listuid = Arrays.asList(uids.split(","));
            if (listuid == null || listuid.size() == 0) {
                throw new PushInfoException(1, "用户id格式不正确");
            }
        }
        PushTypeEnum type = record.getType();
        if (type == null) {
            throw new PushInfoException(1, "推送类型不能为空");
        }
        int pushWay = 0;
        if (PushTypeEnum.ZNX == type) {
            pushWay = 1;
        } else if (PushTypeEnum.URL == type) {
            pushWay = 2;
        } else if (PushTypeEnum.BAICHUAN == type) {
            pushWay = 3;
        } else {
            throw new PushInfoException(1, "推送类型不匹配");
        }
        if (listuid == null) { // 全推
            switch (pushWay) {
            case 1: // 站内信
                pushService.pushZNX(null, title, content, listIOS, listAndroid);
                break;
            case 2: // 网页推送
                pushService.pushUrl(null, title, content, url, listIOS, listAndroid);
                break;
            case 3: // 百川
                pushService.pushBaiChuanUrl(null, title, content, url, listIOS, listAndroid);
                break;
            default:
                throw new PushInfoException(1, "推送类型不匹配");
            }
        } else {
            for (String str_uid : listuid) {
                if (str_uid != null && str_uid.trim().length() > 0) {
                    long uid = Long.parseLong(str_uid);
                    switch (pushWay) {
                    case 1: // 站内信
                        pushService.pushZNX(uid, title, content, listIOS, listAndroid);
                        userSystemMsgService.addUserSystemMsg(uid, UserSystemMsgTypeEnum.question, title, content,
                                UserSystemMsg.TIME_TAG_EMERGENT, null);
                        break;
                    case 2: // 网页推送
                        pushService.pushUrl(uid, title, content, url, listIOS, listAndroid);
                        break;
                    case 3: // 百川
                        pushService.pushBaiChuanUrl(uid, title, content, url, listIOS, listAndroid);
                        break;
                    default:
                        throw new PushInfoException(1, "推送类型不匹配");
                    }
                }
            }
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushGoodsService.java
@@ -21,7 +21,7 @@
    public int updateByPrimaryKey(PushGoods record) throws PushGoodsException;
    public void save(PushGoods record, List<Long> goodsId) throws Exception;
    public void save(PushGoods record, List<Long> goodsId) throws PushGoodsException,Exception;
    
    /**
     * 批量删除
@@ -61,6 +61,27 @@
     * @throws PushGoodsException
     * @throws PushException
     */
    public void executePush(Long id) throws Exception, PushGoodsException, PushException;
    public void executePush(PushGoods record) throws Exception, PushGoodsException, PushException;
    /**
     * 定时推送任务
     * @return
     */
    public List<PushGoods> listTask();
    /**
     * 定时推送处理
     * @param record
     */
    public void taskPush(PushGoods record);
    /**
     * 后端推送
     * @param id
     * @throws Exception
     * @throws PushGoodsException
     * @throws PushException
     */
    public void handPush(Long id) throws Exception, PushGoodsException, PushException;
    
}
fanli/src/main/java/com/yeshi/fanli/service/inter/push/PushInfoService.java
New file
@@ -0,0 +1,66 @@
package com.yeshi.fanli.service.inter.push;
import java.util.List;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.exception.push.PushCouponException;
import com.yeshi.fanli.exception.push.PushInfoException;
public interface PushInfoService {
    public void deleteBatchByPrimaryKey(List<Long> list);
    public void save(PushInfo record) throws PushInfoException,Exception;
    /**
     * 后端查询
     * @param start
     * @param count
     * @param key
     * @param keyType
     * @param state
     * @return
     */
    public List<PushInfo> listQuery(long start, int count, String key, Integer keyType, Integer state, String type);
    public long countQuery(String key, Integer keyType, Integer state, String type);
    /**
     * 后端手动推送
     * @param id
     * @throws Exception
     * @throws PushInfoException
     * @throws PushException
     */
    public void handPush(Long id) throws Exception, PushInfoException, PushException;
    /**
     * 执行推送
     * @param id
     * @throws Exception
     * @throws PushCouponException
     * @throws PushException
     */
    public void executePush(PushInfo pushInfo) throws Exception, PushInfoException, PushException;
    /**
     * 需要推送的任务
     * @return
     */
    public List<PushInfo> listTask();
    /**
     *定时任务推送
     * @param record
     */
    public void taskPush(PushInfo record);
}
fanli/src/main/java/com/yeshi/fanli/util/mybatishandler/PushTypeEnumHandler.java
New file
@@ -0,0 +1,53 @@
package com.yeshi.fanli.util.mybatishandler;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import com.yeshi.fanli.entity.push.PushInfo.PushTypeEnum;
public class PushTypeEnumHandler extends BaseTypeHandler<PushTypeEnum> {
    @Override
    public PushTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            return PushTypeEnum.valueOf(key);
        }
    }
    @Override
    public PushTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return PushTypeEnum.valueOf(key);
        }
    }
    @Override
    public PushTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return PushTypeEnum.valueOf(key);
        }
    }
    @Override
    public void setNonNullParameter(PreparedStatement arg0, int arg1, PushTypeEnum arg2, JdbcType arg3)
            throws SQLException {
        arg0.setString(arg1, arg2.name());
    }
}