| | |
| | | package com.consum.base; |
| | | |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.iplatform.base.PlatformAdapterController; |
| | | import com.iplatform.base.util.UserUtils; |
| | | import com.iplatform.core.BeanContextAware; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | |
| | | public abstract class BaseController extends PlatformAdapterController { |
| | | |
| | | protected TokenCacheProvider getTokenCache() { |
| | | return BeanContextAware.getBeanByType(TokenCacheProvider.class); |
| | | } |
| | | |
| | | protected FinOrgCacheProvider getFinOrgCache() { |
| | | return BeanContextAware.getBeanByType(FinOrgCacheProvider.class); |
| | | } |
| | | |
| | | protected FinSysTenantUserCacheProvider getFinSysTenantUserCache() { |
| | | return BeanContextAware.getBeanByType(FinSysTenantUserCacheProvider.class); |
| | | } |
| | | |
| | | protected FinSysTenantCacheProvider getFinSysTenantCache() { |
| | | return BeanContextAware.getBeanByType(FinSysTenantCacheProvider.class); |
| | | } |
| | | |
| | | /** |
| | | * @Description 获取后台登录用户信息 |
| | | * @Author wh |
| | | * @Date 2023/7/25 9:59 |
| | | */ |
| | | protected FinSysTenantUser getSysInfo() { |
| | | S_user_core userInfo = UserUtils.getUserInfo(); |
| | | FinSysTenantUser finSysTenantUser = new FinSysTenantUser(); |
| | | if (userInfo.getId() == null) { |
| | | return finSysTenantUser; |
| | | } |
| | | // 从缓存中取出用户,如果没有则新增 |
| | | return this.getFinSysTenantUserCache().get(String.valueOf(userInfo.getId())); |
| | | } |
| | | |
| | | protected void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) throws IOException { |
| | | OutputStream out = response.getOutputStream(); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8")); |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | workbook.write(byteArrayOutputStream); |
| | | response.setHeader("Content-Length", String.valueOf(byteArrayOutputStream.size())); |
| | | out.write(byteArrayOutputStream.toByteArray()); |
| | | workbook.close(); |
| | | out.close(); |
| | | } |
| | | } |