 package com.huimv.management.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huimv.management.entity.dto.DiseaseDto;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huimv.management.entity.HealthMedicalRecordEntity;
import com.huimv.management.service.HealthMedicalRecordService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 
 *
 * @author yinhao
 * @email yinhao@163.com
 * @date 2021-06-10 09:44:06
 */
@Api(tags = "病历档案表")
@RestController
@RequestMapping("management/healthmedicalrecord")
public class HealthMedicalRecordController {
    @Autowired
    private HealthMedicalRecordService healthMedicalRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = healthMedicalRecordService.queryPage(params);

        return R.ok().put("page", page);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		HealthMedicalRecordEntity healthMedicalRecord = healthMedicalRecordService.getById(id);

        return R.ok().put("healthMedicalRecord", healthMedicalRecord);
    }




    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HealthMedicalRecordEntity healthMedicalRecord){
		healthMedicalRecordService.save(healthMedicalRecord);

        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HealthMedicalRecordEntity healthMedicalRecord){
		healthMedicalRecordService.updateById(healthMedicalRecord);

        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		healthMedicalRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 查询全部
     */
    @RequestMapping("/findAll")
    public R findAll(Integer formFarmId){
        LambdaQueryWrapper<HealthMedicalRecordEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(HealthMedicalRecordEntity::getFarmId,formFarmId);

        return R.ok().put("all",healthMedicalRecordService.list(wrapper));
    }

    //疾病统计，隔离统计，治疗结果，疫苗记录
    @RequestMapping("/diseaseCount")
    public R diseaseCount(@RequestParam Map<String, Object> params){
        String type = (String)params.get("type");
        String farmId = (String)params.get("formFarmId");
        if (type == null || "".equals(type)){
            R.error("请选择时间");
        }
        if (farmId == null || "".equals(farmId)){
            R.error("请选择牧场");
        }

        Map<String, Object> map  = healthMedicalRecordService.diseaseCount(type,farmId);
        return R.ok().put("data",map);
    }

}
