Commit 09ead190 authored by liaoanyuan's avatar liaoanyuan

新增生成卡片接口

parent a97367b2
package cn.wisenergy.common.utils;
import cn.hutool.core.lang.UUID;
import java.io.Serializable;
import java.math.BigInteger;
public class CardNumberUtil implements Serializable {
private static final long serialVersionUID = -9056417839913098262L;
public static String cardNumber() {
//添加十一位数字生成卡号
String uuid = String.format("%040d", new BigInteger(UUID.randomUUID().toString().replace("-", ""), 16));
return uuid.toString().substring(0,11);
}
}
...@@ -35,4 +35,13 @@ public interface RefillCardMapper extends BaseMapper<RefillCardMapper> { ...@@ -35,4 +35,13 @@ public interface RefillCardMapper extends BaseMapper<RefillCardMapper> {
* @return * @return
*/ */
Integer getUserNumbers(); Integer getUserNumbers();
/**
* 通过ID查询充值卡信息
* @param id
* @return
*/
RefillCard getById(@Param("id") Integer id);
int setIsMakeCard(@Param("id") Integer id);
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<resultMap id="cardMap" type="cn.wisenergy.model.app.CardInfo"> <resultMap id="cardMap" type="cn.wisenergy.model.app.CardInfo">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="batch_number" property="batchNumber"/> <result column="batch_number" property="batchNumber"/>
<result column="card_number" property="cardNumber"/>
<result column="limit" property="limit"/> <result column="limit" property="limit"/>
<result column="secret_key" property="secretKey"/> <result column="secret_key" property="secretKey"/>
<result column="money" property="money"/> <result column="money" property="money"/>
...@@ -24,21 +25,22 @@ ...@@ -24,21 +25,22 @@
</sql> </sql>
<sql id="cols_exclude_id"> <sql id="cols_exclude_id">
banth_number,`limit`, secret_key,money,`status`,is_delete,create_time,update_time banth_number,card_number,`limit`, secret_key,money,`status`,is_delete,create_time,update_time
</sql> </sql>
<sql id="createsVal"> <sql id="createsVal">
#{i.banthNumber},#{i.limit},#{i.secretKey},#{i.money},#{i.status}, #{i.banthNumber},#{i.cardNumber},#{i.limit},#{i.secretKey},#{i.money},#{i.status},
#{i.isDelete},now(),now() #{i.isDelete},now(),now()
</sql> </sql>
<sql id="vals"> <sql id="vals">
#{banthNumber},#{limit},#{secretKey},#{money},#{status}, #{banthNumber},#{cardNumber},#{limit},#{secretKey},#{money},#{status},
#{isDelete},now(),now() #{isDelete},now(),now()
</sql> </sql>
<sql id="updateCondition"> <sql id="updateCondition">
<if test="password != null">banth_number =#{banthNumber},</if> <if test="password != null">banth_number =#{banthNumber},</if>
<if test="password != null">card_number =#{cardNumber},</if>
<if test="phone != null">`limit` =#{limit},</if> <if test="phone != null">`limit` =#{limit},</if>
<if test="headImage != null">secret_key =#{secretKey},</if> <if test="headImage != null">secret_key =#{secretKey},</if>
<if test="sex != null">money =#{money},</if> <if test="sex != null">money =#{money},</if>
...@@ -49,6 +51,7 @@ ...@@ -49,6 +51,7 @@
<sql id="criteria"> <sql id="criteria">
<if test="password != null"> and batch_number =#{batchNumber}</if> <if test="password != null"> and batch_number =#{batchNumber}</if>
<if test="password != null">and card_number =#{cardNumber},</if>
<if test="phone != null">and `limit` =#{limit}</if> <if test="phone != null">and `limit` =#{limit}</if>
<if test="headImage != null"> and secret_key =#{secretKey}</if> <if test="headImage != null"> and secret_key =#{secretKey}</if>
<if test="sex != null">and money =#{money}</if> <if test="sex != null">and money =#{money}</if>
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
</where> </where>
</select> </select>
<select id="getUserNumbers" resultType="java.lang.Integer"> <select id="getUserNumbers" resultType="java.lang.Integer">
SELECT COUNT(id) SELECT COUNT(id)
FROM FROM
...@@ -90,4 +91,22 @@ ...@@ -90,4 +91,22 @@
where is_delete=0 where is_delete=0
</select> </select>
<select id="getById" resultMap="refillCardMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
where id=#{id}
</select>
<update id="setIsMakeCard">
UPDATE
<include refid="table"/>
<set>
is_make_card =0
</set>
<where>
id=#{id}
</where>
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -22,6 +22,12 @@ public class CardInfo implements Serializable { ...@@ -22,6 +22,12 @@ public class CardInfo implements Serializable {
@ApiModelProperty(value = "批次号",name = "batchNumber") @ApiModelProperty(value = "批次号",name = "batchNumber")
private String banthNumber; private String banthNumber;
/**
* 批次号
*/
@ApiModelProperty(value = "批次号",name = "batchNumber")
private String cardNumber;
/** /**
* 次数 * 次数
*/ */
......
...@@ -2,8 +2,12 @@ package cn.wisenergy.service.app; ...@@ -2,8 +2,12 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.RefillCard; import cn.wisenergy.model.app.RefillCard;
import cn.wisenergy.model.dto.RefillCardDto;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface RefillCardService { public interface RefillCardService {
/** /**
* 添加充值卡 * 添加充值卡
...@@ -25,5 +29,11 @@ public interface RefillCardService { ...@@ -25,5 +29,11 @@ public interface RefillCardService {
* @param pageSize * @param pageSize
* @return * @return
*/ */
R getList(Integer pageNo,Integer pageSize); R<PageInfo<RefillCardDto>> getList(Integer pageNo, Integer pageSize);
/**
* 生成卡片
* @return
*/
R<Boolean> createCard(Integer id);
} }
...@@ -107,11 +107,6 @@ public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> impleme ...@@ -107,11 +107,6 @@ public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> impleme
//查询数据; //查询数据;
List<BannerDto> list = bannerMapper.getList(map); List<BannerDto> list = bannerMapper.getList(map);
//判断数据是否获取成功
if (CollectionUtils.isEmpty(list)) {
return R.error("数据查询失败");
}
PageInfo<BannerDto> pageInfo = new PageInfo<>(); PageInfo<BannerDto> pageInfo = new PageInfo<>();
pageInfo.setTotal(bannerMapper.count()); pageInfo.setTotal(bannerMapper.count());
pageInfo.setPageNum(pageNo); pageInfo.setPageNum(pageNo);
......
package cn.wisenergy.service.app.impl; package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.constant.CommonAttributes; import cn.wisenergy.common.constant.CommonAttributes;
import cn.wisenergy.common.utils.DateUtil; import cn.wisenergy.common.utils.*;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.common.utils.SecretkeyUtil;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.mapper.CardMapper; import cn.wisenergy.mapper.CardMapper;
import cn.wisenergy.mapper.RefillCardMapper; import cn.wisenergy.mapper.RefillCardMapper;
import cn.wisenergy.model.app.CardInfo; import cn.wisenergy.model.app.CardInfo;
...@@ -47,7 +44,7 @@ public class RefillCardServiceImpl implements RefillCardService { ...@@ -47,7 +44,7 @@ public class RefillCardServiceImpl implements RefillCardService {
String time = DateUtil.getTime(new Date(), "yyyy.MM.dd.HH.mm.sss"); String time = DateUtil.getTime(new Date(), "yyyy.MM.dd.HH.mm.sss");
refillCard.setBatchNumber(time); refillCard.setBatchNumber(time);
refillCard.setIsActivite(1); refillCard.setIsActivite(1);
refillCard.setIsMakeCard(0); refillCard.setIsMakeCard(1);
refillCard.setIsDelete(0); refillCard.setIsDelete(0);
int add = refillCardMapper.add(refillCard); int add = refillCardMapper.add(refillCard);
...@@ -55,31 +52,12 @@ public class RefillCardServiceImpl implements RefillCardService { ...@@ -55,31 +52,12 @@ public class RefillCardServiceImpl implements RefillCardService {
if (add==0) { if (add==0) {
return R.error("数据添加失败"); return R.error("数据添加失败");
} }
ArrayList<CardInfo> cardInfos = new ArrayList<>();
//子卡添加
for (int i = 0; i < refillCard.getCardNumber(); i++) {
CardInfo cardInfo = new CardInfo();
cardInfo.setBanthNumber(time);
cardInfo.setIsDelete(0);
cardInfo.setMoney("10");
cardInfo.setStatus(0);
cardInfo.setLimit(0);
cardInfo.setSecretKey(SecretkeyUtil.getSecretkey());
cardInfos.add(cardInfo);
}
int add1 = cardMapper.add(cardInfos);
if (add1==0) {
R.error("数据添加失败");
}
return R.ok(0,true); return R.ok(0,true);
} }
@Override @Override
public R<Boolean> update(String batchNumber) { public R<Boolean> update(String batchNumber) {
log.info("RefillCardServiceImpl[].update[].input.param:batchNumber:{}"+batchNumber); log.info("RefillCardServiceImpl[].update[].input.param:batchNumber:"+batchNumber);
if (StringUtils.isEmpty(batchNumber)) { if (StringUtils.isEmpty(batchNumber)) {
return R.error("传入参数为空"); return R.error("传入参数为空");
} }
...@@ -113,9 +91,7 @@ public class RefillCardServiceImpl implements RefillCardService { ...@@ -113,9 +91,7 @@ public class RefillCardServiceImpl implements RefillCardService {
BeanUtils.copyProperties(refillCard,refillCardDto); BeanUtils.copyProperties(refillCard,refillCardDto);
refillCardDtos.add(refillCardDto); refillCardDtos.add(refillCardDto);
} }
if (refillCardDtos.size()==0) {
return R.error("用户数据不存在");
}
PageInfo<RefillCardDto> refillCardDtoPageInfo = new PageInfo<>(); PageInfo<RefillCardDto> refillCardDtoPageInfo = new PageInfo<>();
refillCardDtoPageInfo.setTotal(refillCardMapper.getUserNumbers()); refillCardDtoPageInfo.setTotal(refillCardMapper.getUserNumbers());
refillCardDtoPageInfo.setPageNum(pageNum); refillCardDtoPageInfo.setPageNum(pageNum);
...@@ -124,4 +100,46 @@ public class RefillCardServiceImpl implements RefillCardService { ...@@ -124,4 +100,46 @@ public class RefillCardServiceImpl implements RefillCardService {
return R.ok(refillCardDtoPageInfo); return R.ok(refillCardDtoPageInfo);
} }
@Override
@Transactional
public R<Boolean> createCard(Integer id) {
log.info("RefillCardServiceImpl[].createCard[].input.param:id"+id);
if (null==id||id==0) {
return R.error("传入参数为空");
}
//查询充值卡信息
RefillCard byId = refillCardMapper.getById(id);
if (null==byId) {
return R.error("该充值卡不存在");
}
//获取充值卡的卡数,并生成卡片
ArrayList<CardInfo> cardInfos = new ArrayList<>();
//子卡添加
for (int i = 0; i < byId.getCardNumber(); i++) {
CardInfo cardInfo = new CardInfo();
cardInfo.setBanthNumber(byId.getBatchNumber());
cardInfo.setIsDelete(0);
cardInfo.setMoney("10");
cardInfo.setStatus(0);
cardInfo.setLimit(0);
cardInfo.setSecretKey(SecretkeyUtil.getSecretkey());
cardInfo.setCardNumber(CardNumberUtil.cardNumber());
cardInfos.add(cardInfo);
}
int add1 = cardMapper.add(cardInfos);
if (add1==0) {
R.error("数据添加失败");
}
int isMakeCard = refillCardMapper.setIsMakeCard(id);
if (isMakeCard==0) {
R.error("充值卡是否制卡状态修改失败");
}
return R.ok(-1,true);
}
} }
...@@ -94,9 +94,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -94,9 +94,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
info.setPageNum(queryVo.getPageNo()); info.setPageNum(queryVo.getPageNo());
info.setTotal(usersMapper.getUserNumbers()); info.setTotal(usersMapper.getUserNumbers());
info.setList(list); info.setList(list);
if (info.getList().size() == 0) {
return R.error("占时还没有用户");
}
return R.ok(info); return R.ok(info);
} }
......
...@@ -4,6 +4,7 @@ import cn.wisenergy.common.utils.R; ...@@ -4,6 +4,7 @@ import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.RefillCard; import cn.wisenergy.model.app.RefillCard;
import cn.wisenergy.model.dto.RefillCardDto; import cn.wisenergy.model.dto.RefillCardDto;
import cn.wisenergy.service.app.RefillCardService; import cn.wisenergy.service.app.RefillCardService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
...@@ -26,7 +27,7 @@ public class RefillCardController { ...@@ -26,7 +27,7 @@ public class RefillCardController {
@Autowired @Autowired
private RefillCardService refillCardService; private RefillCardService refillCardService;
@ApiOperation(value = "充值卡管理",notes = "充值卡管理",httpMethod = "POST") @ApiOperation(value = "添加充值卡",notes = "添加充值卡",httpMethod = "POST")
@ApiImplicitParam(name = "numbers",value = "卡的数量",dataType="int",required = true) @ApiImplicitParam(name = "numbers",value = "卡的数量",dataType="int",required = true)
@PostMapping("/manage") @PostMapping("/manage")
public R<Boolean> manage(Integer numbers){ public R<Boolean> manage(Integer numbers){
...@@ -52,8 +53,18 @@ public class RefillCardController { ...@@ -52,8 +53,18 @@ public class RefillCardController {
@ApiImplicitParam(name = "pageSize",value = "每页显示条数",dataType="int") @ApiImplicitParam(name = "pageSize",value = "每页显示条数",dataType="int")
}) })
@GetMapping("/select") @GetMapping("/select")
public R<List<RefillCardDto>> select(Integer pageNo,Integer pageSize){ public R<PageInfo<RefillCardDto>> select(Integer pageNo, Integer pageSize){
log.info("RefillCardController[].select[].input.param.parampageNo,pageSize"+pageNo,pageSize); log.info("RefillCardController[].select[].input.param.parampageNo,pageSize"+pageNo,pageSize);
return refillCardService.getList(pageNo, pageSize); return refillCardService.getList(pageNo, pageSize);
} }
@ApiOperation(value = "生成卡片",notes = "生成卡片",httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "id",value = "充值卡id",dataType="int"),
})
@GetMapping("/createCard")
public R<Boolean> createCard(Integer id){
log.info("RefillCardController[].createCard[].input.param:id"+id);
return refillCardService.createCard(id);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment