Merge remote-tracking branch 'origin/master'

master
bynt 1 year ago
commit 8670e2bce8

@ -98,4 +98,12 @@ public class ProxyController {
proxyService.writeProxy(file);
return Result.success();
}
@PostMapping("/addSurplusDay")
@Inner(value = false)
@ApiOperation("续期剩余使用天数")
public Result<?> addSurplusDay(@RequestBody ProxyDTO proxyDTO) {
proxyService.addSurplusDay(proxyDTO);
return Result.success();
}
}

@ -1,5 +1,6 @@
package com.baiye.dao;
import com.baiye.dto.ProxyDTO;
import com.baiye.entity.ProxyEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@ -21,4 +22,6 @@ public interface ProxyMapper extends BaseMapper<ProxyEntity> {
void updateExpireDateSubtractOne();
void updateExpireDateStatus();
void addSurplusDay(@Param("ids") List<Long> ids,@Param("num") Integer num);
}

@ -3,6 +3,8 @@ package com.baiye.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author YQY
* @Date 2023/3/29
@ -15,4 +17,10 @@ public class ProxyDTO {
@ApiModelProperty("ip地址")
private String ip;
@ApiModelProperty("id")
private List<Long> ids;
@ApiModelProperty("剩余使用天数")
private Integer surplusDay;
}

@ -63,4 +63,9 @@ public interface ProxyService {
*
*/
void writeProxy(MultipartFile file);
/**
*
*/
void addSurplusDay(ProxyDTO proxyDTO);
}

@ -117,6 +117,7 @@ public class IntellectSmartServiceImpl implements IntellectSmartService {
e.printStackTrace();
}
writer.close();
//没有图片了
// delPic(pictureTemplates);
}

@ -58,10 +58,10 @@ public class ProxyServiceImpl implements ProxyService {
// 2、有绑定关系直接返回
ProxyAccountEntity entity = proxyAccountMapper.selectOne(new LambdaQueryWrapper<ProxyAccountEntity>().eq(ProxyAccountEntity::getNid, phone));
if (ObjectUtil.isNull(entity)) {
throw new BadRequestException("未绑定代理Ip请绑定ip后重试");
throw new BadRequestException("未绑定代理Ip请绑定ip后重试,号码:" + phone);
}
ProxyEntity proxyEntity = proxyMapper.selectById(entity.getProxyId());
return verifyProxy(proxyEntity);
return verifyProxy(proxyEntity, phone);
// if (entity != null && entity.getId() != null) {
// return proxyMapper.selectById(entity.getProxyId());
// }
@ -200,7 +200,7 @@ public class ProxyServiceImpl implements ProxyService {
entities = proxyAccountMapper.selectList(new LambdaQueryWrapper<>());
}
Map<Long, List<ProxyAccountEntity>> map = entities.stream().collect(Collectors.groupingBy(ProxyAccountEntity::getProxyId));
wrapper.orderByDesc(ProxyEntity::getCreateTime);
Page<ProxyEntity> iPage = proxyMapper.selectPage(page, wrapper);
for (ProxyEntity record : iPage.getRecords()) {
if (map.containsKey(record.getId())) {
@ -215,7 +215,7 @@ public class ProxyServiceImpl implements ProxyService {
@Override
public List<ProxyEntity> list() {
return proxyMapper.selectList(new QueryWrapper<>());
return proxyMapper.selectList(new QueryWrapper<ProxyEntity>().orderByDesc("create_time"));
}
@Override
@ -226,8 +226,21 @@ public class ProxyServiceImpl implements ProxyService {
@Override
public void addAccountIp(Long proxyId, String phone) {
ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(phone, proxyId);
proxyAccountMapper.insert(proxyAccountEntity);
List<ProxyAccountEntity> list = new ArrayList<>();
String[] split = phone.split(",");
for (String p : split) {
log.info("号码 =" + p.trim());
ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(p.trim(), proxyId);
list.add(proxyAccountEntity);
}
if (CollUtil.isNotEmpty(list)) {
try {
proxyAccountMapper.insertAll(list);
} catch (Exception e) {
throw new BadRequestException("请检查输入是否正确");
}
}
}
@Override
@ -262,13 +275,18 @@ public class ProxyServiceImpl implements ProxyService {
}
}
@Override
public void addSurplusDay(ProxyDTO proxyDTO) {
proxyMapper.addSurplusDay(proxyDTO.getIds(), proxyDTO.getSurplusDay());
}
/**
* ip
*
* @param proxyEntity
* @return
*/
private ProxyEntity verifyProxy(ProxyEntity proxyEntity) {
private ProxyEntity verifyProxy(ProxyEntity proxyEntity, String phone) {
try {
String account = proxyEntity.getAccount();
String password = proxyEntity.getPassword();
@ -290,12 +308,12 @@ public class ProxyServiceImpl implements ProxyService {
.timeout(2_000)
.execute();
if (execute.getStatus() != 200) {
log.info("代理请求失败: {}", proxyEntity.getIp());
throw new BadRequestException("代理Ip不可用请重新绑定");
log.info("代理请求失败: {},号码:{}", proxyEntity.getIp(), phone);
throw new BadRequestException("代理Ip不可用请重新绑定,号码:" + phone);
}
} catch (Exception e) {
log.error("无效的代理地址: {}, 错误信息:{}", proxyEntity.getIp(), e.getMessage());
throw new BadRequestException("代理Ip不可用请重新绑定");
log.error("无效的代理地址: {},号码:{} 错误信息:{}", proxyEntity.getIp(), phone, e.getMessage());
throw new BadRequestException("代理Ip不可用请重新绑定,号码:" + phone);
}
return proxyEntity;
}

@ -14,15 +14,29 @@
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.ip}, #{item.port}, #{item.account}, #{item.password}, #{item.address},
#{item.agreementType}, #{item.surplusDay}, #{item.isDomestic}, #{item.agent}, #{item.status}, #{item.createTime})
#{item.agreementType}, #{item.surplusDay}, #{item.isDomestic}, #{item.agent}, #{item.status},
#{item.createTime})
</foreach>
</insert>
<update id="updateExpireDateSubtractOne">
update tb_proxy set surplus_day = surplus_day - 1 where surplus_day &gt; 0
update tb_proxy
set surplus_day = surplus_day - 1
where surplus_day &gt; 0
</update>
<update id="updateExpireDateStatus">
update tb_proxy set status = 1 where status = 0 AND surplus_day = 0
update tb_proxy
set status = 1
where status = 0
AND surplus_day = 0
</update>
<update id="addSurplusDay">
update tb_proxy
set surplus_day = surplus_day + ${num}
where id in
<foreach collection="ids" index="index" item="index" open="(" separator="," close=")">
#{index}
</foreach>
</update>
</mapper>
Loading…
Cancel
Save