Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / zhz / MeetPlanController.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.MeetPlanDto;
import com.newfiber.api.pc.model.meet.MeetPlan;
import com.newfiber.api.pc.model.meet.MeetPlanFile;
import com.newfiber.api.pc.service.MeetPlanFileService;
import com.newfiber.api.pc.service.MeetPlanService;
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.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author:zzh
 * @CreateDate:2020/11/25 17:09
 * @Description:
 */
@RestController
@RequestMapping("/meetPlan")
@Api(value = "MeetPlanController",tags = "预案管理")
public class MeetPlanController {

    @Autowired
    private MeetPlanService meetPlanService;

    @Autowired
    private MeetPlanFileService meetPlanFileService;

    @PostMapping("/queryPage")
    @ApiOperation("分页显示预案")
    @SysLog(actionType = "4",value = "分页显示预案")
    public ResultObj<PageResultObject<MeetPlan>> queryPage(@RequestBody PageRequestObject<String> pageRequestObject){
        return new ResultObj<PageResultObject<MeetPlan>>(ResultCode.OK,meetPlanService.queryPage(pageRequestObject));
    }
    @PostMapping("/selectById")
    @ApiOperation("根据主键id查找数据")
    @SysLog(actionType = "4",value = "根据主键id查找数据")
    public ResultObj<MeetPlan> selectById(@RequestParam("id")Integer id){
        if(StringUtils.isEmpty(id)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        return new ResultObj<MeetPlan>(ResultCode.OK,meetPlanService.selectMeetPlanInfoById(id));
    }

    @PostMapping("/delete")
    @ApiOperation("删除预案数据")
    @SysLog(actionType = "2",value = "删除预案数据")
    public ResultObj deleteMeetPlan(@RequestParam("id")Integer id){
        if(StringUtils.isEmpty(id)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        MeetPlan meetPlans = meetPlanService.selectById(id);
        //删除文件
        EntityWrapper<MeetPlanFile> wrapper = new EntityWrapper<>();
        wrapper.eq("plan_id",meetPlans.getMId());
        List<MeetPlanFile> meetPlanFiles = meetPlanFileService.selectList(wrapper);
        List<Integer> fileIds = meetPlanFiles.stream().map(MeetPlanFile::getMFId).collect(Collectors.toList());
        if(fileIds != null && fileIds.size() > 0){
            meetPlanFileService.deleteFiles(fileIds);
        }
        meetPlanService.deleteById(id);
        return  ResultObj.ok();
    }

    @PostMapping("/update")
    @ApiOperation("更新预案数据")
    @SysLog(actionType = "3",value = "更新预案数据")
    public ResultObj updateMeetPlan(@RequestBody MeetPlanDto meetPlanDto){
        if(StringUtils.isEmpty(meetPlanDto.getMId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        MeetPlan meetPlan = new MeetPlan();
        meetPlan.setMId(meetPlanDto.getMId());

        meetPlan.setUpdateTime(new Date());
        meetPlan.setPlanLevelName(meetPlanDto.getPlanLevelName());
        meetPlan.setPlanLevelId(meetPlanDto.getPlanLevelId());
        meetPlan.setPlanTypeId(meetPlanDto.getPlanTypeId());
        meetPlan.setPlanTypeName(meetPlanDto.getPlanTypeName());
        meetPlan.setPlanName(meetPlanDto.getPlanName());
        boolean insert = meetPlanService.updateById(meetPlan);
        if(!insert){
            throw new CustomException(ResultCode.SAVE_ERROR);
        }
        return ResultObj.ok();
    }

    @PostMapping("/add")
    @ApiOperation("新增预案数据")
    @SysLog(actionType = "1",value = "新增预案数据")
    public ResultObj addMeetPlan(@RequestBody MeetPlanDto meetPlanDto,HttpServletRequest request){
        String userNo = request.getHeader("userNo");
        if(StringUtils.isEmpty(meetPlanDto)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        MeetPlan meetPlan = new MeetPlan();
        meetPlan.setUserNo(userNo);
        meetPlan.setCreateTime(new Date());
        meetPlan.setPlanLevelName(meetPlanDto.getPlanLevelName());
        meetPlan.setPlanLevelId(meetPlanDto.getPlanLevelId());
        meetPlan.setPlanTypeId(meetPlanDto.getPlanTypeId());
        meetPlan.setPlanTypeName(meetPlanDto.getPlanTypeName());
        meetPlan.setPlanName(meetPlanDto.getPlanName());
        boolean insert = meetPlanService.insert(meetPlan);
        if(!insert){
            throw new CustomException(ResultCode.SAVE_ERROR);
        }
        return ResultObj.ok();

    }





}