package com.gyee.frame.service;

import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.mapper.auto.PartBjCountMapper;
import com.gyee.frame.model.auto.PartBjCount;
import com.gyee.frame.model.auto.PartBjCountExample;
import com.gyee.frame.model.custom.PartbjcountVo;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * PartBjCountService
 *
 * @author gyee_自动生成
 * @Title: PartBjCountService.java 
 * @Package com.gyee.frame.service 
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class PartBjCountService implements BaseService<PartBjCount, PartBjCountExample> {
    @Resource
    private PartBjCountMapper partBjCountMapper;


    @Override
    public int deleteByPrimaryKey(String ids) {

        return -1;

    }


    @Override
    public PartBjCount selectByPrimaryKey(String id) {

        return new PartBjCount();

    }


    @Override
    public int updateByPrimaryKeySelective(PartBjCount record) {
        return -1;
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(PartBjCount record) {


        return partBjCountMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(PartBjCount record, PartBjCountExample example) {

        return partBjCountMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(PartBjCount record, PartBjCountExample example) {

        return partBjCountMapper.updateByExample(record, example);
    }

    @Override
    public List<PartBjCount> selectByExample(PartBjCountExample example) {

        return partBjCountMapper.selectByExample(example);
    }


    @Override
    public long countByExample(PartBjCountExample example) {

        return partBjCountMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(PartBjCountExample example) {

        return partBjCountMapper.deleteByExample(example);
    }

    public List<PartbjcountVo> getPartBjCountList(Date recorddate) {

        List<PartbjcountVo> vos = new ArrayList<>();
        PartBjCountExample example = new PartBjCountExample();

        example.setDistinct(true);
        PartBjCountExample.Criteria criteria = example.createCriteria();
        if (StringUtils.notEmp(recorddate)) {
            Date endDate = DateUtils.addDays(recorddate, 1);
            criteria.andRecodedateGreaterThanOrEqualTo(recorddate).andRecodedateGreaterThan(endDate);

        }

        List<PartBjCount> list = partBjCountMapper.selectByExample(example);

        if (!list.isEmpty()) {
            for (PartBjCount po : list) {
                PartbjcountVo vo = new PartbjcountVo();
                vo.setId(po.getId());
                vo.setLnid(po.getLnid());
                vo.setPart(po.getPart());
                vo.setDate(po.getRecodedate());
                vo.setPartname(getPartnamebyid(po.getPart()));
                if(InitialRunner.lnmap.containsKey(po.getLnid()))
                {
                    vo.setLnname(InitialRunner.lnmap.get(po.getLnid()).getName());
                }

                vos.add(vo);
            }

        }

        return vos;
    }

    private String getPartnamebyid(String part) {
        if (part.equals("ZK")) {
            return "主控";
        } else if (part.equals("FDJ")) {
            return "发电机";
        } else if (part.equals("ZZ")) {
            return "主轴";
        } else if (part.equals("CLX")) {
            return "齿轮箱";
        } else {
            return "机舱";
        }

    }
}