package com.steerinfo.ems.emsprodplanyear.service.impl;

import com.steerinfo.ems.emsprodplanyear.mapper.EmsProdplanYearMapper;
import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
import com.steerinfo.ems.emsprodplanyear.service.IEmsProdplanYearService;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * EmsProdplanYear服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2021-06-26 08:40
 * 类描述
 * 修订历史：
 * 日期：2021-06-26
 * 作者：generator
 * 参考：
 * 描述：EmsProdplanYear服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "emsProdplanYearService")
public class EmsProdplanYearServiceImpl extends BaseServiceImpl<EmsProdplanYear, String> implements IEmsProdplanYearService {

    @Autowired
    private EmsProdplanYearMapper emsProdplanYearMapper;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

    @Override
    protected IBaseMapper<EmsProdplanYear, String> getMapper() {
        return emsProdplanYearMapper;
    }

//    @Override
//    public PageList<Map<String, Object>> getDateEditForPage(HashMap<String, Object> parmas, Integer pageNum,
//                                                            Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<Map<String, Object>> rows = emsProdplanYearMapper.getDateEdit(parmas);
//        PageList<Map<String, Object>> pageInfo = new PageList<Map<String, Object>>(rows);
//        return pageInfo;
//    }

//    @Override
//    public PageList<Map<String, Object>> getDateEditForPage(HashMap<String, Object> parmas, Integer pageNum, Integer pageSize) {
//        return null;
//    }

    @Override
    public List<Map<String, Object>> getDateForProduct(HashMap<String, Object> parmas) {
        return emsProdplanYearMapper.getDateForProduct(parmas);
    }

    @Override
    public int getDaysOfMonth(String date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sdf.parse(date));
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    @Override
    public int getDaysOfMonth(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    @Override
    public int[] avgWeight(Integer sumWeight, Integer day){
        int[] weightArr = new int[day];
       Integer avgWeight = sumWeight / day;
        for(int i = 0;i<day-1;i++){
            weightArr[i] = avgWeight;
        }
        weightArr[day-1] =sumWeight - (avgWeight * ( day - 1));
        return weightArr;
    }
}
