diff --git a/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java b/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java index 21533963..af4e9dca 100644 --- a/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java +++ b/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java @@ -44,6 +44,8 @@ public interface PurchaseOrderService { boolean saveDsPurchaseSetting(Long shopId, DsPurchaseSettingDTO dsPurchaseSettingDTO); + boolean saveDsAutoPurchaseAgreement(Long shopId); + List selectByConditions(PurchaseOrder build); ApiResult checkAllowDsAutoPurchase(Long shopId, String orderId, DsPurchaseSettingDTO autoPurchaseSetting, int orderStatus, Date orderGmtPayTime, Boolean isDsOpOrder); diff --git a/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java b/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java index c32c113d..78246f2e 100644 --- a/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java @@ -85,6 +85,9 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { @Autowired private DsAutoPurchaseSwitchLogMapper dsAutoPurchaseSwitchLogMapper; + @Autowired + private DsAutoPurchaseAgreementMapper dsAutoPurchaseAgreementMapper; + @Autowired private ShopService shopService; @@ -614,6 +617,27 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { return rows.stream().collect(Collectors.toMap(PurchaseOrderSetting::getPurchaseOrderId, x -> x)); } + public boolean saveDsAutoPurchaseAgreement(Long shopId) { + DsAutoPurchaseAgreement obj = new DsAutoPurchaseAgreement(); + obj.setShopId(shopId); + // 之前版本都是从session取,这边后续处理 todo: + obj.setOperateShopId(shopId); +// obj.setOperateIp(""); +// obj.setOperateMemberId(""); + obj.setGmtModified(new Date()); + + DsAutoPurchaseAgreement row = dsAutoPurchaseAgreementMapper.getByShopId(shopId); + int affRow; + if (row == null) { + obj.setGmtCreate(new Date()); + affRow = dsAutoPurchaseAgreementMapper.insertSelective(obj); + } else { + obj.setDsAutoPurchaseAgreementId(row.getDsAutoPurchaseAgreementId()); + affRow = dsAutoPurchaseAgreementMapper.updateByPrimaryKeySelective(obj); + } + return affRow > 0; + } + public PurchaseSettingDTO getPurchaseSetting(Long shopId) { PurchaseSetting purchaseSetting = purchaseSettingMapper.selectByShopId(shopId); // boolean isNewestVersion = purchaseSetting.version = PurchaseOrderConst.CURRENT_PURCHASE_SETTING_VERSION; diff --git a/ms-biz/src/main/java/com/ms/api/spi/order/SaveDsAutoPurchaseAgreementService.java b/ms-biz/src/main/java/com/ms/api/spi/order/SaveDsAutoPurchaseAgreementService.java index 312b6bce..a38a400b 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/order/SaveDsAutoPurchaseAgreementService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/order/SaveDsAutoPurchaseAgreementService.java @@ -4,22 +4,38 @@ import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; import com.ms.api.common.Ret; import com.ms.api.common.SPIBaseService; import com.ms.api.dto.order.SaveDsAutoPurchaseAgreementRequestDTO; +import com.ms.api.service.PurchaseOrderService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; @ExtensionService("saveDsAutoPurchaseAgreement") @Slf4j @AllArgsConstructor public class SaveDsAutoPurchaseAgreementService extends SPIBaseService implements ExtensionServiceHandler { + @Autowired + private PurchaseOrderService purchaseOrderService; + @Override public BaseResponse handle(BaseRequest req) { initHandle(req); Long shopId = Long.valueOf(this.shopId); - return null; + SaveDsAutoPurchaseAgreementRequestDTO requestDTO = req.getData(); + + if (requestDTO.getIsCheckedAgreement() == null || requestDTO.getIsCheckedAgreement() == 0) { + return R.ok(Ret.fail("未勾选使用协议")); + } + + if (!purchaseOrderService.saveDsAutoPurchaseAgreement(shopId)) { + return R.ok(Ret.fail("保存用户协议失败")); + } + + return R.ok(Ret.success()); } } diff --git a/ms-dal/src/main/java/com/ms/dal/mapper/DsAutoPurchaseAgreementMapper.java b/ms-dal/src/main/java/com/ms/dal/mapper/DsAutoPurchaseAgreementMapper.java index 185018e7..8938e4d0 100644 --- a/ms-dal/src/main/java/com/ms/dal/mapper/DsAutoPurchaseAgreementMapper.java +++ b/ms-dal/src/main/java/com/ms/dal/mapper/DsAutoPurchaseAgreementMapper.java @@ -21,4 +21,5 @@ public interface DsAutoPurchaseAgreementMapper { int updateByPrimaryKey(DsAutoPurchaseAgreement record); + DsAutoPurchaseAgreement getByShopId(Long shopId); } diff --git a/ms-dal/src/main/resources/mapper/DsAutoPurchaseAgreementMapper.xml b/ms-dal/src/main/resources/mapper/DsAutoPurchaseAgreementMapper.xml index 59ca79f4..e7b41c27 100644 --- a/ms-dal/src/main/resources/mapper/DsAutoPurchaseAgreementMapper.xml +++ b/ms-dal/src/main/resources/mapper/DsAutoPurchaseAgreementMapper.xml @@ -24,12 +24,17 @@ select from ds_auto_purchase_agreement - where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} + where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} + + delete from ds_auto_purchase_agreement - where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} + where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} insert into ds_auto_purchase_agreement @@ -43,22 +48,22 @@ insert into ds_auto_purchase_agreement - dsAutoPurchaseAgreementId, - shopId, - operateShopId, - operateIp, - operateMemberId, - gmtCreate, - gmtModified, + ds_auto_purchase_agreement_id, + shop_id, + operate_shop_id, + operate_ip, + operate_member_id, + gmt_create, + gmt_modified, - ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT}, - shop_id = #{shopId,jdbcType=BIGINT}, - operate_shop_id = #{operateShopId,jdbcType=BIGINT}, - operate_ip = #{operateIp,jdbcType=VARCHAR}, - operate_member_id = #{operateMemberId,jdbcType=VARCHAR}, - gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, - gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, + #{dsAutoPurchaseAgreementId,jdbcType=BIGINT}, + #{shopId,jdbcType=BIGINT}, + #{operateShopId,jdbcType=BIGINT}, + #{operateIp,jdbcType=VARCHAR}, + #{operateMemberId,jdbcType=VARCHAR}, + #{gmtCreate,jdbcType=TIMESTAMP}, + #{gmtModified,jdbcType=TIMESTAMP}, @@ -83,17 +88,17 @@ gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, - where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} + where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} update ds_auto_purchase_agreement - set + set shop_id = #{shopId,jdbcType=BIGINT}, operate_shop_id = #{operateShopId,jdbcType=BIGINT}, operate_ip = #{operateIp,jdbcType=VARCHAR}, operate_member_id = #{operateMemberId,jdbcType=VARCHAR}, gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} - where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT} + where ds_auto_purchase_agreement_id = #{dsAutoPurchaseAgreementId,jdbcType=BIGINT}