From ae2294be876ac4595d7b31b36c0057726d12354f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 14 五月 2021 16:11:16 +0800 Subject: [PATCH] 淘宝券后价计算方法名称修改 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/QualityFactoryAdminController.java | 1874 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 937 insertions(+), 937 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/QualityFactoryAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/QualityFactoryAdminController.java index 49bafe4..d8f284b 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/QualityFactoryAdminController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/QualityFactoryAdminController.java @@ -1,937 +1,937 @@ -package com.yeshi.fanli.controller.admin; - -import java.io.PrintWriter; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; - -import com.yeshi.fanli.entity.accept.AdminAcceptData; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.taobao.TbImgUtil; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule; -import com.yeshi.fanli.entity.bus.lable.Label; -import com.yeshi.fanli.entity.bus.lable.LabelGoods; -import com.yeshi.fanli.entity.bus.lable.QualityFactory; -import com.yeshi.fanli.entity.common.AdminUser; -import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; -import com.yeshi.fanli.exception.goods.quality.QualityFactoryException; -import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; -import com.yeshi.fanli.service.inter.lable.LabelGoodsService; -import com.yeshi.fanli.service.inter.lable.LabelService; -import com.yeshi.fanli.service.inter.lable.QualityFactoryService; -import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; -import com.yeshi.common.entity.PageEntity; -import com.yeshi.fanli.util.Constant; -import org.yeshi.utils.MoneyBigDecimalUtil; -import com.yeshi.fanli.util.RedisManager; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.taobao.TaoBaoUtil; -import com.yeshi.fanli.util.taobao.TaoKeApiUtil; -import com.yeshi.fanli.vo.quality.QualityFactoryVO; - -import net.sf.json.JSONObject; - -@Controller -@RequestMapping("admin/new/api/v1/qualityFactory") -public class QualityFactoryAdminController { - - @Resource - private RedisManager redisManager; - @Resource - private LabelService labelService; - @Resource - private LabelGoodsService labelGoodsService; - @Resource - private QualityFactoryService qualityFactoryService; - @Resource - private TaoBaoGoodsBriefService taoBaoGoodsBriefService; - @Resource - private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; - - public static final int SALES_ASC = 1; - public static final int SALES_DESC = 2; - - public static final int PRICE_ASC = 3; - public static final int PRICE_DESC = 4; - - public static final int TKRATE_ASC = 5; - public static final int TKRATE_DESC = 6; - - public static final int PROPOR_ASC = 7; - public static final int PROPOR_DESC = 8; - - /** - * 淇濆瓨淇敼绮惧搧搴撳晢鍝佸叧鑱斾俊鎭� - * - * @param callback - * @param label - * @param request - * @param out - */ - @RequestMapping(value = "saveModify") - public void saveModify(AdminAcceptData acceptData, String callback, QualityFactory selectionGoods, HttpServletRequest request, - PrintWriter out) { - - try { - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); - - if (admin == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄�"))); - } else { - - Long id = selectionGoods.getId(); - QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); - - if (resultObj == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); - } else { - Date nowTime = new Date(); - selectionGoods.setUpdatetime(nowTime); - selectionGoods.setUpdateUser(admin); - // 閫夋嫨鎬ф洿鏂版暟鎹� - int result = qualityFactoryService.updateByPrimaryKeySelective(selectionGoods); - - if (result > 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); - } - } - } - - } catch (QualityFactoryException e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - } - - } - - /** - * 缁熻鍟嗗搧鏁伴噺 - * - * @param callback - * @param out - */ - @RequestMapping(value = "getCountAll") - public void getCountAll(AdminAcceptData acceptData,String callback, PrintWriter out) { - - try { - - Map<String, Object> countMap = qualityFactoryService.getCountAll(); - - JSONObject data = new JSONObject(); - data.put("countData", countMap); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("绯荤粺寮傚父"))); - } - } - - /** - * 鎵归噺绉婚櫎鍟嗗搧鑷崇簿鍝佸簱澶�-涓嶅垹闄ゅ晢鍝� - * - * @param callback - * @param ids - * 鍟嗗搧id - * @param out - */ - @RequestMapping(value = "removeGoods") - public void removeGoods(AdminAcceptData acceptData,String callback, String ids, PrintWriter out) { - try { - Gson gson = new Gson(); - List<Long> goodsIds = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { - }.getType()); - - if (goodsIds == null || goodsIds.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈娴嬪埌绉婚櫎鍟嗗搧鏁版嵁"))); - return; - } - - qualityFactoryService.deleteBatchByTaoBaoGoodsId(goodsIds); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("绉婚櫎鎴愬姛"))); - } catch (Exception e) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔澶辫触"))); - e.printStackTrace(); - } - - } - - /** - * 鏌ヨ - * - * @param out - */ - @RequestMapping(value = "query") - public void query(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, Integer sort, - QualityFactoryVO qualityFactoryVO, PrintWriter out) { - - try { - if (pageSize == null) - pageSize = Constant.PAGE_SIZE; - - if (pageIndex == null) - pageIndex = 1; - - Integer price = null; - Integer tkRate = null; - Integer totalSales = null; - Integer propor = null; - - if (sort != null) { - switch (sort) { - case SALES_ASC: - totalSales = 1; - break; - case SALES_DESC: - totalSales = 2; - break; - case PRICE_ASC: - price = 1; - break; - case PRICE_DESC: - price = 2; - break; - case TKRATE_ASC: - tkRate = 1; - break; - case TKRATE_DESC: - tkRate = 2; - break; - case PROPOR_ASC: - propor = 1; - break; - case PROPOR_DESC: - propor = 2; - break; - default: - break; - } - } - - qualityFactoryVO.setPrice(price); - qualityFactoryVO.setTkRate(tkRate); - qualityFactoryVO.setTotalSales(totalSales); - qualityFactoryVO.setPropor(propor); - qualityFactoryVO.setStart((pageIndex - 1) * pageSize); - qualityFactoryVO.setCount(pageSize); - - List<QualityFactory> selectionList = qualityFactoryService.query(qualityFactoryVO); - - /* 鏆傛棤鏁版嵁鏄剧ず */ - if (selectionList == null || selectionList.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁")); - return; - } - - /* 鏈夋暟鎹細澶勭悊杩斿洖鏍煎紡 */ - - long count = qualityFactoryService.queryCount(qualityFactoryVO); - - int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); - - PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); - - List<Map<String, Object>> listmap = new ArrayList<Map<String, Object>>(); - - /* 楠岃瘉缃戠粶: 鑾峰彇鍟嗗搧閾炬帴 鍥剧墖閾炬帴 */ - List<TaoBaoGoodsBrief> goodsBriefList = new ArrayList<TaoBaoGoodsBrief>(); - - StringBuffer idBuf = new StringBuffer(); - StringBuffer auctionIdBuf = new StringBuffer(); - - int j = 0; - for (int i = 0; i < selectionList.size(); i++) { - QualityFactory selectionGoods = selectionList.get(i); - - TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief(); - if (taoBaoGoodsBrief == null) - continue; // 涓虹┖缁撴潫鏈寰幆 - - Long id = taoBaoGoodsBrief.getId(); - idBuf.append(id + ","); - - Long auctionId = taoBaoGoodsBrief.getAuctionId(); - if (auctionId != null) { - j++; - auctionIdBuf.append(auctionId + ","); - } - - if (selectionList.size() <= 40) { - // 灏忎簬40涓弬鏁� - if (i == selectionList.size() - 1) { - if (auctionIdBuf != null && auctionIdBuf.length() > 0) { - String auctionIds = auctionIdBuf.toString(); - String ids = auctionIds.substring(0, auctionIds.length() - 1); - List<TaoBaoGoodsBrief> list = null; - try { - list = TaoKeApiUtil.getBatchGoodsInfos(ids); - } catch (Exception e) { - e.printStackTrace(); - } - - if (list != null && list.size() > 0) { - goodsBriefList.addAll(list); - } - - auctionIdBuf = new StringBuffer(); - } - } - } else { - if (j == 40) { - // 澶т簬40鍙傛暟 - String auctionIds = auctionIdBuf.toString(); - String ids = auctionIds.substring(0, auctionIds.length() - 1); - List<TaoBaoGoodsBrief> list = null; - try { - list = TaoKeApiUtil.getBatchGoodsInfos(ids); - } catch (Exception e) { - e.printStackTrace(); - } - - if (list != null && list.size() > 0) { - goodsBriefList.addAll(list); - } - - j = 0; - auctionIdBuf = new StringBuffer(); - - } else if (i == selectionList.size() - 1) { - // 鏈�鍚庝竴涓� - String auctionIds = auctionIdBuf.toString(); - String ids = auctionIds.substring(0, auctionIds.length() - 1); - List<TaoBaoGoodsBrief> list = null; - try { - list = TaoKeApiUtil.getBatchGoodsInfos(ids); - } catch (Exception e) { - e.printStackTrace(); - } - - if (list != null && list.size() > 0) { - goodsBriefList.addAll(list); - } - auctionIdBuf = new StringBuffer(); - } - } - - } - - for (QualityFactory selectionGoods : selectionList) { - - TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief(); - - if (taoBaoGoodsBrief == null) - continue; // 涓虹┖缁撴潫鏈寰幆 - - // 璁剧疆鍥剧墖澶у皬 - taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize220Img(taoBaoGoodsBrief.getPictUrl())); - - String auctionUrl = taoBaoGoodsBrief.getAuctionUrl(); - if (auctionUrl != null && auctionUrl.trim().length() > 0 && auctionUrl.contains("id=null")) { - auctionUrl = auctionUrl.replace("id=null", "id=" + taoBaoGoodsBrief.getAuctionId()); - taoBaoGoodsBrief.setAuctionUrl(auctionUrl); - } - - Map<String, Object> map = new HashMap<String, Object>(); - - BoutiqueAutoRule boutiqueAutoRule = selectionGoods.getBoutiqueAutoRule(); - if (boutiqueAutoRule == null) { - boutiqueAutoRule = new BoutiqueAutoRule(); - selectionGoods.setBoutiqueAutoRule(boutiqueAutoRule); - } - - String reslutSource = ""; - Integer gsSource = selectionGoods.getGoodsSource(); - if (QualityFactory.SOURCE_TAOBAO == gsSource) { - reslutSource = "娣樺疂"; - } else if (QualityFactory.SOURCE_TAOBAO_MATERIAL == gsSource) { - reslutSource = "娣樺疂鎺ㄨ崘"; - } else if (QualityFactory.SOURCE_TAOBAO_DATAOKE == gsSource) { - reslutSource = "澶ф窐瀹�"; - } else if (QualityFactory.SOURCE_JINGDONG == gsSource) { - reslutSource = "浜笢"; - } else if (QualityFactory.SOURCE_PINDUODUO == gsSource) { - reslutSource = "鎷煎澶�"; - } else if (QualityFactory.SOURCE_WEIPINHUI == gsSource) { - reslutSource = "鍞搧浼�"; - } else if (QualityFactory.SOURCE_OTHER == gsSource) { - reslutSource = "鍟嗗姟鍚堜綔"; - } - - map.put("goodsSource", reslutSource); - - map.put("selectionGoods", selectionGoods); - - /* 鍟嗗搧閿�鍞姸鎬侊細 0 鍦ㄥ敭 1鍋滃敭 */ - int saleStae = 1; - Long auctionId = taoBaoGoodsBrief.getAuctionId(); - if (auctionId != null) { - if (goodsBriefList != null && goodsBriefList.size() > 0) { - for (TaoBaoGoodsBrief tb : goodsBriefList) { - Long auctionIdTB = tb.getAuctionId(); - if (auctionId.equals(auctionIdTB)) { - saleStae = 0; - } - } - } - } - - map.put("saleStae", saleStae); - - /* 1 瀹氬悜璁″垝 2 钀ラ攢杩斿埄 銆侀珮浣� 3 鏅剑 */ - Integer includeDxjh = taoBaoGoodsBrief.getIncludeDxjh(); - String tkMktStatus = taoBaoGoodsBrief.getTkMktStatus(); - - boolean include = false; - if (includeDxjh != null) { - if (includeDxjh == 1) { - // 瀹氬悜璁″垝 - map.put("yongjinType", 1); - include = true; - } - } - - if (!include) { - - if ("1".equals(tkMktStatus)) { - // 钀ラ攢杩斿埄 銆侀珮浣� - map.put("yongjinType", 2); - } else { - // 鏅剑 - map.put("yongjinType", 3); - } - } - - /* 鍒稿悗浠�--璁$畻 */ - BigDecimal couponPrice = TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief); - map.put("couponPrice", couponPrice); - - /* 棰勮鏀剁泭锛� 鍏徃銆佺敤鎴� */ - BigDecimal tkRateBrief = taoBaoGoodsBrief.getTkRate(); - BigDecimal zkPrice = taoBaoGoodsBrief.getZkPrice(); - BigDecimal profit = MoneyBigDecimalUtil.mul(tkRateBrief, zkPrice); - // 璁$畻缁撴灉 - BigDecimal estimateProfit = MoneyBigDecimalUtil.div(profit, new BigDecimal("100")); - // 棰勮鏀剁泭 - map.put("estimateProfit", estimateProfit); - - BigDecimal couponAmount = taoBaoGoodsBrief.getCouponAmount(); - if (couponAmount != null && zkPrice != null) { - BigDecimal propors = couponAmount.divide(zkPrice, 10, BigDecimal.ROUND_HALF_DOWN); - BigDecimal resultPropor = MoneyBigDecimalUtil.mul(propors, new BigDecimal("100")); - map.put("propor", resultPropor); - } else { - map.put("propor", 0); - } - - /* 鍟嗗搧鏍囩鍒楄〃 */ - Long id = taoBaoGoodsBrief.getId(); - int totalLabels = labelGoodsService.getCountQueryByGoodsId(id); - - // List<LabelGoods> labelList = labelService.getByGoodsId(id); - - map.put("totalLabels", totalLabels); - - listmap.add(map); - } - - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.serializeNulls(); // 閲嶇偣 - Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); - - JSONObject data = new JSONObject(); - data.put("pe", pe); - data.put("listGoods", gson.toJson(listmap)); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); - e.printStackTrace(); - } - } - - /** - * 鑾峰彇鍟嗗搧淇℃伅 浠ュ強瀵瑰簲鏍囩鍒楄〃锛涙鍟嗗搧鏍囩鍊欓�夐」 - * - * @param callback - * @param id - * 绮鹃�塱d - * @param request - * @param out - */ - @RequestMapping(value = "getGoodsInfo") - public void getGoodsInfo(AdminAcceptData acceptData,String callback, Long id, HttpServletRequest request, PrintWriter out) { - - try { - - QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); - - if (resultObj == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); - return; - } - - TaoBaoGoodsBrief taobao = resultObj.getTaoBaoGoodsBrief(); - if (taobao == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪"))); - return; - } - - // 鍟嗗搧鍥剧墖 - List<String> imgList = TaoBaoUtil.getTbImg(taobao.getAuctionId() + ""); - - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.serializeNulls(); // 閲嶇偣 - Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); - - JSONObject data = new JSONObject(); - // data.put("taobao", gson.toJson(taobao)); - data.put("imgList", gson.toJson(imgList)); - - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - } - - } - - /** - * 鍗曚釜鍟嗗搧璐翠笂鏍囩 - * - * @param callback - * @param id - * @param labId - * @param request - * @param out - */ - @RequestMapping(value = "addGoodsLable") - public void addGoodsLable(AdminAcceptData acceptData,String callback, Long id, Long labId, HttpServletRequest request, PrintWriter out) { - - try { - // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); - // if (admin == null) { - // out.print(JsonUtil.loadJSONP(callback, - // JsonUtil.loadFalseResult("褰撳墠璐︽埛澶辨晥,璇烽噸鏂扮櫥闄嗐��"))); - // return; - // } - - if (id == null || labId == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭殑鍙傛暟"))); - return; - } - - TaoBaoGoodsBrief taoBaoGoodsBrief = taoBaoGoodsBriefService.selectByPrimaryKey(id); - if (taoBaoGoodsBrief == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅瓨鍦�"))); - return; - } - - Label label = labelService.selectByPrimaryKey(labId); - if (label == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ユ爣绛惧凡涓嶅瓨鍦�"))); - return; - } - - /* 璐翠笂鏍囩 锛� 宸茶创涓嶅鐞嗗垯 */ - Long existence = labelGoodsService.isExistence(id, labId); - - // 璇ュ晢鍝佷笉瀛樺湪姝ゆ爣绛惧垯娣诲姞锛� 鍙嶄箣涓嶅仛澶勭悊 - if (existence == null || existence == 0l) { - Date nowTime = new Date(); - // 璐翠笂鏂版爣绛� - LabelGoods lg = new LabelGoods(); - lg.setLabel(label); - lg.setCreateUser(admin); - lg.setCreatetime(nowTime); - lg.setTaoBaoGoodsBrief(taoBaoGoodsBrief); - - int insert = labelGoodsService.insertSelective(lg); - if (insert > 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛"))); - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞澶辫触"))); - } - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("姝ゅ晢鍝佸凡瀛樺湪璇ユ爣绛�"))); - } - - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - } - - } - - /** - * 鍒犻櫎鍟嗗搧鍏宠仈鐨勬爣绛� - * - * @param callback - * @param rid - * @param request - * @param out - */ - @RequestMapping(value = "removeSingle") - public void removeSingle(AdminAcceptData acceptData,String callback, Long rid, HttpServletRequest request, PrintWriter out) { - - try { - - int deleteId = labelGoodsService.deleteByPrimaryKey(rid); - - if (deleteId > 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("鍒犻櫎鎴愬姛"))); - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鍒犻櫎澶辫触"))); - } - - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - } - - } - - /** - * 璁剧疆鍟嗗搧鏉冮噸銆佺瓑淇℃伅 - * - * @param callback - * @param label - * @param request - * @param out - */ - @RequestMapping(value = "saveInfo") - public void saveInfo(AdminAcceptData acceptData,String callback, QualityFactory selectionGoods, HttpServletRequest request, PrintWriter out) { - - try { - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); - // - // if (admin == null) { - // out.print(JsonUtil.loadJSONP(callback, - // JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄�"))); - // return; - // } - - Long id = selectionGoods.getId(); - QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); - - if (resultObj == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); - } else { - Date nowTime = new Date(); - selectionGoods.setUpdatetime(nowTime); - selectionGoods.setUpdateUser(admin); - // 閫夋嫨鎬ф洿鏂版暟鎹� - int result = qualityFactoryService.updateByPrimaryKeySelective(selectionGoods); - - if (result > 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); - } - } - - } catch (QualityFactoryException e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - } - - } - - @RequestMapping(value = "queryMyLabels") - public void queryMyLabels(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, String ids, - HttpServletRequest request, PrintWriter out) { - - try { - - if (StringUtil.isNullOrEmpty(ids)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:101"))); - return; - } - - Gson gson = new Gson(); - List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { - }.getType()); - if (idList == null || idList.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:102"))); - return; - } - - if (idList.size() > 1) { - // 鍙鐞嗗崟涓晢鍝� - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:103"))); - return; - } - - Long id = idList.get(0); - - if (id == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:104"))); - return; - } - - if (pageIndex == null) - pageIndex = 1; - - if (pageSize == null) - pageSize = Constant.PAGE_SIZE; - - // 鍟嗗搧鏍囩鍒楄〃 - List<LabelGoods> labelList = labelGoodsService.queryByGoodsId((pageIndex - 1) * pageSize, pageSize, id); - - if (labelList == null || labelList.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏍囩")); - return; - } - - int count = labelGoodsService.getCountQueryByGoodsId(id); - - int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; - PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); - - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.serializeNulls(); - Gson rgson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); - - JSONObject data = new JSONObject(); - data.put("pe", pe); - data.put("labelList", rgson.toJson(labelList)); - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); - e.printStackTrace(); - } - } - - /** - * 鏌ヨ鍟嗗搧娣诲姞鏍囩鍊欓�夐」 - * - * @param callback - * @param pageIndex - * @param pageSize - * @param key - * @param id - * @param request - * @param out - */ - @RequestMapping(value = "queryLabel") - public void queryLabel(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, String key, String ids, - HttpServletRequest request, PrintWriter out) { - - try { - - if (StringUtil.isNullOrEmpty(ids)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:101"))); - return; - } - - Gson gson = new Gson(); - List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { - }.getType()); - if (idList == null || idList.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:102"))); - return; - } - - int count = 0; - List<Label> labelList = null; - - if (pageIndex == null) - pageIndex = 1; - - if (pageSize == null) - pageSize = Constant.PAGE_SIZE; - - if (idList.size() > 1) { - // 澶氫釜鍟嗗搧 鏌ヨ鎵�鏈夋爣绛� - labelList = labelService.query((pageIndex - 1) * pageSize, pageSize, key, null, null, null); - - count = labelService.getQueryCount(key, null, null); - - } else { - // 鍗曚釜鍟嗗搧 - Long id = idList.get(0); - if (id == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:104"))); - return; - } - - labelList = labelService.queryGoodsCandidate((pageIndex - 1) * pageSize, pageSize, key, id); - - count = labelService.getCountQueryGoodsCandidate(key, id); - } - - if (labelList == null || labelList.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏍囩")); - return; - } - - int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; - PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); - - GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.serializeNulls(); // 閲嶇偣 - Gson rgson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); - - JSONObject data = new JSONObject(); - data.put("pe", pe); - data.put("labelList", rgson.toJson(labelList)); - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); - e.printStackTrace(); - } - } - - /** - * 鍗曚釜鍟嗗搧鎵归噺娣诲姞鏍囩-鍏宠仈lableId - * - * @param callback - * @param id - * @param type - * @param request - * @param out - */ - @RequestMapping(value = "addBatchcGoodsLabel") - public void addBatchcGoodsLabel(AdminAcceptData acceptData,String callback, String labIds, Long id, HttpServletRequest request, - PrintWriter out) { - - try { - if (StringUtil.isNullOrEmpty(labIds)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈�夋嫨鏍囩")); - return; - } - - if (id == null) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈�夋嫨鍟嗗搧")); - return; - } - - Gson gson = new Gson(); - List<String> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<String>>() { - }.getType()); - if (labIdList == null || labIdList.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇烽�夋嫨鏍囩"))); - return; - } - - TaoBaoGoodsBrief taoBaoGoodsBrief = taoBaoGoodsBriefService.selectByPrimaryKey(id); - - // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); - labelGoodsService.addBatchByLabId(taoBaoGoodsBrief, labIdList, admin); - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎿嶄綔鎴愬姛")); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); - e.printStackTrace(); - } - } - - @RequestMapping(value = "updateGoodsBrief") - public void updateGoodsBrief(AdminAcceptData acceptData,String callback, TaoBaoGoodsBrief tb, PrintWriter out) { - try { - - // 瀹為檯鏈簿閫塈D - Long id = tb.getId(); - - QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); - - if (resultObj == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); - return; - } - - TaoBaoGoodsBrief taobao = resultObj.getTaoBaoGoodsBrief(); - if (taobao == null) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪"))); - return; - } - - String title = tb.getTitle(); - String pictUrl = tb.getPictUrl(); - - if (!StringUtil.isNullOrEmpty(title)) - taobao.setTitle(title); - - if (!StringUtil.isNullOrEmpty(pictUrl)) - taobao.setPictUrl(pictUrl); - - if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite())) - taobao.setPictUrlWhite(tb.getPictUrlWhite()); - - // 鏇存柊鍟嗗搧 - taoBaoGoodsUpdateService.getUpdateTaoBaoGoodsBrief(taobao); - - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); - - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); - } - - } - - /** - * 鎵归噺娣诲姞鏍囩 --- 绮惧搧搴擄紙闅忔満鏉冮噸锛� - * - * @param callback - * @param request - * @param out - * @param 鏉冮噸鑼冨洿 - * 澶у�� - * @param 浣i噾鑼冨洿 - * 灏忓�� - */ - @RequestMapping(value = "setWeightBatch") - public void setWeightBatch(AdminAcceptData acceptData,String callback, String ids, Integer weight, Integer weightSmall, Integer weightLarge, - HttpServletRequest request, PrintWriter out) { - - try { - - if (StringUtil.isNullOrEmpty(ids)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈�夋嫨闇�鎿嶄綔鐨勫晢鍝�"))); - return; - } - - Gson gson = new Gson(); - List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { - }.getType()); - - if (idList == null || idList.size() == 0) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇烽�夋嫨闇�鎿嶄綔鐨勫晢鍝�"))); - return; - } - // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 - AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); - - qualityFactoryService.setWeightBatch(idList, admin, weight, weightSmall, weightLarge); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("璁剧疆鎴愬姛"))); - - } catch (Exception e) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); - e.printStackTrace(); - } - - } - -} +package com.yeshi.fanli.controller.admin; + +import java.io.PrintWriter; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + +import com.yeshi.fanli.entity.accept.AdminAcceptData; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.taobao.TbImgUtil; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule; +import com.yeshi.fanli.entity.bus.lable.Label; +import com.yeshi.fanli.entity.bus.lable.LabelGoods; +import com.yeshi.fanli.entity.bus.lable.QualityFactory; +import com.yeshi.fanli.entity.common.AdminUser; +import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; +import com.yeshi.fanli.exception.goods.quality.QualityFactoryException; +import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; +import com.yeshi.fanli.service.inter.lable.LabelGoodsService; +import com.yeshi.fanli.service.inter.lable.LabelService; +import com.yeshi.fanli.service.inter.lable.QualityFactoryService; +import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; +import com.yeshi.common.entity.PageEntity; +import com.yeshi.fanli.util.Constant; +import org.yeshi.utils.MoneyBigDecimalUtil; +import com.yeshi.fanli.util.RedisManager; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.taobao.TaoBaoUtil; +import com.yeshi.fanli.util.taobao.TaoKeApiUtil; +import com.yeshi.fanli.vo.quality.QualityFactoryVO; + +import net.sf.json.JSONObject; + +@Controller +@RequestMapping("admin/new/api/v1/qualityFactory") +public class QualityFactoryAdminController { + + @Resource + private RedisManager redisManager; + @Resource + private LabelService labelService; + @Resource + private LabelGoodsService labelGoodsService; + @Resource + private QualityFactoryService qualityFactoryService; + @Resource + private TaoBaoGoodsBriefService taoBaoGoodsBriefService; + @Resource + private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; + + public static final int SALES_ASC = 1; + public static final int SALES_DESC = 2; + + public static final int PRICE_ASC = 3; + public static final int PRICE_DESC = 4; + + public static final int TKRATE_ASC = 5; + public static final int TKRATE_DESC = 6; + + public static final int PROPOR_ASC = 7; + public static final int PROPOR_DESC = 8; + + /** + * 淇濆瓨淇敼绮惧搧搴撳晢鍝佸叧鑱斾俊鎭� + * + * @param callback + * @param label + * @param request + * @param out + */ + @RequestMapping(value = "saveModify") + public void saveModify(AdminAcceptData acceptData, String callback, QualityFactory selectionGoods, HttpServletRequest request, + PrintWriter out) { + + try { + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + + if (admin == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄�"))); + } else { + + Long id = selectionGoods.getId(); + QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); + + if (resultObj == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); + } else { + Date nowTime = new Date(); + selectionGoods.setUpdatetime(nowTime); + selectionGoods.setUpdateUser(admin); + // 閫夋嫨鎬ф洿鏂版暟鎹� + int result = qualityFactoryService.updateByPrimaryKeySelective(selectionGoods); + + if (result > 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); + } else { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); + } + } + } + + } catch (QualityFactoryException e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + } + + } + + /** + * 缁熻鍟嗗搧鏁伴噺 + * + * @param callback + * @param out + */ + @RequestMapping(value = "getCountAll") + public void getCountAll(AdminAcceptData acceptData,String callback, PrintWriter out) { + + try { + + Map<String, Object> countMap = qualityFactoryService.getCountAll(); + + JSONObject data = new JSONObject(); + data.put("countData", countMap); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("绯荤粺寮傚父"))); + } + } + + /** + * 鎵归噺绉婚櫎鍟嗗搧鑷崇簿鍝佸簱澶�-涓嶅垹闄ゅ晢鍝� + * + * @param callback + * @param ids + * 鍟嗗搧id + * @param out + */ + @RequestMapping(value = "removeGoods") + public void removeGoods(AdminAcceptData acceptData,String callback, String ids, PrintWriter out) { + try { + Gson gson = new Gson(); + List<Long> goodsIds = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { + }.getType()); + + if (goodsIds == null || goodsIds.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈娴嬪埌绉婚櫎鍟嗗搧鏁版嵁"))); + return; + } + + qualityFactoryService.deleteBatchByTaoBaoGoodsId(goodsIds); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("绉婚櫎鎴愬姛"))); + } catch (Exception e) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔澶辫触"))); + e.printStackTrace(); + } + + } + + /** + * 鏌ヨ + * + * @param out + */ + @RequestMapping(value = "query") + public void query(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, Integer sort, + QualityFactoryVO qualityFactoryVO, PrintWriter out) { + + try { + if (pageSize == null) + pageSize = Constant.PAGE_SIZE; + + if (pageIndex == null) + pageIndex = 1; + + Integer price = null; + Integer tkRate = null; + Integer totalSales = null; + Integer propor = null; + + if (sort != null) { + switch (sort) { + case SALES_ASC: + totalSales = 1; + break; + case SALES_DESC: + totalSales = 2; + break; + case PRICE_ASC: + price = 1; + break; + case PRICE_DESC: + price = 2; + break; + case TKRATE_ASC: + tkRate = 1; + break; + case TKRATE_DESC: + tkRate = 2; + break; + case PROPOR_ASC: + propor = 1; + break; + case PROPOR_DESC: + propor = 2; + break; + default: + break; + } + } + + qualityFactoryVO.setPrice(price); + qualityFactoryVO.setTkRate(tkRate); + qualityFactoryVO.setTotalSales(totalSales); + qualityFactoryVO.setPropor(propor); + qualityFactoryVO.setStart((pageIndex - 1) * pageSize); + qualityFactoryVO.setCount(pageSize); + + List<QualityFactory> selectionList = qualityFactoryService.query(qualityFactoryVO); + + /* 鏆傛棤鏁版嵁鏄剧ず */ + if (selectionList == null || selectionList.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁")); + return; + } + + /* 鏈夋暟鎹細澶勭悊杩斿洖鏍煎紡 */ + + long count = qualityFactoryService.queryCount(qualityFactoryVO); + + int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); + + PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); + + List<Map<String, Object>> listmap = new ArrayList<Map<String, Object>>(); + + /* 楠岃瘉缃戠粶: 鑾峰彇鍟嗗搧閾炬帴 鍥剧墖閾炬帴 */ + List<TaoBaoGoodsBrief> goodsBriefList = new ArrayList<TaoBaoGoodsBrief>(); + + StringBuffer idBuf = new StringBuffer(); + StringBuffer auctionIdBuf = new StringBuffer(); + + int j = 0; + for (int i = 0; i < selectionList.size(); i++) { + QualityFactory selectionGoods = selectionList.get(i); + + TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief(); + if (taoBaoGoodsBrief == null) + continue; // 涓虹┖缁撴潫鏈寰幆 + + Long id = taoBaoGoodsBrief.getId(); + idBuf.append(id + ","); + + Long auctionId = taoBaoGoodsBrief.getAuctionId(); + if (auctionId != null) { + j++; + auctionIdBuf.append(auctionId + ","); + } + + if (selectionList.size() <= 40) { + // 灏忎簬40涓弬鏁� + if (i == selectionList.size() - 1) { + if (auctionIdBuf != null && auctionIdBuf.length() > 0) { + String auctionIds = auctionIdBuf.toString(); + String ids = auctionIds.substring(0, auctionIds.length() - 1); + List<TaoBaoGoodsBrief> list = null; + try { + list = TaoKeApiUtil.getBatchGoodsInfos(ids); + } catch (Exception e) { + e.printStackTrace(); + } + + if (list != null && list.size() > 0) { + goodsBriefList.addAll(list); + } + + auctionIdBuf = new StringBuffer(); + } + } + } else { + if (j == 40) { + // 澶т簬40鍙傛暟 + String auctionIds = auctionIdBuf.toString(); + String ids = auctionIds.substring(0, auctionIds.length() - 1); + List<TaoBaoGoodsBrief> list = null; + try { + list = TaoKeApiUtil.getBatchGoodsInfos(ids); + } catch (Exception e) { + e.printStackTrace(); + } + + if (list != null && list.size() > 0) { + goodsBriefList.addAll(list); + } + + j = 0; + auctionIdBuf = new StringBuffer(); + + } else if (i == selectionList.size() - 1) { + // 鏈�鍚庝竴涓� + String auctionIds = auctionIdBuf.toString(); + String ids = auctionIds.substring(0, auctionIds.length() - 1); + List<TaoBaoGoodsBrief> list = null; + try { + list = TaoKeApiUtil.getBatchGoodsInfos(ids); + } catch (Exception e) { + e.printStackTrace(); + } + + if (list != null && list.size() > 0) { + goodsBriefList.addAll(list); + } + auctionIdBuf = new StringBuffer(); + } + } + + } + + for (QualityFactory selectionGoods : selectionList) { + + TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief(); + + if (taoBaoGoodsBrief == null) + continue; // 涓虹┖缁撴潫鏈寰幆 + + // 璁剧疆鍥剧墖澶у皬 + taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize220Img(taoBaoGoodsBrief.getPictUrl())); + + String auctionUrl = taoBaoGoodsBrief.getAuctionUrl(); + if (auctionUrl != null && auctionUrl.trim().length() > 0 && auctionUrl.contains("id=null")) { + auctionUrl = auctionUrl.replace("id=null", "id=" + taoBaoGoodsBrief.getAuctionId()); + taoBaoGoodsBrief.setAuctionUrl(auctionUrl); + } + + Map<String, Object> map = new HashMap<String, Object>(); + + BoutiqueAutoRule boutiqueAutoRule = selectionGoods.getBoutiqueAutoRule(); + if (boutiqueAutoRule == null) { + boutiqueAutoRule = new BoutiqueAutoRule(); + selectionGoods.setBoutiqueAutoRule(boutiqueAutoRule); + } + + String reslutSource = ""; + Integer gsSource = selectionGoods.getGoodsSource(); + if (QualityFactory.SOURCE_TAOBAO == gsSource) { + reslutSource = "娣樺疂"; + } else if (QualityFactory.SOURCE_TAOBAO_MATERIAL == gsSource) { + reslutSource = "娣樺疂鎺ㄨ崘"; + } else if (QualityFactory.SOURCE_TAOBAO_DATAOKE == gsSource) { + reslutSource = "澶ф窐瀹�"; + } else if (QualityFactory.SOURCE_JINGDONG == gsSource) { + reslutSource = "浜笢"; + } else if (QualityFactory.SOURCE_PINDUODUO == gsSource) { + reslutSource = "鎷煎澶�"; + } else if (QualityFactory.SOURCE_WEIPINHUI == gsSource) { + reslutSource = "鍞搧浼�"; + } else if (QualityFactory.SOURCE_OTHER == gsSource) { + reslutSource = "鍟嗗姟鍚堜綔"; + } + + map.put("goodsSource", reslutSource); + + map.put("selectionGoods", selectionGoods); + + /* 鍟嗗搧閿�鍞姸鎬侊細 0 鍦ㄥ敭 1鍋滃敭 */ + int saleStae = 1; + Long auctionId = taoBaoGoodsBrief.getAuctionId(); + if (auctionId != null) { + if (goodsBriefList != null && goodsBriefList.size() > 0) { + for (TaoBaoGoodsBrief tb : goodsBriefList) { + Long auctionIdTB = tb.getAuctionId(); + if (auctionId.equals(auctionIdTB)) { + saleStae = 0; + } + } + } + } + + map.put("saleStae", saleStae); + + /* 1 瀹氬悜璁″垝 2 钀ラ攢杩斿埄 銆侀珮浣� 3 鏅剑 */ + Integer includeDxjh = taoBaoGoodsBrief.getIncludeDxjh(); + String tkMktStatus = taoBaoGoodsBrief.getTkMktStatus(); + + boolean include = false; + if (includeDxjh != null) { + if (includeDxjh == 1) { + // 瀹氬悜璁″垝 + map.put("yongjinType", 1); + include = true; + } + } + + if (!include) { + + if ("1".equals(tkMktStatus)) { + // 钀ラ攢杩斿埄 銆侀珮浣� + map.put("yongjinType", 2); + } else { + // 鏅剑 + map.put("yongjinType", 3); + } + } + + /* 鍒稿悗浠�--璁$畻 */ + BigDecimal couponPrice = TaoBaoUtil.getCouponPrice(taoBaoGoodsBrief); + map.put("couponPrice", couponPrice); + + /* 棰勮鏀剁泭锛� 鍏徃銆佺敤鎴� */ + BigDecimal tkRateBrief = taoBaoGoodsBrief.getTkRate(); + BigDecimal zkPrice = taoBaoGoodsBrief.getZkPrice(); + BigDecimal profit = MoneyBigDecimalUtil.mul(tkRateBrief, zkPrice); + // 璁$畻缁撴灉 + BigDecimal estimateProfit = MoneyBigDecimalUtil.div(profit, new BigDecimal("100")); + // 棰勮鏀剁泭 + map.put("estimateProfit", estimateProfit); + + BigDecimal couponAmount = taoBaoGoodsBrief.getCouponAmount(); + if (couponAmount != null && zkPrice != null) { + BigDecimal propors = couponAmount.divide(zkPrice, 10, BigDecimal.ROUND_HALF_DOWN); + BigDecimal resultPropor = MoneyBigDecimalUtil.mul(propors, new BigDecimal("100")); + map.put("propor", resultPropor); + } else { + map.put("propor", 0); + } + + /* 鍟嗗搧鏍囩鍒楄〃 */ + Long id = taoBaoGoodsBrief.getId(); + int totalLabels = labelGoodsService.getCountQueryByGoodsId(id); + + // List<LabelGoods> labelList = labelService.getByGoodsId(id); + + map.put("totalLabels", totalLabels); + + listmap.add(map); + } + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.serializeNulls(); // 閲嶇偣 + Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); + + JSONObject data = new JSONObject(); + data.put("pe", pe); + data.put("listGoods", gson.toJson(listmap)); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + e.printStackTrace(); + } + } + + /** + * 鑾峰彇鍟嗗搧淇℃伅 浠ュ強瀵瑰簲鏍囩鍒楄〃锛涙鍟嗗搧鏍囩鍊欓�夐」 + * + * @param callback + * @param id + * 绮鹃�塱d + * @param request + * @param out + */ + @RequestMapping(value = "getGoodsInfo") + public void getGoodsInfo(AdminAcceptData acceptData,String callback, Long id, HttpServletRequest request, PrintWriter out) { + + try { + + QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); + + if (resultObj == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); + return; + } + + TaoBaoGoodsBrief taobao = resultObj.getTaoBaoGoodsBrief(); + if (taobao == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪"))); + return; + } + + // 鍟嗗搧鍥剧墖 + List<String> imgList = TaoBaoUtil.getTbImg(taobao.getAuctionId() + ""); + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.serializeNulls(); // 閲嶇偣 + Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); + + JSONObject data = new JSONObject(); + // data.put("taobao", gson.toJson(taobao)); + data.put("imgList", gson.toJson(imgList)); + + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + } + + } + + /** + * 鍗曚釜鍟嗗搧璐翠笂鏍囩 + * + * @param callback + * @param id + * @param labId + * @param request + * @param out + */ + @RequestMapping(value = "addGoodsLable") + public void addGoodsLable(AdminAcceptData acceptData,String callback, Long id, Long labId, HttpServletRequest request, PrintWriter out) { + + try { + // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + // if (admin == null) { + // out.print(JsonUtil.loadJSONP(callback, + // JsonUtil.loadFalseResult("褰撳墠璐︽埛澶辨晥,璇烽噸鏂扮櫥闄嗐��"))); + // return; + // } + + if (id == null || labId == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭殑鍙傛暟"))); + return; + } + + TaoBaoGoodsBrief taoBaoGoodsBrief = taoBaoGoodsBriefService.selectByPrimaryKey(id); + if (taoBaoGoodsBrief == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅瓨鍦�"))); + return; + } + + Label label = labelService.selectByPrimaryKey(labId); + if (label == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ユ爣绛惧凡涓嶅瓨鍦�"))); + return; + } + + /* 璐翠笂鏍囩 锛� 宸茶创涓嶅鐞嗗垯 */ + Long existence = labelGoodsService.isExistence(id, labId); + + // 璇ュ晢鍝佷笉瀛樺湪姝ゆ爣绛惧垯娣诲姞锛� 鍙嶄箣涓嶅仛澶勭悊 + if (existence == null || existence == 0l) { + Date nowTime = new Date(); + // 璐翠笂鏂版爣绛� + LabelGoods lg = new LabelGoods(); + lg.setLabel(label); + lg.setCreateUser(admin); + lg.setCreatetime(nowTime); + lg.setTaoBaoGoodsBrief(taoBaoGoodsBrief); + + int insert = labelGoodsService.insertSelective(lg); + if (insert > 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛"))); + } else { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞澶辫触"))); + } + } else { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("姝ゅ晢鍝佸凡瀛樺湪璇ユ爣绛�"))); + } + + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + } + + } + + /** + * 鍒犻櫎鍟嗗搧鍏宠仈鐨勬爣绛� + * + * @param callback + * @param rid + * @param request + * @param out + */ + @RequestMapping(value = "removeSingle") + public void removeSingle(AdminAcceptData acceptData,String callback, Long rid, HttpServletRequest request, PrintWriter out) { + + try { + + int deleteId = labelGoodsService.deleteByPrimaryKey(rid); + + if (deleteId > 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("鍒犻櫎鎴愬姛"))); + } else { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鍒犻櫎澶辫触"))); + } + + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + } + + } + + /** + * 璁剧疆鍟嗗搧鏉冮噸銆佺瓑淇℃伅 + * + * @param callback + * @param label + * @param request + * @param out + */ + @RequestMapping(value = "saveInfo") + public void saveInfo(AdminAcceptData acceptData,String callback, QualityFactory selectionGoods, HttpServletRequest request, PrintWriter out) { + + try { + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + // + // if (admin == null) { + // out.print(JsonUtil.loadJSONP(callback, + // JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄�"))); + // return; + // } + + Long id = selectionGoods.getId(); + QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); + + if (resultObj == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); + } else { + Date nowTime = new Date(); + selectionGoods.setUpdatetime(nowTime); + selectionGoods.setUpdateUser(admin); + // 閫夋嫨鎬ф洿鏂版暟鎹� + int result = qualityFactoryService.updateByPrimaryKeySelective(selectionGoods); + + if (result > 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); + } else { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); + } + } + + } catch (QualityFactoryException e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + } + + } + + @RequestMapping(value = "queryMyLabels") + public void queryMyLabels(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, String ids, + HttpServletRequest request, PrintWriter out) { + + try { + + if (StringUtil.isNullOrEmpty(ids)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:101"))); + return; + } + + Gson gson = new Gson(); + List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { + }.getType()); + if (idList == null || idList.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:102"))); + return; + } + + if (idList.size() > 1) { + // 鍙鐞嗗崟涓晢鍝� + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:103"))); + return; + } + + Long id = idList.get(0); + + if (id == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:104"))); + return; + } + + if (pageIndex == null) + pageIndex = 1; + + if (pageSize == null) + pageSize = Constant.PAGE_SIZE; + + // 鍟嗗搧鏍囩鍒楄〃 + List<LabelGoods> labelList = labelGoodsService.queryByGoodsId((pageIndex - 1) * pageSize, pageSize, id); + + if (labelList == null || labelList.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏍囩")); + return; + } + + int count = labelGoodsService.getCountQueryByGoodsId(id); + + int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; + PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.serializeNulls(); + Gson rgson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); + + JSONObject data = new JSONObject(); + data.put("pe", pe); + data.put("labelList", rgson.toJson(labelList)); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + e.printStackTrace(); + } + } + + /** + * 鏌ヨ鍟嗗搧娣诲姞鏍囩鍊欓�夐」 + * + * @param callback + * @param pageIndex + * @param pageSize + * @param key + * @param id + * @param request + * @param out + */ + @RequestMapping(value = "queryLabel") + public void queryLabel(AdminAcceptData acceptData,String callback, Integer pageIndex, Integer pageSize, String key, String ids, + HttpServletRequest request, PrintWriter out) { + + try { + + if (StringUtil.isNullOrEmpty(ids)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:101"))); + return; + } + + Gson gson = new Gson(); + List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { + }.getType()); + if (idList == null || idList.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:102"))); + return; + } + + int count = 0; + List<Label> labelList = null; + + if (pageIndex == null) + pageIndex = 1; + + if (pageSize == null) + pageSize = Constant.PAGE_SIZE; + + if (idList.size() > 1) { + // 澶氫釜鍟嗗搧 鏌ヨ鎵�鏈夋爣绛� + labelList = labelService.query((pageIndex - 1) * pageSize, pageSize, key, null, null, null); + + count = labelService.getQueryCount(key, null, null); + + } else { + // 鍗曚釜鍟嗗搧 + Long id = idList.get(0); + if (id == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇蜂紶閫掓纭弬鏁�:104"))); + return; + } + + labelList = labelService.queryGoodsCandidate((pageIndex - 1) * pageSize, pageSize, key, id); + + count = labelService.getCountQueryGoodsCandidate(key, id); + } + + if (labelList == null || labelList.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏍囩")); + return; + } + + int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; + PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); + + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.serializeNulls(); // 閲嶇偣 + Gson rgson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create(); + + JSONObject data = new JSONObject(); + data.put("pe", pe); + data.put("labelList", rgson.toJson(labelList)); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + e.printStackTrace(); + } + } + + /** + * 鍗曚釜鍟嗗搧鎵归噺娣诲姞鏍囩-鍏宠仈lableId + * + * @param callback + * @param id + * @param type + * @param request + * @param out + */ + @RequestMapping(value = "addBatchcGoodsLabel") + public void addBatchcGoodsLabel(AdminAcceptData acceptData,String callback, String labIds, Long id, HttpServletRequest request, + PrintWriter out) { + + try { + if (StringUtil.isNullOrEmpty(labIds)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈�夋嫨鏍囩")); + return; + } + + if (id == null) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈�夋嫨鍟嗗搧")); + return; + } + + Gson gson = new Gson(); + List<String> labIdList = gson.fromJson(labIds, new TypeToken<ArrayList<String>>() { + }.getType()); + if (labIdList == null || labIdList.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇烽�夋嫨鏍囩"))); + return; + } + + TaoBaoGoodsBrief taoBaoGoodsBrief = taoBaoGoodsBriefService.selectByPrimaryKey(id); + + // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + labelGoodsService.addBatchByLabId(taoBaoGoodsBrief, labIdList, admin); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎿嶄綔鎴愬姛")); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + e.printStackTrace(); + } + } + + @RequestMapping(value = "updateGoodsBrief") + public void updateGoodsBrief(AdminAcceptData acceptData,String callback, TaoBaoGoodsBrief tb, PrintWriter out) { + try { + + // 瀹為檯鏈簿閫塈D + Long id = tb.getId(); + + QualityFactory resultObj = qualityFactoryService.selectByPrimaryKey(id); + + if (resultObj == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪绮惧搧搴撲腑"))); + return; + } + + TaoBaoGoodsBrief taobao = resultObj.getTaoBaoGoodsBrief(); + if (taobao == null) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇ュ晢鍝佸凡涓嶅湪"))); + return; + } + + String title = tb.getTitle(); + String pictUrl = tb.getPictUrl(); + + if (!StringUtil.isNullOrEmpty(title)) + taobao.setTitle(title); + + if (!StringUtil.isNullOrEmpty(pictUrl)) + taobao.setPictUrl(pictUrl); + + if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite())) + taobao.setPictUrlWhite(tb.getPictUrlWhite()); + + // 鏇存柊鍟嗗搧 + taoBaoGoodsUpdateService.getUpdateTaoBaoGoodsBrief(taobao); + + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"))); + + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淇敼澶辫触"))); + } + + } + + /** + * 鎵归噺娣诲姞鏍囩 --- 绮惧搧搴擄紙闅忔満鏉冮噸锛� + * + * @param callback + * @param request + * @param out + * @param 鏉冮噸鑼冨洿 + * 澶у�� + * @param 浣i噾鑼冨洿 + * 灏忓�� + */ + @RequestMapping(value = "setWeightBatch") + public void setWeightBatch(AdminAcceptData acceptData,String callback, String ids, Integer weight, Integer weightSmall, Integer weightLarge, + HttpServletRequest request, PrintWriter out) { + + try { + + if (StringUtil.isNullOrEmpty(ids)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈�夋嫨闇�鎿嶄綔鐨勫晢鍝�"))); + return; + } + + Gson gson = new Gson(); + List<Long> idList = gson.fromJson(ids, new TypeToken<ArrayList<Long>>() { + }.getType()); + + if (idList == null || idList.size() == 0) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("璇烽�夋嫨闇�鎿嶄綔鐨勫晢鍝�"))); + return; + } + // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛 + AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); + + qualityFactoryService.setWeightBatch(idList, admin, weight, weightSmall, weightLarge); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("璁剧疆鎴愬姛"))); + + } catch (Exception e) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"))); + e.printStackTrace(); + } + + } + +} -- Gitblit v1.8.0