parent
1e6be8154d
commit
1c4250adf0
9 changed files with 338 additions and 11 deletions
@ -0,0 +1,120 @@ |
||||
package com.huoran.nakadai.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.huoran.api.UserClient; |
||||
import com.huoran.common.response.R; |
||||
import com.huoran.common.utils.TokenUtils; |
||||
import com.huoran.nakadai.entity.ExplosiveRecommendation; |
||||
import com.huoran.nakadai.entity.req.ExplosiveRecommendationReq; |
||||
import com.huoran.nakadai.service.ExplosiveRecommendationService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.ObjectUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @描述:控制类 |
||||
* @作者: Rong |
||||
* @日期: 2023-12-28 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/explosiveRecommendation") |
||||
@Api(value = "营销管理/banner管理:ExplosiveRecommendationController", tags = "营销管理/banner管理") |
||||
public class ExplosiveRecommendationController { |
||||
|
||||
@Autowired |
||||
public ExplosiveRecommendationService service; |
||||
|
||||
@Autowired |
||||
private UserClient userClient; |
||||
|
||||
@PostMapping("/explosiveList") |
||||
@ApiOperation(value = "爆款推荐列表", response = ExplosiveRecommendation.class) |
||||
public R explosiveList(@RequestBody ExplosiveRecommendationReq explosiveRecommendation) { |
||||
IPage<ExplosiveRecommendation> iPage = new Page<>(explosiveRecommendation.getPageNum(), explosiveRecommendation.getPageSize()); |
||||
QueryWrapper<ExplosiveRecommendation> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("type",explosiveRecommendation.getType()); |
||||
if (!ObjectUtils.isEmpty(explosiveRecommendation.getEnabledState())) { |
||||
queryWrapper.eq("enabled_state", explosiveRecommendation.getEnabledState()); |
||||
} |
||||
queryWrapper.orderByDesc("create_time"); |
||||
IPage<ExplosiveRecommendation> pageList = service.page(iPage, queryWrapper); |
||||
return R.ok().put("data", pageList); |
||||
} |
||||
|
||||
|
||||
//排序
|
||||
@PostMapping("/sort") |
||||
@ApiOperation(value = "排序", response = ExplosiveRecommendation.class) |
||||
public R sort(@RequestBody LinkedList<ExplosiveRecommendation> explosiveRecommendation) { |
||||
|
||||
//获取类型(0.爆款推荐 1.banner管理)
|
||||
ExplosiveRecommendation firstRecommendation = explosiveRecommendation.stream() |
||||
.findFirst() |
||||
.orElse(null); |
||||
Integer type = firstRecommendation.getType(); |
||||
|
||||
QueryWrapper<ExplosiveRecommendation> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("type", type); |
||||
//删除原集合
|
||||
service.remove(queryWrapper); |
||||
|
||||
//todo 还需要对中间表进行删除信息
|
||||
|
||||
Integer serialNumber = 0; |
||||
for (ExplosiveRecommendation item : explosiveRecommendation) { |
||||
item.setSequence(++serialNumber); |
||||
} |
||||
//添加排序后的集合
|
||||
service.saveBatch(explosiveRecommendation); |
||||
|
||||
return R.ok(); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = ExplosiveRecommendation.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
ExplosiveRecommendation explosiveRecommendation = service.getById(id); |
||||
return R.ok().put("data", explosiveRecommendation); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
@ApiOperation(value = "新增", response = ExplosiveRecommendation.class) |
||||
public R save(@RequestBody @ApiParam(name = "对象", value = "传入json格式", required = true) ExplosiveRecommendation explosiveRecommendation, HttpServletRequest request) { |
||||
String accountId = TokenUtils.getIdByJwtToken(request); |
||||
Integer schoolId = userClient.getSchoolIdByAccountId(accountId); |
||||
boolean addState = service.save(explosiveRecommendation); |
||||
return addState ? R.ok() : R.error("新增失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = ExplosiveRecommendation.class) |
||||
public R update(@RequestBody @ApiParam(name = "对象", value = "传入json格式", required = true) ExplosiveRecommendation explosiveRecommendation, HttpServletRequest request) { |
||||
String accountId = TokenUtils.getIdByJwtToken(request); |
||||
boolean updateState = service.updateById(explosiveRecommendation); |
||||
return updateState ? R.ok() : R.error("编辑失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除", response = ExplosiveRecommendation.class) |
||||
public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestBody List<Integer> ids) { |
||||
boolean delState = service.removeByIds(ids); |
||||
return delState ? R.ok() : R.error("删除失败"); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,89 @@ |
||||
package com.huoran.nakadai.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import java.util.Date; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import java.io.Serializable; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
* <p> |
||||
* |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2023-12-28 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@ApiModel(value="ExplosiveRecommendation对象", description="") |
||||
public class ExplosiveRecommendation implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "产品名称") |
||||
private String productName; |
||||
|
||||
@ApiModelProperty(value = "封面图(多张逗号隔开)") |
||||
private String coverUrl; |
||||
|
||||
@ApiModelProperty(value = "顺序") |
||||
private Integer sequence; |
||||
|
||||
@ApiModelProperty(value = "(0.爆款推荐 1.banner管理") |
||||
private Integer type; |
||||
|
||||
@ApiModelProperty(value = "启用状态(0开启 1未开启 默认0)") |
||||
private Integer enabledState; |
||||
|
||||
|
||||
@ApiModelProperty(value = "产品详情(1详情/2链接)") |
||||
private String details; |
||||
|
||||
@ApiModelProperty(value = "链接类型(1小程序链接/2.外链接)") |
||||
private String link; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@ApiModelProperty("创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "选择链接内容(1.商品、2.活动、3.供应商、4.店铺)") |
||||
private String selectLinkId; |
||||
|
||||
@ApiModelProperty(value = "对应链接id的主键(如:选择活动则保存的活动id)") |
||||
private Integer correspondingLinkId; |
||||
|
||||
@ApiModelProperty(value = "跳转链接") |
||||
private String jumpLink; |
||||
|
||||
@ApiModelProperty(value = "发布状态(0默认未发布/1已发布)") |
||||
private Integer publishStatus; |
||||
|
||||
/** |
||||
* 修改时间 |
||||
*/ |
||||
@ApiModelProperty("修改时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,36 @@ |
||||
package com.huoran.nakadai.entity.req; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* <p> |
||||
* |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2023-12-28 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
public class ExplosiveRecommendationReq extends PageReq{ |
||||
|
||||
@ApiModelProperty(value = "启用状态(0开启 1未开启 默认0)") |
||||
private Integer enabledState; |
||||
|
||||
@ApiModelProperty(value = "(0.爆款推荐 1.banner管理") |
||||
private Integer type; |
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.huoran.nakadai.mapper; |
||||
|
||||
import com.huoran.nakadai.entity.ExplosiveRecommendation; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
||||
/** |
||||
* <p> |
||||
* Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2023-12-28 |
||||
*/ |
||||
public interface ExplosiveRecommendationMapper extends BaseMapper<ExplosiveRecommendation> { |
||||
|
||||
} |
@ -0,0 +1,5 @@ |
||||
<?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.huoran.nakadai.mapper.ExplosiveRecommendationMapper"> |
||||
|
||||
</mapper> |
@ -0,0 +1,16 @@ |
||||
package com.huoran.nakadai.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.huoran.nakadai.entity.ExplosiveRecommendation; |
||||
|
||||
/** |
||||
* <p> |
||||
* 服务类 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2023-12-28 |
||||
*/ |
||||
public interface ExplosiveRecommendationService extends IService<ExplosiveRecommendation> { |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.huoran.nakadai.service.impl; |
||||
|
||||
import com.huoran.nakadai.entity.ExplosiveRecommendation; |
||||
import com.huoran.nakadai.mapper.ExplosiveRecommendationMapper; |
||||
import com.huoran.nakadai.service.ExplosiveRecommendationService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2023-12-28 |
||||
*/ |
||||
@Service |
||||
public class ExplosiveRecommendationServiceImpl extends ServiceImpl<ExplosiveRecommendationMapper, ExplosiveRecommendation> implements ExplosiveRecommendationService { |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue