分享好友模块
This commit is contained in:
parent
090e5d320e
commit
b6d3701806
|
|
@ -88,6 +88,18 @@ public class JSONUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T> List<T> parseJSONStrTList(String jsonStr, Class<T> clazz) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
// 将JSON字符串转换为List<T>
|
||||
return objectMapper.readValue(jsonStr, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list 某集合
|
||||
* @param clazz 要转成的实体
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package cn.ysk.cashier.controller;
|
||||
|
||||
|
||||
import cn.ysk.cashier.annotation.AnonymousAccess;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopShare;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopShareService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺分享(TbShopShare)表控制层
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-11-06 15:47:37
|
||||
*/
|
||||
@Api(tags = "分享")
|
||||
@RestController
|
||||
@RequestMapping("tbShopShare")
|
||||
public class TbShopShareController {
|
||||
|
||||
@Resource
|
||||
private TbShopShareService tbShopShareService;
|
||||
|
||||
@GetMapping("byShopId")
|
||||
@ApiOperation("通过shopId查询详情")
|
||||
public ResponseEntity<?> getByShopId(
|
||||
@RequestParam Integer shopId
|
||||
) {
|
||||
return ResponseEntity.ok(tbShopShareService.getByShopId(shopId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("新增")
|
||||
public ResponseEntity<Object> insert(@RequestBody TbShopShare tbShopShare) {
|
||||
return new ResponseEntity<>(tbShopShareService.save(tbShopShare), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@ApiOperation("通过id修改")
|
||||
public ResponseEntity<Object> update(@RequestBody TbShopShare tbShopShare) {
|
||||
tbShopShareService.updateById(tbShopShare);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除")
|
||||
public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
|
||||
tbShopShareService.removeByIds(Arrays.asList(ids));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.ysk.cashier.utils.JSONUtil;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺分享(TbShopShare)表实体类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-11-06 15:47:37
|
||||
*/
|
||||
@Data
|
||||
@SuppressWarnings("serial")
|
||||
public class TbShopShare extends Model<TbShopShare> {
|
||||
|
||||
private Integer id;
|
||||
//店铺Id
|
||||
private Integer shopId;
|
||||
//标题
|
||||
private String title;
|
||||
//分享封面图
|
||||
private String shareImg;
|
||||
//邀请顶部图
|
||||
private String invitedImg;
|
||||
//被邀顶部图
|
||||
private String beInvitedImg;
|
||||
//活动开始时间
|
||||
private Date startTime;
|
||||
//活动结束时间
|
||||
private Date endTime;
|
||||
//新用户获得券
|
||||
private String newCoupon;
|
||||
//邀请num人数 可获奖励券
|
||||
private Integer invitedNum;
|
||||
//奖励券
|
||||
private String rewardCoupon;
|
||||
//获取方法 get-新用户领取获得 use-新用户使用获得
|
||||
private String getMethod;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ShareCoupons> newCoupons;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ShareCoupons> rewardCoupons;
|
||||
|
||||
public void setNewCoupon(String newCoupon) {
|
||||
this.newCoupon = newCoupon;
|
||||
if(StringUtils.isNotBlank(newCoupon)){
|
||||
this.newCoupons = JSONUtil.parseJSONStrTList(newCoupon,ShareCoupons.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRewardCoupon(String rewardCoupon) {
|
||||
this.rewardCoupon = rewardCoupon;
|
||||
if(StringUtils.isNotBlank(rewardCoupon)){
|
||||
this.newCoupons = JSONUtil.parseJSONStrTList(rewardCoupon,ShareCoupons.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewCoupons(List<ShareCoupons> newCoupons) {
|
||||
this.newCoupons = newCoupons;
|
||||
if(CollectionUtil.isNotEmpty(newCoupons)){
|
||||
this.newCoupon = JSONUtil.toJSONString(newCoupons);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRewardCoupons(List<ShareCoupons> rewardCoupons) {
|
||||
this.rewardCoupons = rewardCoupons;
|
||||
if(CollectionUtil.isNotEmpty(rewardCoupons)){
|
||||
this.rewardCoupon = JSONUtil.toJSONString(rewardCoupons);
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ShareCoupons {
|
||||
//优惠券Id
|
||||
private Integer couponId;
|
||||
//优惠券名称
|
||||
private String couponName;
|
||||
//优惠券数量
|
||||
private Integer couponNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopShare;
|
||||
|
||||
/**
|
||||
* 店铺分享(TbShopShare)表数据库访问层
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-11-06 15:47:37
|
||||
*/
|
||||
public interface TbShopShareMapper extends BaseMapper<TbShopShare> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopShare;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 店铺分享(TbShopShare)表服务接口
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-11-06 15:47:37
|
||||
*/
|
||||
public interface TbShopShareService extends IService<TbShopShare> {
|
||||
TbShopShare getByShopId(Integer shopId);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopShareMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopShare;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopShareService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 店铺分享(TbShopShare)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-11-06 15:47:37
|
||||
*/
|
||||
@Service("tbShopShareService")
|
||||
public class TbShopShareServiceImpl extends ServiceImpl<TbShopShareMapper, TbShopShare> implements TbShopShareService {
|
||||
|
||||
@Autowired
|
||||
private TbShopShareMapper tbShopSharemapper;
|
||||
|
||||
@Override
|
||||
public TbShopShare getByShopId(Integer shopId) {
|
||||
QueryWrapper<TbShopShare> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("shop_id", shopId);
|
||||
return tbShopSharemapper.selectOne(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue