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

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.ReqBodyObj;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.core.commons.ResultObj;
import com.newfiber.api.pc.model.meet.MeetSchedule;
import com.newfiber.api.pc.model.vo.MeetScheduleParam;
import com.newfiber.api.pc.model.vo.MeetScheduleVo;
import com.newfiber.api.pc.service.MeetScheduleService;
import com.newfiber.api.core.utils.ExportExcel;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 人员排班功能
 */
@RestController
@RequestMapping("/schedule")
@Api(value = "MeetScheduleController",tags = "人员排班功能")
public class MeetScheduleController {

    @Autowired
    private MeetScheduleService meetScheduleService;

    @PostMapping("/list")
    @ApiOperation("获取人员排班列表")
    @SysLog(actionType = "4",value = "获取人员排班列表")
    public ResultObj relevance(@RequestBody ReqBodyObj<Map<String, Object>> params){
        Integer taskId = StringUtils.isEmpty(params.getData().get("taskId"))?null:Integer.valueOf(params.getData().get("taskId").toString());
        String userName = StringUtils.isEmpty(params.getData().get("userName"))?null:params.getData().get("userName").toString();
        String startTime = StringUtils.isEmpty(params.getData().get("startTime"))?null:params.getData().get("startTime").toString();
        String endTime = StringUtils.isEmpty(params.getData().get("endTime"))?null:params.getData().get("endTime").toString();
        Integer pageNo = params.getCurrent() == 0 ?null:params.getCurrent();
        Integer pageSize = params.getSize() == 0 ?null:params.getSize();
        //查询传入月的月开始时间和月结束时间
        return new ResultObj<>(ResultCode.OK,meetScheduleService.selectListByTime(taskId,userName,startTime,endTime,pageNo,pageSize));
    }

    @PostMapping("/datalist")
    @ApiOperation("日期获取人员排班列表")
    @SysLog(actionType = "4",value = "日期获取人员排班列表")
    public ResultObj datelist(@RequestBody com.newfiber.api.core.bean.ReqBodyObj<Map<String, Object>> params){
        Integer taskId = StringUtils.isEmpty(params.getData().get("taskId"))?null:Integer.valueOf(params.getData().get("taskId").toString());
        Integer taskType = StringUtils.isEmpty(params.getData().get("taskType"))?null:Integer.valueOf(params.getData().get("taskType").toString());
        String userName = StringUtils.isEmpty(params.getData().get("userName"))?null:params.getData().get("userName").toString();
        String startTime = StringUtils.isEmpty(params.getData().get("startTime"))?null:params.getData().get("startTime").toString();
        String endTime = StringUtils.isEmpty(params.getData().get("endTime"))?null:params.getData().get("endTime").toString();
        Integer pageNo = params.getCurrent() == 0 ?null:params.getCurrent();
        Integer pageSize = params.getSize() == 0 ?null:params.getSize();
        //查询传入月的月开始时间和月结束时间
        return new ResultObj<>(ResultCode.OK,meetScheduleService.selectDataListByTime(taskId,taskType,userName,startTime,endTime,pageNo,pageSize));
    }

    @PostMapping("/update")
    @ApiOperation("更新人员排班信息")
    @SysLog(actionType = "3",value = "更新人员排班信息")
    public ResultObj update(@RequestBody ReqBodyObj<MeetSchedule> params){
        return new ResultObj<>(ResultCode.OK,meetScheduleService.updateById(params.getData()));
    }

    @PostMapping("/delete")
    @ApiOperation("删除人员排班信息")
    @SysLog(actionType = "2",value = "删除人员排班信息")
    public ResultObj delete(@RequestBody ReqBodyObj<MeetSchedule> params){
        EntityWrapper<MeetSchedule> wrapper = new EntityWrapper<>();
        wrapper.in("id",params.getData().getId().toString());
        return new ResultObj<>(ResultCode.OK,meetScheduleService.delete(wrapper));
    }

    @PostMapping("/add")
    @ApiOperation("人员排班添加")
    @SysLog(actionType = "1",value = "人员排班添加")
    public ResultObj add(@RequestBody ReqBodyObj<MeetScheduleParam> params){
        return meetScheduleService.addTask(params.getData());
    }

    @PostMapping("/addOne")
    @ApiOperation("人员排班单独添加")
    @SysLog(actionType = "1",value = "人员排班单独添加")
    public ResultObj addOne(@RequestBody ReqBodyObj<MeetSchedule> params){
        return new ResultObj<>(ResultCode.OK,meetScheduleService.addOne(params.getData()));
    }

    @PostMapping("/getOne")
    @ApiOperation("获取当天的排班人员")
    @SysLog(actionType = "4",value = "获取当天的排班人员")
    public ResultObj getOne(){
        return new ResultObj<>(ResultCode.OK,meetScheduleService.getOne());
    }

    @ApiOperation("excel导出")
    @PostMapping(value = "excelExport", produces = "application/json;charset=utf-8")
    public void excelExport(@RequestBody ReqBodyObj<Map<String, Object>> params, OutputStream out, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        List<String> headers = new ArrayList<>();
        headers.add("时间");
        headers.add("星期");
        headers.add("姓名");
        headers.add("排班开始");
        headers.add("排班结束");
        headers.add("排班任务时间");
        try {
            Integer taskId = StringUtils.isEmpty(params.getData().get("taskId"))?null:Integer.valueOf(params.getData().get("taskId").toString());
            String userName = StringUtils.isEmpty(params.getData().get("userName"))?null:params.getData().get("userName").toString();
            String endTime = StringUtils.isEmpty(params.getData().get("endTime"))?null:params.getData().get("endTime").toString();
            String startTime = StringUtils.isEmpty(params.getData().get("startTime"))?null:params.getData().get("startTime").toString();
            Integer pageNo = params.getCurrent() == 0 ?null:params.getCurrent();
            Integer pageSize = params.getSize() == 0 ?null:params.getSize();
            PageInfo<MeetScheduleVo> re = meetScheduleService.selectListByTime(taskId, userName, startTime, endTime, pageNo, pageSize);
            List<MeetScheduleVo> list = re.getList();
            List<List> result = new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (MeetScheduleVo meet : list) {
                List<String> strs = new ArrayList<>();
                strs.add(new SimpleDateFormat("yyyy-MM-dd").format(meet.getStartTime()));
                strs.add(new SimpleDateFormat("EEEE").format(meet.getStartTime()));
                strs.add(meet.getUserName());
                strs.add(sdf.format(meet.getStartTime()));
                strs.add(sdf.format(meet.getEndTime()));
                strs.add(sdf.format(meet.getTaskTime()));
                result.add(strs);
            }
            ExportExcel excel = new ExportExcel();
            excel.exportExcel3("排班表", headers, result, out, response,(new Date()).toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}