package org.jeecg.modules.fbsDispatchLists.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.fbsDispatchLists.entity.FbsDispatchLists;
import org.jeecg.modules.fbsDispatchLists.mapper.FbsDispatchListsMapper;
import org.jeecg.modules.fbsDispatchLists.service.IFbsDispatchListsService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 销售发货退货单主表（表题）
 * @author： jeecg-boot
 * @date：   2020-10-22
 * @version： V1.0
 */
@Service
@DS("multi-datasource1")
public class FbsDispatchListsServiceImpl extends ServiceImpl<FbsDispatchListsMapper, FbsDispatchLists> implements IFbsDispatchListsService {

    @Resource
    FbsDispatchListsMapper fbsDispatchListsMapper;

    @Override
    public Map<String, Object> getProjectDelivery() {
        List<FbsDispatchLists> fbsDispatchListsList=fbsDispatchListsMapper.getProjectDelivery();
        Map<String, Object> map=new HashMap<>();
        if(fbsDispatchListsList!=null){
            for(FbsDispatchLists fbsDispatchLists:fbsDispatchListsList){
                if(StringUtils.isBlank(fbsDispatchLists.getCitemname())){
                    fbsDispatchLists.setCitemname("空");
                }
//                if(fbsDispatchLists.getCitemname().length())
//                fbsDispatchLists.setCitemname(fbsDispatchLists.getCitemname().substring(1,5)+"...");
                map.put(fbsDispatchLists.getCitemname(),fbsDispatchLists.getIquantity());
            }
        }
        return map;
    }

    @Override
    public Map<String, Object> getMonthSendByProject() {

        List<FbsDispatchLists> fbsDispatchListsList=fbsDispatchListsMapper.getMonthSendByProject();
        Map<String,Object> map=new LinkedHashMap<>();
        String[] moths=new String[]{"01","02","03","04","05","06","07","08","09","10","11","12"};
        //根据月份获取每个月数据
        if(fbsDispatchListsList!=null){
            for(String month:moths){
                boolean ismonth=false;
                for(FbsDispatchLists fbsDispatchLists:fbsDispatchListsList){
                    if(StringUtils.isNotBlank(fbsDispatchLists.getMonths())){
                        if(month.equals(fbsDispatchLists.getMonths())){
                            map.put(month+"月",fbsDispatchLists.getItemCount());
                            ismonth=true;
                        }
                    }
                }
                if(ismonth==false){
                    map.put(month+"月","0");
                }
            }
        }

        return map;
    }
}
