From b6d370180685cbca62268c77ef9938b2c8df0f7a Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 6 Nov 2024 16:36:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=A5=BD=E5=8F=8B=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/utils/JSONUtil.java | 12 +++ .../controller/TbShopShareController.java | 63 +++++++++++++ .../cashier/mybatis/entity/TbShopShare.java | 93 +++++++++++++++++++ .../mybatis/mapper/TbShopShareMapper.java | 15 +++ .../mybatis/service/TbShopShareService.java | 18 ++++ .../service/impl/TbShopShareServiceImpl.java | 35 +++++++ 6 files changed, 236 insertions(+) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShare.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareMapper.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareServiceImpl.java diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/JSONUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/JSONUtil.java index 23a32691..0e75d57a 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/JSONUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/JSONUtil.java @@ -88,6 +88,18 @@ public class JSONUtil { } } + + public static List parseJSONStrTList(String jsonStr, Class clazz) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + // 将JSON字符串转换为List + return objectMapper.readValue(jsonStr, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + /** * @param list 某集合 * @param clazz 要转成的实体 diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java new file mode 100644 index 00000000..863c59d3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java @@ -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 insert(@RequestBody TbShopShare tbShopShare) { + return new ResponseEntity<>(tbShopShareService.save(tbShopShare), HttpStatus.CREATED); + } + + @PutMapping + @ApiOperation("通过id修改") + public ResponseEntity update(@RequestBody TbShopShare tbShopShare) { + tbShopShareService.updateById(tbShopShare); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + + + @DeleteMapping + @ApiOperation("删除") + public ResponseEntity delete(@RequestBody Integer[] ids) { + tbShopShareService.removeByIds(Arrays.asList(ids)); + return new ResponseEntity<>(HttpStatus.OK); + } +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShare.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShare.java new file mode 100644 index 00000000..85fbecd3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShare.java @@ -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 { + + 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 newCoupons; + + @TableField(exist = false) + private List 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 newCoupons) { + this.newCoupons = newCoupons; + if(CollectionUtil.isNotEmpty(newCoupons)){ + this.newCoupon = JSONUtil.toJSONString(newCoupons); + } + } + + public void setRewardCoupons(List 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; + } +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareMapper.java new file mode 100644 index 00000000..54b3e894 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareMapper.java @@ -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 { + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareService.java new file mode 100644 index 00000000..e93a7682 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareService.java @@ -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 getByShopId(Integer shopId); + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareServiceImpl.java new file mode 100644 index 00000000..5216c3de --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareServiceImpl.java @@ -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 implements TbShopShareService { + + @Autowired + private TbShopShareMapper tbShopSharemapper; + + @Override + public TbShopShare getByShopId(Integer shopId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("shop_id", shopId); + return tbShopSharemapper.selectOne(wrapper); + } +} +