// Path: acmeair-customer-service/src/main/java/com/acmeair/morphia/entities/CouponImpl.java
// @Document(collection = "coupon")
// @Entity(name = "coupon")
// public class CouponImpl implements Coupon, Serializable {
// 
//   private static final long serialVersionUID = 1L;
// 
//   @Id
//   @Column(name = "id")
//   private int id;
// 
//   private String promotionId;
// 
//   private Date time;
// 
//   private float discount;
// 
//   private String customerId;
// 
//   private boolean isUsed;
// 
//   public int getId() {
//     return id;
//   }
// 
//   public void setId(int id) {
//     this.id = id;
//   }
// 
//   public String getPromotionId() {
//     return promotionId;
//   }
// 
//   public void setPromotionId(String promotionId) {
//     this.promotionId = promotionId;
//   }
// 
//   public Date getTime() {
//     return time;
//   }
// 
//   public void setTime(Date time) {
//     this.time = time;
//   }
// 
//   public float getDiscount() {
//     return discount;
//   }
// 
//   public void setDiscount(float discount) {
//     this.discount = discount;
//   }
// 
//   public String getCustomerId() {
//     return customerId;
//   }
// 
//   public void setCustomerId(String customerId) {
//     this.customerId = customerId;
//   }
// 
//   public boolean isUsed() {
//     return isUsed;
//   }
// 
//   public void setUsed(boolean used) {
//     isUsed = used;
//   }
// 
//   public CouponImpl() {
//   }
// 
//   public CouponImpl(int id, String promotionId, Date time, float discount, String customerId, boolean isUsed) {
//     this.id = id;
//     this.promotionId = promotionId;
//     this.time = time;
//     this.discount = discount;
//     this.customerId = customerId;
//     this.isUsed = isUsed;
//   }
// }
// 
// Path: acmeair-customer-service/src/main/java/com/acmeair/morphia/repositories/CouponRepository.java
// public interface CouponRepository extends CrudRepository<CouponImpl, Integer> {
//   List<CouponImpl> findByCustomerIdAndIsUsed(String customerId, boolean isUsed);
// 
//   CouponImpl findTopByOrderByIdDesc();
// }
// 
// Path: acmeair-customer-common/src/main/java/com/acmeair/web/dto/CouponInfo.java
// public class CouponInfo implements Serializable {
//   private static final long serialVersionUID = 1L;
// 
//   private int id;
// 
//   private String promotionId;
// 
//   private Date time;
// 
//   private float discount;
// 
//   private String customerId;
// 
//   public CouponInfo() {
//   }
// 
//   public static long getSerialVersionUID() {
//     return serialVersionUID;
//   }
// 
//   public int getId() {
//     return id;
//   }
// 
//   public void setId(int id) {
//     this.id = id;
//   }
// 
//   public String getPromotionId() {
//     return promotionId;
//   }
// 
//   public void setPromotionId(String promotionId) {
//     this.promotionId = promotionId;
//   }
// 
//   public Date getTime() {
//     return time;
//   }
// 
//   public void setTime(Date time) {
//     this.time = time;
//   }
// 
//   public float getDiscount() {
//     return discount;
//   }
// 
//   public void setDiscount(float discount) {
//     this.discount = discount;
//   }
// 
//   public String getCustomerId() {
//     return customerId;
//   }
// 
//   public void setCustomerId(String customerId) {
//     this.customerId = customerId;
//   }
// }


import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.acmeair.morphia.entities.CouponImpl;
import com.acmeair.morphia.repositories.CouponRepository;
import com.acmeair.service.CouponService;
import com.acmeair.service.SeckillService;
import com.acmeair.web.dto.CouponInfo;
/*
 *   Copyright 2017 Huawei Technologies Co., Ltd
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.acmeair.morphia.services;




@Service
public class CouponServiceImpl implements CouponService {


  private final CouponRepository couponRepository;

  private final SeckillService seckillService;

  @Autowired
  public CouponServiceImpl(CouponRepository couponRepository, SeckillService seckillService) {
    this.couponRepository = couponRepository;
    this.seckillService = seckillService;

    final Runnable executor = () -> {
      CouponImpl latestCoupon = this.couponRepository.findTopByOrderByIdDesc();
      int latestId = latestCoupon == null ? 0 : latestCoupon.getId();
      List<CouponInfo> seckillCoupons = this.seckillService.syncCoupons(latestId);
      for (CouponInfo coupon : seckillCoupons) {
        if (coupon.getId() > latestId) {
          couponRepository.save(new CouponImpl(
              coupon.getId(),
              coupon.getPromotionId(),
// Path: acmeair-customer-service/src/main/java/com/acmeair/morphia/entities/CouponImpl.java
// @Document(collection = "coupon")
// @Entity(name = "coupon")
// public class CouponImpl implements Coupon, Serializable {
// 
//   private static final long serialVersionUID = 1L;
// 
//   @Id
//   @Column(name = "id")
//   private int id;
// 
//   private String promotionId;
// 
//   private Date time;
// 
//   private float discount;
// 
//   private String customerId;
// 
//   private boolean isUsed;
// 
//   public int getId() {
//     return id;
//   }
// 
//   public void setId(int id) {
//     this.id = id;
//   }
// 
//   public String getPromotionId() {
//     return promotionId;
//   }
// 
//   public void setPromotionId(String promotionId) {
//     this.promotionId = promotionId;
//   }
// 
//   public Date getTime() {
//     return time;
//   }
// 
//   public void setTime(Date time) {
//     this.time = time;
//   }
// 
//   public float getDiscount() {
//     return discount;
//   }
// 
//   public void setDiscount(float discount) {
//     this.discount = discount;
//   }
// 
//   public String getCustomerId() {
//     return customerId;
//   }
// 
//   public void setCustomerId(String customerId) {
//     this.customerId = customerId;
//   }
// 
//   public boolean isUsed() {
//     return isUsed;
//   }
// 
//   public void setUsed(boolean used) {
//     isUsed = used;
//   }
// 
//   public CouponImpl() {
//   }
// 
//   public CouponImpl(int id, String promotionId, Date time, float discount, String customerId, boolean isUsed) {
//     this.id = id;
//     this.promotionId = promotionId;
//     this.time = time;
//     this.discount = discount;
//     this.customerId = customerId;
//     this.isUsed = isUsed;
//   }
// }
// 
// Path: acmeair-customer-service/src/main/java/com/acmeair/morphia/repositories/CouponRepository.java
// public interface CouponRepository extends CrudRepository<CouponImpl, Integer> {
//   List<CouponImpl> findByCustomerIdAndIsUsed(String customerId, boolean isUsed);
// 
//   CouponImpl findTopByOrderByIdDesc();
// }
// 
// Path: acmeair-customer-common/src/main/java/com/acmeair/web/dto/CouponInfo.java
// public class CouponInfo implements Serializable {
//   private static final long serialVersionUID = 1L;
// 
//   private int id;
// 
//   private String promotionId;
// 
//   private Date time;
// 
//   private float discount;
// 
//   private String customerId;
// 
//   public CouponInfo() {
//   }
// 
//   public static long getSerialVersionUID() {
//     return serialVersionUID;
//   }
// 
//   public int getId() {
//     return id;
//   }
// 
//   public void setId(int id) {
//     this.id = id;
//   }
// 
//   public String getPromotionId() {
//     return promotionId;
//   }
// 
//   public void setPromotionId(String promotionId) {
//     this.promotionId = promotionId;
//   }
// 
//   public Date getTime() {
//     return time;
//   }
// 
//   public void setTime(Date time) {
//     this.time = time;
//   }
// 
//   public float getDiscount() {
//     return discount;
//   }
// 
//   public void setDiscount(float discount) {
//     this.discount = discount;
//   }
// 
//   public String getCustomerId() {
//     return customerId;
//   }
// 
//   public void setCustomerId(String customerId) {
//     this.customerId = customerId;
//   }
// }


// Path: acmeair-customer-service/src/main/java/com/acmeair/morphia/services/CouponServiceImpl.java
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.acmeair.morphia.entities.CouponImpl;
import com.acmeair.morphia.repositories.CouponRepository;
import com.acmeair.service.CouponService;
import com.acmeair.service.SeckillService;
import com.acmeair.web.dto.CouponInfo;

/*
 *   Copyright 2017 Huawei Technologies Co., Ltd
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.acmeair.morphia.services;




@Service
public class CouponServiceImpl implements CouponService {


  private final CouponRepository couponRepository;

  private final SeckillService seckillService;

  @Autowired
  public CouponServiceImpl(CouponRepository couponRepository, SeckillService seckillService) {
    this.couponRepository = couponRepository;
    this.seckillService = seckillService;

    final Runnable executor = () -> {
      CouponImpl latestCoupon = this.couponRepository.findTopByOrderByIdDesc();
      int latestId = latestCoupon == null ? 0 : latestCoupon.getId();
      List<CouponInfo> seckillCoupons = this.seckillService.syncCoupons(latestId);
      for (CouponInfo coupon : seckillCoupons) {
        if (coupon.getId() > latestId) {
          couponRepository.save(new CouponImpl(
              coupon.getId(),
              coupon.getPromotionId(),
              coupon.getTime(),