Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / zhz / DiscussionDicController.java
package com.newfiber.api.pc.controller.zhz;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.*;
import com.newfiber.api.pc.model.entity.DiscussionDic;
import com.newfiber.api.pc.service.DiscussionDicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DiscussionDicController
 * @Description TODO
 * @Author 张鸿志
 * @Date 2021年6月3日13:46:15 13:46
 * Version 1.0
 **/
@RestController
@RequestMapping("/discussion")
@Api(value = "DiscussionDicController",tags = "会商字典表控制层")
public class DiscussionDicController {

    @Autowired
    private DiscussionDicService discussionDicService;

    @PostMapping("/create")
    @ApiOperation("创建字典")
    @SysLog(actionType = "1",value = "创建会商字典")
    public ResultObj create(@RequestBody DiscussionDic discussionDic){
        if(StringUtils.isEmpty(discussionDic)){
            throw  new CustomException(ResultCode.PARAM_NULL);
        }
        discussionDic.setStatus(0);
        boolean insert = discussionDicService.insert(discussionDic);
        if(insert){
            return ResultObj.ok();
        }
        return ResultObj.error();
    }

    @PostMapping("/selectPage")
    @ApiOperation("分页查找字典数据")
    @SysLog(actionType = "4",value = "分页查找会商字典")
    public ResultObj<PageResultObject<DiscussionDic>> selectPage(@RequestBody PageRequestObject<String> pageRequestObject){
        Page<DiscussionDic> page = new Page<DiscussionDic>(pageRequestObject.getCurrent(), pageRequestObject.getSize());
        EntityWrapper<DiscussionDic> wrapper = new EntityWrapper<>();
        if(!StringUtils.isEmpty(pageRequestObject.getObject())){
            wrapper.eq("type",pageRequestObject.getObject());
        }
        wrapper.eq("status",0);
        Page<DiscussionDic> discussionDicPage = discussionDicService.selectPage(page,wrapper);
        int selectCount = discussionDicService.selectCount(wrapper);
        return new ResultObj<>(ResultCode.OK,new PageResultObject<>(pageRequestObject.getCurrent(), pageRequestObject.getSize(),(long)selectCount,discussionDicPage.getRecords()));
    }

    @PostMapping("/delete")
    @ApiOperation("删除字典")
    @SysLog(actionType = "2",value = "删除会商字典")
    public ResultObj deleteDic(@RequestParam("id") Integer id){
        if(StringUtils.isEmpty(id)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        DiscussionDic dic = discussionDicService.selectById(id);
        dic.setStatus(1);
        if(discussionDicService.updateById(dic)){
            return ResultObj.ok("删除成功!");
        }
        return ResultObj.error("删除失败!");

    }

    @PostMapping("/update")
    @ApiOperation("修改字典")
    @SysLog(actionType = "3",value = "修改会商字典")
    public ResultObj updateDic(@RequestBody DiscussionDic discussionDic){
        if(StringUtils.isEmpty(discussionDic.getId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        DiscussionDic dic = discussionDicService.selectById(discussionDic.getId());
        if(!StringUtils.isEmpty(dic)){
            if(discussionDicService.updateById(discussionDic)){
                return ResultObj.ok();
            }
        }
        return ResultObj.error("修改失败!");
    }


    @PostMapping("/selectList")
    @ApiOperation("查询某一个类别下的所有字典数据")
    @SysLog(actionType = "4",value = "查询某一个类别下的所有会商字典数据")
    public ResultObj<List<DiscussionDic>> selectListByType(@RequestParam(value = "type")Integer type){
        EntityWrapper<DiscussionDic> wrapper = new EntityWrapper<>();
        wrapper.eq("type",type);
        return new ResultObj<>(ResultCode.OK,discussionDicService.selectList(wrapper));
    }


}