package com.huimv.admin.controller;


import cn.hutool.core.util.ObjectUtil;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.BillClean;
import com.huimv.admin.entity.BillDry;
import com.huimv.admin.service.IBillCleanService;
import com.huimv.admin.service.IBillDryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.service.IBillCleanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Map;

/**
 * <p>
 * 洗消表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/bill-clean")
@CrossOrigin
public class BillCleanController {
    @Autowired
    private IBillCleanService billCleanService;
    @Autowired
    private IBillDryService billDryService;

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

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

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

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

    @PostMapping("/getCleanAndDryDetail")
    public Result getCleanAndDryDetail(@RequestBody Map<String, String> paramsMap){
        String type = paramsMap.get("type");
        if (type.equals("1")){
            BillClean billClean = billCleanService.getById(paramsMap.get("id"));
            if (ObjectUtil.isEmpty(billClean.getImgUrl())){
                billClean.setImgUrl("");
            }
            return new Result(ResultCode.SUCCESS, billClean);
        }else {
            BillDry billDry = billDryService.getById(paramsMap.get("id"));
            if (ObjectUtil.isEmpty(billDry.getImgUrl())){
                billDry.setImgUrl("");
            }
            return new Result(ResultCode.SUCCESS, billDry);
        }

    }

    @Autowired
    private IBillCleanService cleanService;

    @RequestMapping("/listClean")
    public Result listClean(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return cleanService.listAll(httpServletRequest, paramsMap);
    }
    @RequestMapping("/listById")
    public Result listById(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return cleanService.listById(httpServletRequest, paramsMap);
    }

    @RequestMapping("/listByIdCar")
    public Result listByIdDry(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return cleanService.listByIdDry(httpServletRequest, paramsMap);
    }
    @RequestMapping("/editClean")
    public Result editClean(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) throws ParseException {
        return cleanService.commitClean(httpServletRequest, paramsMap);
    }
    @PostMapping("/carCommit")
    public Result addAdmission(HttpServletRequest httpServletRequest, @RequestParam("id") String id,
                               @RequestParam("data") String data,
                               @RequestParam(value = "img1",required = false) MultipartFile img1,
                               @RequestParam(value = "img2",required = false) MultipartFile img2,
                               @RequestParam(value = "img3",required = false) MultipartFile img3,
                               @RequestParam(value = "img4",required = false) MultipartFile img4,
                               @RequestParam(value = "img5",required = false) MultipartFile img5,
                               @RequestParam("farmId") String farmId,
                               @RequestParam("type") String type) throws IOException, ParseException {
        return cleanService.carClean(httpServletRequest, farmId, id, data, img1, img2, img3, img4, img5,type);
    }

    @PostMapping("/goodsCarClean")
    public Result goodsCarClean(HttpServletRequest httpServletRequest, @RequestParam("id") String id,
                               @RequestParam("data") String data,
                               @RequestParam(value = "img1",required = false) MultipartFile img1,
                               @RequestParam(value = "img2",required = false) MultipartFile img2,
                               @RequestParam(value = "img3",required = false) MultipartFile img3,
                               @RequestParam(value = "img4",required = false) MultipartFile img4,
                               @RequestParam(value = "img5",required = false) MultipartFile img5,
                               @RequestParam("farmId") String farmId,
                               @RequestParam("type") String type,
                                @RequestParam("result") String result) throws IOException, ParseException {
        return cleanService.goodsCarClean(httpServletRequest, farmId, id, data, img1, img2, img3, img4, img5,type,result);
    }
}
