|
@@ -1,10 +1,14 @@
|
|
|
package com.bosshand.virgo.api.workark.service;
|
|
|
|
|
|
import com.bosshand.virgo.api.workark.dao.ProductCouponDao;
|
|
|
+import com.bosshand.virgo.api.workark.dao.ProductCouponModelDao;
|
|
|
import com.bosshand.virgo.api.workark.model.ProductCoupon;
|
|
|
+import com.bosshand.virgo.api.workark.model.ProductCouponModel;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
@@ -13,6 +17,9 @@ public class ProductCouponService {
|
|
|
@Autowired
|
|
|
ProductCouponDao productCouponDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ProductCouponModelDao productCouponModelDao;
|
|
|
+
|
|
|
public void delete(long id) {
|
|
|
productCouponDao.delete(id);
|
|
|
}
|
|
@@ -42,4 +49,26 @@ public class ProductCouponService {
|
|
|
return productCouponDao.get(id);
|
|
|
}
|
|
|
|
|
|
+ public List<ProductCouponModel> nowReceive(long organizationId, long userId) {
|
|
|
+ List<ProductCoupon> list = productCouponDao.getProductCouponModelId(organizationId, userId);
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return productCouponModelDao.getAll();
|
|
|
+ }
|
|
|
+ List<Long> ids = new ArrayList();
|
|
|
+ list.forEach(ls -> ids.add(ls.getId()));
|
|
|
+ return productCouponModelDao.nowReceive(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void receive(long organizationId, long userId, long productCouponModelId) {
|
|
|
+ ProductCouponModel productCouponModel = productCouponModelDao.get(productCouponModelId);
|
|
|
+ ProductCoupon productCoupon = new ProductCoupon();
|
|
|
+ BeanUtils.copyProperties(productCouponModel, productCoupon);
|
|
|
+ productCoupon.setOrganizationId(organizationId);
|
|
|
+ productCoupon.setUserId(userId);
|
|
|
+ productCoupon.setProductCouponModelId(productCouponModel.getId());
|
|
|
+ productCouponDao.save(productCoupon);
|
|
|
+ productCoupon.setState(1);
|
|
|
+ productCouponDao.update(productCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
}
|