package com.huimv.receive.controller;


import com.huimv.receive.common.utils.PdfUtil;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.service.IBillIsolateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 隔离 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/bill-isolate")
@CrossOrigin
public class BillIsolateController {
    @Autowired
    private IBillIsolateService billIsolateService;

    @PostMapping("/listPersonalIsolate")
    public Result listPersonalIsolate(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap){
        return billIsolateService.listPersonalIsolate(httpServletRequest,paramsMap);
    }

    @PostMapping("/getDetail")
    public Result getDetail(@RequestBody Map<String, String> paramsMap){
        return new Result(ResultCode.SUCCESS,billIsolateService.getById(paramsMap.get("id")));
    }

    //后台
    @PostMapping("/isolateList")
    public Result isolateList(HttpServletRequest httpServletRequest,@RequestBody Map<String, String> paramsMap){
        return billIsolateService.Isolate(httpServletRequest, paramsMap);
    }

    @PostMapping("/isolateSelect")
    public Result isolateSelect(HttpServletRequest httpServletRequest,@RequestBody Map<String, String> paramsMap){
        return billIsolateService.IsolateSelect(httpServletRequest, paramsMap);
    }

    @PostMapping("/delete")
    public Result delete(HttpServletRequest httpServletRequest,@RequestBody Map<String, String> paramsMap){
        String ids = paramsMap.get("ids");
        String[] split = ids.split(",");
        for (String s : split) {
            billIsolateService.removeById(s);
        }
        return new Result(10000,"删除成功！",true);
    }

    @GetMapping("/printIsolate")
    public void printIsolate(HttpServletResponse response, @RequestParam(name = "ids") String ids) throws Exception {
        Map<String, String> map = new HashMap<>();
        map.put("ids", ids);
        billIsolateService.printIsolate(response, map);
        String path = "/opt/huatong/isolate.xls";
        PdfUtil.returnPdfStream3(response, path, "隔离详情列表");
    }

}
