package com.saye.hospitalgd.service.impl;

import com.saye.hospitalgd.commons.date.DateDUtil;
import com.saye.hospitalgd.commons.string.StringDUtil;
import com.saye.hospitalgd.mapper.OperatorMapper;
import com.saye.hospitalgd.service.OperatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * @author thuang
 * @version 1.0
 * @description: TODO
 * @date 2021/9/29 14:55
 */
@Service
@Transactional
public class OperatorServiceImpl implements OperatorService {

    @Autowired
    private OperatorMapper operatorMapper;

    @Override
    public List<HashMap<Object, Object>> findAllOperator(HashMap<Object, Object> map) throws Exception {
        return operatorMapper.findAllOperator(map);
    }

    @Override
    public void addOperator(HashMap<Object, Object> map) throws Exception {
        String hisOperCode = StringDUtil.changeNullToEmpty(map.get("hisOperCode"));

        //先查询是否已有
        List<HashMap<Object,Object>> list = operatorMapper.findAllOperatorByCode(map);
        //有更新，没有添加
        map.put("is_active","1");
        map.put("modify_time", DateDUtil.getCurrentDate(DateDUtil.yyyy_MM_dd_HH_mm_ss));

        if (list.size()>0){
            operatorMapper.updateOperatorByCode(map);
        }else {
            operatorMapper.addOperator(map);
        }
    }

    @Override
    public void modifyOperator(HashMap<Object, Object> map) throws Exception {
        map.put("modify_time", DateDUtil.getCurrentDate(DateDUtil.yyyy_MM_dd_HH_mm_ss));
        operatorMapper.updateOperatorByCode(map);
    }

    @Override
    public void deleteOperator(HashMap<Object, Object> map) throws Exception {
        map.put("is_active","0");
        map.put("modify_time", DateDUtil.getCurrentDate(DateDUtil.yyyy_MM_dd_HH_mm_ss));
        operatorMapper.updateOperatorByCode(map);
    }
}
