package com.huimv.admin.service.impl;

import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.WriteProtData;
import com.huimv.admin.entity.vo.WriteProtDataVo2;
import com.huimv.admin.entity.vo.WriteProtVo2;
import com.huimv.admin.mapper.WriteProtDataMapper;
import com.huimv.admin.service.IWriteProtDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 环保排水监测填报 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-11-17
 */
@Service
public class WriteProtDataServiceImpl extends ServiceImpl<WriteProtDataMapper, WriteProtData> implements IWriteProtDataService {

    @Autowired
    private WriteProtDataMapper protDataMapper;

    @Override
    public Result add(HttpServletRequest httpServletRequest, WriteProtData writeProtData) {
        return new Result(ResultCode.SUCCESS, protDataMapper.insert(writeProtData));
    }

    @Override
    public Result addList(HttpServletRequest httpServletRequest, WriteProtDataVo2 writeProtDataVo2) {
        String farmId = writeProtDataVo2.getFarmId();
        WriteProtData protData = writeProtDataVo2.getDeal();
        protData.setFarmId(Integer.parseInt(farmId));
        protData.setCreateDate(new Date());
        protDataMapper.insert(protData);
        WriteProtData protData1 = writeProtDataVo2.getIn();
        protData1.setFarmId(Integer.parseInt(farmId));
        protData1.setCreateDate(new Date());
        protDataMapper.insert(protData1);
        WriteProtData protData2 = writeProtDataVo2.getOut();
        protData2.setFarmId(Integer.parseInt(farmId));
        protData2.setCreateDate(new Date());
        protDataMapper.insert(protData2);

//        WriteProtVo2 deal = writeProtDataVo2.getDeal();
//        WriteProtData writeProtData = new WriteProtData();
//        writeProtData.setCod(deal.getCod());
//        writeProtData.setFarmId(Integer.parseInt(farmId));
//        writeProtData.setFlow(deal.getFlow());
//        writeProtData.setNh3n(deal.getNh3n());
//        writeProtData.setPh(deal.getPh());
//        writeProtData.setTn(deal.getTn());
//        writeProtData.setTp(deal.getTp());
//        writeProtData.setType(deal.getType());
//        writeProtData.setCreateDate(new Date());
//        WriteProtVo2 in = writeProtDataVo2.getIn();
//        WriteProtData writeProtData1 = new WriteProtData();
//        writeProtData1.setCod(in.getCod());
//        writeProtData1.setFarmId(Integer.parseInt(farmId));
//        writeProtData1.setFlow(in.getFlow());
//        writeProtData1.setNh3n(in.getNh3n());
//        writeProtData1.setPh(in.getPh());
//        writeProtData1.setTn(in.getTn());
//        writeProtData1.setTp(in.getTp());
//        writeProtData1.setType(in.getType());
//        writeProtData1.setCreateDate(new Date());
//        WriteProtVo2 out = writeProtDataVo2.getOut();
//        WriteProtData writeProtData2 = new WriteProtData();
//        writeProtData2.setCod(out.getCod());
//        writeProtData2.setFarmId(Integer.parseInt(farmId));
//        writeProtData2.setFlow(out.getFlow());
//        writeProtData2.setNh3n(out.getNh3n());
//        writeProtData2.setPh(out.getPh());
//        writeProtData2.setTn(out.getTn());
//        writeProtData2.setTp(out.getTp());
//        writeProtData2.setType(out.getType());
//        writeProtData2.setCreateDate(new Date());
//        protDataMapper.insert(writeProtData);
//        protDataMapper.insert(writeProtData1);
//        protDataMapper.insert(writeProtData2);
        return new Result(ResultCode.SUCCESS);
    }

}
