test-demo-record

常规

@ApiOperation(value = "发送短信")
	@PostMapping("/test/sendSms")
	@ActionLog(action = "发送短信", remark = "发送短信")
	public R sendSms(@Valid @RequestBody SendSmsREQ req , @RequestHeader("Tenant-Id") String tenantId) {
		R r = shopRegisterService.sendSms(req, tenantId);
		return r;
	}
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

@Data
@ApiModel(value = "短信发送对象")
public class SendSmsREQ implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 手机号
	 */
	@ApiModelProperty(value = "手机号")
	@NotBlank(message = "手机号不能为空")
	private String phonenum;


	/**
	 * 发送短信场景(0:用户注册;1:申请成为合作伙伴;2:忘记密码;3:个人设置修改绑定手机号 4:绑定手机号)
	 * //用于校验一小时内短信发送次数不能超过配置的最大值
	 */
	@NotBlank(message = "发送短信场景枚举值不能为空")
	private String scene;

}
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_sms_code")
@ApiModel(value="SysSmsCode对象", description="短信验证码表")
public class SysSmsCode {

    private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "手机号码")
	@TableField("phonenum")
	private String phonenum;

	@ApiModelProperty(value = "验证码内容")
	@TableField("code")
	private String code;

	@ApiModelProperty(value = "最后修改时间")
	@TableField("update_time")
	private Date updateTime;

	@ApiModelProperty(value = "创建人id")
	@TableField("creator_id")
	private Long creatorId;

	@ApiModelProperty(value = "更新人id")
	@TableField("update_id")
	private Long updateId;

	@ApiModelProperty(value = "发送短信场景")
	@TableField("scene")
	private String scene;

}
@Override
	public Integer queryCountByPhoneNum(Map<String, Object> paramMap) {

		Date oneHourBefore = DateUtils.addHours(new Date(), -1);
		paramMap.put("oneHourBefore", oneHourBefore);
		int count = shopRegisterMapper.queryCountByPhoneNum(paramMap);

		return count;
	}
public interface RegisterMapper extends BaseMapper<SysSmsCode> {

	Integer queryCountByPhoneNum(Map<String,Object> paramMap);

	Integer queryUserByAccount(@Param("account") String account);

}
   <select id="queryCountByPhoneNum" parameterType="java.util.Map" resultType="java.lang.Integer">
        select count(*) from
        sys_sms_code
        where phonenum =#{phoneNum}
        and create_time between #{oneHourBefore} and now()
        and scene = #{scene}
    </select>

    <select id="queryUserByAccount" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(*) from user where account=#{account} and is_deleted=0
    </select>
Mapper.java
	User queryUserByPhone(Map<String,Object> paramMap);
	IPage<ShopUserVO> getShopUserList(@Param("req") UserQueryREQ req, @Param("page") Page page);
    <select id="queryUserByPhone" parameterType="java.util.Map" resultType="org.test.entity.User">
        select u.id,u.account,u.phonenum
        from user u join tenant_user_rel tur on u.id = tur.user_id
        where
        u.is_deleted = '0' and
        u.phonenum = #{phoneNum}
        <if test="boundRealPhone != null and boundRealPhone != '' ">
            AND tur.bound_real_phone = #{boundRealPhone}
        </if>
    </select>

 <select id="getShopUserList" resultType="org.test.vo.ShopUserVO">
        SELECT
        t1.id,
        t1.account,
        t1.phonenum,
        t1.supplier_id,
        t1.status,
        t1.update_time,
        t1.create_time,
        t2.supplier_name
        FROM
        `user` t1
        INNER JOIN `shop_supplier` t2 ON t1.`supplier_id` = t2.`id`
        <where>
            t1.is_deleted = '0' AND t1.supplier_id <![CDATA[ <> ]]> 0
            <if test="req.search != null and req.search!='' ">
                AND t1.phonenum LIKE concat('%',#{req.search},'%')
            </if>
            <if test="req.status != null and req.status!= '' ">
                AND t1.status = #{req.status}
            </if>
            <if test="req.supplierName != null and req.supplierName!= '' ">
                AND t2.supplier_name = #{req.supplierName}
            </if>
            <if test="req.startTime != null and req.startTime!=''">
                AND t1.update_time <![CDATA[>=]]> #{req.startTime}
            </if>
            <if test="req.endTime != null and req.endTime!='' ">
                AND t1.update_time <![CDATA[<=]]> #{req.endTime}
            </if>
        </where>
        order by t1.id desc
    </select>

    <insert id="saveTenantUserRelInfo" parameterType="org.test.user.entity.TenantUserRel">
      INSERT INTO tenant_user_rel
      (id,user_id,bound_real_phone,register_type)
      values (
      #{id},
      #{userId},
      #{boundRealPhone},
      #{registerType})
    </insert>

    <update id="updateTenantUserRelInfo" parameterType="java.util.Map" >
        update tenant_user_rel set bound_real_phone = #{boundRealPhone}
        where user_id = #{userId}
    </update>

mybatis-plus 的stream写法

TutorStudent one = this.lambdaQuery().eq(TutorStudent::getId, req.getId()).one();

	@Override
	public List<ShopOrder> getOrderPayList(String param) {
		return this.lambdaQuery()
		.eq(ShopOrder::getOrderStatus, CommonConstant.ORDER_STATUS)
		.eq(ShopOrder::getIsDeleted, CommonConstant.NO)
		.list();
	}


@Override
	public Boolean deleteOrderPayInfo(Long orderId) {
		boolean flag = this.lambdaUpdate()
		.eq(ShopOrder::getId, orderId)
		.set(ShopOrder::getIsDeleted, CommonConstant.YES)
		.update();
		return flag;
	}


  boolean result = this.lambdaUpdate()
  .set(CourseApplication::getApproveStatus, status)
  .eq(CourseApplication::getId, id)
  .update();

	@Override
	public Boolean addBatchTypeAbilityBusiness(List<CommonAttachmentAddREQ> entitys) {
		if(Func.isEmpty(entitys)){
			return false;
		}
		Set<String> ablrIds = entitys.stream().map(CommonAttachmentAddREQ::getBizId).collect(Collectors.toSet());

		this.lambdaUpdate().in(CommonAttachment::getBizId, ablrIds)
			.eq(CommonAttachment::getCreatorId, AuthUtil.getUserId())
			.eq(CommonAttachment::getType, "ability")
			.remove();

		return this.addBatchTypeAbility(entitys);
}


	List<String> userIds = this.lambdaQuery().select(LiveSignUp::getUserId).in(LiveSignUp::getId, signUpIds).list()
			.stream().map(e -> Func.toStr(e.getUserId())).collect(Collectors.toList());
		List<Long> userLongs = userIds.stream().map(Func::toLong).collect(Collectors.toList());

	@Override
	public R<Boolean> updateUserInfoById(String userId) {
		ShopUser user = shopUserService.lambdaQuery().eq(ShopUser::getId, userId).eq(ShopUser::getStatus, CommonConstant.YES).one();
		if (Func.isEmpty(user)) {
			return R.status(false);
		}
		boolean flag = this.lambdaUpdate().eq(ShopSupplier::getId, user.getSupplierId()).set(ShopSupplier::getIsCommissionid, CommonConstant.YES).set(ShopSupplier::getUpdateTime, new Date()).update();
		if (flag) {
			return R.status(true);
		}
		return R.status(false);
	}

导出

controller
	/**
	 * 导出线上必修总览统计
	 */
	@GetMapping("/v1/export")
	@ApiOperation(value = "导出线上必修总览统计", notes = "导出线上必修总览统计")
	public void complusoryOverviewExport(@NotBlank String startTime, @NotBlank String endTime, @NotBlank String exportSignature) throws Exception {
		countCompulsoryService.compulsoryOverviewExport(startTime, endTime, exportSignature);
	}

public interface ICountCompulsoryService {
void compulsoryOverviewExport(String startTime,String endTime,String exportSignature) throws IOException;
}
impl
	@Override
	public void compulsoryOverviewExport(String startTime,String endTime,String exportSignature) throws IOException {
		CountCompulsoryREQ req = new CountCompulsoryREQ ();
		req.setStartTime(startTime);
		req.setEndTime(endTime);
		List<CountCompulsoryOverviewVO> compulsoryOverviewList = countCompulsoryMapper.queryCompulsoryOverviewList(req);
		// 异步处理导出
		AsyncExportStudyPlanOverviewImpl impl = SpringUtil.getBean(AsyncExportStudyPlanOverviewImpl.class);
		impl.exportToRedisRela(startTime, endTime, exportSignature, CountCompulsoryOverviewVO.class, AuthUtil.getTenantId(), compulsoryOverviewList.size(),DataScopeUtil.getParam(DataScopeUtil.getMgmtDeptAncestors(AuthUtil.getUser())));
	}

@Async(CommonConstant.ASYNC_EXECUTOR)
	public <T> CompletableFuture<String> exportToRedis(String startTime, String endTime, String key, Class<T> clz, String tenantId, int count, String mgmtOrgIds) {
		try {
			key = key + ":" + tenantId;
			redisUtils.setExpireTime(key, 60L, TimeUnit.MINUTES);
			if (count < 1) {
				// 说明无数据
				redisUtils.set(key, EXPORT_NO_RESULT);
				return CompletableFuture.completedFuture("");
			} else {
				String fileName = startTime + "-" + endTime + ".xlsx";
				int totalSheet = (int) Math.ceil((double) count / HALF_MILLION);
				ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
				// 这里 指定文件
				try(ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream, clz).build()){
					for (int i = 0; i < totalSheet; i++) {
						// 每次都要创建writeSheet 这里注意必须指定sheetNo 而且sheetName必须不一样
						WriteSheet writeSheet = EasyExcel.writerSheet(i, "sheet" + i).build();
						// 分页去数据库查询数据 这里可以去数据库查询每一页的数据
						int sheetStart = i * HALF_MILLION;
						List data = exportRealData(startTime, endTime, sheetStart, HALF_MILLION, mgmtOrgIds);
						// 写数据
						excelWriter.write(data, writeSheet);
					}
				}
				// 将输出流转为输入流
				ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
				// 上传至华为OBS 并拿到文件地址
				MultipartFile file = generateMultipartFile(inputStream, fileName);
				R response = client.putFile(file, tenantId);
				String fileUrl = null;
				if (response.isSuccess()) {
					fileUrl = (String) response.getResponse();
					// 存入Redis
					redisUtils.set(key, fileUrl);
					return CompletableFuture.completedFuture("");
				}
				redisUtils.set(key, EXPORT_FAIL);
			}
		} catch (Exception e) {
			redisUtils.set(key, EXPORT_FAIL);
			e.printStackTrace();
		}
		return CompletableFuture.completedFuture("");
	}


	private MultipartFile generateMultipartFile(ByteArrayInputStream inputStream, String fileName) {
		FileItemFactory factory = new DiskFileItemFactory();
		DiskFileItem item = (DiskFileItem) factory.createItem("file", MediaType.APPLICATION_OCTET_STREAM_VALUE, true, fileName);
		try (OutputStream out = item.getOutputStream()) {
			IOUtils.copy(inputStream, out);
			return new CommonsMultipartFile(item);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

@Override
	public R putFile(MultipartFile file, String tenantId) throws IOException {
		BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
		return R.data(bladeFile.getLink());
	}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值