|
@@ -0,0 +1,1041 @@
|
|
|
|
|
+package com.sapit.client.app.third.controller.goods;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.sapit.client.app.user.service.system.CommonApiService;
|
|
|
|
|
+import com.sapit.common.bean.mobile.GoodsBean;
|
|
|
|
|
+import com.sapit.common.bean.mobile.GoodsModelBean;
|
|
|
|
|
+import com.sapit.common.bean.mobile.GoodsPropertyBean;
|
|
|
|
|
+import com.sapit.common.bean.mobile.GoodsTypeBean;
|
|
|
|
|
+import com.sapit.common.bean.storemobile.GoodsInfoBean;
|
|
|
|
|
+import com.sapit.common.constant.ReturnCode;
|
|
|
|
|
+import com.sapit.common.constant.Status;
|
|
|
|
|
+import com.sapit.common.entity.goods.BuGoods;
|
|
|
|
|
+import com.sapit.common.entity.goods.BuGoodsModel;
|
|
|
|
|
+import com.sapit.common.entity.goods.BuGoodsProperty;
|
|
|
|
|
+import com.sapit.common.entity.goods.BuGoodsType;
|
|
|
|
|
+import com.sapit.common.framwork.BaseDao;
|
|
|
|
|
+import com.sapit.common.framwork.ResultBean;
|
|
|
|
|
+import com.sapit.common.search.goods.BuGoodsTypeSearchBean;
|
|
|
|
|
+import com.sapit.common.util.DateUtil;
|
|
|
|
|
+import com.sapit.common.util.FileFtpUploadUtil;
|
|
|
|
|
+import com.sapit.common.util.RedisTool;
|
|
|
|
|
+import com.sapit.common.util.StringUtil;
|
|
|
|
|
+
|
|
|
|
|
+@SuppressWarnings("rawtypes")
|
|
|
|
|
+@Service
|
|
|
|
|
+@Transactional
|
|
|
|
|
+public class ThirdStoreGoodsManageCtltestService extends BaseDao {
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ThirdStoreGoodsManageCtltestService.class);
|
|
|
|
|
+
|
|
|
|
|
+ private static final long MAX_IMAGE_SIZE = 204800L;
|
|
|
|
|
+ private static final String IMAGE_DIR = "/goods";
|
|
|
|
|
+ private static final String REDIS_KEY_PREFIX = "a%sk%s";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisTool redisTool;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonApiService commonApiService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取店铺商品类型列表
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean selectByStoreId(Long storeId) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ List<GoodsTypeBean> typeList = getStoreGoodsTypeListForThird(storeId);
|
|
|
|
|
+ result.setList(typeList);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取店铺商品列表
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param goodsTypeId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean getStoreGoodsListForThird(Long storeId, Long goodsTypeId) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (storeId == null || goodsTypeId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsBean> goodsList = getGoodsListByStoreIdForThird(storeId, goodsTypeId);
|
|
|
|
|
+ List<Long> goodsIdList = extractGoodsIds(goodsList);
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsModelBean> modelList = getModelByGoodsIdsForThird(goodsIdList);
|
|
|
|
|
+ List<String> modelIdList = extractModelIds(modelList);
|
|
|
|
|
+
|
|
|
|
|
+ fillInventory(modelList, modelIdList);
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsPropertyBean> propertyList = getPropertyByGoodsIdsForStore(goodsIdList);
|
|
|
|
|
+
|
|
|
|
|
+ assembleGoodsWithModelsAndProperties(goodsList, modelList, propertyList);
|
|
|
|
|
+
|
|
|
|
|
+ result.setList(goodsList);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取店铺商品类型列表(含新品标记)
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<GoodsTypeBean> getStoreGoodsTypeListForThird(Long storeId) {
|
|
|
|
|
+ List<GoodsTypeBean> typeList = getGoodsTypeListForThird(storeId);
|
|
|
|
|
+ List<GoodsBean> goodsList = getBeanByStoreId(storeId, null);
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(typeList) || CollectionUtils.isEmpty(goodsList)) {
|
|
|
|
|
+ return typeList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (GoodsTypeBean type : typeList) {
|
|
|
|
|
+ for (GoodsBean goods : goodsList) {
|
|
|
|
|
+ if (goods.getGoodsTypeId().equals(type.getGoodsTypeId())) {
|
|
|
|
|
+ goods.setSalePrice(goods.getCostPrice());
|
|
|
|
|
+ if (Long.valueOf(1L).equals(goods.getNewGoodsFlg())) {
|
|
|
|
|
+ type.setNewFlag(goods.getNewGoodsFlg());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return typeList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查商品是否为特殊商品
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean checkSpecialForStore(Long storeId, Long goodsId) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (storeId == null || goodsId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG);
|
|
|
|
|
+ }
|
|
|
|
|
+ result.setObj(checkGoodsInSpecialForStore(goodsId));
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品图片
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateGoodsPicForThird(Long goodsId, MultipartFile file) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (goodsId == null || file == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String imageUrl = tryUploadImage(file, result);
|
|
|
|
|
+ if (imageUrl == null) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(goodsId);
|
|
|
|
|
+ goods.setPictureUrl(imageUrl);
|
|
|
|
|
+
|
|
|
|
|
+ return updateEntityAndWrapResult(goods, result, "更新成功", "更新失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品名称
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param goodsName
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateGoodsNameForThird(Long goodsId, String goodsName) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (goodsId == null || goodsName == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(goodsId);
|
|
|
|
|
+ goods.setGoodsName(goodsName);
|
|
|
|
|
+
|
|
|
|
|
+ return updateEntityAndWrapResult(goods, result, "更新成功", "更新失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品价格
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param modelBeanListJson
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateGoodsPriceForThird(Long goodsId, String modelBeanListJson) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (goodsId == null || modelBeanListJson == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(goodsId);
|
|
|
|
|
+ boolean isSpecial = checkGoodsInSpecialForStore(goodsId);
|
|
|
|
|
+ JSONArray modelArray = JSONArray.parseArray(modelBeanListJson);
|
|
|
|
|
+
|
|
|
|
|
+ if (!modelArray.isEmpty()) {
|
|
|
|
|
+ long price = parsePriceInCents(modelArray, 0);
|
|
|
|
|
+ goods.setCostPrice(price);
|
|
|
|
|
+ if (!isSpecial) {
|
|
|
|
|
+ goods.setSalePrice(price);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.update(goods);
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < modelArray.size(); i++) {
|
|
|
|
|
+ JSONObject modelJson = modelArray.getJSONObject(i);
|
|
|
|
|
+ String modelId = modelJson.getString("modelId");
|
|
|
|
|
+ if (modelId == null || modelId.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BuGoodsModel model = (BuGoodsModel) findById(BuGoodsModel.class, Long.valueOf(modelId));
|
|
|
|
|
+ long costPrice = parsePriceInCents(modelArray, i);
|
|
|
|
|
+ model.setCostPrice(costPrice);
|
|
|
|
|
+ if (!isSpecial) {
|
|
|
|
|
+ model.setSalePrice(costPrice);
|
|
|
|
|
+ }
|
|
|
|
|
+ model.setPackingFee(parsePriceInCents(modelJson, "packingFee"));
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.update(model)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "编辑商品价格失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.update(goods)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "更新失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("更新成功");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品库存
|
|
|
|
|
+ * @param modelBeanListJson
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateGoodsInventoryForThird(String modelBeanListJson) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (modelBeanListJson == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray modelArray = JSONArray.parseArray(modelBeanListJson);
|
|
|
|
|
+ for (int i = 0; i < modelArray.size(); i++) {
|
|
|
|
|
+ JSONObject modelJson = modelArray.getJSONObject(i);
|
|
|
|
|
+ String modelId = modelJson.getString("modelId");
|
|
|
|
|
+ if (modelId != null && !modelId.isEmpty()) {
|
|
|
|
|
+ adjustGoods(Long.parseLong(modelId), Long.parseLong(modelJson.getString("inventory")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品是否为新商品
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param dayCount
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateGoodsNewFlag(Long storeId, Long goodsId, Integer dayCount) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (storeId == null || goodsId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(goodsId);
|
|
|
|
|
+ if (dayCount == null) {
|
|
|
|
|
+ goods.setNewGoodsEnddate(null);
|
|
|
|
|
+ goods.setNewGoodsFlg(0L);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ goods.setNewGoodsFlg(1L);
|
|
|
|
|
+ goods.setNewGoodsEnddate(DateUtil.addDay(new Date(), dayCount));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.update(goods)) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("更新成功!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("更新失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品状态
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ * @param status
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean changeStatus(Long storeId, Long goodsId, Long status) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (storeId == null || goodsId == null || status == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (changeStatusForStore(goodsId, status, storeId)) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("更新成功!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("更新失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增或修改店铺商品
|
|
|
|
|
+ * @param infoBean
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateStoreGoodsForThird(GoodsInfoBean infoBean, Long storeId, MultipartFile file) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (infoBean == null || storeId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (file != null && file.getOriginalFilename() != null) {
|
|
|
|
|
+ String imageUrl = tryUploadImage(file, result);
|
|
|
|
|
+ if (imageUrl == null) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ infoBean.setPictureUrl(imageUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Timestamp now = DateUtil.getSqlToday();
|
|
|
|
|
+ JSONArray modelArray = JSONArray.parseArray(infoBean.getModelBeanListJson());
|
|
|
|
|
+ JSONArray propertyArray = JSONArray.parseArray(infoBean.getPropertyBeanListJson());
|
|
|
|
|
+
|
|
|
|
|
+ if (infoBean.getGoodsId() == null) {
|
|
|
|
|
+ return createNewGoods(result, infoBean, storeId, modelArray, propertyArray, now);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return updateExistingGoods(result, infoBean, storeId, modelArray, propertyArray, now);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除店铺商品
|
|
|
|
|
+ * @param goodsId
|
|
|
|
|
+ */
|
|
|
|
|
+ public void deleteGoods(Long goodsId) {
|
|
|
|
|
+ String sql = "UPDATE bu_goods SET DEL_FLAG = 1 WHERE GOODS_ID = " + goodsId + " AND STATUS = 0";
|
|
|
|
|
+ executeSql(sql);
|
|
|
|
|
+ log.info("逻辑删除商品, goodsId={}", goodsId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品排序
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @param stepsIds
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateStoreGoodsSortForThird(Long storeId, List<Long> stepsIds) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (storeId == null || stepsIds == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < stepsIds.size(); i++) {
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(stepsIds.get(i));
|
|
|
|
|
+ goods.setOrderKey((long) (stepsIds.size() - i + 1));
|
|
|
|
|
+ this.update(goods);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增或修改店铺商品类型
|
|
|
|
|
+ * @param type
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean updateStoreGoodsTypeForThird(BuGoodsType type) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (type == null || type.getStoreId() == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long maxOrderKey = findMaxTypeOrderKey(type.getStoreId());
|
|
|
|
|
+
|
|
|
|
|
+ if (type.getGoodsTypeId() == null) {
|
|
|
|
|
+ if (type.getType() == 1 && !checkGoodsTypeByType(type.getStoreId(), null)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "最多只能添加一个必选分类");
|
|
|
|
|
+ }
|
|
|
|
|
+ type.setCreateDate(DateUtil.getSqlToday());
|
|
|
|
|
+ type.setOrderKey(maxOrderKey + 1);
|
|
|
|
|
+ if (!this.save(type)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "新增失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (type.getType() == 1 && !checkGoodsTypeByType(type.getStoreId(), type.getGoodsTypeId())) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "最多只能添加一个必选分类");
|
|
|
|
|
+ }
|
|
|
|
|
+ BuGoodsType existingType = (BuGoodsType) findById(BuGoodsType.class, type.getGoodsTypeId());
|
|
|
|
|
+ existingType.setGoodsTypeName(type.getGoodsTypeName());
|
|
|
|
|
+ existingType.setType(type.getType());
|
|
|
|
|
+ if (!this.update(existingType)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "更新失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除店铺商品类型
|
|
|
|
|
+ * @param goodsTypeId
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean deleteTypeByIdForThird(Long goodsTypeId, Long storeId) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (goodsTypeId == null || storeId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (checkTypeIsUsed(goodsTypeId, storeId)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "该分类下有商品,无法删除");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (deleteTypeByIdForStore(goodsTypeId, storeId)) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("删除成功!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("删除失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改店铺商品类型排序
|
|
|
|
|
+ * @param id
|
|
|
|
|
+ * @param type
|
|
|
|
|
+ * @param storeId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultBean changeOrderKey(Long id, Long type, Long storeId) {
|
|
|
|
|
+ ResultBean result = newResult();
|
|
|
|
|
+ if (id == null || type == null || storeId == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.PARAM_WRONG, "参数错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (type == 1) {
|
|
|
|
|
+ return moveTypeUp(result, id, storeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type == 2) {
|
|
|
|
|
+ return moveTypeToTop(result, id, storeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品库存列表
|
|
|
|
|
+ * @param modelIdList
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Long> getGoodsStoreListForThird(List<String> modelIdList) {
|
|
|
|
|
+ List<Long> resultList = new ArrayList<>();
|
|
|
|
|
+ Long sysAreaId = commonApiService.getSysAreaId();
|
|
|
|
|
+ List<String> redisKeys = new ArrayList<>();
|
|
|
|
|
+ for (String id : modelIdList) {
|
|
|
|
|
+ redisKeys.add(String.format(REDIS_KEY_PREFIX, sysAreaId, id));
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> outList = redisTool.getValueList(redisKeys);
|
|
|
|
|
+ for (String store : outList) {
|
|
|
|
|
+ resultList.add(Long.valueOf(store));
|
|
|
|
|
+ }
|
|
|
|
|
+ return resultList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 调整商品库存
|
|
|
|
|
+ * @param goodsModelId
|
|
|
|
|
+ * @param value
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public boolean adjustGoods(Long goodsModelId, long value) {
|
|
|
|
|
+ Long sysAreaId = commonApiService.getSysAreaId();
|
|
|
|
|
+ return redisTool.set(String.format(REDIS_KEY_PREFIX, sysAreaId, goodsModelId), value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean newResult() {
|
|
|
|
|
+ return new ResultBean();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean fail(ResultBean result, Long code) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(code);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg(ReturnCode.getName(code));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean fail(ResultBean result, Long code, String msg) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(code);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg(msg);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean updateEntityAndWrapResult(BuGoods entity, ResultBean result, String successMsg, String failMsg) {
|
|
|
|
|
+ if (this.update(entity)) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg(successMsg);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg(failMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String tryUploadImage(MultipartFile file, ResultBean result) {
|
|
|
|
|
+ if (file.getSize() > MAX_IMAGE_SIZE) {
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("图片大小超过200K,请调整清晰度之后再试!");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String imageType = file.getOriginalFilename()
|
|
|
|
|
+ .substring(file.getOriginalFilename().lastIndexOf(".") + 1);
|
|
|
|
|
+ String filename = DateUtil.getStrToday("yyyyMMddHHmmssSSS") + "." + imageType;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!FileFtpUploadUtil.uploadFile(IMAGE_DIR, filename, file.getInputStream())) {
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SYSTEMERR);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("文件上传失败,请重新尝试!");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("文件上传异常", e);
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SYSTEMERR);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("文件上传失败,请重新尝试!");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return FileFtpUploadUtil.rootURL + IMAGE_DIR + "/" + filename;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private long parsePriceInCents(JSONArray array, int index) {
|
|
|
|
|
+ JSONObject obj = array.getJSONObject(index);
|
|
|
|
|
+ BigDecimal price = new BigDecimal(obj.getString("costPrice"));
|
|
|
|
|
+ return price.multiply(BigDecimal.valueOf(100)).longValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private long parsePriceInCents(JSONObject obj, String field) {
|
|
|
|
|
+ return new BigDecimal(obj.getString(field)).multiply(BigDecimal.valueOf(100)).longValue();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Long> extractGoodsIds(List<GoodsBean> goodsList) {
|
|
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
|
|
+ for (GoodsBean goods : goodsList) {
|
|
|
|
|
+ ids.add(goods.getGoodsId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return ids;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> extractModelIds(List<GoodsModelBean> modelList) {
|
|
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
|
|
+ for (GoodsModelBean model : modelList) {
|
|
|
|
|
+ ids.add(model.getModelId());
|
|
|
|
|
+ }
|
|
|
|
|
+ return ids;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void fillInventory(List<GoodsModelBean> modelList, List<String> modelIdList) {
|
|
|
|
|
+ List<Long> inventoryList = getGoodsStoreListForThird(modelIdList);
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(inventoryList)) {
|
|
|
|
|
+ for (int i = 0; i < modelList.size(); i++) {
|
|
|
|
|
+ modelList.get(i).setInventory(inventoryList.get(i));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void assembleGoodsWithModelsAndProperties(List<GoodsBean> goodsList,
|
|
|
|
|
+ List<GoodsModelBean> modelList,
|
|
|
|
|
+ List<GoodsPropertyBean> propertyList) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(goodsList)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (GoodsBean goods : goodsList) {
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(modelList)) {
|
|
|
|
|
+ List<GoodsModelBean> goodsModels = new ArrayList<>();
|
|
|
|
|
+ for (GoodsModelBean model : modelList) {
|
|
|
|
|
+ if (model.getGoodsId().equals(goods.getGoodsId())) {
|
|
|
|
|
+ goodsModels.add(model);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setSkuList(goodsModels);
|
|
|
|
|
+ if (Long.valueOf(1L).equals(goods.getSingleFlg()) && CollectionUtils.isNotEmpty(goodsModels)) {
|
|
|
|
|
+ goods.setModelId(goodsModels.get(0).getModelId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyList)) {
|
|
|
|
|
+ List<GoodsPropertyBean> goodsProperties = new ArrayList<>();
|
|
|
|
|
+ for (GoodsPropertyBean prop : propertyList) {
|
|
|
|
|
+ if (prop.getGoodsId().equals(goods.getGoodsId())) {
|
|
|
|
|
+ goodsProperties.add(prop);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setParams(goodsProperties);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean createNewGoods(ResultBean result, GoodsInfoBean infoBean, Long storeId,
|
|
|
|
|
+ JSONArray modelArray, JSONArray propertyArray, Timestamp now) {
|
|
|
|
|
+ Long maxOrderKey = findMaxGoodsOrderKey(storeId);
|
|
|
|
|
+
|
|
|
|
|
+ BuGoods goods = new BuGoods();
|
|
|
|
|
+ goods.setGoodsName(infoBean.getGoodsName());
|
|
|
|
|
+ goods.setPictureUrl(infoBean.getPictureUrl());
|
|
|
|
|
+ goods.setMiniNum(infoBean.getMiniNum());
|
|
|
|
|
+ goods.setGoodsTypeId(infoBean.getGoodsTypeId());
|
|
|
|
|
+ goods.setUtils(infoBean.getUtils());
|
|
|
|
|
+ goods.setRmk(infoBean.getRmk());
|
|
|
|
|
+ goods.setOrderKey(maxOrderKey + 1);
|
|
|
|
|
+ goods.setStatus(Status.STATUS_UNVALID);
|
|
|
|
|
+ goods.setStoreId(storeId);
|
|
|
|
|
+ goods.setDelFlag(0L);
|
|
|
|
|
+ goods.setSalesCount(0L);
|
|
|
|
|
+
|
|
|
|
|
+ if (!modelArray.isEmpty()) {
|
|
|
|
|
+ long price = parsePriceInCents(modelArray, 0);
|
|
|
|
|
+ goods.setCostPrice(price);
|
|
|
|
|
+ goods.setSalePrice(price);
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setSingleFlg(modelArray.size() > 1 ? 0L : 1L);
|
|
|
|
|
+ goods.setCreateDate(now);
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.save(goods)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "新增商品失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < modelArray.size(); i++) {
|
|
|
|
|
+ JSONObject modelJson = modelArray.getJSONObject(i);
|
|
|
|
|
+ BuGoodsModel model = new BuGoodsModel();
|
|
|
|
|
+ model.setModelName(modelJson.getString("modelName"));
|
|
|
|
|
+ model.setCostPrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ model.setSalePrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ model.setPackingFee(parsePriceInCents(modelJson, "packingFee"));
|
|
|
|
|
+ model.setGoodsId(goods.getGoodsId());
|
|
|
|
|
+ model.setCreateDate(now);
|
|
|
|
|
+ if (!this.save(model)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "新增商品规格失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ adjustGoods(model.getModelId(), Long.parseLong(modelJson.getString("inventory")));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return saveProperties(result, propertyArray, goods.getGoodsId(), now, "新增商品属性失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean updateExistingGoods(ResultBean result, GoodsInfoBean infoBean, Long storeId,
|
|
|
|
|
+ JSONArray modelArray, JSONArray propertyArray, Timestamp now) {
|
|
|
|
|
+ boolean isSpecial = checkGoodsInSpecialForStore(infoBean.getGoodsId());
|
|
|
|
|
+ BuGoods goods = getGoodsByIdForThird(infoBean.getGoodsId());
|
|
|
|
|
+
|
|
|
|
|
+ deleteOldImageIfChanged(goods, infoBean);
|
|
|
|
|
+
|
|
|
|
|
+ goods.setGoodsName(infoBean.getGoodsName());
|
|
|
|
|
+ goods.setPictureUrl(infoBean.getPictureUrl());
|
|
|
|
|
+ goods.setMiniNum(infoBean.getMiniNum());
|
|
|
|
|
+ goods.setGoodsTypeId(infoBean.getGoodsTypeId());
|
|
|
|
|
+ goods.setUtils(infoBean.getUtils());
|
|
|
|
|
+ goods.setRmk(infoBean.getRmk());
|
|
|
|
|
+
|
|
|
|
|
+ if (!modelArray.isEmpty()) {
|
|
|
|
|
+ long price = parsePriceInCents(modelArray, 0);
|
|
|
|
|
+ goods.setCostPrice(price);
|
|
|
|
|
+ if (!isSpecial) {
|
|
|
|
|
+ goods.setSalePrice(price);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ goods.setSingleFlg(modelArray.size() > 1 ? 0L : 1L);
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.update(goods)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "编辑商品失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ deleteGoodsPropertyByGoodsForStore(goods.getGoodsId());
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < modelArray.size(); i++) {
|
|
|
|
|
+ JSONObject modelJson = modelArray.getJSONObject(i);
|
|
|
|
|
+ String modelId = modelJson.getString("modelId");
|
|
|
|
|
+ if (modelId != null && !modelId.isEmpty()) {
|
|
|
|
|
+ BuGoodsModel model = (BuGoodsModel) findById(BuGoodsModel.class, Long.valueOf(modelId));
|
|
|
|
|
+ model.setModelName(modelJson.getString("modelName"));
|
|
|
|
|
+ model.setCostPrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ if (!isSpecial) {
|
|
|
|
|
+ model.setSalePrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ }
|
|
|
|
|
+ model.setPackingFee(parsePriceInCents(modelJson, "packingFee"));
|
|
|
|
|
+ if (!this.update(model)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "编辑商品规格失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ adjustGoods(model.getModelId(), Long.parseLong(modelJson.getString("inventory")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BuGoodsModel newModel = new BuGoodsModel();
|
|
|
|
|
+ newModel.setGoodsId(goods.getGoodsId());
|
|
|
|
|
+ newModel.setModelName(modelJson.getString("modelName"));
|
|
|
|
|
+ newModel.setCostPrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ newModel.setSalePrice(parsePriceInCents(modelArray, i));
|
|
|
|
|
+ newModel.setPackingFee(parsePriceInCents(modelJson, "packingFee"));
|
|
|
|
|
+ newModel.setCreateDate(now);
|
|
|
|
|
+ if (!this.save(newModel)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, "新增商品规格失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+ adjustGoods(newModel.getModelId(), Long.parseLong(modelJson.getString("inventory")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return saveProperties(result, propertyArray, goods.getGoodsId(), now, "新增商品属性失败,请重新尝试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void deleteOldImageIfChanged(BuGoods goods, GoodsInfoBean infoBean) {
|
|
|
|
|
+ if (!StringUtil.isBlank(goods.getPictureUrl()) && !infoBean.getPictureUrl().equals(goods.getPictureUrl())) {
|
|
|
|
|
+ String filename = goods.getPictureUrl().substring(goods.getPictureUrl().lastIndexOf("/") + 1);
|
|
|
|
|
+ FileFtpUploadUtil.deleteFile(IMAGE_DIR, filename);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean saveProperties(ResultBean result, JSONArray propertyArray, Long goodsId,
|
|
|
|
|
+ Timestamp now, String failMsg) {
|
|
|
|
|
+ if (propertyArray.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (int i = 0; i < propertyArray.size(); i++) {
|
|
|
|
|
+ if ("null".equals(propertyArray.get(i))) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject propJson = propertyArray.getJSONObject(i);
|
|
|
|
|
+ if (propJson.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String propertyName = propJson.getString("propertyName");
|
|
|
|
|
+ String propertyList = propJson.getString("propertyList");
|
|
|
|
|
+ if (propertyName == null || propertyName.isEmpty() || propertyList == null || propertyList.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ BuGoodsProperty property = new BuGoodsProperty();
|
|
|
|
|
+ property.setPropertyName(propertyName);
|
|
|
|
|
+ property.setPropertyList(propertyList);
|
|
|
|
|
+ property.setGoodsId(goodsId);
|
|
|
|
|
+ if (now != null) {
|
|
|
|
|
+ property.setCreateDate(now);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this.save(property)) {
|
|
|
|
|
+ return fail(result, ReturnCode.FAILED, failMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean moveTypeUp(ResultBean result, Long typeId, Long storeId) {
|
|
|
|
|
+ BuGoodsType currentType = (BuGoodsType) findById(BuGoodsType.class, typeId);
|
|
|
|
|
+ if (currentType == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.SYSTEMERR, "商品分类未找到!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long currentOrder = currentType.getOrderKey();
|
|
|
|
|
+ BuGoodsTypeSearchBean searchBean = new BuGoodsTypeSearchBean();
|
|
|
|
|
+ searchBean.setStoreId(storeId);
|
|
|
|
|
+ searchBean.setOrderKey(currentOrder + 1);
|
|
|
|
|
+ BuGoodsType previousType = getGoodsTypeLastForStore(searchBean);
|
|
|
|
|
+ if (previousType == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.SYSTEMERR, "该分类已经置顶无法上移!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long previousOrder = previousType.getOrderKey();
|
|
|
|
|
+ currentType.setOrderKey(previousOrder);
|
|
|
|
|
+ previousType.setOrderKey(currentOrder);
|
|
|
|
|
+ this.update(currentType);
|
|
|
|
|
+ this.update(previousType);
|
|
|
|
|
+
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("上移成功!");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultBean moveTypeToTop(ResultBean result, Long typeId, Long storeId) {
|
|
|
|
|
+ BuGoodsType currentType = (BuGoodsType) findById(BuGoodsType.class, typeId);
|
|
|
|
|
+ if (currentType == null) {
|
|
|
|
|
+ return fail(result, ReturnCode.SYSTEMERR, "商品分类未找到!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long currentOrder = currentType.getOrderKey();
|
|
|
|
|
+ Long maxOrderKey = findMaxTypeOrderKey(storeId);
|
|
|
|
|
+
|
|
|
|
|
+ BuGoodsTypeSearchBean searchBean = new BuGoodsTypeSearchBean();
|
|
|
|
|
+ searchBean.setStoreId(storeId);
|
|
|
|
|
+ searchBean.setLastOrderKey(currentOrder);
|
|
|
|
|
+ List<BuGoodsType> lowerTypes = getGoodsTypeForStore(searchBean);
|
|
|
|
|
+ for (BuGoodsType lowerType : lowerTypes) {
|
|
|
|
|
+ lowerType.setOrderKey(lowerType.getOrderKey() - 1);
|
|
|
|
|
+ this.update(lowerType);
|
|
|
|
|
+ }
|
|
|
|
|
+ currentType.setOrderKey(maxOrderKey);
|
|
|
|
|
+ this.update(currentType);
|
|
|
|
|
+
|
|
|
|
|
+ result.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
|
|
+ result.getRtnBean().setRtnMsg("置顶成功!");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Long findMaxTypeOrderKey(Long storeId) {
|
|
|
|
|
+ List<BuGoodsType> typeList = getGoodsTypeMaxOrderKeyForStore(storeId);
|
|
|
|
|
+ return typeList.isEmpty() ? 0L : typeList.get(0).getOrderKey();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Long findMaxGoodsOrderKey(Long storeId) {
|
|
|
|
|
+ List<BuGoods> goodsList = getGoodsMaxOrderKeyForStore(storeId);
|
|
|
|
|
+ return goodsList.isEmpty() ? 0L : goodsList.get(0).getOrderKey();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BuGoods getGoodsByIdForThird(Long goodsId) {
|
|
|
|
|
+ return (BuGoods) findById(BuGoods.class, goodsId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<GoodsBean> getGoodsListByStoreIdForThird(Long storeId, Long goodsTypeId) {
|
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
|
+ sql.append("SELECT T.GOODS_ID, T.GOODS_NAME, T.GOODS_TYPE_ID, T.SALES_COUNT, T.SALE_PRICE, T.COST_PRICE, T.LIMITED_NUM, ");
|
|
|
|
|
+ sql.append("T.MINI_NUM, T.PICTURE_URL, T.NEW_GOODS_FLG, T.SINGLE_FLG, T.STORE_ID, T.STATUS, W.MODEL_ID, T.ORDER_KEY, T.RMK")
|
|
|
|
|
+ .append(" FROM bu_goods T LEFT JOIN bu_goods_model W ON T.GOODS_ID = W.GOODS_ID WHERE 1 = 1 ");
|
|
|
|
|
+ if (storeId != null) {
|
|
|
|
|
+ sql.append("AND STORE_ID = ").append(storeId).append(" ");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (goodsTypeId != null) {
|
|
|
|
|
+ sql.append("AND GOODS_TYPE_ID = ").append(goodsTypeId).append(" ");
|
|
|
|
|
+ }
|
|
|
|
|
+ sql.append(" AND DEL_FLAG = 0 GROUP BY T.GOODS_ID ORDER BY T.ORDER_KEY DESC");
|
|
|
|
|
+ List<Object> list = searchBySql(sql.toString());
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsBean> result = new ArrayList<>();
|
|
|
|
|
+ for (Object object : list) {
|
|
|
|
|
+ Object[] row = (Object[]) object;
|
|
|
|
|
+ GoodsBean bean = new GoodsBean();
|
|
|
|
|
+ bean.setGoodsId(row[0] == null ? null : Long.valueOf(row[0].toString()));
|
|
|
|
|
+ bean.setGoodsName(row[1] == null ? null : row[1].toString());
|
|
|
|
|
+ bean.setGoodsTypeId(row[2] == null ? null : Long.valueOf(row[2].toString()));
|
|
|
|
|
+ bean.setSalesCount(row[3] == null ? null : Long.valueOf(row[3].toString()));
|
|
|
|
|
+ bean.setSalePrice(row[4] == null ? null : Long.valueOf(row[4].toString()));
|
|
|
|
|
+ bean.setCostPrice(row[5] == null ? null : Long.valueOf(row[5].toString()));
|
|
|
|
|
+ bean.setLimitedNum(row[6] == null ? null : Long.valueOf(row[6].toString()));
|
|
|
|
|
+ bean.setMiniNum(row[7] == null ? null : Long.valueOf(row[7].toString()));
|
|
|
|
|
+ bean.setPictureUrl(row[8] == null ? null : row[8].toString());
|
|
|
|
|
+ bean.setNewGoodsFlg(row[9] == null ? 0L : Long.valueOf(row[9].toString()));
|
|
|
|
|
+ bean.setDiscount(String.format("%.1f", (bean.getSalePrice() * 10d) / bean.getCostPrice()));
|
|
|
|
|
+ bean.setSingleFlg(row[10] == null ? 0L : Long.valueOf(row[10].toString()));
|
|
|
|
|
+ bean.setStoreId(row[11] == null ? null : Long.valueOf(row[11].toString()));
|
|
|
|
|
+ bean.setStatus(row[12] == null ? null : Long.valueOf(row[12].toString()));
|
|
|
|
|
+ bean.setModelId(row[13] == null ? null : row[13].toString());
|
|
|
|
|
+ bean.setOrderKey(row[14] == null ? null : Long.valueOf(row[14].toString()));
|
|
|
|
|
+ bean.setRmk(row[15] == null ? null : row[15].toString());
|
|
|
|
|
+ result.add(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<GoodsModelBean> getModelByGoodsIdsForThird(List<Long> goodsIds) {
|
|
|
|
|
+ StringBuilder sql = new StringBuilder("SELECT MODEL_ID, MODEL_CODE, MODEL_NAME, GOODS_ID, COST_PRICE, SALE_PRICE, PACKING_FEE FROM bu_goods_model WHERE 1 = 1 ");
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsIds)) {
|
|
|
|
|
+ sql.append("AND GOODS_ID IN ( ");
|
|
|
|
|
+ for (int i = 0; i < goodsIds.size(); i++) {
|
|
|
|
|
+ sql.append("'").append(goodsIds.get(i)).append("'");
|
|
|
|
|
+ if (i != goodsIds.size() - 1) {
|
|
|
|
|
+ sql.append(", ");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ sql.append(") ");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Object> list = searchBySql(sql.toString());
|
|
|
|
|
+ List<GoodsModelBean> result = new ArrayList<>();
|
|
|
|
|
+ for (Object object : list) {
|
|
|
|
|
+ Object[] row = (Object[]) object;
|
|
|
|
|
+ GoodsModelBean bean = new GoodsModelBean();
|
|
|
|
|
+ bean.setModelId(row[0] == null ? null : row[0].toString());
|
|
|
|
|
+ bean.setModelCode(row[1] == null ? null : row[1].toString());
|
|
|
|
|
+ bean.setModelName(row[2] == null ? null : row[2].toString());
|
|
|
|
|
+ bean.setGoodsId(row[3] == null ? null : Long.valueOf(row[3].toString()));
|
|
|
|
|
+ bean.setCostPrice(row[4] == null ? null : Long.valueOf(row[4].toString()));
|
|
|
|
|
+ bean.setSalePrice(row[5] == null ? null : Long.valueOf(row[5].toString()));
|
|
|
|
|
+ bean.setPackingFee(row[6] == null ? null : Long.valueOf(row[6].toString()));
|
|
|
|
|
+ result.add(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<GoodsPropertyBean> getPropertyByGoodsIdsForStore(List<Long> goodsIds) {
|
|
|
|
|
+ StringBuilder sql = new StringBuilder("SELECT PROPERTY_ID, PROPERTY_NAME, PROPERTY_LIST, GOODS_ID FROM bu_goods_property WHERE 1 = 1 ");
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsIds)) {
|
|
|
|
|
+ sql.append("AND GOODS_ID IN ( ");
|
|
|
|
|
+ for (int i = 0; i < goodsIds.size(); i++) {
|
|
|
|
|
+ sql.append("'").append(goodsIds.get(i)).append("'");
|
|
|
|
|
+ if (i != goodsIds.size() - 1) {
|
|
|
|
|
+ sql.append(", ");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ sql.append(") ");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Object> list = searchBySql(sql.toString());
|
|
|
|
|
+ List<GoodsPropertyBean> result = new ArrayList<>();
|
|
|
|
|
+ for (Object object : list) {
|
|
|
|
|
+ Object[] row = (Object[]) object;
|
|
|
|
|
+ GoodsPropertyBean bean = new GoodsPropertyBean();
|
|
|
|
|
+ bean.setPropertyId(row[0] == null ? null : Long.valueOf(row[0].toString()));
|
|
|
|
|
+ bean.setPropertyName(row[1] == null ? null : row[1].toString());
|
|
|
|
|
+ bean.setPropertyList(row[2] == null ? null : row[2].toString());
|
|
|
|
|
+ bean.setGoodsId(row[3] == null ? null : Long.valueOf(row[3].toString()));
|
|
|
|
|
+ result.add(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean checkGoodsInSpecialForStore(Long goodsId) {
|
|
|
|
|
+ String sql = "select count(*) from bu_store_special_goods t LEFT JOIN bu_store_special_activity g on t.STORE_SPECIAL_ACTIVITY_ID = g.STORE_SPECIAL_ACTIVITY_ID WHERE t.GOODS_ID = " + goodsId;
|
|
|
|
|
+ List<?> list = searchBySql(sql);
|
|
|
|
|
+ boolean rtn = true;
|
|
|
|
|
+ if (list != null && !list.isEmpty() && Long.valueOf(list.get(0).toString()) < 1) {
|
|
|
|
|
+ rtn = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return rtn;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean changeStatusForStore(Long goodsId, Long status, Long storeId) {
|
|
|
|
|
+ String sql = "update bu_goods set STATUS = " + status + " where GOODS_ID = " + goodsId + " AND STORE_ID = " + storeId;
|
|
|
|
|
+ return executeSql(sql) >= 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean deleteGoodsPropertyByGoodsForStore(Long goodsId) {
|
|
|
|
|
+ String sql = "delete from bu_goods_property where GOODS_ID = " + goodsId;
|
|
|
|
|
+ return executeSql(sql) == 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<BuGoods> getGoodsMaxOrderKeyForStore(Long storeId) {
|
|
|
|
|
+ String hql = "from BuGoods where 1=1 and STORE_ID = " + storeId + " ORDER BY ORDER_KEY DESC ";
|
|
|
|
|
+ return searchByHql(hql);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<GoodsTypeBean> getGoodsTypeListForThird(Long storeId) {
|
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
|
+ sql.append("SELECT t.GOODS_TYPE_ID, t.GOODS_TYPE_NAME, count(w.GOODS_ID), t.TYPE FROM bu_goods_type t ")
|
|
|
|
|
+ .append("LEFT JOIN bu_goods w on t.GOODS_TYPE_ID = w.GOODS_TYPE_ID ")
|
|
|
|
|
+ .append("WHERE t.STORE_ID = ").append(storeId)
|
|
|
|
|
+ .append(" AND w.DEL_FLAG = 0 GROUP BY t.GOODS_TYPE_ID ORDER BY t.ORDER_KEY DESC");
|
|
|
|
|
+ List<Object> list = searchBySql(sql.toString());
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsTypeBean> result = new ArrayList<>();
|
|
|
|
|
+ for (Object object : list) {
|
|
|
|
|
+ Object[] row = (Object[]) object;
|
|
|
|
|
+ GoodsTypeBean bean = new GoodsTypeBean();
|
|
|
|
|
+ bean.setGoodsTypeId(row[0] == null ? null : Long.valueOf(row[0].toString()));
|
|
|
|
|
+ bean.setGoodsTypeName(row[1] == null ? null : row[1].toString());
|
|
|
|
|
+ bean.setGoodsCounts(row[2] == null ? null : Long.valueOf(row[2].toString()));
|
|
|
|
|
+ bean.setType(row[3] == null ? null : Long.valueOf(row[3].toString()));
|
|
|
|
|
+ bean.setSpecial(0L);
|
|
|
|
|
+ result.add(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<GoodsBean> getBeanByStoreId(Long storeId, String searchValue) {
|
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
|
+ sql.append("SELECT T.GOODS_ID, T.GOODS_NAME, T.GOODS_TYPE_ID, T.SALES_COUNT, T.SALE_PRICE, T.COST_PRICE, T.LIMITED_NUM, ");
|
|
|
|
|
+ sql.append("T.MINI_NUM, T.PICTURE_URL, T.NEW_GOODS_FLG, T.SINGLE_FLG, T.STORE_ID, G.MAX_NUM, T.RMK FROM bu_goods T ")
|
|
|
|
|
+ .append("LEFT JOIN bu_store_special_goods G ON T.GOODS_ID = G.GOODS_ID WHERE T.STATUS = 1 ");
|
|
|
|
|
+ if (storeId != null) {
|
|
|
|
|
+ sql.append("AND T.STORE_ID = ").append(storeId).append(" ");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (searchValue != null && !searchValue.isEmpty()) {
|
|
|
|
|
+ sql.append("AND T.GOODS_NAME LIKE '%").append(searchValue).append("%' ");
|
|
|
|
|
+ }
|
|
|
|
|
+ sql.append("ORDER BY IFNULL(T.NEW_GOODS_FLG, 0) DESC, T.ORDER_KEY DESC");
|
|
|
|
|
+ List<Object> list = searchBySql(sql.toString());
|
|
|
|
|
+
|
|
|
|
|
+ List<GoodsBean> result = new ArrayList<>();
|
|
|
|
|
+ for (Object object : list) {
|
|
|
|
|
+ Object[] row = (Object[]) object;
|
|
|
|
|
+ GoodsBean bean = new GoodsBean();
|
|
|
|
|
+ bean.setGoodsId(row[0] == null ? null : Long.valueOf(row[0].toString()));
|
|
|
|
|
+ bean.setGoodsName(row[1] == null ? null : row[1].toString());
|
|
|
|
|
+ bean.setGoodsTypeId(row[2] == null ? null : Long.valueOf(row[2].toString()));
|
|
|
|
|
+ bean.setSalesCount(row[3] == null ? null : Long.valueOf(row[3].toString()));
|
|
|
|
|
+ bean.setSalePrice(row[4] == null ? null : Long.valueOf(row[4].toString()));
|
|
|
|
|
+ bean.setCostPrice(row[5] == null ? null : Long.valueOf(row[5].toString()));
|
|
|
|
|
+ bean.setLimitedNum(row[6] == null ? null : Long.valueOf(row[6].toString()));
|
|
|
|
|
+ bean.setMiniNum(row[7] == null ? null : Long.valueOf(row[7].toString()));
|
|
|
|
|
+ bean.setPictureUrl(row[8] == null ? null : row[8].toString());
|
|
|
|
|
+ bean.setNewGoodsFlg(row[9] == null ? 0L : Long.valueOf(row[9].toString()));
|
|
|
|
|
+ bean.setSingleFlg(row[10] == null ? 0L : Long.valueOf(row[10].toString()));
|
|
|
|
|
+ bean.setStoreId(row[11] == null ? null : Long.valueOf(row[11].toString()));
|
|
|
|
|
+ bean.setSpecialLimitedNum(row[12] == null ? null : Long.valueOf(row[12].toString()));
|
|
|
|
|
+ bean.setRmk(row[13] == null ? null : row[13].toString());
|
|
|
|
|
+ result.add(bean);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<BuGoodsType> getGoodsTypeForStore(BuGoodsTypeSearchBean searchBean) {
|
|
|
|
|
+ String hql = "from BuGoodsType where 1=1" + searchBean.getSerchCondition() + " ORDER BY ORDER_KEY DESC";
|
|
|
|
|
+ return searchByHql(hql);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<BuGoodsType> getGoodsTypeMaxOrderKeyForStore(Long storeId) {
|
|
|
|
|
+ String hql = "from BuGoodsType where 1=1 and STORE_ID = " + storeId + " ORDER BY ORDER_KEY DESC ";
|
|
|
|
|
+ return searchByHql(hql);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean checkGoodsTypeByType(Long storeId, Long goodsTypeId) {
|
|
|
|
|
+ String sql = "select count(*) from bu_goods_type WHERE 1=1 AND TYPE = 1 AND STORE_ID = " + storeId;
|
|
|
|
|
+ if (goodsTypeId != null) {
|
|
|
|
|
+ sql += " AND GOODS_TYPE_ID <> " + goodsTypeId;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<?> list = searchBySql(sql);
|
|
|
|
|
+ return list != null && !list.isEmpty() && Long.valueOf(list.get(0).toString()) < 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean checkTypeIsUsed(Long goodsTypeId, Long storeId) {
|
|
|
|
|
+ String sql = "select count(*) from bu_goods WHERE GOODS_TYPE_ID = " + goodsTypeId + " AND STORE_ID = " + storeId;
|
|
|
|
|
+ List<?> list = searchBySql(sql);
|
|
|
|
|
+ return list != null && !list.isEmpty() && Long.valueOf(list.get(0).toString()) > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean deleteTypeByIdForStore(Long goodsTypeId, Long storeId) {
|
|
|
|
|
+ String sql = "delete from bu_goods_type where GOODS_TYPE_ID = " + goodsTypeId + " AND STORE_ID = " + storeId;
|
|
|
|
|
+ return executeSql(sql) == 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BuGoodsType getGoodsTypeLastForStore(BuGoodsTypeSearchBean searchBean) {
|
|
|
|
|
+ String hql = "from BuGoodsType where 1=1 " + searchBean.getSerchCondition();
|
|
|
|
|
+ List<BuGoodsType> list = searchByHql(hql);
|
|
|
|
|
+ return (list != null && !list.isEmpty()) ? list.get(0) : null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|