package com.prolog.cs.biz.outbound.service.impl;

import com.prolog.cs.biz.outbound.Application;
import com.prolog.cs.biz.outbound.dao.WaveBillMapper;
import com.prolog.cs.biz.outbound.model.entity.WaveBillDO;
import com.prolog.framework.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 基础测试类
 *
 * @author stylefeng
 * @Date 2017/5/21 16:10
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
@Slf4j
//@Transactional //打开的话测试之后数据可自动回滚
public class WorkStageJunit {

    @Autowired
    WebApplicationContext webApplicationContext;
    @Autowired
    PickTaskAppServiceImpl PickTaskAppServiceImpl;
    @Autowired
    WorkStageServiceImpl WorkStageServiceImpl;

    protected MockMvc mockMvc;

    @Autowired
    private WaveBillMapper billMapper;
    
    @Before
    public void setupMockMvc(){
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Before
    public void initDatabase(){
    }

    private static Logger logger = LoggerFactory.getLogger(WorkStageJunit.class);
    
    @Test
    public void calculusWorkspaces() throws Exception {
        Map<String, BigDecimal> numberByBuilding = new HashMap<>();
        //numberByBuilding.put("646346682396708864",new BigDecimal(5));
        numberByBuilding.put("003",new BigDecimal(78));
        String billGroupId="ZHYZFT000001";
        billGroupId="ZHYZFT000008";
        //billGroupId="ZHYZFT000006";
        List<WaveBillDO> waveBillDOS = billMapper.findByMap(MapUtils.put("billGroupId", billGroupId).getMap(), WaveBillDO.class);
        WaveBillDO billDO = waveBillDOS.get(0);
        WorkStageServiceImpl.calculusWorkspaces(billDO.getWaveId(),billGroupId,numberByBuilding,5,10);
    }

    public static void main(String[] args) {
//        List list= Arrays.asList(new Integer[]{1,2,3,4});
//        list.forEach(x -> {
//            if((Integer) x==2){
//                return;
//            }
//            System.out.println(x);
//        });

        System.out.println(new BigDecimal(51).divide(new BigDecimal(10),0,BigDecimal.ROUND_UP));
    }
}
