parent
800e79d338
commit
c3aec6b7fd
13 changed files with 345 additions and 0 deletions
@ -0,0 +1,97 @@ |
||||
package com.huoran.nakadai.controller; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.huoran.api.UserClient; |
||||
import com.huoran.common.response.R; |
||||
import com.huoran.common.utils.TokenUtils; |
||||
import com.huoran.nakadai.entity.CollectionProvider; |
||||
import com.huoran.nakadai.service.CollectionProviderService; |
||||
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.web.bind.annotation.*; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @描述:关注供应商控制类 |
||||
* @作者: Rong |
||||
* @日期: 2024-01-12 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/collectionProvider") |
||||
@Api(value = "关注供应商:CollectionProviderController", tags = "供应商关注") |
||||
public class CollectionProviderController { |
||||
|
||||
@Autowired |
||||
public CollectionProviderService service; |
||||
|
||||
@Autowired |
||||
private UserClient userClient; |
||||
|
||||
/*@PostMapping("/listByEntity") |
||||
@ApiOperation(value = "分页查询", response = CollectionProvider.class) |
||||
public R listByEntity(@RequestBody CollectionProvider collectionProvider) { |
||||
|
||||
return null; |
||||
}*/ |
||||
|
||||
|
||||
@PostMapping("/findById") |
||||
@ApiOperation(value = "查询详情", response = CollectionProvider.class) |
||||
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
CollectionProvider collectionProvider = service.getById(id); |
||||
return R.ok().put("data", collectionProvider); |
||||
} |
||||
|
||||
|
||||
|
||||
@PostMapping("/collect") |
||||
@ApiOperation(value = "关注", response = CollectionProvider.class) |
||||
public R collect(@RequestBody @ApiParam(name = "关注供应商对象", value = "传入json格式", required = true) CollectionProvider collectionProvider, HttpServletRequest request) { |
||||
String accountId = TokenUtils.getIdByJwtToken(request); |
||||
collectionProvider.setAccountId(Integer.valueOf(accountId)); |
||||
if (checkCollect(collectionProvider.getSupplierAccountId(), Integer.valueOf(accountId))){ |
||||
return R.ok("您已关注!请勿重复关注"); |
||||
} |
||||
boolean addState = service.save(collectionProvider); |
||||
return addState ? R.ok(collectionProvider.getId()) : R.error("新增失败"); |
||||
} |
||||
|
||||
//校验是否收藏过
|
||||
public boolean checkCollect(Integer supplierAccountId, Integer accountId) { |
||||
QueryWrapper<CollectionProvider> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("account_id", accountId); |
||||
queryWrapper.eq("supplier_account_id", supplierAccountId); |
||||
CollectionProvider collectionProvider = service.getOne(queryWrapper); |
||||
return collectionProvider != null; |
||||
} |
||||
|
||||
/* @PostMapping("/update") |
||||
@ApiOperation(value = "修改", response = CollectionProvider.class) |
||||
public R update(@RequestBody @ApiParam(name = "关注供应商对象", value = "传入json格式", required = true) CollectionProvider collectionProvider, HttpServletRequest request) { |
||||
String accountId = TokenUtils.getIdByJwtToken(request); |
||||
Integer schoolId = userClient.getSchoolIdByAccountId(accountId); |
||||
collectionProvider.setAccountId(Integer.valueOf(accountId)); |
||||
boolean updateState = service.updateById(collectionProvider); |
||||
return updateState ? R.ok() : R.error("编辑失败"); |
||||
}*/ |
||||
|
||||
@PostMapping("/cancelCollection") |
||||
@ApiOperation(value = "取消关注", response = CollectionProvider.class) |
||||
public R cancelCollection(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { |
||||
boolean delState = service.removeById(id); |
||||
return delState ? R.ok() : R.error("取消失败"); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/batchDeletion") |
||||
@ApiOperation(value = "批量删除", response = CollectionProvider.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,51 @@ |
||||
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 2024-01-12 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@ApiModel(value="CollectionProvider对象", description="收藏供应商") |
||||
public class CollectionProvider implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "主键") |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty(value = "账号id(关注人id)") |
||||
private Integer accountId; |
||||
|
||||
@ApiModelProperty(value = "被关注供应商的账号id") |
||||
private Integer supplierAccountId; |
||||
|
||||
@ApiModelProperty(value = "创建时间") |
||||
@TableField(fill = FieldFill.INSERT) |
||||
private Date createTime; |
||||
|
||||
@ApiModelProperty(value = "更新时间") |
||||
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
private Date updateTime; |
||||
|
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.huoran.nakadai.mapper; |
||||
|
||||
import com.huoran.nakadai.entity.CollectionProvider; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
||||
/** |
||||
* <p> |
||||
* 收藏供应商 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2024-01-12 |
||||
*/ |
||||
public interface CollectionProviderMapper extends BaseMapper<CollectionProvider> { |
||||
|
||||
} |
@ -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.CollectionProviderMapper"> |
||||
|
||||
</mapper> |
@ -0,0 +1,16 @@ |
||||
package com.huoran.nakadai.service; |
||||
|
||||
import com.huoran.nakadai.entity.CollectionProvider; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* <p> |
||||
* 收藏供应商 服务类 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2024-01-12 |
||||
*/ |
||||
public interface CollectionProviderService extends IService<CollectionProvider> { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.huoran.nakadai.service.impl; |
||||
|
||||
import com.huoran.nakadai.entity.CollectionProvider; |
||||
import com.huoran.nakadai.mapper.CollectionProviderMapper; |
||||
import com.huoran.nakadai.service.CollectionProviderService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 收藏供应商 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author chen |
||||
* @since 2024-01-12 |
||||
*/ |
||||
@Service |
||||
public class CollectionProviderServiceImpl extends ServiceImpl<CollectionProviderMapper, CollectionProvider> implements CollectionProviderService { |
||||
|
||||
} |
Loading…
Reference in new issue