读取文件Nickname
parent
d720f01812
commit
43b7455ec0
@ -0,0 +1,37 @@
|
|||||||
|
package com.hchbox.controller;
|
||||||
|
|
||||||
|
import com.hchbox.entity.master.Shop;
|
||||||
|
import com.hchbox.model.param.CommonResult;
|
||||||
|
import com.hchbox.service.ShopService;
|
||||||
|
import com.taobao.api.domain.Item;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YQY
|
||||||
|
* @date : 2021/11/23
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Api(tags = "店铺操作")
|
||||||
|
@RequestMapping("/source/shop")
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
private final ShopService shopService;
|
||||||
|
|
||||||
|
@GetMapping("/readFile")
|
||||||
|
@ApiOperation("读取文件")
|
||||||
|
public void readFile() {
|
||||||
|
shopService.readFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/queryNick")
|
||||||
|
@ApiOperation("查询nick_name")
|
||||||
|
public CommonResult<List<Shop>> queryNick() {
|
||||||
|
return new CommonResult<List<Shop>>().success(shopService.queryNick());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.hchbox.entity.master;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YQY
|
||||||
|
* @date : 2021/11/23
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "nick_name")
|
||||||
|
public class Shop implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5051120357215189176L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "nk_name")
|
||||||
|
@ApiModelProperty(value = "店铺名称")
|
||||||
|
private String nkName;
|
||||||
|
|
||||||
|
@Column(name = "status")
|
||||||
|
@ApiModelProperty(value = "状态")
|
||||||
|
private Integer status;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.hchbox.repository.master;
|
||||||
|
|
||||||
|
import com.hchbox.entity.master.Shop;
|
||||||
|
import com.hchbox.model.param.CommonResult;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YQY
|
||||||
|
* @date : 2021/11/23
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface ShopRepository extends JpaRepository<Shop, Long>, JpaSpecificationExecutor<Shop> {
|
||||||
|
|
||||||
|
@Query(value = "select * from nick_name where status = 0 limit 0 , ?1" ,nativeQuery = true)
|
||||||
|
List<Shop> findNice(Integer num);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.hchbox.service;
|
||||||
|
|
||||||
|
import com.hchbox.entity.master.Shop;
|
||||||
|
import com.hchbox.model.param.CommonResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YQY
|
||||||
|
* @date : 2021/11/23
|
||||||
|
*/
|
||||||
|
public interface ShopService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读文件
|
||||||
|
*/
|
||||||
|
void readFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询nick_name
|
||||||
|
*
|
||||||
|
* @return {@link CommonResult}<{@link List}<{@link Shop}>>
|
||||||
|
*/
|
||||||
|
List<Shop> queryNick();
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.hchbox.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.file.FileReader;
|
||||||
|
import com.hchbox.entity.master.Shop;
|
||||||
|
import com.hchbox.model.param.CommonResult;
|
||||||
|
import com.hchbox.repository.master.ShopRepository;
|
||||||
|
import com.hchbox.service.ShopService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YQY
|
||||||
|
* @date : 2021/11/23
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ShopServiceImpl implements ShopService {
|
||||||
|
|
||||||
|
private final ShopRepository shopRepository;
|
||||||
|
private static Integer NUM = 30;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFile() {
|
||||||
|
FileReader fileReader = new FileReader("/usr/local/webapp/店铺名称统计.txt");
|
||||||
|
String[] nickNames = fileReader.readString().split(",");
|
||||||
|
if (nickNames.length > 0) {
|
||||||
|
Set<String> set = new HashSet();
|
||||||
|
for (int i = 0; i < nickNames.length; i++) {
|
||||||
|
set.add(nickNames[i]);
|
||||||
|
}
|
||||||
|
set.forEach(c -> {
|
||||||
|
Shop shop = new Shop();
|
||||||
|
shop.setNkName(c);
|
||||||
|
shop.setStatus(0);
|
||||||
|
shopRepository.save(shop);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Shop> queryNick() {
|
||||||
|
List<Shop> nice = shopRepository.findNice(NUM);
|
||||||
|
if (nice.size() > 0) {
|
||||||
|
for (Shop shop : nice) {
|
||||||
|
Shop sp = new Shop();
|
||||||
|
sp.setId(shop.getId());
|
||||||
|
sp.setStatus(1);
|
||||||
|
shopRepository.save(sp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nice;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue