package com.yihu.jw.dict.service;

import com.yihu.jw.dict.dao.PrivateDictDao;
import com.yihu.jw.entity.hospital.dict.PrivateDictDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import com.yihu.jw.hospital.message.dao.BaseBannerDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrivateDictService extends BaseJpaService<PrivateDictDO, PrivateDictDao> {
    @Autowired
    private PrivateDictDao privateDictDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    //查找隐私策略
    public List<PrivateDictDO> findByHospitalCodeAndDictCode(String dictCode){
        return privateDictDao.findByDictCodeAndIsDel(dictCode);
        /*if (StringUtils.isNotBlank(dictCode)){
            return privateDictDao.findoneByCode(dictCode);
        }else {
            return privateDictDao.findALL();
        }*/
    }
    //添加隐私策略
    public MixEnvelop addPrivateDict(String id,String dictCode,String dictName, String dictValue,String hospitalCode,String hospitalName,String imgUrl){
        PrivateDictDO  privateDictDO = new PrivateDictDO();
        MixEnvelop mixEnvelop = new MixEnvelop();
        if (StringUtils.isNotBlank(id)){
            privateDictDO = privateDictDao.findOne(id);
        }
        if (StringUtils.isNotBlank(dictCode)){
            privateDictDO.setDictCode(dictCode);
            privateDictDO.setDictValue(dictValue);
            privateDictDO.setDictName(dictName);
            privateDictDO.setIsDel(1);
            privateDictDO.setHospitalCode(hospitalCode);
            privateDictDO.setHospitalName(hospitalName);
            privateDictDO.setImgUrl(imgUrl);
            privateDictDao.save(privateDictDO);
            mixEnvelop.setMessage("success");
            mixEnvelop.setStatus(200);
        }else{
            mixEnvelop.setMessage("隐私政策code不能为空");
            mixEnvelop.setStatus(-1);
        }
        return mixEnvelop;
    }
    //删除隐私政策
    public MixEnvelop deleteById(String id){
        PrivateDictDO  privateDictDO = privateDictDao.findOne(id);
        MixEnvelop mixEnvelop = new MixEnvelop();
        if (null!=privateDictDO){
            privateDictDao.delete(id);
            mixEnvelop.setStatus(200);
            mixEnvelop.setMessage("删除成功");
        }else {
            mixEnvelop.setStatus(-1);
            mixEnvelop.setMessage("删除失败");
        }
        return mixEnvelop;
    }
}
