|
|
@@ -28,8 +28,11 @@ import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
|
|
|
import com.yami.shop.bean.po.EnterpriseUserLogPo;
|
|
|
import com.yami.shop.bean.po.EnterpriseUserPo;
|
|
|
import com.yami.shop.bean.vo.EnterpriseUserVo;
|
|
|
+import com.yami.shop.bean.vo.OrderRefundSkuVo;
|
|
|
+import com.yami.shop.bean.vo.OrderRefundVo;
|
|
|
import com.yami.shop.bean.vo.UserPointsVO;
|
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
|
+import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.common.util.IPHelper;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.common.util.RedisUtil;
|
|
|
@@ -38,8 +41,15 @@ import com.yami.shop.dao.UserMapper;
|
|
|
import com.yami.shop.service.UserExtensionService;
|
|
|
import com.yami.shop.service.UserService;
|
|
|
import com.yami.shop.utils.CullenUtils;
|
|
|
+import com.yami.shop.utils.ExportUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -55,6 +65,7 @@ import java.util.Objects;
|
|
|
* @author lgh on 2018/09/11.
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
@AllArgsConstructor
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
|
|
|
@@ -244,4 +255,127 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
CullenUtils.validateDataThrowException(channelList.size() > 1, "查询到多条渠道,请检查后重试...");
|
|
|
return channelList.get(0).getId();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出用户列表
|
|
|
+ * @param po
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void export(EnterpriseUserPo po, HttpServletResponse response) {
|
|
|
+ List<EnterpriseUserVo> enterpriseUserVos= userMapper.exportList(po);
|
|
|
+ if (enterpriseUserVos.isEmpty()){
|
|
|
+ throw new GlobalException("该次导出未查询到数据,不允许导出");
|
|
|
+ }
|
|
|
+ exportNormalOrders(enterpriseUserVos,response,"员工列表");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 导出正常订单数据到Excel(直接输出到HttpServletResponse)
|
|
|
+ */
|
|
|
+ public void exportNormalOrders(List<EnterpriseUserVo> orderList,
|
|
|
+ HttpServletResponse response,
|
|
|
+ String fileName) {
|
|
|
+ // 设置响应头
|
|
|
+ ExportUtils.setupResponse(response, fileName);
|
|
|
+
|
|
|
+ try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
+ // 创建Sheet
|
|
|
+ Sheet sheet = workbook.createSheet("员工列表");
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ setupColumnWidth(sheet);
|
|
|
+
|
|
|
+ // 创建表头样式
|
|
|
+ CellStyle headerStyle = ExportUtils.createHeaderStyle(workbook);
|
|
|
+
|
|
|
+ // 创建数据样式
|
|
|
+ CellStyle dataStyle = ExportUtils.createDataStyle(workbook);
|
|
|
+ CellStyle numberStyle = ExportUtils.createNumberStyle(workbook);
|
|
|
+ CellStyle dateStyle = ExportUtils.createDateStyle(workbook);
|
|
|
+
|
|
|
+
|
|
|
+ String[] headers = {
|
|
|
+ "序号","所属企业", "员工姓名", "员工手机号", "总充值积分", "当前可用积分",
|
|
|
+ "已过期积分", "已消耗积分"
|
|
|
+ };
|
|
|
+ // 创建合并单元格的表头
|
|
|
+ ExportUtils.createMergedHeader(sheet, headerStyle,"员工列表");
|
|
|
+
|
|
|
+ // 创建列标题行
|
|
|
+ ExportUtils.createColumnHeaders(sheet, headerStyle,headers);
|
|
|
+
|
|
|
+ // 填充数据
|
|
|
+ fillOrderData(sheet, orderList, dataStyle, numberStyle, dateStyle);
|
|
|
+
|
|
|
+ // 写入响应流
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+
|
|
|
+ log.info("订单导出成功,文件:{},记录数:{}", fileName, orderList.size());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单导出失败", e);
|
|
|
+ throw new RuntimeException("导出失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置列宽
|
|
|
+ */
|
|
|
+ private void setupColumnWidth(Sheet sheet) {
|
|
|
+ // 根据模板设置列宽(单位:1/256字符宽度)
|
|
|
+ sheet.setColumnWidth(0, 12 * 256); // 序号
|
|
|
+ sheet.setColumnWidth(1, 12 * 256); // 所属企业
|
|
|
+ sheet.setColumnWidth(2, 18 * 256); // 员工姓名
|
|
|
+ sheet.setColumnWidth(3, 18 * 256); // 员工手机号
|
|
|
+ sheet.setColumnWidth(4, 10 * 256); // 总充值积分
|
|
|
+ sheet.setColumnWidth(5, 8 * 256); // 当前可用积分
|
|
|
+ sheet.setColumnWidth(6, 25 * 256); // 已过期积分
|
|
|
+ sheet.setColumnWidth(7, 20 * 256); // 已消耗积分
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充订单数据
|
|
|
+ */
|
|
|
+ private void fillOrderData(Sheet sheet, List<EnterpriseUserVo> orderList,
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
+ int rowNum = 2; // 从第3行开始(0-based索引)
|
|
|
+ int indexNum= 1; //序号
|
|
|
+ for (EnterpriseUserVo enterpriseUserVo : orderList) {
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
+ row.setHeightInPoints(18);
|
|
|
+ // 序号
|
|
|
+ ExportUtils.createCell(sheet,row, 0,0,0, indexNum, dataStyle);
|
|
|
+ fillOrderRowData(sheet,row, enterpriseUserVo, dataStyle, numberStyle, dateStyle);
|
|
|
+ indexNum++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充单行订单数据
|
|
|
+ */
|
|
|
+ private void fillOrderRowData(Sheet sheet,Row row, EnterpriseUserVo orderRefundVo,
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
+
|
|
|
+ // 所属企业
|
|
|
+ ExportUtils.createCell(sheet,row, 1,0,0, orderRefundVo.getChannelName(), dataStyle);
|
|
|
+
|
|
|
+ // 员工姓名
|
|
|
+ ExportUtils.createCell(sheet,row, 2,0,0, orderRefundVo.getRealName(), dateStyle);
|
|
|
+
|
|
|
+ // 员工手机号
|
|
|
+ ExportUtils.createCell(sheet,row, 3,0,0, orderRefundVo.getUserMobile(), dateStyle);
|
|
|
+
|
|
|
+ // 总充值积分
|
|
|
+ ExportUtils.createCell(sheet,row, 4,0,0,orderRefundVo.getTotal(), numberStyle);
|
|
|
+
|
|
|
+ // 可用积分
|
|
|
+ ExportUtils.createCell(sheet,row, 5,0,0, orderRefundVo.getAvailable(), numberStyle);
|
|
|
+ // 已过期积分
|
|
|
+ ExportUtils.createCell(sheet,row, 6,0,0, orderRefundVo.getExpired(), numberStyle);
|
|
|
+ // 已消耗积分
|
|
|
+ ExportUtils.createCell(sheet,row, 6,0,0, orderRefundVo.getUsed(), numberStyle);
|
|
|
+ }
|
|
|
}
|