|  | @@ -11,16 +11,22 @@ import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  | +import com.ym.mec.util.excel.POIUtil;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.security.access.prepost.PreAuthorize;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.GetMapping;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.RequestMapping;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  | +import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.io.OutputStream;
 | 
	
		
			
				|  |  |  import java.util.Arrays;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Api(tags = "经营报表服务")
 | 
	
	
		
			
				|  | @@ -37,7 +43,7 @@ public class OperatingReportController extends BaseController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("报表列表")
 | 
	
		
			
				|  |  |      @GetMapping(value = "/queryPage")
 | 
	
		
			
				|  |  | -    @PreAuthorize("@pcs.hasPermissions('sellOrder/queryPage')")
 | 
	
		
			
				|  |  | +    @PreAuthorize("@pcs.hasPermissions('operatingReport/queryPage')")
 | 
	
		
			
				|  |  |      public HttpResponseResult<PageInfo<OperatingReport>> queryPage(OperatingReportQueryInfo queryInfo) {
 | 
	
		
			
				|  |  |          SysUser sysUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  |          if (sysUser == null) {
 | 
	
	
		
			
				|  | @@ -62,4 +68,60 @@ public class OperatingReportController extends BaseController {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return succeed(operatingReportService.queryPage(queryInfo));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation(value = "经营报表导出")
 | 
	
		
			
				|  |  | +    @GetMapping("operatingReport/export")
 | 
	
		
			
				|  |  | +    @PreAuthorize("@pcs.hasPermissions('operatingReport/export')")
 | 
	
		
			
				|  |  | +    public void operatingReport(OperatingReportQueryInfo queryInfo, HttpServletResponse response) throws IOException {
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  | +        if (sysUser == null) {
 | 
	
		
			
				|  |  | +            throw new IOException("用户信息获取失败");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!sysUser.getIsSuperAdmin()) {
 | 
	
		
			
				|  |  | +            Employee employee = employeeDao.get(sysUser.getId());
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(queryInfo.getOrganIdList())) {
 | 
	
		
			
				|  |  | +                queryInfo.setOrganIdList(employee.getOrganIdList());
 | 
	
		
			
				|  |  | +            } else if (StringUtils.isEmpty(employee.getOrganIdList())) {
 | 
	
		
			
				|  |  | +                throw new IOException("用户所在分部异常");
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
 | 
	
		
			
				|  |  | +                if (!list.containsAll(Arrays.asList(queryInfo.getOrganIdList().split(",")))) {
 | 
	
		
			
				|  |  | +                    throw new IOException("非法请求");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        queryInfo.setRows(65000);
 | 
	
		
			
				|  |  | +        PageInfo<OperatingReport> pageList = operatingReportService.queryPage(queryInfo);
 | 
	
		
			
				|  |  | +        if (pageList.getTotal() <= 0) {
 | 
	
		
			
				|  |  | +            response.setStatus(200);
 | 
	
		
			
				|  |  | +            response.setContentType("Content-Type: application/json;charset=UTF-8");
 | 
	
		
			
				|  |  | +            response.getOutputStream().write("{\"data\": null, \"code\": 500, \"status\": false, \"msg\": \"没有可导出的记录\"}".getBytes());
 | 
	
		
			
				|  |  | +            response.flushBuffer();
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        OutputStream outputStream = response.getOutputStream();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            String[] header = {"分部","学校","销售收入(元)","服务收入(元)","业务退费(元)","收入合计(元)","销售成本(元)","固定支出(元)", "变动支出(元)", "分摊费用(元)", "成本费用合计(元)", "利润(元)"};
 | 
	
		
			
				|  |  | +            String[] body = {"organName", "schoolName", "sellAmount", "serviceAmount", "refundAmount", "incomeTotal", "sellCost","expensesAmount","variableCost","distributionAmount","costAmount","profit"};
 | 
	
		
			
				|  |  | +            HSSFWorkbook workbook = POIUtil.exportExcel(header, body, pageList.getRows());
 | 
	
		
			
				|  |  | +            response.setContentType("application/octet-stream");
 | 
	
		
			
				|  |  | +            response.setHeader("Content-Disposition", "attachment;filename=cooperationOrgan-" + DateUtil.getDate(new Date()) + ".xls");
 | 
	
		
			
				|  |  | +            response.flushBuffer();
 | 
	
		
			
				|  |  | +            outputStream = response.getOutputStream();
 | 
	
		
			
				|  |  | +            workbook.write(outputStream);
 | 
	
		
			
				|  |  | +            outputStream.flush();
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +        } finally {
 | 
	
		
			
				|  |  | +            if (outputStream != null) {
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    outputStream.close();
 | 
	
		
			
				|  |  | +                } catch (IOException e) {
 | 
	
		
			
				|  |  | +                    e.printStackTrace();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |