/**
 * Copyright (C), 2015-2019
 * Author:   HJL
 * Date:     2019/7/19 15:32
 * Description:缺陷分类
 */
package com.emr.controller;

import com.emr.entity.Emr_Fault_Type;
import com.emr.entity.Emr_Fault_Vo;
import com.emr.service.Emr_Fault_TypeService;
import com.emr.util.IDHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/faultType")
public class faultTypeController {
    @Autowired
    private Emr_Fault_TypeService emrFaultTypeService;

    @RequestMapping(value = "/faultTypes")
    public String faultTypes(Model model) {
        return "faultTypeDir/faultTypeList";
    }

    @ResponseBody
    @RequestMapping(value = "/faultTypeList")
    public List<Emr_Fault_Type> faultTypeList(HttpServletRequest request, HttpServletResponse response, Emr_Fault_Type emrFaultType) {
        List<Emr_Fault_Type> list = emrFaultTypeService.selectByCol(emrFaultType);
        return list;
    }

    @ResponseBody
    @RequestMapping(value = "/updateByClo")
    public int updateByClo(HttpServletRequest request, HttpServletResponse response, Emr_Fault_Type emrFaultType) throws Exception{
        int bol=0;
        //判断id是否存在
        if(emrFaultType.getId()!=null){
        //判断是否存在记录
            if (emrFaultTypeService.selectById(emrFaultType.getId()) != null) {
                 bol = emrFaultTypeService.updateByClo(emrFaultType);
            }
        }else{
            //不存在则添加缺陷类别记录
            //查询id最大的数据，取id+1作为新id的值
            Emr_Fault_Type emrFaultTypeNew=emrFaultTypeService.selectByColDesc();
            emrFaultType.setId(emrFaultTypeNew.getId()+1);
           bol= emrFaultTypeService.insertClo(emrFaultType);
        }
       return bol;

    }


    @ResponseBody
    @RequestMapping(value = "/delById")
    public int delById(HttpServletRequest request, HttpServletResponse response,Integer id) {
        int bol = 0;
        //判断id是否存在
        if (id!= null) {
            //判断是否存在记录
            bol = emrFaultTypeService.delById(id);
        }
        return bol;

    }
}
 

