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

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.*;
import com.newfiber.api.pc.dto.MeetPlanSubDTO;
import com.newfiber.api.pc.model.meet.MeetPlanSub;
import com.newfiber.api.pc.service.MeetPlanSubService;
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 javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 预案物资控制层
 * @Author:zhz
 * @CreateDate:2020/11/26 15:22
 * @Description:
 */
@RestController
@RequestMapping("/meet/sub/")
@Api(value = "MeetPlanSubController",tags = "预案物资表管理")
public class MeetPlanSubController {

    @Autowired
    private MeetPlanSubService meetPlanSubService;

    @PostMapping("/querPage")
    @ApiOperation("分页查找预案物资数据")
    @SysLog(actionType = "4",value = "分页查找预案物资数据")
    public ResultObj<PageResultObject<MeetPlanSub>> queryPage(@RequestBody PageRequestObject<String> page,@RequestParam("planId")Integer planId){
        if(StringUtils.isEmpty(planId)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        return new ResultObj<PageResultObject<MeetPlanSub>>(ResultCode.OK,meetPlanSubService.queryPage(page,planId));
    }
    @PostMapping("/list")
    @ApiOperation("查找全部数据-不分页")
    @SysLog(actionType = "4",value = "查找全部数据-不分页")
    public ResultObj<List<MeetPlanSub>> list(@RequestParam("planId")Integer planId){
        if(StringUtils.isEmpty(planId)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        EntityWrapper<MeetPlanSub> wrapper = new EntityWrapper<>();
        wrapper.eq("plan_id",planId);
        return new ResultObj<List<MeetPlanSub>>(ResultCode.OK,meetPlanSubService.selectList(wrapper));
    }
    @PostMapping("/selectById")
    @ApiOperation("根据主键id查找数据")
    @SysLog(actionType = "4",value = "根据主键id查找数据")
    public ResultObj<MeetPlanSub> selectById(@RequestParam("id")Integer id){
        if(StringUtils.isEmpty(id)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        return new ResultObj<MeetPlanSub>(ResultCode.OK,meetPlanSubService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("添加预案物资")
    @SysLog(actionType = "1",value = "添加预案物资")
    public ResultObj addMeetLevel(@RequestBody List<MeetPlanSubDTO> meetPlanSubDTO, HttpServletRequest request){
        if(StringUtils.isEmpty(meetPlanSubDTO)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        String userNo = request.getHeader("userNo");
        List<MeetPlanSub> sups = new ArrayList<>();
        for(MeetPlanSubDTO dto :  meetPlanSubDTO){
            MeetPlanSub meetPlanSub = new MeetPlanSub();
            meetPlanSub.setCreateTime(new Date());
            meetPlanSub.setCreateUserNo(userNo);
            meetPlanSub.setPlanId(dto.getPlanId());
            meetPlanSub.setSubCount(dto.getSubCount());
            meetPlanSub.setSubId(dto.getSubId());
            meetPlanSub.setSubName(dto.getSubName());
            meetPlanSub.setNature(dto.getNature());
            sups.add(meetPlanSub);
        }
        boolean insert = meetPlanSubService.insertBatch(sups);
        if(!insert){
            throw new CustomException(ResultCode.SAVE_ERROR);
        }
        return ResultObj.ok();
    }


    @PostMapping("/update")
    @ApiOperation("修改预案物资")
    @SysLog(actionType = "3",value = "修改预案物资")
    public ResultObj updateLevel(@RequestBody MeetPlanSubDTO meetPlanSubDTO){
        if(StringUtils.isEmpty(meetPlanSubDTO.getMSId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        MeetPlanSub meetPlanSub = new MeetPlanSub();
        meetPlanSub.setUpdateTime(new Date());
        meetPlanSub.setSubCount(meetPlanSubDTO.getSubCount());
        meetPlanSub.setSubId(meetPlanSubDTO.getSubId());
        meetPlanSub.setSubName(meetPlanSubDTO.getSubName());
        meetPlanSub.setNature(meetPlanSubDTO.getNature());
        boolean update = meetPlanSubService.updateById(meetPlanSub);
        if(!update){
            throw new CustomException(ResultCode.UPDATE_ERROR);
        }
        return ResultObj.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除预案物资")
    @SysLog(actionType = "2",value = "删除预案物资")
    public ResultObj deletLevel(@RequestParam("ids") List<Integer> ids){
        if(StringUtils.isEmpty(ids)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        boolean batchIds = meetPlanSubService.deleteBatchIds(ids);
        if(!batchIds){
            throw new CustomException(ResultCode.DELETE_ERROR);
        }
        return ResultObj.ok();
    }






}