| | |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.builder.ExcelWriterBuilder; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.admin.entity.Withdraw; |
| | | import com.ruoyi.admin.entity.WithdrawalSetting; |
| | | import com.ruoyi.admin.mapper.WithdrawMapper; |
| | | import com.ruoyi.admin.service.WithdrawService; |
| | | import com.ruoyi.admin.service.WithdrawalSettingService; |
| | | import com.ruoyi.admin.vo.UserWithdrawRecordRequestVO; |
| | | import com.ruoyi.admin.vo.UserWithdrawRecordVO; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import org.apache.commons.codec.CharEncoding; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-05-29 |
| | | */ |
| | | @Service |
| | | public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> implements WithdrawService { |
| | | |
| | | @Resource |
| | | private WithdrawalSettingService withdrawalSettingService; |
| | | public class WithdrawServiceImpl implements WithdrawService { |
| | | |
| | | @Override |
| | | public R<String> excelExport(List<String> ids, HttpServletResponse response) { |
| | | public R<String> excelExport(List<com.ruoyi.order.api.entity.UserWithdrawRecordVO> data, HttpServletResponse response) { |
| | | try { |
| | | response.setCharacterEncoding(Constants.UTF8); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-disposition"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(Constants.EXCEL_WITHDRAWAL_FILE_NAME, CharEncoding.UTF_8) + ".xlsx"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + |
| | | URLEncoder.encode(Constants.EXCEL_WITHDRAWAL_FILE_NAME, CharEncoding.UTF_8) + ".xlsx"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | return R.fail("excel导出失败!"); |
| | | } |
| | | try { |
| | | List<Withdraw> list = lambdaQuery().in(Withdraw::getId, ids).eq(Withdraw::getIsDelete, 0).list(); |
| | | if (null == data) { |
| | | throw new GlobalException("excel导出失败,请检查所筛选数据是否正确!"); |
| | | } |
| | | // excel模板封装 |
| | | ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream()); |
| | | InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" + Constants.EXCEL_WITHDRAWAL_FILE_NAME + ".xlsx"); |
| | | InputStream stream = Thread.currentThread().getContextClassLoader() |
| | | .getResourceAsStream("template/" + Constants.EXCEL_WITHDRAWAL_FILE_NAME + ".xlsx"); |
| | | // 自动释放资源 |
| | | try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) { |
| | | WriteSheet writeSheet = EasyExcelFactory.writerSheet().build(); |
| | | excelWriter.fill(list, writeSheet); |
| | | excelWriter.fill(data, writeSheet); |
| | | excelWriter.finish(); |
| | | } catch (Exception e) { |
| | | return R.fail("excel导出失败!"); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal withdrawalTotalMoney(List<String> cityIdList) { |
| | | return baseMapper.withdrawalTotalMoney(cityIdList); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal withdrawalTotalMoneyByYear(List<String> cityIdList) { |
| | | return baseMapper.withdrawalTotalMoneyByYear(cityIdList); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal withdrawalTotalMoneyByMonth(List<String> cityIdList) { |
| | | return baseMapper.withdrawalTotalMoneyByMonth(cityIdList); |
| | | } |
| | | |
| | | @Override |
| | | public UserWithdrawRecordRequestVO withdrawList(Integer userId, Page<UserWithdrawRecordVO> page) { |
| | | IPage<UserWithdrawRecordVO> record = baseMapper.withdrawList(userId, page); |
| | | // 全局审核设置 |
| | | WithdrawalSetting setting = withdrawalSettingService.lambdaQuery().one(); |
| | | Integer enableProcess; |
| | | if (null == setting) { |
| | | enableProcess = 0; |
| | | } else { |
| | | enableProcess = setting.getEnableProcess(); |
| | | } |
| | | return new UserWithdrawRecordRequestVO(record, enableProcess); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean enableProcess(Integer enableProcess) { |
| | | Integer[] state = {0, 1}; |
| | | boolean contains = Arrays.stream(state).collect(Collectors.toList()).contains(enableProcess); |
| | | if (!contains) { |
| | | throw new GlobalException("系统设置关闭/开启审核状态异常!"); |
| | | } |
| | | return withdrawalSettingService.lambdaUpdate().set(WithdrawalSetting::getEnableProcess, enableProcess).update(); |
| | | } |
| | | |
| | | @Override |
| | | public WithdrawalSetting withdrawProcess() { |
| | | return withdrawalSettingService.lambdaQuery().one(); |
| | | } |
| | | } |