|
|
@@ -0,0 +1,310 @@
|
|
|
+package com.sapit.client.app.third.controller.operate;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sapit.client.app.persistence.goods.GoodsDao;
|
|
|
+import com.sapit.client.app.persistence.goods.GoodsModelDao;
|
|
|
+import com.sapit.client.app.persistence.store.StoreSpecialActivityDao;
|
|
|
+import com.sapit.client.app.persistence.store.StoreSpecialGoodsDao;
|
|
|
+import com.sapit.client.app.store.service.activity.StoreSpecialActivityApiService;
|
|
|
+import com.sapit.client.app.store.service.activity.StoreSpecialGoodsApiService;
|
|
|
+import com.sapit.client.app.store.service.goods.StoreGoodsManageApiService;
|
|
|
+import com.sapit.common.bean.store.StoreSpecialGoodsBean;
|
|
|
+import com.sapit.common.constant.ReturnCode;
|
|
|
+import com.sapit.common.entity.store.BuStoreSpecialActivity;
|
|
|
+import com.sapit.common.entity.store.BuStoreSpecialGoods;
|
|
|
+import com.sapit.common.framwork.ResultBean;
|
|
|
+import com.sapit.common.search.store.StoreSpecialActivitySearchBean;
|
|
|
+import com.sapit.common.search.store.StoreSpecialGoodsSearchBean;
|
|
|
+import com.sapit.common.util.DateUtil;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class StoreSpecialsThirdApiControllertestService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StoreSpecialActivityDao storeSpecialActivityDao;
|
|
|
+ @Autowired
|
|
|
+ private StoreGoodsManageApiService storeGoodsManageApiService;
|
|
|
+ @Autowired
|
|
|
+ private StoreSpecialGoodsApiService storeSpecialGoodsApiService;
|
|
|
+ @Autowired
|
|
|
+ private StoreSpecialActivityApiService storeSpecialActivityApiService;
|
|
|
+ @Autowired
|
|
|
+ private StoreSpecialGoodsDao storeSpecialGoodsDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsModelDao goodsModelDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取店铺特价菜列表
|
|
|
+ * @param storeId
|
|
|
+ * @param activityName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultBean getStoreSpecialActivityListForThird(Long storeId, String activityName) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ // 空值校验
|
|
|
+ if (storeId == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("参数错误!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ if (activityName != null) {
|
|
|
+ activityName = activityName.trim();
|
|
|
+ if (activityName.isEmpty()) {
|
|
|
+ activityName = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StoreSpecialActivitySearchBean searchBean = new StoreSpecialActivitySearchBean();
|
|
|
+ searchBean.setStoreId(storeId);
|
|
|
+ searchBean.setActivityName(activityName);
|
|
|
+ List<BuStoreSpecialActivity> activityList = storeSpecialActivityDao.getStoreSpecialActivityListForThird(searchBean);
|
|
|
+ if (activityList == null) {
|
|
|
+ activityList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ bean.setList(activityList);
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取店铺可添加的特价菜商品列表
|
|
|
+ */
|
|
|
+ public ResultBean getStoreSingleGoodsForSpecialForThird(Long storeId, String goodsName, String ids) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ if (storeId == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg(ReturnCode.getName(ReturnCode.PARAM_WRONG));
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ String idsStr = null;
|
|
|
+ if (ids != null && !ids.equals("")) {
|
|
|
+ StringBuilder idstemp = new StringBuilder();
|
|
|
+ idstemp.append("(").append(ids).append(")");
|
|
|
+ idsStr = idstemp.toString();
|
|
|
+ }
|
|
|
+ bean.setList(storeGoodsManageApiService.getStoreSingleGoodsForSpecialForStore(storeId, goodsName, idsStr));
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新店铺特价菜活动状态
|
|
|
+ */
|
|
|
+ public ResultBean updateStoreSpecialActivityStatusForThird(Long storeId, Long id, Long status) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ if (storeId == null || id == null || status == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("参数错误!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ boolean rtn = storeSpecialActivityDao.updateStoreSpecialActivityStatusForStore(storeId, id, status);
|
|
|
+ if (rtn) {
|
|
|
+ storeSpecialGoodsApiService.updateStoreSpecialGoodsPriceForStore(id, status);
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
+ bean.getRtnBean().setRtnMsg("更新成功");
|
|
|
+ } else {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
+ bean.getRtnBean().setRtnMsg("更新失败!");
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过ID获取店铺特价菜活动详情
|
|
|
+ */
|
|
|
+ public ResultBean getStoreSpecialActivityByIdForThird(Long storeId, Long id) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ if (storeId == null || id == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("参数错误!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ StoreSpecialActivitySearchBean searchBean = new StoreSpecialActivitySearchBean();
|
|
|
+ searchBean.setStoreId(storeId);
|
|
|
+ searchBean.setStoreSpecialActivityId(id);
|
|
|
+ BuStoreSpecialActivity activity = storeSpecialActivityDao.getStoreSpecialActivityForStore(searchBean);
|
|
|
+
|
|
|
+ StoreSpecialGoodsSearchBean searchBean1 = new StoreSpecialGoodsSearchBean();
|
|
|
+ searchBean1.setStoreSpecialActivityId(id);
|
|
|
+ List<StoreSpecialGoodsBean> goodsList = storeSpecialGoodsApiService.getStoreSpecialGoodsListForStore(searchBean1);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsList)) {
|
|
|
+ List<Long> modelIds = new ArrayList<>();
|
|
|
+ for (StoreSpecialGoodsBean bean1 : goodsList) {
|
|
|
+ modelIds.add(bean1.getModelId());
|
|
|
+ }
|
|
|
+ List<Long> goodsStore = storeSpecialGoodsApiService.getSpecialGoodsStoreList(modelIds);
|
|
|
+ for (int i = 0; i < goodsList.size(); i++) {
|
|
|
+ goodsList.get(i).setInventory(goodsStore.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bean.setObj(activity);
|
|
|
+ bean.setList(goodsList);
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增/编辑店铺特价菜活动
|
|
|
+ */
|
|
|
+ public ResultBean saveStoreSpecialActivityForThird(String goodsListStr, BuStoreSpecialActivity activity, Long storeId) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ if (storeId == null || activity == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("参数错误!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ JSONArray goodsList = JSONArray.parseArray(goodsListStr);
|
|
|
+ if (goodsList.isEmpty()) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("商品不能为空!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ if (activity.getStoreSpecialActivityId() == null) {
|
|
|
+ // --- 新增 ---
|
|
|
+ StringBuilder ids = new StringBuilder();
|
|
|
+ for (int i = 0; i < goodsList.size(); i++) {
|
|
|
+ ids.append(",").append(JSON.parseObject(goodsList.get(i).toString()).getString("goodsId"));
|
|
|
+ }
|
|
|
+ StoreSpecialGoodsSearchBean searchBean = new StoreSpecialGoodsSearchBean();
|
|
|
+ searchBean.setGoodsIds(ids.substring(1));
|
|
|
+ List<StoreSpecialGoodsBean> beanList = storeSpecialGoodsApiService.getStoreSpecialGoodsListForStore(searchBean);
|
|
|
+ if (beanList != null && !beanList.isEmpty()) {
|
|
|
+ StringBuilder goodsName = new StringBuilder();
|
|
|
+ for (StoreSpecialGoodsBean temp : beanList) {
|
|
|
+ goodsName.append(",").append(temp.getGoodsName());
|
|
|
+ }
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
+ bean.getRtnBean().setRtnMsg(goodsName.substring(1) + "已经添加到其他特价菜活动中了,不能重复添加");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ activity.setStoreId(storeId);
|
|
|
+ activity.setUpdateDate(DateUtil.getSqlToday());
|
|
|
+ activity.setStatus(0L);
|
|
|
+ storeSpecialActivityDao.save(activity);
|
|
|
+ for (int i = 0; i < goodsList.size(); i++) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(goodsList.get(i).toString());
|
|
|
+ BuStoreSpecialGoods goods = new BuStoreSpecialGoods();
|
|
|
+ goods.setActivityNum(jsonObject.getLong("activityNum"));
|
|
|
+ goods.setActivityPrice(jsonObject.getBigDecimal("activityPrice").multiply(new BigDecimal(100)).longValue());
|
|
|
+ goods.setCreateDate(DateUtil.getSqlToday());
|
|
|
+ goods.setGoodsId(jsonObject.getLong("goodsId"));
|
|
|
+ goods.setMaxNum(jsonObject.getLong("maxNum"));
|
|
|
+ goods.setModelId(jsonObject.getLong("modelId"));
|
|
|
+ goods.setStoreSpecialActivityId(activity.getStoreSpecialActivityId());
|
|
|
+ storeSpecialGoodsApiService.save(goods);
|
|
|
+ }
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
+ bean.getRtnBean().setRtnMsg("新增成功");
|
|
|
+ bean.setObj(activity.getStoreSpecialActivityId());
|
|
|
+ } else {
|
|
|
+ // --- 编辑 ---
|
|
|
+ StoreSpecialActivitySearchBean searchBean = new StoreSpecialActivitySearchBean();
|
|
|
+ searchBean.setStoreId(storeId);
|
|
|
+ searchBean.setStoreSpecialActivityId(activity.getStoreSpecialActivityId());
|
|
|
+ BuStoreSpecialActivity oldActivity = storeSpecialActivityApiService.getStoreSpecialActivityForStore(searchBean);
|
|
|
+ if (oldActivity != null) {
|
|
|
+ oldActivity.setActivityName(activity.getActivityName());
|
|
|
+ oldActivity.setActivityComment(activity.getActivityComment());
|
|
|
+ oldActivity.setEndDate(activity.getEndDate());
|
|
|
+ oldActivity.setStartDate(activity.getStartDate());
|
|
|
+ oldActivity.setUpdateDate(DateUtil.getSqlToday());
|
|
|
+ storeSpecialActivityApiService.update(oldActivity);
|
|
|
+
|
|
|
+ StoreSpecialGoodsSearchBean searchBean1 = new StoreSpecialGoodsSearchBean();
|
|
|
+ searchBean1.setStoreSpecialActivityId(activity.getStoreSpecialActivityId());
|
|
|
+ List<StoreSpecialGoodsBean> beanList = storeSpecialGoodsApiService.getStoreSpecialGoodsListForStore(searchBean1);
|
|
|
+ List<Long> existIds = new ArrayList<>();
|
|
|
+ for (StoreSpecialGoodsBean storeSpecialGoodsBean : beanList) {
|
|
|
+ existIds.add(storeSpecialGoodsBean.getStoreSpecialGoodsId());
|
|
|
+ }
|
|
|
+ List<Long> goodsIds = new ArrayList<>();
|
|
|
+ for (Object o : goodsList) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(o.toString());
|
|
|
+ if (jsonObject.get("storeSpecialGoodsId") != null && !jsonObject.get("storeSpecialGoodsId").equals("null")) {
|
|
|
+ goodsIds.add(jsonObject.getLong("storeSpecialGoodsId"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除被移除的商品
|
|
|
+ for (Long existId : existIds) {
|
|
|
+ if (!goodsIds.contains(existId)) {
|
|
|
+ storeSpecialGoodsDao.deleteStoreSpecialGoodsByGoodsIdForStore(existId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存商品列表
|
|
|
+ for (int i = 0; i < goodsList.size(); i++) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(goodsList.get(i).toString());
|
|
|
+ if (jsonObject.get("storeSpecialGoodsId") == null || jsonObject.get("storeSpecialGoodsId").equals("null")) {
|
|
|
+ BuStoreSpecialGoods goods = new BuStoreSpecialGoods();
|
|
|
+ goods.setActivityNum(jsonObject.getLong("activityNum"));
|
|
|
+ goods.setActivityPrice(jsonObject.getBigDecimal("activityPrice").multiply(new BigDecimal(100)).longValue());
|
|
|
+ goods.setCreateDate(DateUtil.getSqlToday());
|
|
|
+ goods.setGoodsId(jsonObject.getLong("goodsId"));
|
|
|
+ goods.setMaxNum(jsonObject.getLong("maxNum"));
|
|
|
+ goods.setModelId(jsonObject.getLong("modelId"));
|
|
|
+ goods.setStoreSpecialActivityId(activity.getStoreSpecialActivityId());
|
|
|
+ storeSpecialGoodsApiService.save(goods);
|
|
|
+ } else {
|
|
|
+ BuStoreSpecialGoods goods = new BuStoreSpecialGoods();
|
|
|
+ goods.setActivityNum(jsonObject.getLong("activityNum"));
|
|
|
+ goods.setActivityPrice(jsonObject.getBigDecimal("activityPrice").multiply(new BigDecimal(100)).longValue());
|
|
|
+ goods.setCreateDate(DateUtil.getSqlToday());
|
|
|
+ goods.setGoodsId(jsonObject.getLong("goodsId"));
|
|
|
+ goods.setMaxNum(jsonObject.getLong("maxNum"));
|
|
|
+ goods.setModelId(jsonObject.getLong("modelId"));
|
|
|
+ goods.setStoreSpecialGoodsId(jsonObject.getLong("storeSpecialGoodsId"));
|
|
|
+ goods.setStoreSpecialActivityId(jsonObject.getLong("storeSpecialActivityId"));
|
|
|
+ storeSpecialGoodsApiService.update(goods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.SYSTEMERR);
|
|
|
+ bean.getRtnBean().setRtnMsg(ReturnCode.getName(ReturnCode.SYSTEMERR));
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.SUCCESS);
|
|
|
+ bean.getRtnBean().setRtnMsg("更新成功");
|
|
|
+ bean.setObj(activity.getStoreSpecialActivityId());
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除店铺特价菜活动
|
|
|
+ */
|
|
|
+ public ResultBean deleteStoreSpecialActivityForThird(Long storeId, Long id) {
|
|
|
+ ResultBean bean = new ResultBean();
|
|
|
+ if (storeId == null || id == null) {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.PARAM_WRONG);
|
|
|
+ bean.getRtnBean().setRtnMsg("参数错误!");
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+ boolean rtn = storeSpecialActivityDao.deleteStoreSpecialActivityForThird(storeId, id);
|
|
|
+ if (rtn) {
|
|
|
+ StoreSpecialGoodsSearchBean searchBean1 = new StoreSpecialGoodsSearchBean();
|
|
|
+ searchBean1.setStoreSpecialActivityId(id);
|
|
|
+ List<BuStoreSpecialGoods> goodsList = storeSpecialGoodsDao.getStoreSpecialGoodsList(searchBean1);
|
|
|
+ for (int i = 0; i < goodsList.size(); i++) {
|
|
|
+ goodsModelDao.updateGoodsModelSalePriceBatch(goodsList.get(i).getModelId());
|
|
|
+ goodsDao.updateGoodsSalesPriceBatch(goodsList.get(i).getGoodsId());
|
|
|
+ }
|
|
|
+ storeSpecialGoodsApiService.deleteStoreSpecialGoodsForStore(id);
|
|
|
+ } else {
|
|
|
+ bean.getRtnBean().setRtnCode(ReturnCode.FAILED);
|
|
|
+ bean.getRtnBean().setRtnMsg("删除失败!");
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|