| | |
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.push.PushCoupon;
|
| | | import com.yeshi.fanli.exception.PushException;
|
| | | import com.yeshi.fanli.exception.push.PushCouponException;
|
| | | import com.yeshi.fanli.exception.push.PushException;
|
| | | import com.yeshi.fanli.service.inter.push.PushCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.push.PushCouponService;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | |
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "save")
|
| | | public void save(String callback, PushCoupon pushCoupon, PrintWriter out) {
|
| | | public void save(String callback, PushCoupon pushCoupon, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | pushCouponService.save(pushCoupon);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
|
| | | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("发放成功"));
|
| | | } catch (PushCouponException e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("发送失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
| | | long receivedCount = pushCouponRecordService.countByPushId(pushCoupon.getId());
|
| | | pushCouponVO.setReceivedCount(receivedCount);
|
| | |
|
| | | convertVersionList(pushCouponVO);
|
| | | |
| | | Date createTime = pushCouponVO.getCreateTime();
|
| | | pushCouponVO.setPushTime(createTime);
|
| | | |
| | | listVO.add(pushCouponVO);
|
| | | }
|
| | |
|
| | |
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder();
|
| | | gsonBuilder.serializeNulls();
|
| | | Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
|
| | | Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd").create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("pe", pe);
|
| | |
| | | * @throws Exception
|
| | | */
|
| | | @RequestMapping(value = "push")
|
| | | public void push(String callback, Long id, PrintWriter out) throws Exception {
|
| | | public void push(String callback, String idArray, PrintWriter out) throws Exception {
|
| | |
|
| | | if (id == null) {
|
| | | if (idArray == null || idArray.trim().length() == 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递参数不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | try {
|
| | | |
| | | pushCouponService.executePush(id);
|
| | | 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) {
|
| | | pushCouponService.executePush(id);
|
| | | }
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 版本转换为list
|
| | | * @param pushGoods
|
| | | */
|
| | | public void convertVersionList(PushCouponVO pushCouponVO) {
|
| | | String versions = pushCouponVO.getVersions();
|
| | | List<String> listIOS = null;
|
| | | List<String> listAndroid = null;
|
| | | if (versions == null || versions.trim().length() == 0) {
|
| | | listIOS = new ArrayList<String>();
|
| | | listAndroid = new ArrayList<String>();
|
| | | } else {
|
| | | JSONObject json = JSONObject.fromObject(versions);
|
| | | |
| | | String versionsIOS = json.getString("IOS");
|
| | | if (versionsIOS != null && versionsIOS.trim().length() > 0) {
|
| | | listIOS = Arrays.asList(versionsIOS.split(","));
|
| | | }
|
| | | |
| | | String versionsAndroid = json.getString("Android");
|
| | | if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
|
| | | listAndroid = Arrays.asList(versionsAndroid.split(","));
|
| | | }
|
| | | }
|
| | | pushCouponVO.setListIOS(listIOS);
|
| | | pushCouponVO.setListAndroid(listAndroid);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 转换json
|
| | | * @param pushGoods
|
| | | */
|
| | | public void convertVersion(PushCoupon pushCoupon, String arrayIOS, String arrayAndroid) {
|
| | | |
| | | List<String> listIOS = convertList(arrayIOS);
|
| | | List<String> listAndroid = convertList(arrayAndroid);
|
| | | if ((listIOS == null || listIOS.size() == 0) && (listAndroid == null || listAndroid.size() == 0)) {
|
| | | return;
|
| | | }
|
| | | |
| | | JSONObject json = new JSONObject();
|
| | | if (listIOS != null && listIOS.size() > 0) {
|
| | | String versions = "";
|
| | | for (String version: listIOS) {
|
| | | versions += version + ",";
|
| | | }
|
| | | if (versions.endsWith(",")) {
|
| | | versions = versions.substring(0, versions.length() - 1);
|
| | | }
|
| | | json.put("IOS", versions);
|
| | | }
|
| | | |
| | | if (listAndroid != null && listAndroid.size() > 0) {
|
| | | String versions = "";
|
| | | for (String version: listAndroid) {
|
| | | versions += version + ",";
|
| | | }
|
| | | if (versions.endsWith(",")) {
|
| | | versions = versions.substring(0, versions.length() - 1);
|
| | | }
|
| | | json.put("Android", versions);
|
| | | }
|
| | | |
| | | pushCoupon.setVersions(json.toString());
|
| | | }
|
| | | |
| | | /**
|
| | | * 版本处理
|
| | | * @param array
|
| | | * @return
|
| | | */
|
| | | public List<String> convertList (String array) {
|
| | | Gson gson = new Gson();
|
| | | List<String> list = null;
|
| | | if (array != null && array.trim().length() > 0) {
|
| | | list = gson.fromJson(array, new TypeToken<ArrayList<String>>() {}.getType());
|
| | | }
|
| | | return list;
|
| | | }
|
| | | |
| | | }
|