fangyuan
2022-11-21 c435158ed1ff587939314e84347ee6e38e8f25ec
ycl-platform/src/main/java/com/ycl/controller/NewsColumnInformationController.java
@@ -7,11 +7,17 @@
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.entity.NewsColumnInformation;
import com.ycl.entity.NewsInformation;
import com.ycl.service.NewsColumnInformationService;
import com.ycl.service.NewsInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
@@ -22,6 +28,7 @@
 */
@RestController
@RequestMapping("newsColumnInformation")
@Api(tags = "栏目咨询中间表控制层")
public class NewsColumnInformationController extends ApiController {
    /**
     * 服务对象
@@ -29,6 +36,8 @@
    @Resource
    private NewsColumnInformationService newsColumnInformationService;
    @Autowired
    private NewsInformationService newsInformationService;
    /**
     * 分页查询所有数据
     *
@@ -37,6 +46,7 @@
     * @return 所有数据
     */
    @GetMapping
    @ApiOperation(value = "查询所有数据")
    public R selectAll(Page<NewsColumnInformation> page, NewsColumnInformation newsColumnInformation) {
        return success(this.newsColumnInformationService.page(page, new QueryWrapper<>(newsColumnInformation)));
    }
@@ -48,6 +58,7 @@
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "按id查询数据")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.newsColumnInformationService.getById(id));
    }
@@ -59,6 +70,7 @@
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "新增数据")
    public R insert(@RequestBody NewsColumnInformation newsColumnInformation) {
        return success(this.newsColumnInformationService.save(newsColumnInformation));
    }
@@ -70,6 +82,7 @@
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation(value = "修改数据")
    public R update(@RequestBody NewsColumnInformation newsColumnInformation) {
        return success(this.newsColumnInformationService.updateById(newsColumnInformation));
    }
@@ -81,8 +94,25 @@
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation(value = "删除数据")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.newsColumnInformationService.removeByIds(idList));
    }
}
    /**
     * 通过栏目id查对应资讯
     *
     * @param id 栏目id
     * @return 资讯查询结果
     */
    @GetMapping("column/{id}")
    @ApiOperation(value = "按")
    public R selectInformationByColumnId(@PathVariable Serializable id) {
        List<NewsColumnInformation> newsColumnInformationList = newsColumnInformationService.list(new QueryWrapper<NewsColumnInformation>().eq("column_id", id));
        List<NewsInformation> resultList=new ArrayList<>();
        for (NewsColumnInformation newsColumnInformation:newsColumnInformationList){
            resultList.add(newsInformationService.selectInformationById(newsColumnInformation.getInformationId()));
        }
        return success(resultList);
    }}