24 changed files with 1238 additions and 332 deletions
@ -0,0 +1,119 @@ |
|||
package com.mmxt.web.controller.mmxt; |
|||
|
|||
import java.util.List; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
import com.mmxt.business.domain.vo.MmxtMeiyuTextbookActivateVo; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.PutMapping; |
|||
import org.springframework.web.bind.annotation.DeleteMapping; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import com.mmxt.common.annotation.Log; |
|||
import com.mmxt.common.core.controller.BaseController; |
|||
import com.mmxt.common.core.domain.AjaxResult; |
|||
import com.mmxt.common.enums.BusinessType; |
|||
import com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch; |
|||
import com.mmxt.business.service.IMmxtMeiyuTextbookActivateBatchService; |
|||
import com.mmxt.common.utils.poi.ExcelUtil; |
|||
import com.mmxt.common.core.page.TableDataInfo; |
|||
|
|||
/** |
|||
* 美美学堂智慧美育教材学习卡激活批次Controller |
|||
* |
|||
* @author mmxt |
|||
* @date 2026-03-04 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/mmxt/mmxtMeiyuTextbookActivateBatch") |
|||
public class MmxtMeiyuTextbookActivateBatchController extends BaseController |
|||
{ |
|||
@Autowired |
|||
private IMmxtMeiyuTextbookActivateBatchService mmxtMeiyuTextbookActivateBatchService; |
|||
|
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次列表 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:list')") |
|||
@GetMapping("/list") |
|||
public TableDataInfo list(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
startPage(); |
|||
List<MmxtMeiyuTextbookActivateBatch> list = mmxtMeiyuTextbookActivateBatchService.selectMmxtMeiyuTextbookActivateBatchList(mmxtMeiyuTextbookActivateBatch); |
|||
return getDataTable(list); |
|||
} |
|||
|
|||
/** |
|||
* 导出美美学堂智慧美育教材学习卡激活批次列表 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:export')") |
|||
@Log(title = "美美学堂智慧美育教材学习卡激活批次", businessType = BusinessType.EXPORT) |
|||
@PostMapping("/export") |
|||
public void export(HttpServletResponse response, MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
List<MmxtMeiyuTextbookActivateBatch> list = mmxtMeiyuTextbookActivateBatchService.selectMmxtMeiyuTextbookActivateBatchList(mmxtMeiyuTextbookActivateBatch); |
|||
ExcelUtil<MmxtMeiyuTextbookActivateBatch> util = new ExcelUtil<MmxtMeiyuTextbookActivateBatch>(MmxtMeiyuTextbookActivateBatch.class); |
|||
util.exportExcel(response, list, "美美学堂智慧美育教材学习卡激活批次数据"); |
|||
} |
|||
|
|||
/** |
|||
* 获取美美学堂智慧美育教材学习卡激活批次详细信息 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:query')") |
|||
@GetMapping(value = "/{batchId}") |
|||
public AjaxResult getInfo(@PathVariable("batchId") Long batchId) |
|||
{ |
|||
return success(mmxtMeiyuTextbookActivateBatchService.selectMmxtMeiyuTextbookActivateBatchByBatchId(batchId)); |
|||
} |
|||
|
|||
/** |
|||
* 新增美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:add')") |
|||
@Log(title = "美美学堂智慧美育教材学习卡激活批次", businessType = BusinessType.INSERT) |
|||
@PostMapping |
|||
public AjaxResult add(@RequestBody MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
return toAjax(mmxtMeiyuTextbookActivateBatchService.insertMmxtMeiyuTextbookActivateBatch(mmxtMeiyuTextbookActivateBatch)); |
|||
} |
|||
|
|||
/** |
|||
* 修改美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:edit')") |
|||
@Log(title = "美美学堂智慧美育教材学习卡激活批次", businessType = BusinessType.UPDATE) |
|||
@PutMapping |
|||
public AjaxResult edit(@RequestBody MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
return toAjax(mmxtMeiyuTextbookActivateBatchService.updateMmxtMeiyuTextbookActivateBatch(mmxtMeiyuTextbookActivateBatch)); |
|||
} |
|||
|
|||
/** |
|||
* 删除美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
@PreAuthorize("@ss.hasPermi('mmxt:mmxtMeiyuTextbookActivateBatch:remove')") |
|||
@Log(title = "美美学堂智慧美育教材学习卡激活批次", businessType = BusinessType.DELETE) |
|||
@DeleteMapping("/{batchIds}") |
|||
public AjaxResult remove(@PathVariable Long[] batchIds) |
|||
{ |
|||
return toAjax(mmxtMeiyuTextbookActivateBatchService.deleteMmxtMeiyuTextbookActivateBatchByBatchIds(batchIds)); |
|||
} |
|||
|
|||
/** |
|||
* 批量生成激活码 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/batchInsertTextbookActivate") |
|||
public AjaxResult batchInsertMmxtMeiyuTextbookActivate(@RequestBody MmxtMeiyuTextbookActivateBatch param){ |
|||
return success(mmxtMeiyuTextbookActivateBatchService.batchInsertMmxtMeiyuTextbookActivate(param)); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,167 @@ |
|||
package com.mmxt.business.domain; |
|||
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder; |
|||
import org.apache.commons.lang3.builder.ToStringStyle; |
|||
import com.mmxt.common.annotation.Excel; |
|||
import com.mmxt.common.core.domain.BaseEntity; |
|||
|
|||
/** |
|||
* 美美学堂智慧美育教材学习卡激活批次对象 mmxt_meiyu_textbook_activate_batch |
|||
* |
|||
* @author mmxt |
|||
* @date 2026-03-04 |
|||
*/ |
|||
public class MmxtMeiyuTextbookActivateBatch extends BaseEntity |
|||
{ |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** 批次id */ |
|||
private Long batchId; |
|||
|
|||
/** 教材id(关联mmxt_meiyu_textbook) */ |
|||
private String textbookId; |
|||
|
|||
/** 批次名称 */ |
|||
@Excel(name = "批次名称") |
|||
private String batchName; |
|||
|
|||
/** 地域id (关联mmxt_meiyu_region) */ |
|||
private Long regionId; |
|||
|
|||
/** 地域地址 */ |
|||
@Excel(name = "地域地址") |
|||
private String regionAddr; |
|||
|
|||
/** 已激活数量 */ |
|||
@Excel(name = "已激活数量") |
|||
private Long activationCount; |
|||
|
|||
/** 未激活数量 */ |
|||
@Excel(name = "未激活数量") |
|||
private Long unactivationCount; |
|||
|
|||
/** 删除标志 0存在 1删除 */ |
|||
private String delFlag; |
|||
|
|||
|
|||
/** 生成数量 */ |
|||
private Integer generateCount; |
|||
|
|||
|
|||
/** |
|||
* 学科 美术 、书法 、舞蹈、戏剧、影视 |
|||
*/ |
|||
private String subject; |
|||
|
|||
public String getRegionAddr() { |
|||
return regionAddr; |
|||
} |
|||
|
|||
public void setRegionAddr(String regionAddr) { |
|||
this.regionAddr = regionAddr; |
|||
} |
|||
|
|||
public String getSubject() { |
|||
return subject; |
|||
} |
|||
|
|||
public void setSubject(String subject) { |
|||
this.subject = subject; |
|||
} |
|||
|
|||
|
|||
public Integer getGenerateCount() { |
|||
return generateCount; |
|||
} |
|||
|
|||
public void setGenerateCount(Integer generateCount) { |
|||
this.generateCount = generateCount; |
|||
} |
|||
|
|||
public void setBatchId(Long batchId) |
|||
{ |
|||
this.batchId = batchId; |
|||
} |
|||
|
|||
public Long getBatchId() |
|||
{ |
|||
return batchId; |
|||
} |
|||
|
|||
public void setTextbookId(String textbookId) |
|||
{ |
|||
this.textbookId = textbookId; |
|||
} |
|||
|
|||
public String getTextbookId() |
|||
{ |
|||
return textbookId; |
|||
} |
|||
|
|||
public void setBatchName(String batchName) |
|||
{ |
|||
this.batchName = batchName; |
|||
} |
|||
|
|||
public String getBatchName() |
|||
{ |
|||
return batchName; |
|||
} |
|||
|
|||
public void setRegionId(Long regionId) |
|||
{ |
|||
this.regionId = regionId; |
|||
} |
|||
|
|||
public Long getRegionId() |
|||
{ |
|||
return regionId; |
|||
} |
|||
|
|||
public void setActivationCount(Long activationCount) |
|||
{ |
|||
this.activationCount = activationCount; |
|||
} |
|||
|
|||
public Long getActivationCount() |
|||
{ |
|||
return activationCount; |
|||
} |
|||
|
|||
public void setUnactivationCount(Long unactivationCount) |
|||
{ |
|||
this.unactivationCount = unactivationCount; |
|||
} |
|||
|
|||
public Long getUnactivationCount() |
|||
{ |
|||
return unactivationCount; |
|||
} |
|||
|
|||
public void setDelFlag(String delFlag) |
|||
{ |
|||
this.delFlag = delFlag; |
|||
} |
|||
|
|||
public String getDelFlag() |
|||
{ |
|||
return delFlag; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
|||
.append("batchId", getBatchId()) |
|||
.append("textbookId", getTextbookId()) |
|||
.append("batchName", getBatchName()) |
|||
.append("regionId", getRegionId()) |
|||
.append("activationCount", getActivationCount()) |
|||
.append("unactivationCount", getUnactivationCount()) |
|||
.append("createTime", getCreateTime()) |
|||
.append("createBy", getCreateBy()) |
|||
.append("updateTime", getUpdateTime()) |
|||
.append("updateBy", getUpdateBy()) |
|||
.append("delFlag", getDelFlag()) |
|||
.toString(); |
|||
} |
|||
} |
|||
@ -0,0 +1,129 @@ |
|||
package com.mmxt.business.domain.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.mmxt.common.annotation.Excel; |
|||
import com.mmxt.common.core.domain.BaseEntity; |
|||
|
|||
import java.util.Date; |
|||
|
|||
public class MmxtMeiyuTextbookActivateVo extends BaseEntity { |
|||
/** 批次id 关联mmxt_meiyu_textbook_activate_batch */ |
|||
private Long batchId; |
|||
|
|||
@Excel(name = "批次名称") |
|||
private String batchName; |
|||
|
|||
/** 激活码 */ |
|||
@Excel(name = "激活码") |
|||
private String activateCode; |
|||
|
|||
/** 二维码 */ |
|||
@Excel(name = "二维码") |
|||
private String qrCode; |
|||
|
|||
@Excel(name = "学生名称") |
|||
private String studentName; |
|||
|
|||
/** IP地址 */ |
|||
@Excel(name = "IP地址") |
|||
private String ipaddr; |
|||
|
|||
/** 浏览器类型 */ |
|||
@Excel(name = "浏览器类型") |
|||
private String browser; |
|||
|
|||
/** 操作系统 */ |
|||
@Excel(name = "操作系统") |
|||
private String os; |
|||
|
|||
/** 激活时间 */ |
|||
@JsonFormat(pattern = "yyyy-MM-dd") |
|||
@Excel(name = "激活时间", width = 30, dateFormat = "yyyy-MM-dd") |
|||
private Date logTime; |
|||
|
|||
public String getBatchName() { |
|||
return batchName; |
|||
} |
|||
|
|||
public void setBatchName(String batchName) { |
|||
this.batchName = batchName; |
|||
} |
|||
|
|||
public Long getBatchId() { |
|||
return batchId; |
|||
} |
|||
|
|||
public void setBatchId(Long batchId) { |
|||
this.batchId = batchId; |
|||
} |
|||
|
|||
public String getActivateCode() { |
|||
return activateCode; |
|||
} |
|||
|
|||
public void setActivateCode(String activateCode) { |
|||
this.activateCode = activateCode; |
|||
} |
|||
|
|||
public String getQrCode() { |
|||
return qrCode; |
|||
} |
|||
|
|||
public void setQrCode(String qrCode) { |
|||
this.qrCode = qrCode; |
|||
} |
|||
|
|||
public String getStudentName() { |
|||
return studentName; |
|||
} |
|||
|
|||
public void setStudentName(String studentName) { |
|||
this.studentName = studentName; |
|||
} |
|||
|
|||
public String getIpaddr() { |
|||
return ipaddr; |
|||
} |
|||
|
|||
public void setIpaddr(String ipaddr) { |
|||
this.ipaddr = ipaddr; |
|||
} |
|||
|
|||
public String getBrowser() { |
|||
return browser; |
|||
} |
|||
|
|||
public void setBrowser(String browser) { |
|||
this.browser = browser; |
|||
} |
|||
|
|||
public String getOs() { |
|||
return os; |
|||
} |
|||
|
|||
public void setOs(String os) { |
|||
this.os = os; |
|||
} |
|||
|
|||
public Date getLogTime() { |
|||
return logTime; |
|||
} |
|||
|
|||
public void setLogTime(Date logTime) { |
|||
this.logTime = logTime; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "MmxtMeiyuTextbookActivateVo{" + |
|||
"batchId=" + batchId + |
|||
", activateCode='" + activateCode + '\'' + |
|||
", qrCode='" + qrCode + '\'' + |
|||
", studentName='" + studentName + '\'' + |
|||
", ipaddr='" + ipaddr + '\'' + |
|||
", browser='" + browser + '\'' + |
|||
", os='" + os + '\'' + |
|||
", logTime=" + logTime + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
package com.mmxt.business.mapper; |
|||
|
|||
import java.util.List; |
|||
import com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch; |
|||
|
|||
/** |
|||
* 美美学堂智慧美育教材学习卡激活批次Mapper接口 |
|||
* |
|||
* @author mmxt |
|||
* @date 2026-03-04 |
|||
*/ |
|||
public interface MmxtMeiyuTextbookActivateBatchMapper |
|||
{ |
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
public MmxtMeiyuTextbookActivateBatch selectMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId); |
|||
|
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次列表 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次集合 |
|||
*/ |
|||
public List<MmxtMeiyuTextbookActivateBatch> selectMmxtMeiyuTextbookActivateBatchList(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 新增美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
public int insertMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 修改美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
public int updateMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 删除美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId); |
|||
|
|||
/** |
|||
* 批量删除美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchIds 需要删除的数据主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchIds(Long[] batchIds); |
|||
|
|||
/** |
|||
* 修改批次未激活数量 |
|||
* @param mmxtMeiyuTextbookActivateBatch |
|||
* @return |
|||
*/ |
|||
public int updateBatchUnactivationCount(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
package com.mmxt.business.service; |
|||
|
|||
import java.util.List; |
|||
import com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch; |
|||
import com.mmxt.business.domain.vo.MmxtMeiyuTextbookActivateVo; |
|||
import com.mmxt.common.core.domain.AjaxResult; |
|||
|
|||
/** |
|||
* 美美学堂智慧美育教材学习卡激活批次Service接口 |
|||
* |
|||
* @author mmxt |
|||
* @date 2026-03-04 |
|||
*/ |
|||
public interface IMmxtMeiyuTextbookActivateBatchService |
|||
{ |
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
public MmxtMeiyuTextbookActivateBatch selectMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId); |
|||
|
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次列表 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次集合 |
|||
*/ |
|||
public List<MmxtMeiyuTextbookActivateBatch> selectMmxtMeiyuTextbookActivateBatchList(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 新增美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
public int insertMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 修改美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
public int updateMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch); |
|||
|
|||
/** |
|||
* 批量删除美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchIds 需要删除的美美学堂智慧美育教材学习卡激活批次主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchIds(Long[] batchIds); |
|||
|
|||
/** |
|||
* 删除美美学堂智慧美育教材学习卡激活批次信息 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId); |
|||
|
|||
/** |
|||
* 批量生成激活码 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
public AjaxResult batchInsertMmxtMeiyuTextbookActivate(MmxtMeiyuTextbookActivateBatch param); |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,233 @@ |
|||
package com.mmxt.business.service.impl; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.concurrent.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|||
import com.mmxt.business.domain.MmxtMeiyuTextbookActivate; |
|||
import com.mmxt.business.domain.vo.MmxtMeiyuTextbookActivateVo; |
|||
import com.mmxt.business.mapper.MmxtMeiyuTextbookActivateMapper; |
|||
import com.mmxt.business.mapper.MmxtMeiyuTextbookMapper; |
|||
import com.mmxt.common.constant.Constants; |
|||
import com.mmxt.common.core.domain.AjaxResult; |
|||
import com.mmxt.common.exception.ServiceException; |
|||
import com.mmxt.common.utils.DateUtils; |
|||
import com.mmxt.common.utils.QrCodeUtil; |
|||
import com.mmxt.common.utils.RandomCodeUtil; |
|||
import com.mmxt.common.utils.bean.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import com.mmxt.business.mapper.MmxtMeiyuTextbookActivateBatchMapper; |
|||
import com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch; |
|||
import com.mmxt.business.service.IMmxtMeiyuTextbookActivateBatchService; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.transaction.support.TransactionTemplate; |
|||
|
|||
import static com.mmxt.common.utils.OSSUtil.uploadQrCodeToOss; |
|||
import static com.mmxt.common.utils.SecurityUtils.getUsername; |
|||
|
|||
/** |
|||
* 美美学堂智慧美育教材学习卡激活批次Service业务层处理 |
|||
* |
|||
* @author mmxt |
|||
* @date 2026-03-04 |
|||
*/ |
|||
@Service |
|||
public class MmxtMeiyuTextbookActivateBatchServiceImpl implements IMmxtMeiyuTextbookActivateBatchService |
|||
{ |
|||
@Autowired |
|||
private MmxtMeiyuTextbookActivateBatchMapper mmxtMeiyuTextbookActivateBatchMapper; |
|||
|
|||
@Autowired |
|||
private TransactionTemplate transactionTemplate; |
|||
|
|||
@Autowired |
|||
private MmxtMeiyuTextbookActivateMapper mmxtMeiyuTextbookActivateMapper; |
|||
|
|||
private static final ExecutorService EXECUTOR = new ThreadPoolExecutor( |
|||
8, 16, 60L, TimeUnit.SECONDS, |
|||
new LinkedBlockingQueue<>(1000), |
|||
new ThreadFactoryBuilder().setNameFormat("qr-gen-%d").build(), |
|||
new ThreadPoolExecutor.CallerRunsPolicy() // 队列满时由主线程执行,起到限流作用
|
|||
); |
|||
|
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
@Override |
|||
public MmxtMeiyuTextbookActivateBatch selectMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId) |
|||
{ |
|||
return mmxtMeiyuTextbookActivateBatchMapper.selectMmxtMeiyuTextbookActivateBatchByBatchId(batchId); |
|||
} |
|||
|
|||
/** |
|||
* 查询美美学堂智慧美育教材学习卡激活批次列表 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 美美学堂智慧美育教材学习卡激活批次 |
|||
*/ |
|||
@Override |
|||
public List<MmxtMeiyuTextbookActivateBatch> selectMmxtMeiyuTextbookActivateBatchList(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
return mmxtMeiyuTextbookActivateBatchMapper.selectMmxtMeiyuTextbookActivateBatchList(mmxtMeiyuTextbookActivateBatch); |
|||
} |
|||
|
|||
/** |
|||
* 新增美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int insertMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
mmxtMeiyuTextbookActivateBatch.setCreateTime(DateUtils.getNowDate()); |
|||
mmxtMeiyuTextbookActivateBatch.setCreateBy(getUsername()); |
|||
return mmxtMeiyuTextbookActivateBatchMapper.insertMmxtMeiyuTextbookActivateBatch(mmxtMeiyuTextbookActivateBatch); |
|||
} |
|||
|
|||
/** |
|||
* 修改美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param mmxtMeiyuTextbookActivateBatch 美美学堂智慧美育教材学习卡激活批次 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
public int updateMmxtMeiyuTextbookActivateBatch(MmxtMeiyuTextbookActivateBatch mmxtMeiyuTextbookActivateBatch) |
|||
{ |
|||
mmxtMeiyuTextbookActivateBatch.setUpdateTime(DateUtils.getNowDate()); |
|||
mmxtMeiyuTextbookActivateBatch.setUpdateBy(getUsername()); |
|||
return mmxtMeiyuTextbookActivateBatchMapper.updateMmxtMeiyuTextbookActivateBatch(mmxtMeiyuTextbookActivateBatch); |
|||
} |
|||
|
|||
/** |
|||
* 批量删除美美学堂智慧美育教材学习卡激活批次 |
|||
* |
|||
* @param batchIds 需要删除的美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchIds(Long[] batchIds) |
|||
{ |
|||
for (Long batchId : batchIds){ |
|||
MmxtMeiyuTextbookActivateBatch batch = mmxtMeiyuTextbookActivateBatchMapper.selectMmxtMeiyuTextbookActivateBatchByBatchId(batchId); |
|||
if (batch.getActivationCount() > 0){ |
|||
throw new ServiceException(batch.getBatchName() +"批次下有激活码已经激活,不能删除该批次"); |
|||
} |
|||
} |
|||
// 删除当前批次下的所有激活码
|
|||
mmxtMeiyuTextbookActivateMapper.deleteMmxtMeiyuTextbookActivateByBatchIds(batchIds); |
|||
|
|||
return mmxtMeiyuTextbookActivateBatchMapper.deleteMmxtMeiyuTextbookActivateBatchByBatchIds(batchIds); |
|||
} |
|||
|
|||
/** |
|||
* 删除美美学堂智慧美育教材学习卡激活批次信息 |
|||
* |
|||
* @param batchId 美美学堂智慧美育教材学习卡激活批次主键 |
|||
* @return 结果 |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int deleteMmxtMeiyuTextbookActivateBatchByBatchId(Long batchId) |
|||
{ |
|||
MmxtMeiyuTextbookActivateBatch batch = mmxtMeiyuTextbookActivateBatchMapper.selectMmxtMeiyuTextbookActivateBatchByBatchId(batchId); |
|||
if (batch.getActivationCount() > 0){ |
|||
throw new ServiceException(batch.getBatchName() +"批次下有激活码已经激活,不能删除该批次"); |
|||
} |
|||
// 删除当前批次下的所有激活码
|
|||
mmxtMeiyuTextbookActivateMapper.deleteMmxtMeiyuTextbookActivateByBatchId(batchId); |
|||
|
|||
return mmxtMeiyuTextbookActivateBatchMapper.deleteMmxtMeiyuTextbookActivateBatchByBatchId(batchId); |
|||
} |
|||
|
|||
/** |
|||
* 批量生成激活码 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public AjaxResult batchInsertMmxtMeiyuTextbookActivate(MmxtMeiyuTextbookActivateBatch param) { |
|||
Integer count = param.getGenerateCount(); |
|||
if (count == null || count <= 0) { |
|||
return AjaxResult.error("生成数量必须大于0"); |
|||
} |
|||
|
|||
// 新增激活码批次
|
|||
param.setUnactivationCount(count.longValue()); |
|||
param.setActivationCount(0L); |
|||
param.setCreateTime(DateUtils.getNowDate()); |
|||
param.setCreateBy(getUsername()); |
|||
mmxtMeiyuTextbookActivateBatchMapper.insertMmxtMeiyuTextbookActivateBatch(param); |
|||
|
|||
|
|||
// 提前获取上下文信息,防止子线程丢失
|
|||
String createBy = getUsername(); |
|||
String ossDir = isSite(param.getSubject()) + Constants.OSS_IMAGE; |
|||
|
|||
List<CompletableFuture<MmxtMeiyuTextbookActivate>> futures = new ArrayList<>(); |
|||
|
|||
// 并行处理耗时的 OSS 上传和二维码生成
|
|||
for (int i = 0; i < count; i++) { |
|||
futures.add(CompletableFuture.supplyAsync(() -> { |
|||
MmxtMeiyuTextbookActivate entity = new MmxtMeiyuTextbookActivate(); |
|||
entity.setBatchId(param.getBatchId()); |
|||
entity.setRecordId(null); |
|||
|
|||
String activateCode = RandomCodeUtil.generateCode(); |
|||
entity.setActivateCode(activateCode); |
|||
|
|||
byte[] qrBytes = QrCodeUtil.generateBarcode(activateCode, 200, 100); |
|||
String qrUrl = uploadQrCodeToOss(qrBytes, ossDir); |
|||
|
|||
entity.setQrCode(qrUrl); |
|||
entity.setCreateBy(createBy); |
|||
return entity; |
|||
}, EXECUTOR)); |
|||
} |
|||
|
|||
try { |
|||
// 等待所有并行任务完成
|
|||
List<MmxtMeiyuTextbookActivate> list = futures.stream() |
|||
.map(CompletableFuture::join) |
|||
.collect(Collectors.toList()); |
|||
|
|||
// 3. 使用 TransactionTemplate 执行数据库操作
|
|||
transactionTemplate.execute(status -> { |
|||
batchInsertInChunks(list, 500); |
|||
return null; |
|||
}); |
|||
|
|||
return AjaxResult.success("批量生成激活码成功,共生成 " + count + " 条"); |
|||
} catch (Exception e) { |
|||
return AjaxResult.error("操作失败:" + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
private void batchInsertInChunks(List<MmxtMeiyuTextbookActivate> list, int chunkSize) { |
|||
for (int i = 0; i < list.size(); i += chunkSize) { |
|||
int end = Math.min(i + chunkSize, list.size()); |
|||
List<MmxtMeiyuTextbookActivate> subList = list.subList(i, end); |
|||
mmxtMeiyuTextbookActivateMapper.batchInsertMmxtMeiyuTextbookActivate(subList); |
|||
} |
|||
} |
|||
|
|||
public String isSite(String flag) { |
|||
if ("美术".equals(flag)) { |
|||
return Constants.OSS_list + Constants.MEISHU_SITE; |
|||
} |
|||
if ("书法".equals(flag)) { |
|||
return Constants.OSS_list + Constants.SHUFA365_SITE; |
|||
} |
|||
return Constants.OSS_list + Constants.XINSANKE_SITE; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,146 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.mmxt.business.mapper.MmxtMeiyuTextbookActivateBatchMapper"> |
|||
|
|||
<resultMap type="com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch" id="MmxtMeiyuTextbookActivateBatchResult"> |
|||
<result property="batchId" column="batch_id" /> |
|||
<result property="textbookId" column="textbook_id" /> |
|||
<result property="batchName" column="batch_name" /> |
|||
<result property="regionId" column="region_id" /> |
|||
<result property="activationCount" column="activation_count" /> |
|||
<result property="unactivationCount" column="unactivation_count" /> |
|||
<result property="createTime" column="create_time" /> |
|||
<result property="createBy" column="create_by" /> |
|||
<result property="updateTime" column="update_time" /> |
|||
<result property="updateBy" column="update_by" /> |
|||
<result property="delFlag" column="del_flag" /> |
|||
</resultMap> |
|||
|
|||
<sql id="selectMmxtMeiyuTextbookActivateBatchVo"> |
|||
select batch_id, textbook_id, batch_name, region_id, activation_count, unactivation_count, create_time, create_by, update_time, update_by, del_flag from mmxt_meiyu_textbook_activate_batch |
|||
</sql> |
|||
|
|||
<select id="selectMmxtMeiyuTextbookActivateBatchList" parameterType="com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch" resultMap="MmxtMeiyuTextbookActivateBatchResult"> |
|||
WITH RECURSIVE region_tree AS ( |
|||
-- 激活码表关联的最底层区域 |
|||
SELECT |
|||
r.region_id, |
|||
r.region_name, |
|||
r.parent_id, |
|||
r.region_id AS leaf_region_id, |
|||
CAST(r.region_name AS CHAR(500)) AS full_path |
|||
FROM mmxt_meiyu_region r |
|||
WHERE r.region_id IN ( |
|||
SELECT DISTINCT region_id FROM mmxt_meiyu_textbook_activate_batch |
|||
) |
|||
|
|||
UNION ALL |
|||
|
|||
-- 向上递归父级 |
|||
SELECT |
|||
parent.region_id, |
|||
parent.region_name, |
|||
parent.parent_id, |
|||
child.leaf_region_id, |
|||
CONCAT(parent.region_name, '', child.full_path) AS full_path |
|||
FROM mmxt_meiyu_region parent |
|||
INNER JOIN region_tree child |
|||
ON child.parent_id = parent.region_id |
|||
) |
|||
|
|||
SELECT |
|||
a.batch_id, |
|||
a.textbook_id, |
|||
a.batch_name, |
|||
a.region_id, |
|||
a.activation_count, |
|||
a.unactivation_count, |
|||
a.create_time, |
|||
a.create_by, |
|||
a.update_time, |
|||
a.update_by, |
|||
rt.full_path AS regionAddr |
|||
FROM mmxt_meiyu_textbook_activate_batch a |
|||
LEFT JOIN region_tree rt |
|||
ON a.region_id = rt.leaf_region_id |
|||
<where> |
|||
a.del_flag = 0 and (rt.parent_id = 0 OR rt.parent_id IS NULL) |
|||
<if test="textbookId != null and textbookId != ''"> and a.textbook_id = #{textbookId}</if> |
|||
<if test="batchName != null and batchName != ''"> and a.batch_name like concat('%', #{batchName}, '%')</if> |
|||
<if test="regionId != null "> and a.region_id = #{regionId}</if> |
|||
<if test="activationCount != null "> and a.activation_count = #{activationCount}</if> |
|||
<if test="unactivationCount != null "> and a.unactivation_count = #{unactivationCount}</if> |
|||
</where> |
|||
order by a.create_time desc,a.batch_id desc |
|||
</select> |
|||
|
|||
<select id="selectMmxtMeiyuTextbookActivateBatchByBatchId" parameterType="Long" resultMap="MmxtMeiyuTextbookActivateBatchResult"> |
|||
<include refid="selectMmxtMeiyuTextbookActivateBatchVo"/> |
|||
where batch_id = #{batchId} and del_flag = 0 |
|||
</select> |
|||
|
|||
<insert id="insertMmxtMeiyuTextbookActivateBatch" parameterType="com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch" useGeneratedKeys="true" keyProperty="batchId"> |
|||
insert into mmxt_meiyu_textbook_activate_batch |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="textbookId != null and textbookId != ''">textbook_id,</if> |
|||
<if test="batchName != null">batch_name,</if> |
|||
<if test="regionId != null">region_id,</if> |
|||
<if test="activationCount != null">activation_count,</if> |
|||
<if test="unactivationCount != null">unactivation_count,</if> |
|||
<if test="createTime != null">create_time,</if> |
|||
<if test="createBy != null">create_by,</if> |
|||
<if test="updateTime != null">update_time,</if> |
|||
<if test="updateBy != null">update_by,</if> |
|||
<if test="delFlag != null">del_flag,</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="textbookId != null and textbookId != ''">#{textbookId},</if> |
|||
<if test="batchName != null">#{batchName},</if> |
|||
<if test="regionId != null">#{regionId},</if> |
|||
<if test="activationCount != null">#{activationCount},</if> |
|||
<if test="unactivationCount != null">#{unactivationCount},</if> |
|||
<if test="createTime != null">#{createTime},</if> |
|||
<if test="createBy != null">#{createBy},</if> |
|||
<if test="updateTime != null">#{updateTime},</if> |
|||
<if test="updateBy != null">#{updateBy},</if> |
|||
<if test="delFlag != null">#{delFlag},</if> |
|||
</trim> |
|||
</insert> |
|||
|
|||
<update id="updateMmxtMeiyuTextbookActivateBatch" parameterType="com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch"> |
|||
update mmxt_meiyu_textbook_activate_batch |
|||
<trim prefix="SET" suffixOverrides=","> |
|||
<if test="textbookId != null and textbookId != ''">textbook_id = #{textbookId},</if> |
|||
<if test="batchName != null">batch_name = #{batchName},</if> |
|||
<if test="regionId != null">region_id = #{regionId},</if> |
|||
<if test="activationCount != null">activation_count = #{activationCount},</if> |
|||
<if test="unactivationCount != null">unactivation_count = #{unactivationCount},</if> |
|||
<if test="createTime != null">create_time = #{createTime},</if> |
|||
<if test="createBy != null">create_by = #{createBy},</if> |
|||
<if test="updateTime != null">update_time = #{updateTime},</if> |
|||
<if test="updateBy != null">update_by = #{updateBy},</if> |
|||
<if test="delFlag != null">del_flag = #{delFlag},</if> |
|||
</trim> |
|||
where batch_id = #{batchId} |
|||
</update> |
|||
|
|||
<update id="updateBatchUnactivationCount" parameterType="com.mmxt.business.domain.MmxtMeiyuTextbookActivateBatch"> |
|||
update mmxt_meiyu_textbook_activate_batch |
|||
set unactivation_count = unactivation_count - #{unactivationCount} |
|||
where batch_id = #{batchId} |
|||
and unactivation_count > 0 |
|||
</update> |
|||
|
|||
<update id="deleteMmxtMeiyuTextbookActivateBatchByBatchId" parameterType="Long"> |
|||
update mmxt_meiyu_textbook_activate_batch set del_flag = 1 where batch_id = #{batchId} |
|||
</update> |
|||
|
|||
<update id="deleteMmxtMeiyuTextbookActivateBatchByBatchIds" parameterType="String"> |
|||
update mmxt_meiyu_textbook_activate_batch set del_flag = 1 where batch_id in |
|||
<foreach item="batchId" collection="array" open="(" separator="," close=")"> |
|||
#{batchId} |
|||
</foreach> |
|||
</update> |
|||
</mapper> |
|||
Loading…
Reference in new issue