package com.yihu.jw.base.service.clientSearch;


import com.yihu.jw.base.dao.searchClient.BaseSearchNoveltyRepeatDao;
import com.yihu.jw.entity.base.searchClient.BaseSearchNoveltyRepeatDO;

import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * Created by wsy on 2021/9/4.
 */
@Service
public class ClientSearchService extends BaseJpaService<BaseSearchNoveltyRepeatDO,BaseSearchNoveltyRepeatDao>{

    @Autowired
    private BaseSearchNoveltyRepeatDao baseSearchNoveltyRepeatDao;

    public BaseSearchNoveltyRepeatDO saveBaseSearchNoveltyRepeat(BaseSearchNoveltyRepeatDO baseSearchNoveltyRepeatDO){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
        Date date = new Date();
        Random r = new Random();
        //获取随机数
        int number = r.nextInt();
        baseSearchNoveltyRepeatDO.setNumber(Integer.toString(number).replace("-",""));
        baseSearchNoveltyRepeatDO.setStatus(1);
        baseSearchNoveltyRepeatDO.setStatusName("待接收");
        baseSearchNoveltyRepeatDO.setCreateTime(new Date());
        baseSearchNoveltyRepeatDO.setShowType("1");       //默认值是1，显示
        return baseSearchNoveltyRepeatDao.save(baseSearchNoveltyRepeatDO);
    }


    public void deleteByid(String id) {
        if (baseSearchNoveltyRepeatDao.findOne(id)!=null) {
            baseSearchNoveltyRepeatDao.delete(id);
        }

    }

    public List<BaseSearchNoveltyRepeatDO> findBySearchData(String searchData) {
        List list = new ArrayList();
        list = baseSearchNoveltyRepeatDao.findBySearchData(searchData);
        baseSearchNoveltyRepeatDao.findAll();
        return list;
    }


    public void updateById(String id, Integer status) {
        BaseSearchNoveltyRepeatDO baseSearchNoveltyRepeatDO = baseSearchNoveltyRepeatDao.findOne(id);


        if (baseSearchNoveltyRepeatDO != null){
            if(status == 1){
                baseSearchNoveltyRepeatDO.setStatusName("待接收");
            }
            if(status == 2){
                baseSearchNoveltyRepeatDO.setStatusName("办理中");
            }
            if(status == 3){
                baseSearchNoveltyRepeatDO.setStatusName("已退回");
            }
            if(status == 4){
                baseSearchNoveltyRepeatDO.setStatusName("已办结");
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
            Date date = new Date();
           /* baseSearchNoveltyRepeatDO.setUpdate_time(sdf.format(date));*/
            baseSearchNoveltyRepeatDO.setUpdateTime(new Date());
            baseSearchNoveltyRepeatDO.setStatus(status);
            baseSearchNoveltyRepeatDao.save(baseSearchNoveltyRepeatDO);
        }
    }

    public void updateReply(String id, String reply,String updataUser) {
        BaseSearchNoveltyRepeatDO baseSearchNoveltyRepeatDO = baseSearchNoveltyRepeatDao.findOne(id);
        if (baseSearchNoveltyRepeatDO != null){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
            Date date = new Date();
           /* baseSearchNoveltyRepeatDO.setUpdate_time(sdf.format(date));*/
            baseSearchNoveltyRepeatDO.setUpdateTime(new Date());
            baseSearchNoveltyRepeatDO.setReversion(reply);
            baseSearchNoveltyRepeatDO.setUpdateUserName(updataUser);
            baseSearchNoveltyRepeatDao.save(baseSearchNoveltyRepeatDO);
        }
    }

    public BaseSearchNoveltyRepeatDO findFileById(String id){
        BaseSearchNoveltyRepeatDO baseSearchNoveltyRepeatDO = new BaseSearchNoveltyRepeatDO();
        baseSearchNoveltyRepeatDO = baseSearchNoveltyRepeatDao.findOne(id);
        return baseSearchNoveltyRepeatDO;
    }

    public void updataShowType(String id,String showType) {
        BaseSearchNoveltyRepeatDO baseSearchNoveltyRepeatDO = baseSearchNoveltyRepeatDao.findOne(id);
        if (baseSearchNoveltyRepeatDO != null){
            baseSearchNoveltyRepeatDO.setShowType(showType);
            baseSearchNoveltyRepeatDao.save(baseSearchNoveltyRepeatDO);
        }
    }
}
