|
|
|
@ -1,18 +1,22 @@ |
|
|
|
package com.gaotao.modules.factory.service.impl; |
|
|
|
|
|
|
|
import cn.idev.excel.FastExcel; |
|
|
|
import cn.idev.excel.write.metadata.style.WriteCellStyle; |
|
|
|
import cn.idev.excel.write.metadata.style.WriteFont; |
|
|
|
import cn.idev.excel.write.style.HorizontalCellStyleStrategy; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.gaotao.common.constant.SysMsgConstant; |
|
|
|
import com.gaotao.common.utils.WrapperGenerate; |
|
|
|
import com.gaotao.common.utils.R; |
|
|
|
import com.gaotao.modules.factory.dao.SiteMapper; |
|
|
|
import com.gaotao.modules.factory.entity.Site; |
|
|
|
import com.gaotao.modules.factory.entity.vo.SiteVo; |
|
|
|
import com.gaotao.modules.factory.service.SiteService; |
|
|
|
import com.gaotao.modules.label.entity.LabelFormat; |
|
|
|
import com.gaotao.modules.label.service.LabelFormatService; |
|
|
|
import com.gaotao.modules.pallet.entity.CatchPallet; |
|
|
|
import com.gaotao.modules.part.entity.Part; |
|
|
|
import com.gaotao.modules.part.service.PartService; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import com.gaotao.modules.sys.service.SysMenuService; |
|
|
|
import com.gaotao.modules.sys.service.SysMsgService; |
|
|
|
import com.gaotao.modules.sys.service.SysUserService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -20,6 +24,9 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
@ -93,4 +100,46 @@ public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements Si |
|
|
|
public Site getSiteById(String id) { |
|
|
|
return lambdaQuery().eq(Site::getSiteId, id).one(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void export(HttpServletResponse response, Site site) { |
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
response.setStatus(200); |
|
|
|
List<Site> list = baseMapper.selectSiteList(site); |
|
|
|
|
|
|
|
if (list.isEmpty()) { |
|
|
|
// 设置返回类型为 JSON |
|
|
|
response.setContentType("application/json;charset=UTF-8"); |
|
|
|
response.setStatus(HttpServletResponse.SC_OK); // 仍返回 200,但内容为 R.error |
|
|
|
try { |
|
|
|
R errorResponse = R.error(500, "not find any Site Data"); |
|
|
|
String json = new ObjectMapper().writeValueAsString(errorResponse); |
|
|
|
response.getWriter().write(json); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
String fileName = URLEncoder.encode("Site List", "UTF-8").replaceAll("\\+", "%20"); |
|
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
|
|
|
|
|
|
|
WriteCellStyle contentCellStyle = new WriteCellStyle(); |
|
|
|
WriteFont writeFont = new WriteFont(); |
|
|
|
writeFont.setFontName("Arial"); |
|
|
|
contentCellStyle.setWriteFont(writeFont); |
|
|
|
|
|
|
|
// 注册策略 |
|
|
|
HorizontalCellStyleStrategy strategy = new HorizontalCellStyleStrategy(null, contentCellStyle); |
|
|
|
|
|
|
|
|
|
|
|
FastExcel.write(response.getOutputStream(), CatchPallet.class) |
|
|
|
.registerWriteHandler(strategy) |
|
|
|
.sheet("site List") |
|
|
|
.doWrite(list); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |