package cn.com.qmth.stmms.ms.marking.exporter;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import cn.com.qmth.stmms.ms.commons.utils.excel.ExportUtils;
import cn.com.qmth.stmms.ms.marking.assembler.MarkerAssembler;
import cn.com.qmth.stmms.ms.marking.dto.MarkerDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.com.qmth.stmms.ms.core.domain.user.Role;
import cn.com.qmth.stmms.ms.core.repository.MarkUserRepo;

/**
 * 
 * @Description: 科组长API
 * @author ting.yin
 * @date 2016年10月21日
 */
@RestController
@RequestMapping("export/markleaders")
public class MakrLeaderExporter {

    @Autowired
    private MarkUserRepo markUserRepo;
    
	@Autowired
	private MarkerAssembler markerAssembler;

    @RequestMapping(method = RequestMethod.GET)
    public void list(@RequestParam Long workId,HttpServletResponse response){
    	List<MarkerDTO> markUsers = new ArrayList<>();
    	markUserRepo.findByWorkIdAndRole(workId,Role.MARK_LEADER).forEach(m -> {
    		markUsers.add(markerAssembler.toDTO(m));
        });
    	ExportUtils.exportEXCEL("科组长列表", MarkerDTO.class, markUsers, response);
    }
    
}
