package cn.common.api;

import cn.common.req.HealthArchivesAddReq;
import cn.common.req.HealthArchivesReq;
import cn.common.req.HealthArchivesUpdateReq;
import cn.common.req.base.BaseDeleteReq;
import cn.common.interaction.resp.base.ApiResponse;
import cn.common.interaction.resp.page.Pagination;
import cn.common.resp.HealthArchivesResp;
import cn.common.service.HealthArchivesService;
import cn.common.common.anon.ApiLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
* @author Singer create by Singer email:singer-coder@qq.com
* @packageName cn.common.api.controller
* @Description: 健康档案表信息前端控制器
* @date 2021-04-23
*/
@RestController
@RequestMapping(value = "api/v1/healthArchives")
@Slf4j
public class HealthArchivesController extends BaseApiController {

    @Resource
    private HealthArchivesService healthArchivesService;

    @Resource
    private HttpServletResponse response;

    /**
     * 新增健康档案表信息
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2021/2/15
     * @param addReq 新增Req
     */
    @PostMapping(value = "/addItem")
    @ApiLog(value = "新增信息")
    @RequiresPermissions("healthArchives:add")
    public ApiResponse addItem(@RequestBody @Valid HealthArchivesAddReq addReq){
        healthArchivesService.addItem(addReq);
        return apiResponse();
    }

    /**
     * 数据导入
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2022/3/21
     * @param file 文件
     * @return
    */
    @PostMapping(value = "/importData")
    @ApiLog(value = "数据导入")
    public ApiResponse importData(@RequestParam("file") MultipartFile file){
        healthArchivesService.importData(file);
        return apiResponse();
    }

    /**
     * 导出健康档案表信息数据
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2022/3/21
     * @param pageReq
     * @return java.util.List
    */
    @PostMapping(value = "/exportData")
    @ApiLog(value = "健康档案表信息数据导出")
    public void exportData(@RequestBody(required = false) @Valid HealthArchivesReq pageReq){
        healthArchivesService.exportData(pageReq);
    }

    /**
     * 主键ID集合批量删除健康档案表信息
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2021/2/2
     * @param req 需要被删除的信息
     */
    @PostMapping(value = "/batchDeleteItem")
    @ApiLog(value = "根据主键ID集合批量删除")
    @RequiresPermissions("healthArchives:batchDelete")
    public ApiResponse batchDeleteItem(@RequestBody BaseDeleteReq req){
        healthArchivesService.batchDeleteItem(req);
        return apiResponse();
    }

    /**
     * 更新健康档案表信息
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2021/4/2
     * @param updateReq 更新请求参数
     */
    @PutMapping(value = "/updateItem")
    @ApiLog(value = "更新信息")
    @RequiresPermissions("healthArchives:edit")
    public ApiResponse updateItem(@RequestBody @Valid HealthArchivesUpdateReq updateReq){
        healthArchivesService.updateItem(updateReq);
        return apiResponse();
    }

    /**
     * 查询所有健康档案表信息信息
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2022/3/13
     * @param
     * @return java.util.List
     */
    @GetMapping(value = "/queryAllHealthArchives")
    @ApiLog(value = "查询所有信息")
    public ApiResponse<List<HealthArchivesResp>> queryAllHealthArchives(){
        return apiResponse(healthArchivesService.queryAllHealthArchives());
    }

    /**
     * 分页查询健康档案表信息
     * @author: create by singer - Singer email:singer-coder@qq.com
     * @date 2021/2/15
     * @param  pageReq 分页查询Req
     * @return Pagination
     */
    @PostMapping(value = "/queryByPage")
    @ApiLog(value = "分页查询信息")
    @RequiresPermissions("healthArchives:itemList")
    public ApiResponse<Pagination<HealthArchivesResp>> queryByPage(
        @RequestBody @Valid HealthArchivesReq pageReq){
        return apiResponse(healthArchivesService.queryByPage(pageReq));
    }
}
