| | |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>com.yeshi</groupId> |
| | | <artifactId>utils</artifactId> |
| | | <version>0.0.4</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | |
| | | <exclusion> |
| | | <groupId>ch.qos.logback</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | |
| | | public final static int CODE_USER_CREATE_NUM_LIMIT = 2001; |
| | | //用户创建淘礼金的金额超限 |
| | | public final static int CODE_USER_CREATE_MONEY_LIMIT = 2002; |
| | | //用户余额不足 |
| | | public final static int CODE_USER_BALANCE_NOT_ENOUGH = 2003; |
| | | |
| | | |
| | | public LiJinUserException(int code, String msg) { |
| | |
| | | @Column(name = "rd_update_time") |
| | | private Date updateTime; |
| | | |
| | | public LiJinExpendRecord() { |
| | | } |
| | | |
| | | public LiJinExpendRecord(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public Long getId() { |
| | | return id; |
| | |
| | | public final static int ERROR_CODE_GOODS_NOT_ENOUGH = 20; |
| | | |
| | | //其他错误 |
| | | public final static int ERROR_CODE_OTHER=30; |
| | | public final static int ERROR_CODE_OTHER = 30; |
| | | |
| | | |
| | | @Column(name = "ac_id") |
| | |
| | | @Column(name = "ac_state") |
| | | private Integer state; |
| | | |
| | | //错误码 0-无错误 |
| | | /** |
| | | * 权重 |
| | | */ |
| | | @Column(name = "ac_weight") |
| | | private Integer weight; |
| | | |
| | | /** |
| | | * /错误码 0-无错误 |
| | | */ |
| | | @Column(name = "ac_error_code") |
| | | private Integer errorCode; |
| | | @Column(name = "ac_error_msg") |
| | |
| | | public void setErrorMsg(String errorMsg) { |
| | | this.errorMsg = errorMsg; |
| | | } |
| | | |
| | | public Integer getWeight() { |
| | | return weight; |
| | | } |
| | | |
| | | public void setWeight(Integer weight) { |
| | | this.weight = weight; |
| | | } |
| | | } |
| | |
| | | package com.ks.lijin.pojo.DTO.taobao; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * 淘礼金报告 |
| | | */ |
| | |
| | | * fp_refund_num : 1 //退款红包个数 |
| | | */ |
| | | |
| | | private String unfreeze_amount; |
| | | private BigDecimal unfreeze_amount; |
| | | private Integer unfreeze_num; |
| | | private String refund_amount; |
| | | private BigDecimal refund_amount; |
| | | private Integer refund_num; |
| | | private String alipay_amount; |
| | | private String use_amount; |
| | | private BigDecimal alipay_amount; |
| | | private BigDecimal use_amount; |
| | | private Integer use_num; |
| | | private String win_amount; |
| | | private BigDecimal win_amount; |
| | | private Integer win_num; |
| | | private String pre_commission_amount; |
| | | private String fp_refund_amount; |
| | | private BigDecimal pre_commission_amount; |
| | | private BigDecimal fp_refund_amount; |
| | | private Integer fp_refund_num; |
| | | |
| | | public String getUnfreeze_amount() { |
| | | public BigDecimal getUnfreeze_amount() { |
| | | return unfreeze_amount; |
| | | } |
| | | |
| | | public void setUnfreeze_amount(String unfreeze_amount) { |
| | | public void setUnfreeze_amount(BigDecimal unfreeze_amount) { |
| | | this.unfreeze_amount = unfreeze_amount; |
| | | } |
| | | |
| | |
| | | this.unfreeze_num = unfreeze_num; |
| | | } |
| | | |
| | | public String getRefund_amount() { |
| | | public BigDecimal getRefund_amount() { |
| | | return refund_amount; |
| | | } |
| | | |
| | | public void setRefund_amount(String refund_amount) { |
| | | public void setRefund_amount(BigDecimal refund_amount) { |
| | | this.refund_amount = refund_amount; |
| | | } |
| | | |
| | |
| | | this.refund_num = refund_num; |
| | | } |
| | | |
| | | public String getAlipay_amount() { |
| | | public BigDecimal getAlipay_amount() { |
| | | return alipay_amount; |
| | | } |
| | | |
| | | public void setAlipay_amount(String alipay_amount) { |
| | | public void setAlipay_amount(BigDecimal alipay_amount) { |
| | | this.alipay_amount = alipay_amount; |
| | | } |
| | | |
| | | public String getUse_amount() { |
| | | public BigDecimal getUse_amount() { |
| | | return use_amount; |
| | | } |
| | | |
| | | public void setUse_amount(String use_amount) { |
| | | public void setUse_amount(BigDecimal use_amount) { |
| | | this.use_amount = use_amount; |
| | | } |
| | | |
| | |
| | | this.use_num = use_num; |
| | | } |
| | | |
| | | public String getWin_amount() { |
| | | public BigDecimal getWin_amount() { |
| | | return win_amount; |
| | | } |
| | | |
| | | public void setWin_amount(String win_amount) { |
| | | public void setWin_amount(BigDecimal win_amount) { |
| | | this.win_amount = win_amount; |
| | | } |
| | | |
| | |
| | | this.win_num = win_num; |
| | | } |
| | | |
| | | public String getPre_commission_amount() { |
| | | public BigDecimal getPre_commission_amount() { |
| | | return pre_commission_amount; |
| | | } |
| | | |
| | | public void setPre_commission_amount(String pre_commission_amount) { |
| | | public void setPre_commission_amount(BigDecimal pre_commission_amount) { |
| | | this.pre_commission_amount = pre_commission_amount; |
| | | } |
| | | |
| | | public String getFp_refund_amount() { |
| | | public BigDecimal getFp_refund_amount() { |
| | | return fp_refund_amount; |
| | | } |
| | | |
| | | public void setFp_refund_amount(String fp_refund_amount) { |
| | | public void setFp_refund_amount(BigDecimal fp_refund_amount) { |
| | | this.fp_refund_amount = fp_refund_amount; |
| | | } |
| | | |
| | |
| | | package com.ks.lijin.utils.taobao; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.ks.lijin.pojo.DO.TaoBaoOrderRecord; |
| | | import net.sf.json.JSONObject; |
| | |
| | | }.getType(); |
| | | |
| | | if (data.optJSONObject("results") != null && data.optJSONObject("results").optJSONArray("publisher_order_dto") != null) { |
| | | List<TaoBaoOrderRecord> recordList = new Gson().fromJson(data.optJSONObject("results").optJSONArray("publisher_order_dto").toString(), type); |
| | | List<TaoBaoOrderRecord> recordList = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().fromJson(data.optJSONObject("results").optJSONArray("publisher_order_dto").toString(), type); |
| | | taoBaoOrderResult.setOrderList(recordList); |
| | | } |
| | | return taoBaoOrderResult; |
| | |
| | | case "FAIL_CHECK_TLJ_MIN_FACE_ERROR": |
| | | throw new LiJinAmountException(LiJinAmountException.CODE_LIJIN_AMOUNT_OUTOFRANGE, msgInfo); |
| | | default: |
| | | throw new LiJinException(Integer.parseInt(msgCode), root.toString()); |
| | | throw new LiJinException(1, root.toString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | taolijinReport("eC2%2FoV8gigdzVO5CvuRDjDVC0SEP1L7d",new TaoKeAppInfo("27743325","527a23554f71557d7b786bc479fcd5fe")); |
| | | TaoLiJinReportDTO dto = taolijinReport("eC2%2FoV8gigdzVO5CvuRDjDVC0SEP1L7d", new TaoKeAppInfo("27743325", "527a23554f71557d7b786bc479fcd5fe")); |
| | | System.out.println(dto); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>com.yeshi</groupId> |
| | | <artifactId>utils</artifactId> |
| | | <version>0.0.4</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | |
| | | <exclusion> |
| | | <groupId>ch.qos.logback</groupId> |
| | | <artifactId>logback-core</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>ch.qos.logback</groupId> |
| | | <artifactId>logback-classic</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-httpclient</groupId> |
| | | <artifactId>commons-httpclient</artifactId> |
| | | <version>3.1</version> |
New file |
| | |
| | | package com.ks.vip.exception; |
| | | |
| | | import com.ks.lib.common.exception.BaseException; |
| | | |
| | | public class LijinBalanceException extends BaseException { |
| | | |
| | | public final static int CODE_NOT_INIT = 10001; |
| | | |
| | | public final static int CODE_BALANCE_NOT_ENOUGH = 20001; |
| | | |
| | | |
| | | public LijinBalanceException(int code, String msg) { |
| | | super(code, msg); |
| | | } |
| | | |
| | | public LijinBalanceException() { |
| | | super(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public synchronized Throwable fillInStackTrace() { |
| | | return this; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.pojo.DO; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 礼金余额 |
| | | */ |
| | | @Table("lijin_balance") |
| | | public class LijinBalance implements Serializable { |
| | | |
| | | @Id |
| | | @Column(name = "id") |
| | | private String id; |
| | | @Column(name = "balance") |
| | | private BigDecimal balance; |
| | | @Column(name = "create_time") |
| | | private Date createTime; |
| | | @Column(name = "update_time") |
| | | private Date updateTime; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public BigDecimal getBalance() { |
| | | return balance; |
| | | } |
| | | |
| | | public void setBalance(BigDecimal balance) { |
| | | this.balance = balance; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public Date getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Date updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.pojo.DO; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 礼金余额 |
| | | */ |
| | | @Document("userLijinRecord") |
| | | public class UserLijinRecord implements Serializable { |
| | | |
| | | public enum Category { |
| | | createGoodsLijin, newer |
| | | } |
| | | |
| | | /** |
| | | * 增加 |
| | | */ |
| | | public final static int TYPE_ADD = 1; |
| | | /** |
| | | * 消费 |
| | | */ |
| | | public final static int TYPE_CONSUME = 2; |
| | | |
| | | |
| | | @Id |
| | | private String id; |
| | | private String uid; |
| | | private BigDecimal money; |
| | | private Integer type; |
| | | /** |
| | | * 分类 |
| | | */ |
| | | private String category; |
| | | private String title; |
| | | private String identifyCode; |
| | | private Date createTime; |
| | | private Date updateTime; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getUid() { |
| | | return uid; |
| | | } |
| | | |
| | | public void setUid(String uid) { |
| | | this.uid = uid; |
| | | } |
| | | |
| | | public BigDecimal getMoney() { |
| | | return money; |
| | | } |
| | | |
| | | public void setMoney(BigDecimal money) { |
| | | this.money = money; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public Date getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Date updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | |
| | | public String getIdentifyCode() { |
| | | return identifyCode; |
| | | } |
| | | |
| | | public void setIdentifyCode(String identifyCode) { |
| | | this.identifyCode = identifyCode; |
| | | } |
| | | |
| | | public String getCategory() { |
| | | return category; |
| | | } |
| | | |
| | | public void setCategory(String category) { |
| | | this.category = category; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.service; |
| | | |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | public interface LijinBalanceService { |
| | | |
| | | /** |
| | | * 初始化 |
| | | * |
| | | * @param uid |
| | | */ |
| | | public void init(String uid); |
| | | |
| | | /** |
| | | * 获取余额 |
| | | * |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public BigDecimal getBalance(String uid); |
| | | |
| | | /** |
| | | * 添加礼金 |
| | | * |
| | | * @param uid |
| | | * @param money |
| | | * @param title |
| | | * @throws LijinBalanceException |
| | | */ |
| | | public void addLijin(String uid, BigDecimal money, String title, String category, String identifyCode) throws LijinBalanceException; |
| | | |
| | | /** |
| | | * 消耗礼金 |
| | | * |
| | | * @param uid |
| | | * @param money |
| | | * @param title |
| | | * @throws LijinBalanceException |
| | | */ |
| | | public void consumeLijin(String uid, BigDecimal money, String title, String category, String identifyCode) throws LijinBalanceException; |
| | | |
| | | /** |
| | | * 获取正在使用的礼金 |
| | | * |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public BigDecimal getUsingLijin(String uid); |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.vip.service; |
| | | |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 礼金记录 |
| | | */ |
| | | public interface LijinRecordService { |
| | | |
| | | |
| | | /** |
| | | * 获取礼金记录 |
| | | * |
| | | * @param uid |
| | | * @param type |
| | | * @param page |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | public List<UserLijinRecord> listRecord(String uid, Integer type, int page, int pageSize); |
| | | |
| | | /** |
| | | * 礼金记录计数 |
| | | * |
| | | * @param uid |
| | | * @param type |
| | | * @return |
| | | */ |
| | | public long countRecord(String uid, Integer type); |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @param type |
| | | * @param category |
| | | * @param identifyCode |
| | | * @return |
| | | */ |
| | | public UserLijinRecord getRecord(String uid, Integer type, String category, String identifyCode); |
| | | |
| | | } |
| | |
| | | package cccc.com.ks; |
| | | |
| | | import com.ks.vip.pojo.DO.VipOrder; |
| | | import org.junit.jupiter.api.Test; |
| | | import com.ks.lib.common.dao.MongodbBaseDao; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import org.yeshi.utils.generater.SpringComponentGenerater; |
| | | import org.yeshi.utils.generater.entity.MongoDBDaoData; |
| | | import org.yeshi.utils.generater.mybatis.MyBatisMapperUtil; |
| | | |
| | | public class MyBatisTest22 { |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | MyBatisMapperUtil.createMapper(VipOrder.class); |
| | | public static void main(String[] args) throws Exception { |
| | | // MyBatisMapperUtil.createMapper(UserLijinRecord.class); |
| | | SpringComponentGenerater.createMongoDao(new MongoDBDaoData.Builder().setEntityClass(UserLijinRecord.class).setDaoPackageName("com.ks.vip.dao").setBaseDaoClass(MongodbBaseDao.class).create(), "D:\\项目\\返利券\\特价\\tejia\\service-vip\\src\\main\\java\\com\\ks\\vip\\dao\\"); |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | </dependency> |
| | | |
| | | <!--<dependency>--> |
| | | <!--<groupId>org.freemarker</groupId>--> |
| | | <!--<artifactId>freemarker</artifactId>--> |
| | | <!--<version>2.3.23</version>--> |
| | | <!--</dependency>--> |
| | | |
| | | <dependency> |
| | | <groupId>com.yeshi</groupId> |
| | | <artifactId>utils</artifactId> |
| | | <version>0.0.8</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.slf4j</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | |
| | | <exclusion> |
| | | <groupId>ch.qos.logback</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-io</groupId> |
| | | <artifactId>commons-io</artifactId> |
| | | <version>2.4</version> |
| | | </dependency> |
| | | |
| | | |
| | | <!--安全框架 --> |
| | | <!-- <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | |
| | | @Resource |
| | | private LiJinProviderAccountService liJinProviderAccountService; |
| | | |
| | | |
| | | /** |
| | | * 保存最近2分钟的淘宝订单数据 |
| | | * |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @XxlJob("lijin-order-syncLijinData") |
| | | public ReturnT<String> syncLijinData(String param) throws Exception { |
| | | |
| | | |
| | | |
| | | @XxlJob("lijin-order-syncLijinReportData") |
| | | public ReturnT<String> syncLijinReportData(String param) throws Exception { |
| | | lijinOrderManager.syncOnGoingLijin(); |
| | | return ReturnT.SUCCESS; |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 获取正在进行中的礼金 |
| | | * |
| | | * @param minCreateTime |
| | | * @param maxCreateTime |
| | | * @param start |
| | |
| | | */ |
| | | List<LiJinExpendRecord> listOnGoingLijin(@Param("minCreateTime") Date minCreateTime, @Param("maxCreateTime") Date maxCreateTime, @Param("start") int start, @Param("count") int count); |
| | | |
| | | |
| | | /** |
| | | * 获取正在进行中的礼金数量 |
| | | * |
| | | * @param minCreateTime |
| | | * @param maxCreateTime |
| | | * @return |
| | | */ |
| | | long countOnGoingLijin(@Param("minCreateTime") Date minCreateTime, @Param("maxCreateTime") Date maxCreateTime); |
| | | |
| | | } |
| | |
| | | public class LijinGoodsManager { |
| | | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | Logger logger = LoggerFactory.getLogger(LijinGoodsManager.class); |
| | | |
| | |
| | | String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"); |
| | | String key = String.format("lijingoodslimit-%s-%s", day, auctionId); |
| | | logger.info("key值为:" + key); |
| | | Boolean hasKey = redisTemplate.hasKey(key); |
| | | logger.info("hasKey:" + hasKey); |
| | | if (hasKey == null || !hasKey) { |
| | | Object object = redisTemplate.opsForValue().get(key); |
| | | if (object == null) { |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | package com.ks.lijin.service.manager; |
| | | |
| | | import com.ks.lijin.dao.TaoBaoOrderRecordDao; |
| | | import com.ks.lijin.mapper.LiJinExpendRecordMapper; |
| | | import com.ks.lijin.mapper.LiJinProviderAccountMapper; |
| | | import com.ks.lijin.pojo.DO.LiJinExpendRecord; |
| | | import com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount; |
| | | import com.ks.lijin.pojo.DO.TaoBaoOrderRecord; |
| | | import com.ks.lijin.pojo.DTO.taobao.TaoKeAppInfo; |
| | | import com.ks.lijin.pojo.DTO.taobao.TaoLiJinReportDTO; |
| | | import com.ks.lijin.service.LiJinProviderAccountService; |
| | | import com.ks.lijin.utils.taobao.TaoKeApiUtil; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.service.LijinBalanceService; |
| | | import com.ks.vip.service.LijinRecordService; |
| | | import org.apache.dubbo.config.annotation.Reference; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 礼金订单管理 |
| | |
| | | |
| | | @Resource |
| | | private LijinDangerGoodsManager lijinDangerGoodsManager; |
| | | |
| | | @Resource |
| | | private LiJinExpendRecordMapper liJinExpendRecordMapper; |
| | | |
| | | @Resource |
| | | private LiJinProviderAccountMapper liJinProviderAccountMapper; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinBalanceService lijinBalanceService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinRecordService lijinRecordService; |
| | | |
| | | /** |
| | | * 保存淘宝订单 |
| | |
| | | } |
| | | |
| | | |
| | | public void syncOnGoingLijin() { |
| | | long now = System.currentTimeMillis(); |
| | | Date maxCreateTime = new Date(now - 1000 * 60 * 2); |
| | | Date minCreateTime = new Date(maxCreateTime.getTime() - 1000 * 60 * 60 * 24L); |
| | | long count = liJinExpendRecordMapper.countOnGoingLijin(minCreateTime, maxCreateTime); |
| | | int page = (int) (count % 100 == 0 ? count / 100 : count / 100 + 1); |
| | | for (int i = 0; i < page; i++) { |
| | | List<LiJinExpendRecord> recordList = liJinExpendRecordMapper.listOnGoingLijin(minCreateTime, maxCreateTime, 100 * i, 100); |
| | | if (recordList != null) { |
| | | for (LiJinExpendRecord record : recordList) { |
| | | LiJinProviderTaoKeAccount account = liJinProviderAccountMapper.selectByPrimaryKey(record.getAccountId()); |
| | | TaoLiJinReportDTO reportDTO = TaoKeApiUtil.taolijinReport(record.getRightsId(), new TaoKeAppInfo(account.getAppKey(), account.getAppSecret(), account.getPid())); |
| | | if (reportDTO != null) { |
| | | //有数据 |
| | | if (reportDTO.getFp_refund_num() != null || reportDTO.getRefund_num() != null || reportDTO.getUnfreeze_num() != null || reportDTO.getUse_num() != null || reportDTO.getWin_num() != null) { |
| | | LiJinExpendRecord update = new LiJinExpendRecord(record.getId()); |
| | | update.setRefundAmount(reportDTO.getRefund_amount()); |
| | | update.setRefundNum(reportDTO.getRefund_num()); |
| | | update.setUnfreezeAmount(reportDTO.getUnfreeze_amount()); |
| | | update.setUnfreezeNum(reportDTO.getUnfreeze_num()); |
| | | update.setUseAmount(reportDTO.getUse_amount()); |
| | | update.setUseNum(reportDTO.getUse_num()); |
| | | update.setWinAmount(reportDTO.getUse_amount()); |
| | | update.setWinNum(reportDTO.getWin_num()); |
| | | update.setUpdateTime(new Date()); |
| | | update.setPreCommissionAmount(reportDTO.getPre_commission_amount()); |
| | | liJinExpendRecordMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | //判断是否为当天创建 |
| | | if (!TimeUtil.getGernalTime(now, "yyyyMMdd").equalsIgnoreCase(TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyyMMdd"))) { |
| | | //不是当天创建的,而且没有使用 |
| | | if (reportDTO.getUse_num() == null || reportDTO.getUse_num() == 0) { |
| | | UserLijinRecord record1 = lijinRecordService.getRecord(record.getUid(), UserLijinRecord.TYPE_ADD, UserLijinRecord.Category.createGoodsLijin.name(), record.getId() + ""); |
| | | if (record1 != null) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | lijinBalanceService.addLijin(record.getUid(), record.getMoney(), "未抵退回", UserLijinRecord.Category.createGoodsLijin.name(), record.getId() + ""); |
| | | } catch (LijinBalanceException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | @Service(version = "1.0") |
| | |
| | | query.start = 0; |
| | | query.count = 1000; |
| | | query.errorCode = errorCode; |
| | | query.sortList= Arrays.asList(new String[]{"ac_weight desc","ac_id asc"}); |
| | | return liJinProviderAccountMapper.listByPage(query); |
| | | } |
| | | |
| | |
| | | import com.ks.lijin.util.Constant; |
| | | import com.ks.lijin.utils.taobao.TaoBaoUtil; |
| | | import com.ks.lijin.utils.taobao.TaoKeApiUtil; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.pojo.DO.VipGradePotence; |
| | | import com.ks.vip.pojo.Enums.VIPEnum; |
| | | import com.ks.vip.service.LijinBalanceService; |
| | | import com.ks.vip.service.VipCenterService; |
| | | import com.ks.vip.service.VipGradePotenceService; |
| | | import com.ks.vip.service.VipGradeService; |
| | |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private VipGradeService vipGradeService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinBalanceService lijinBalanceService; |
| | | |
| | | @Resource |
| | | private LiJinExpendRecordService liJinExpendRecordService; |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 每日最大次数判断 |
| | | Integer numMax = potence.getTaolijinMaxNumber(); |
| | | if (numMax == null || numMax.intValue() <= 0) { |
| | |
| | | if (potence == null) { |
| | | return false; |
| | | } |
| | | //查询礼金余额 |
| | | BigDecimal balance = lijinBalanceService.getBalance(uid); |
| | | if (balance != null) { |
| | | if (money.compareTo(balance) > 0) { |
| | | throw new LiJinUserException(LiJinUserException.CODE_USER_BALANCE_NOT_ENOUGH, "礼金余额不足"); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 每日最大次数判断 |
| | | Integer numMax = potence.getTaolijinMaxNumber(); |
| | |
| | | // 创建的淘礼金-金额 |
| | | BigDecimal lijinAmount = getTBLijinAmount(goods, vipRank); |
| | | |
| | | //查询礼金余额 |
| | | BigDecimal balance = lijinBalanceService.getBalance(uid); |
| | | if (balance != null && lijinAmount != null) { |
| | | if (lijinAmount.compareTo(balance) > 0) { |
| | | throw new LiJinUserException(LiJinUserException.CODE_USER_BALANCE_NOT_ENOUGH, "礼金余额不足"); |
| | | } |
| | | } |
| | | |
| | | // 执行创建淘礼金 |
| | | LiJinCreateParam params = getLiJinCreateBaseParam(); |
| | | |
| | |
| | | liJinExpendRecordMapper.insertSelective(record); |
| | | //添加 |
| | | liJinProviderTaoKeAccountManager.createLijinSuccess(taoLiJinDTO.getAccount().getId(), goodsId, lijinAmount.multiply(new BigDecimal(num)), now); |
| | | //礼金余额扣除 |
| | | try { |
| | | lijinBalanceService.consumeLijin(uid, lijinAmount, "购物抵现", UserLijinRecord.Category.createGoodsLijin.name(), record.getId()+""); |
| | | } catch (LijinBalanceException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return record; |
| | | } |
| | | |
| | |
| | | <include refid="Base_Column_List"/> |
| | | from tlj_expend_record |
| | | where (rd_win_num=0 || rd_win_num IS NULL || rd_use_num=0 || rd_use_num IS NULL) AND (rd_refund_num=0 || |
| | | rd_refund_num IS NULL) AND (rd_fp_refund_num=0||rd_fp_refund_num IS NULL) |
| | | rd_refund_num IS NULL) |
| | | <if test="minCreateTime!=null"> |
| | | AND rd_create_time>=#{minCreateTime} |
| | | </if> |
| | |
| | | limit #{start},#{count} |
| | | </select> |
| | | |
| | | |
| | | <select id="countOnGoingLijin" resultType="java.lang.Long"> |
| | | select count(*) from tlj_expend_record |
| | | where (rd_win_num=0 || rd_win_num IS NULL || rd_use_num=0 || rd_use_num IS NULL) AND (rd_refund_num=0 || |
| | | rd_refund_num IS NULL) |
| | | <if test="minCreateTime!=null"> |
| | | AND rd_create_time>=#{minCreateTime} |
| | | </if> |
| | | <if test="maxCreateTime!=null"> |
| | | AND #{maxCreateTime}>rd_create_time |
| | | </if> |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | <result column="ac_update_time" property="updateTime" jdbcType="TIMESTAMP"/> |
| | | <result column="ac_error_code" property="errorCode" jdbcType="INTEGER"/> |
| | | <result column="ac_error_msg" property="errorMsg" jdbcType="VARCHAR"/> |
| | | <result column="ac_weight" property="weight" jdbcType="INTEGER"/> |
| | | </resultMap> |
| | | <sql id="Base_Column_List">ac_id,ac_provider_id,ac_account_name,ac_app_key,ac_app_secret,ac_pid,ac_max_money,ac_max_number,ac_today_consume_money,ac_today_consume_number,ac_state,ac_creator_id,ac_create_time,ac_updator_id,ac_update_time,ac_error_code,ac_error_msg</sql> |
| | | <sql id="Base_Column_List">ac_id,ac_provider_id,ac_account_name,ac_app_key,ac_app_secret,ac_pid,ac_max_money,ac_max_number,ac_today_consume_money,ac_today_consume_number,ac_state,ac_creator_id,ac_create_time,ac_updator_id,ac_update_time,ac_error_code,ac_error_msg,ac_weight</sql> |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select |
| | | <include refid="Base_Column_List"/>from tlj_provider_account where ac_id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | |
| | | <delete id="deleteByPrimaryKey" |
| | | parameterType="java.lang.Long">delete from tlj_provider_account where ac_id = #{id,jdbcType=BIGINT}</delete> |
| | | <insert id="insert" parameterType="com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount" useGeneratedKeys="true" |
| | | keyProperty="id">insert into tlj_provider_account (ac_id, ac_provider_id, ac_account_name, ac_app_key, ac_app_secret,ac_pid, ac_max_money, ac_max_number, ac_today_consume_money, ac_today_consume_number, ac_state, ac_creator_id, ac_create_time, ac_updator_id, ac_update_time,ac_error_code,ac_error_msg) values (#{id,jdbcType=BIGINT}, #{providerId,jdbcType=BIGINT}, #{accountName,jdbcType=VARCHAR}, #{appKey,jdbcType=VARCHAR}, #{appSecret,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{maxMoney,jdbcType=DECIMAL}, #{maxNumber,jdbcType=INTEGER}, #{todayConsumeMoney,jdbcType=DECIMAL}, #{todayConsumeNumber,jdbcType=INTEGER}, #{state,jdbcType=INTEGER}, #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updatorId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP},#{errorCode,jdbcType=INTEGER},#{errorMsg,jdbcType=VARCHAR})</insert> |
| | | keyProperty="id">insert into tlj_provider_account (ac_id, ac_provider_id, ac_account_name, ac_app_key, ac_app_secret,ac_pid, ac_max_money, ac_max_number, ac_today_consume_money, ac_today_consume_number, ac_state, ac_creator_id, ac_create_time, ac_updator_id, ac_update_time,ac_error_code,ac_error_msg,ac_weight) values (#{id,jdbcType=BIGINT}, #{providerId,jdbcType=BIGINT}, #{accountName,jdbcType=VARCHAR}, #{appKey,jdbcType=VARCHAR}, #{appSecret,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{maxMoney,jdbcType=DECIMAL}, #{maxNumber,jdbcType=INTEGER}, #{todayConsumeMoney,jdbcType=DECIMAL}, #{todayConsumeNumber,jdbcType=INTEGER}, #{state,jdbcType=INTEGER}, #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updatorId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP},#{errorCode,jdbcType=INTEGER},#{errorMsg,jdbcType=VARCHAR},#{weight,jdbcType=INTEGER})</insert> |
| | | <insert id="insertSelective" parameterType="com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount" useGeneratedKeys="true" |
| | | keyProperty="id">insert into tlj_provider_account |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | |
| | | <if test="updateTime != null">ac_update_time,</if> |
| | | <if test="errorCode != null">ac_error_code,</if> |
| | | <if test="errorMsg != null">ac_error_msg,</if> |
| | | <if test="weight != null">ac_weight,</if> |
| | | </trim> |
| | | values |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | |
| | | <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | <if test="errorCode != null">#{errorCode,jdbcType=INTEGER},</if> |
| | | <if test="errorMsg != null">#{errorMsg,jdbcType=VARCHAR},</if> |
| | | <if test="weight != null">#{weight,jdbcType=INTEGER}</if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKey" |
| | | parameterType="com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount">update tlj_provider_account set ac_provider_id = #{providerId,jdbcType=BIGINT},ac_account_name = #{accountName,jdbcType=VARCHAR},ac_app_key = #{appKey,jdbcType=VARCHAR},ac_app_secret = #{appSecret,jdbcType=VARCHAR},ac_pid = #{pid,jdbcType=VARCHAR},ac_max_money = #{maxMoney,jdbcType=DECIMAL},ac_max_number = #{maxNumber,jdbcType=INTEGER},ac_today_consume_money = #{todayConsumeMoney,jdbcType=DECIMAL},ac_today_consume_number = #{todayConsumeNumber,jdbcType=INTEGER},ac_state = #{state,jdbcType=INTEGER},ac_creator_id = #{creatorId,jdbcType=BIGINT},ac_create_time = #{createTime,jdbcType=TIMESTAMP},ac_updator_id = #{updatorId,jdbcType=BIGINT},ac_update_time = #{updateTime,jdbcType=TIMESTAMP},ac_error_code =#{errorCode,jdbcType=INTEGER} ,ac_error_msg =#{errorMsg,jdbcType=VARCHAR} where ac_id = #{id,jdbcType=BIGINT}</update> |
| | | parameterType="com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount">update tlj_provider_account set ac_provider_id = #{providerId,jdbcType=BIGINT},ac_account_name = #{accountName,jdbcType=VARCHAR},ac_app_key = #{appKey,jdbcType=VARCHAR},ac_app_secret = #{appSecret,jdbcType=VARCHAR},ac_pid = #{pid,jdbcType=VARCHAR},ac_max_money = #{maxMoney,jdbcType=DECIMAL},ac_max_number = #{maxNumber,jdbcType=INTEGER},ac_today_consume_money = #{todayConsumeMoney,jdbcType=DECIMAL},ac_today_consume_number = #{todayConsumeNumber,jdbcType=INTEGER},ac_state = #{state,jdbcType=INTEGER},ac_creator_id = #{creatorId,jdbcType=BIGINT},ac_create_time = #{createTime,jdbcType=TIMESTAMP},ac_updator_id = #{updatorId,jdbcType=BIGINT},ac_update_time = #{updateTime,jdbcType=TIMESTAMP},ac_error_code =#{errorCode,jdbcType=INTEGER} ,ac_error_msg =#{errorMsg,jdbcType=VARCHAR} ,ac_weight =#{weight,jdbcType=INTEGER} where ac_id = #{id,jdbcType=BIGINT}</update> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount">update |
| | | tlj_provider_account |
| | | <set> |
| | |
| | | <if test="updateTime != null">ac_update_time=#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | <if test="errorCode !=null">ac_error_code =#{errorCode,jdbcType=INTEGER},</if> |
| | | <if test="errorMsg !=null">ac_error_msg =#{errorMsg,jdbcType=VARCHAR},</if> |
| | | <if test="weight !=null">ac_weight =#{weight,jdbcType=INTEGER},</if> |
| | | </set> |
| | | where ac_id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | |
| | | <include refid="Base_Column_List"/> |
| | | from tlj_provider_account where 1=1 |
| | | <include refid="listWhere"/> |
| | | <if test="query.sortList!=null"> |
| | | <foreach collection="query.sortList" item="item" open=" order by " separator=",">${item}</foreach> |
| | | </if> |
| | | limit #{query.start},#{query.count} |
| | | </select> |
| | | <select id="count" resultType="java.lang.Long">select count(*) from tlj_provider_account where 1=1 |
| | |
| | | import com.ks.lijin.LiJinApplication; |
| | | import com.ks.lijin.dao.LijinConfigDao; |
| | | import com.ks.lijin.job.LijinOrderJob; |
| | | import com.ks.lijin.pojo.DO.LiJinProviderTaoKeAccount; |
| | | import com.ks.lijin.pojo.DO.LijinConfig; |
| | | import com.ks.lijin.service.LiJinProviderAccountService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | |
| | | @Resource |
| | | private LijinConfigDao lijinConfigDao; |
| | | @Resource |
| | | private LiJinProviderAccountService liJinProviderAccountService; |
| | | |
| | | @Test |
| | | public void test() { |
| | |
| | | System.out.println(hasKey); |
| | | } |
| | | |
| | | @Test |
| | | public void syncLijinReportData() throws Exception { |
| | | lijinOrderJob.syncLijinReportData(""); |
| | | } |
| | | |
| | | @Test |
| | | public void getTaoKeAccount() { |
| | | List<LiJinProviderTaoKeAccount> list = liJinProviderAccountService.listValidByProviderId(1L, null); |
| | | System.out.println(list); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <dependency> |
| | | <groupId>com.ks</groupId> |
| | | <artifactId>facade-vip</artifactId> |
New file |
| | |
| | | package com.ks.vip.dao; |
| | | |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.Date; |
| | | |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.lib.common.dao.MongodbBaseDao; |
| | | |
| | | import java.lang.String; |
| | | import java.lang.Integer; |
| | | import java.util.ArrayList; |
| | | |
| | | |
| | | @Repository |
| | | public class UserLijinRecordDao extends MongodbBaseDao<UserLijinRecord> { |
| | | |
| | | public void updateSelective(UserLijinRecord bean) { |
| | | Query query = new Query(); |
| | | Update update = new Update(); |
| | | query.addCriteria(Criteria.where("id").is(bean.getId())); |
| | | if (bean.getUid() != null) { |
| | | update.set("uid", bean.getUid()); |
| | | } |
| | | if (bean.getMoney() != null) { |
| | | update.set("money", bean.getMoney()); |
| | | } |
| | | if (bean.getType() != null) { |
| | | update.set("type", bean.getType()); |
| | | } |
| | | |
| | | if (bean.getCategory() != null) { |
| | | update.set("category", bean.getCategory()); |
| | | } |
| | | |
| | | if (bean.getTitle() != null) { |
| | | update.set("title", bean.getTitle()); |
| | | } |
| | | if (bean.getCreateTime() != null) { |
| | | update.set("createTime", bean.getCreateTime()); |
| | | } |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | } |
| | | |
| | | |
| | | public List<UserLijinRecord> list(DaoQuery daoQuery) { |
| | | Query query = getQuery(daoQuery); |
| | | if (daoQuery.sortList != null && daoQuery.sortList.size() > 0) { |
| | | query.with(Sort.by(daoQuery.sortList)); |
| | | } |
| | | query.skip(daoQuery.start); |
| | | query.limit(daoQuery.count); |
| | | return findList(query); |
| | | } |
| | | |
| | | public long count(DaoQuery daoQuery) { |
| | | Query query = getQuery(daoQuery); |
| | | return count(query); |
| | | } |
| | | |
| | | private Query getQuery(DaoQuery daoQuery) { |
| | | List<Criteria> andList = new ArrayList<>(); |
| | | if (daoQuery.uid != null) { |
| | | andList.add(Criteria.where("uid").is(daoQuery.uid)); |
| | | } |
| | | if (daoQuery.money != null) { |
| | | andList.add(Criteria.where("money").is(daoQuery.money)); |
| | | } |
| | | if (daoQuery.type != null) { |
| | | andList.add(Criteria.where("type").is(daoQuery.type)); |
| | | } |
| | | |
| | | if (daoQuery.category != null) { |
| | | andList.add(Criteria.where("category").is(daoQuery.category)); |
| | | } |
| | | |
| | | |
| | | if (daoQuery.title != null) { |
| | | andList.add(Criteria.where("title").is(daoQuery.title)); |
| | | } |
| | | if (daoQuery.identifyCode != null) { |
| | | andList.add(Criteria.where("identifyCode").is(daoQuery.identifyCode)); |
| | | } |
| | | if (daoQuery.minCreateTime != null) { |
| | | andList.add(Criteria.where("createTime").gte(daoQuery.minCreateTime)); |
| | | } |
| | | if (daoQuery.maxCreateTime != null) { |
| | | andList.add(Criteria.where("createTime").lt(daoQuery.maxCreateTime)); |
| | | } |
| | | Query query = new Query(); |
| | | Criteria[] ands = new Criteria[andList.size()]; |
| | | andList.toArray(ands); |
| | | if (ands.length > 0) { |
| | | query.addCriteria(new Criteria().andOperator(ands)); |
| | | } |
| | | return query; |
| | | } |
| | | |
| | | public static class DaoQuery { |
| | | public String uid; |
| | | public BigDecimal money; |
| | | public Integer type; |
| | | public String category; |
| | | public String title; |
| | | public String identifyCode; |
| | | public Date minCreateTime; |
| | | public Date maxCreateTime; |
| | | public int start; |
| | | public int count; |
| | | public List<Sort.Order> sortList; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.mapper; |
| | | |
| | | import com.ks.vip.pojo.DO.LijinBalance; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public interface LijinBalanceMapper { |
| | | |
| | | int deleteByPrimaryKey(String id); |
| | | |
| | | int insert(LijinBalance balance); |
| | | |
| | | int insertSelective(LijinBalance balance); |
| | | |
| | | LijinBalance selectByPrimaryKey(String id); |
| | | |
| | | int updateByPrimaryKeySelective(LijinBalance balance); |
| | | |
| | | int updateByPrimaryKey(LijinBalance balance); |
| | | |
| | | |
| | | LijinBalance selectByPrimaryKeyForUpdate(@Param("id") String id); |
| | | |
| | | List<LijinBalance> list(@Param("query") DaoQuery query); |
| | | |
| | | long count(@Param("query") DaoQuery query); |
| | | |
| | | public static class DaoQuery { |
| | | public String id; |
| | | public BigDecimal balance; |
| | | public Date minCreateTime; |
| | | public Date maxCreateTime; |
| | | public Date minUpdateTime; |
| | | public Date maxUpdateTime; |
| | | public long start; |
| | | public int count; |
| | | public List<String> sortList; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.service.remote; |
| | | |
| | | import com.ks.vip.dao.UserLijinRecordDao; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.mapper.LijinBalanceMapper; |
| | | import com.ks.vip.pojo.DO.LijinBalance; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.service.LijinBalanceService; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Service(version = "1.0") |
| | | public class LijinBalanceServiceImpl implements LijinBalanceService { |
| | | |
| | | @Resource |
| | | private LijinBalanceMapper lijinBalanceMapper; |
| | | |
| | | @Resource |
| | | private UserLijinRecordDao userLijinRecordDao; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void init(String uid) { |
| | | LijinBalance balance = lijinBalanceMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (balance != null) { |
| | | return; |
| | | } |
| | | balance = new LijinBalance(); |
| | | balance.setBalance(new BigDecimal(0)); |
| | | balance.setCreateTime(new Date()); |
| | | balance.setId(uid); |
| | | lijinBalanceMapper.insertSelective(balance); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public BigDecimal getBalance(String uid) { |
| | | LijinBalance balance = lijinBalanceMapper.selectByPrimaryKey(uid); |
| | | if (balance == null) { |
| | | return null; |
| | | } |
| | | return balance.getBalance(); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void addLijin(String uid, BigDecimal money, String title, String category, String identifyCode) throws LijinBalanceException { |
| | | //添加记录 |
| | | LijinBalance lijinBalance = lijinBalanceMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (lijinBalance == null) { |
| | | throw new LijinBalanceException(LijinBalanceException.CODE_NOT_INIT, "余额未初始化"); |
| | | } |
| | | //增加余额 |
| | | LijinBalance update = new LijinBalance(); |
| | | update.setId(uid); |
| | | update.setBalance(lijinBalance.getBalance().add(money)); |
| | | update.setUpdateTime(new Date()); |
| | | lijinBalanceMapper.updateByPrimaryKeySelective(update); |
| | | //增加记录 |
| | | UserLijinRecord record = new UserLijinRecord(); |
| | | record.setMoney(money); |
| | | record.setId(uid + "-" + UUID.randomUUID().toString()); |
| | | record.setTitle(title); |
| | | record.setType(UserLijinRecord.TYPE_ADD); |
| | | record.setUid(uid); |
| | | record.setCategory(category); |
| | | record.setCreateTime(new Date()); |
| | | record.setIdentifyCode(identifyCode); |
| | | userLijinRecordDao.save(record); |
| | | } |
| | | |
| | | @Override |
| | | public void consumeLijin(String uid, BigDecimal money, String title, String category, String identifyCode) throws LijinBalanceException { |
| | | //添加记录 |
| | | LijinBalance lijinBalance = lijinBalanceMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (lijinBalance == null) { |
| | | throw new LijinBalanceException(LijinBalanceException.CODE_NOT_INIT, "余额未初始化"); |
| | | } |
| | | if (lijinBalance.getBalance().compareTo(money) < 0) { |
| | | throw new LijinBalanceException(LijinBalanceException.CODE_BALANCE_NOT_ENOUGH, "礼金余额不足"); |
| | | } |
| | | |
| | | |
| | | //增加余额 |
| | | LijinBalance update = new LijinBalance(); |
| | | update.setId(uid); |
| | | update.setBalance(lijinBalance.getBalance().subtract(money)); |
| | | update.setUpdateTime(new Date()); |
| | | lijinBalanceMapper.updateByPrimaryKeySelective(update); |
| | | //增加记录 |
| | | UserLijinRecord record = new UserLijinRecord(); |
| | | record.setMoney(money); |
| | | record.setId(uid + "-" + UUID.randomUUID().toString()); |
| | | record.setTitle(title); |
| | | record.setType(UserLijinRecord.TYPE_CONSUME); |
| | | record.setUid(uid); |
| | | record.setCategory(category); |
| | | record.setCreateTime(new Date()); |
| | | record.setIdentifyCode(identifyCode); |
| | | userLijinRecordDao.save(record); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getUsingLijin(String uid) { |
| | | UserLijinRecordDao.DaoQuery daoQuery = new UserLijinRecordDao.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.type = UserLijinRecord.TYPE_CONSUME; |
| | | daoQuery.category = UserLijinRecord.Category.createGoodsLijin.name(); |
| | | daoQuery.count = 100; |
| | | daoQuery.maxCreateTime = new Date(); |
| | | daoQuery.minCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(daoQuery.minCreateTime.getTime(), "yyyyMMdd"), "yyyyMMdd")); |
| | | List<UserLijinRecord> list = userLijinRecordDao.list(daoQuery); |
| | | BigDecimal using = new BigDecimal(0); |
| | | if (list != null) { |
| | | for (UserLijinRecord record : list) { |
| | | using = using.add(record.getMoney()); |
| | | } |
| | | } |
| | | return using; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.vip.service.remote; |
| | | |
| | | import com.ks.vip.dao.UserLijinRecordDao; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.service.LijinRecordService; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.data.domain.Sort; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service(version = "1.0") |
| | | public class LijinRecordServiceImpl implements LijinRecordService { |
| | | |
| | | @Resource |
| | | private UserLijinRecordDao userLijinRecordDao; |
| | | |
| | | @Override |
| | | public List<UserLijinRecord> listRecord(String uid, Integer type, int page, int pageSize) { |
| | | UserLijinRecordDao.DaoQuery daoQuery = new UserLijinRecordDao.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.type = type; |
| | | daoQuery.start = (page - 1) * pageSize; |
| | | daoQuery.count = pageSize; |
| | | daoQuery.sortList = Arrays.asList(new Sort.Order[]{new Sort.Order(Sort.Direction.DESC, "createTime")}); |
| | | return userLijinRecordDao.list(daoQuery); |
| | | } |
| | | |
| | | @Override |
| | | public long countRecord(String uid, Integer type) { |
| | | UserLijinRecordDao.DaoQuery daoQuery = new UserLijinRecordDao.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.type = type; |
| | | return userLijinRecordDao.count(daoQuery); |
| | | } |
| | | |
| | | @Override |
| | | public UserLijinRecord getRecord(String uid, Integer type, String category, String identifyCode) { |
| | | |
| | | UserLijinRecordDao.DaoQuery daoQuery = new UserLijinRecordDao.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.type = type; |
| | | daoQuery.identifyCode = identifyCode; |
| | | daoQuery.category = category; |
| | | daoQuery.start = 0; |
| | | daoQuery.count = 1; |
| | | daoQuery.sortList = Arrays.asList(new Sort.Order[]{new Sort.Order(Sort.Direction.DESC, "createTime")}); |
| | | List<UserLijinRecord> list = userLijinRecordDao.list(daoQuery); |
| | | if (list == null || list.size() == 0) { |
| | | return null; |
| | | } |
| | | return list.get(0); |
| | | } |
| | | } |
| | |
| | | vipOrderQuery.maxCreateTime = DateUtil.plusDayDate(1, vipOrderQuery.minCreateTime); |
| | | long count = vipOrderMapper.count(vipOrderQuery); |
| | | //TODO 写入配置信息 |
| | | return count < 5; |
| | | return count < 3; |
| | | } |
| | | |
| | | @Override |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | |
| | | <mapper namespace="com.ks.vip.mapper.LijinBalanceMapper"> |
| | | <resultMap id="BaseResultMap" type="com.ks.vip.pojo.DO.LijinBalance"> |
| | | <id column="id" property="id" jdbcType="VARCHAR"/> |
| | | <result column="balance" property="balance" jdbcType="DECIMAL"/> |
| | | <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> |
| | | <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/> |
| | | </resultMap> |
| | | <sql id="Base_Column_List">id,balance,create_time,update_time</sql> |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">select |
| | | <include refid="Base_Column_List"/> |
| | | from lijin_balance where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap" parameterType="java.lang.String">select |
| | | <include refid="Base_Column_List"/> |
| | | from lijin_balance where id = #{id,jdbcType=BIGINT} for update |
| | | </select> |
| | | |
| | | <sql id="listWhereSQL"> |
| | | <if test="query.id!=null">AND id = #{query.id}</if> |
| | | <if test="query.balance!=null">AND balance = #{query.balance}</if> |
| | | <if test="query.minCreateTime!=null">AND create_time >= #{query.minCreateTime}</if> |
| | | <if test="query.maxCreateTime!=null">AND #{query.maxCreateTime} > create_time</if> |
| | | <if test="query.minUpdateTime!=null">AND update_time >= #{query.minUpdateTime}</if> |
| | | <if test="query.maxUpdateTime!=null">AND #{query.maxUpdateTime} > update_time</if> |
| | | </sql> |
| | | <select id="list" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from lijin_balance where 1=1 |
| | | <include refid="listWhereSQL"/> |
| | | <if test="query.sortList!=null"> |
| | | <foreach collection="query.sortList" item="item" open=" order by " separator=",">#{item}</foreach> |
| | | </if> |
| | | limit #{query.start},#{query.count} |
| | | </select> |
| | | <select id="count" resultType="java.lang.Long"> |
| | | select count(*) from lijin_balance where 1=1 |
| | | <include refid="listWhereSQL"/> |
| | | </select> |
| | | <delete id="deleteByPrimaryKey" |
| | | parameterType="java.lang.Long">delete from lijin_balance where id = #{id,jdbcType=BIGINT}</delete> |
| | | <insert id="insert" parameterType="com.ks.vip.pojo.DO.LijinBalance" useGeneratedKeys="true" |
| | | keyProperty="id">insert into lijin_balance (id,balance,create_time,update_time) values (#{id,jdbcType=VARCHAR},#{balance,jdbcType=DECIMAL},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert> |
| | | <insert id="insertSelective" parameterType="com.ks.vip.pojo.DO.LijinBalance" useGeneratedKeys="true" |
| | | keyProperty="id">insert into lijin_balance |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">id,</if> |
| | | <if test="balance != null">balance,</if> |
| | | <if test="createTime != null">create_time,</if> |
| | | <if test="updateTime != null">update_time,</if> |
| | | </trim> |
| | | values |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">#{id,jdbcType=VARCHAR},</if> |
| | | <if test="balance != null">#{balance,jdbcType=DECIMAL},</if> |
| | | <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if> |
| | | <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKey" |
| | | parameterType="com.ks.vip.pojo.DO.LijinBalance">update lijin_balance set balance = #{balance,jdbcType=DECIMAL},create_time = #{createTime,jdbcType=TIMESTAMP},update_time = #{updateTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=VARCHAR}</update> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.ks.vip.pojo.DO.LijinBalance">update lijin_balance |
| | | <set> |
| | | <if test="balance != null">balance=#{balance,jdbcType=DECIMAL},</if> |
| | | <if test="createTime != null">create_time=#{createTime,jdbcType=TIMESTAMP},</if> |
| | | <if test="updateTime != null">update_time=#{updateTime,jdbcType=TIMESTAMP},</if> |
| | | </set> |
| | | where id = #{id,jdbcType=VARCHAR} |
| | | </update> |
| | | </mapper> |
New file |
| | |
| | | package com.ks; |
| | | |
| | | import com.ks.vip.VIPApplication; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.mapper.LijinBalanceMapper; |
| | | import com.ks.vip.pojo.DO.LijinBalance; |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.service.LijinBalanceService; |
| | | import com.ks.vip.service.LijinRecordService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @SpringBootTest(classes = VIPApplication.class) |
| | | public class LijinTest { |
| | | @Resource |
| | | private LijinBalanceService lijinBalanceService; |
| | | |
| | | @Resource |
| | | private LijinRecordService lijinRecordService; |
| | | |
| | | @Test |
| | | public void addBalance() { |
| | | try { |
| | | lijinBalanceService.addLijin("tejia-123123", new BigDecimal("60"), "新人赠送", "", ""); |
| | | } catch (LijinBalanceException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void subBalance() { |
| | | try { |
| | | lijinBalanceService.consumeLijin("tejia-123123", new BigDecimal("59.36"), "消耗礼金", "", ""); |
| | | } catch (LijinBalanceException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void getBanlance() { |
| | | BigDecimal bigDecimal = lijinBalanceService.getBalance("tejia-123123"); |
| | | System.out.println("余额:" + bigDecimal); |
| | | } |
| | | |
| | | @Test |
| | | public void getRecord() { |
| | | List<UserLijinRecord> list = lijinRecordService.listRecord("tejia-123123", 1, 1, 10); |
| | | long count = lijinRecordService.countRecord("tejia-123123", 1); |
| | | System.out.println("数量:" + count); |
| | | } |
| | | } |
| | |
| | | public void test(){ |
| | | // MyBatisMapperUtil.createMapper(LiJinGoofsDepotFirstOrder.class); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.ks.test.dao; |
| | | |
| | | import com.ks.vip.VIPApplication; |
| | | import com.ks.vip.mapper.LijinBalanceMapper; |
| | | import com.ks.vip.pojo.DO.LijinBalance; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | @SpringBootTest(classes = VIPApplication.class) |
| | | public class DaoTest { |
| | | @Resource |
| | | private LijinBalanceMapper lijinBalanceMapper; |
| | | |
| | | @Test |
| | | public void addBalance(){ |
| | | LijinBalance balance=new LijinBalance(); |
| | | balance.setId("tejia-123123"); |
| | | balance.setBalance(new BigDecimal(0)); |
| | | balance.setCreateTime(new Date()); |
| | | lijinBalanceMapper.insertSelective(balance); |
| | | } |
| | | } |