Browse Source

分期权限店铺维护修改

wangyc 8 years ago
parent
commit
31bf50030c

+ 18 - 33
src/main/java/com/uas/platform/b2c/fa/payment/controller/InstallmentStoreController.java

@@ -1,15 +1,11 @@
 package com.uas.platform.b2c.fa.payment.controller;
 package com.uas.platform.b2c.fa.payment.controller;
 
 
-import com.uas.platform.b2c.common.account.model.Enterprise;
-import com.uas.platform.b2c.core.support.SystemSession;
-import com.uas.platform.b2c.fa.payment.model.Installment;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import com.uas.platform.b2c.fa.payment.service.InstallmentStoreService;
 import com.uas.platform.b2c.fa.payment.service.InstallmentStoreService;
-import com.uas.platform.core.exception.IllegalOperatorException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 /**
 /**
@@ -32,55 +28,44 @@ public class InstallmentStoreController {
     /**
     /**
      * 分期权限店铺的保存功能
      * 分期权限店铺的保存功能
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
-     * @param storeId 店铺id
-     * @param enuu 企业uu
-     * @param enable 是否启用 启用:1,禁用:0
      */
      */
-    @RequestMapping(value = "/save", method = RequestMethod.POST)
-    public void saveStore(@RequestParam("storeUuid") String storeUuid , @RequestParam("storeId") Long storeId , @RequestParam("enuu") Long enuu , @RequestParam("enable") Short enable) {
-        installmentStoreService.saveStore(storeUuid, storeId, enuu, enable);
+    @RequestMapping(value = "/{storeUuid}", method = RequestMethod.POST)
+    public InstallmentStore saveStore(@PathVariable("storeUuid") String storeUuid) {
+        return installmentStoreService.saveStore(storeUuid);
     }
     }
 
 
     /**
     /**
      * 分期权限店铺的删除功能
      * 分期权限店铺的删除功能
-     * @param id
+     * @param storeUuid 店铺uuid
      */
      */
-    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
-    public void deleteStore(@RequestParam("id") Long id) {
-        installmentStoreService.deleteStore(id);
+    @RequestMapping(value = "/{storeUuid}", method = RequestMethod.DELETE)
+    public void deleteStore(@PathVariable("storeUuid") String storeUuid) {
+        installmentStoreService.deleteStore(storeUuid);
     }
     }
 
 
     /**
     /**
-     * 分期权限店铺的开启功能
+     * 分期权限店铺的禁用功能
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
      */
      */
-    @RequestMapping(value = "/capsOFF", method = RequestMethod.GET)
-    public void capsOFF(@RequestParam("storeUuid") String storeUuid) {
-        installmentStoreService.capsOFF(storeUuid);
+    @RequestMapping(value = "/disable/{storeUuid}", method = RequestMethod.PUT)
+    public InstallmentStore capsOFF(@PathVariable("storeUuid") String storeUuid) {
+        return installmentStoreService.capsOFF(storeUuid);
     }
     }
 
 
     /**
     /**
-     * 分期权限店铺的关闭功能
+     * 分期权限店铺的启用功能
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
      */
      */
-    @RequestMapping(value = "/capsON", method = RequestMethod.GET)
-    public void capsON(@RequestParam("storeUuid") String storeUuid) {
-        installmentStoreService.capsON(storeUuid);
+    @RequestMapping(value = "/enable/{storeUuid}", method = RequestMethod.PUT)
+    public InstallmentStore capsON(@PathVariable("storeUuid") String storeUuid) {
+        return installmentStoreService.capsON(storeUuid);
     }
     }
 
 
     /**
     /**
      * 分期权限店铺开启分期功能的验证
      * 分期权限店铺开启分期功能的验证
      */
      */
     @RequestMapping(value = "/capsOFFVerify", method = RequestMethod.GET)
     @RequestMapping(value = "/capsOFFVerify", method = RequestMethod.GET)
-    public String capsOFFVerify(@RequestParam(defaultValue = "0",value = "enable") Short enable) {
-        Enterprise enterprise = SystemSession.getUser().getEnterprise();
-        if (enterprise == null) {
-            throw new IllegalOperatorException("该账号为个人账号");
-        }
-        InstallmentStore installmentStore = installmentStoreService.getInstallmentByEnuuAndEnable(enterprise.getUu(), enable);
-        if (installmentStore == null) {
-            return "fail";
-        }
-        return "success";
+    public String capsOFFVerify() {
+        return installmentStoreService.capsOFFVerify();
     }
     }
 }
 }

+ 5 - 32
src/main/java/com/uas/platform/b2c/fa/payment/dao/InstallmentStoreDao.java

@@ -3,9 +3,6 @@ package com.uas.platform.b2c.fa.payment.dao;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
 /**
 /**
@@ -24,36 +21,12 @@ public interface InstallmentStoreDao extends JpaSpecificationExecutor<Installmen
      * @param enable 是否启用
      * @param enable 是否启用
      * @return
      * @return
      */
      */
-    public InstallmentStore findByEnuuAndEnable(Long enuu, Short enable);
+    InstallmentStore findByEnuuAndEnable(Long enuu, Short enable);
 
 
     /**
     /**
-     * 通过店铺uuid保存拥有分期权限店铺
-     *
-     * @param storeUuid 店铺uuid
-     * @param storeId 店铺id
-     * @param enuu 企业uu
-     * @param enable 是否启用 启用:1,禁用:0
-     */
-    @Modifying
-    @Query(value = "insert into trade$installment_store(inss_storeuuid, inss_storeid, enuu, enable) values(:storeUuid, :storeId, :enuu, :enable)", nativeQuery = true)
-    public void saveStore(@Param("storeUuid") String storeUuid, @Param("id") Long storeId, @Param("enuu") Long enuu, @Param("enable") Short enable);
-
-    /**
-     * 通过店铺uuid删除拥有分期权限店铺
-     *
-     * @param id 店铺uuid
-     */
-    @Modifying
-    @Query(value = "delete from trade$installment_store where inss_id =:id", nativeQuery = true)
-    public void deleteStore(@Param("id") Long id);
-
-    /**
-     * 通过店铺uuid更新拥有分期权限的店铺
-     *
-     * @param storeUuid 店铺uuid
-     * @param enable 是否启用 启用:1,禁用:0
+     * 通过店铺uuid获取权限信息
+     * @param storeUuid
+     * @return
      */
      */
-    @Modifying
-    @Query(value = "update trade$installment_store set inss_enable =:enable where inss_storeuuid =:storeuuid", nativeQuery = true)
-    public void updateStore(@Param("storeuuid") String storeUuid,@Param("enable") short enable);
+    InstallmentStore findByStoreUuid(String storeUuid);
 }
 }

+ 9 - 14
src/main/java/com/uas/platform/b2c/fa/payment/service/InstallmentStoreService.java

@@ -14,38 +14,33 @@ public interface InstallmentStoreService {
      * 分期权限店铺的保存功能
      * 分期权限店铺的保存功能
      *
      *
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
-     * @param storeId 店铺id
-     * @param enuu 企业uu
-     * @param enable 是否启用 启用:1,禁用:0
      */
      */
-    void saveStore(String storeUuid , Long storeId , Long enuu , Short enable);
+    InstallmentStore saveStore(String storeUuid);
 
 
     /**
     /**
      * 分期权限店铺的删除功能
      * 分期权限店铺的删除功能
      *
      *
-     * @param id
+     * @param storeUuid 店铺uuid
      */
      */
-    void deleteStore(Long id);
+    void deleteStore(String storeUuid);
 
 
     /**
     /**
-     * 分期权限店铺的开启功能
+     * 分期权限店铺的禁用功能
      *
      *
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
      */
      */
-    void capsOFF(String storeUuid);
+    InstallmentStore capsOFF(String storeUuid);
 
 
     /**
     /**
-     * 分期权限店铺的关闭功能
+     * 分期权限店铺的启用功能
      *
      *
      * @param storeUuid 店铺uuid
      * @param storeUuid 店铺uuid
      */
      */
-    void capsON(String storeUuid);
+    InstallmentStore capsON(String storeUuid);
 
 
     /**
     /**
-     * 分期权限店铺的关闭功能
-     *  @param enuu 企业uu
-     * @param enable 是否启用 启用:1,禁用:0
+     * 验证分期权限店铺的是否开启功能
      */
      */
-    InstallmentStore getInstallmentByEnuuAndEnable(Long enuu, Short enable);
+    String capsOFFVerify();
 
 
 }
 }

+ 56 - 12
src/main/java/com/uas/platform/b2c/fa/payment/service/impl/InstallmentStoreServiceImpl.java

@@ -1,10 +1,12 @@
 package com.uas.platform.b2c.fa.payment.service.impl;
 package com.uas.platform.b2c.fa.payment.service.impl;
 
 
+import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.fa.payment.dao.InstallmentStoreDao;
 import com.uas.platform.b2c.fa.payment.dao.InstallmentStoreDao;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
 import com.uas.platform.b2c.fa.payment.service.InstallmentStoreService;
 import com.uas.platform.b2c.fa.payment.service.InstallmentStoreService;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
+import com.uas.platform.core.exception.IllegalOperatorException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -15,37 +17,79 @@ import org.springframework.stereotype.Service;
  * @version 2017/9/7 11:23 wangyc
  * @version 2017/9/7 11:23 wangyc
  */
  */
 @Service
 @Service
-public class InstallmentStoreServiceImpl implements InstallmentStoreService {
+public class InstallmentStoreServiceImpl implements InstallmentStoreService{
 
 
     private final InstallmentStoreDao installmentStoreDao;
     private final InstallmentStoreDao installmentStoreDao;
 
 
+    private final StoreInDao storeInDao;
+
     @Autowired
     @Autowired
-    public InstallmentStoreServiceImpl(InstallmentStoreDao installmentStoreDao) {
+    public InstallmentStoreServiceImpl(InstallmentStoreDao installmentStoreDao, StoreInDao storeInDao) {
         this.installmentStoreDao = installmentStoreDao;
         this.installmentStoreDao = installmentStoreDao;
+        this.storeInDao = storeInDao;
     }
     }
 
 
     @Override
     @Override
-    public void saveStore(String storeUuid, Long storeId, Long enuu, Short enable) {
-        installmentStoreDao.saveStore(storeUuid, storeId, enuu, enable);
+    public InstallmentStore saveStore(String storeUuid) {
+        StoreIn storeIn = storeInDao.findByUuid(storeUuid);
+        if (storeIn == null)
+            throw new IllegalOperatorException("此店铺不存在,请重新确认店铺信息");
+
+        InstallmentStore installmentStore = installmentStoreDao.findByStoreUuid(storeUuid);
+        if (installmentStore != null)
+            throw new IllegalOperatorException("店铺: " + storeIn.getStoreName() + " 已存在权限列表中,如需维护请找到该店铺进行维护");
+
+        installmentStore.setEnable((short) 1);
+        installmentStore.setEnuu(storeIn.getEnUU());
+        installmentStore.setStoreId(storeIn.getId());
+        installmentStore.setStoreUuid(storeUuid);
+
+        return installmentStoreDao.save(installmentStore);
     }
     }
 
 
     @Override
     @Override
-    public void deleteStore(Long id) {
-        installmentStoreDao.deleteStore(id);
+    public void deleteStore(String storeUuid) {
+        InstallmentStore installmentStore = installmentStoreDao.findByStoreUuid(storeUuid);
+        if (installmentStore == null)
+            throw new IllegalOperatorException("此店铺并不存在权限列表中,无需删除");
+        installmentStoreDao.delete(installmentStore.getId());
     }
     }
 
 
     @Override
     @Override
-    public void capsOFF(String storeUuid) {
-        installmentStoreDao.updateStore(storeUuid,(short)1);
+    public InstallmentStore capsOFF(String storeUuid) {
+        return toggleStore(storeUuid, (short) 0);
     }
     }
 
 
     @Override
     @Override
-    public void capsON(String storeUuid) {
-        installmentStoreDao.updateStore(storeUuid,(short)0);
+    public InstallmentStore capsON(String storeUuid) {
+        return toggleStore(storeUuid, (short) 1);
+    }
+
+    /**
+     * 启用/禁用店铺
+     * @param enable
+     * @return
+     */
+    public InstallmentStore toggleStore(String storeUuid, short enable) {
+        InstallmentStore installmentStore = installmentStoreDao.findByStoreUuid(storeUuid);
+        if (installmentStore == null)
+            throw new IllegalOperatorException("此店铺并不存在权限列表中,无需删除");
+
+        installmentStore.setEnable(enable);
+
+        return installmentStoreDao.save(installmentStore);
     }
     }
 
 
     @Override
     @Override
-    public InstallmentStore getInstallmentByEnuuAndEnable(Long enuu, Short enable) {
-        return installmentStoreDao.findByEnuuAndEnable(enuu, enable);
+    public String capsOFFVerify() {
+        if (SystemSession.getUser().getEnterprise() == null)
+            throw new IllegalOperatorException("当前用户为个人用户,请选择企业进行分期操作");
+
+        InstallmentStore installmentStore = installmentStoreDao.findByEnuuAndEnable(SystemSession.getUser().getEnterprise().getUu(), (short) 1);
+        if (installmentStore == null) {
+            return "fail";
+        } else {
+            return "success";
+        }
     }
     }
 }
 }