deal some bug

master
ourEmpire 6 years ago
parent 4c733a2df6
commit 45a4452f3b

@ -1,5 +1,6 @@
package cache
import database.mongo.Company
import database.mongo.CompanyRepo
import database.mongo.StudyWay
import database.mongo.StudyWayRepo
@ -33,7 +34,7 @@ class DataSet {
var orderList = ArrayList<OrdersEntity>()
val wayMap = ConcurrentHashMap<String, StudyWay>()
var wayList = ArrayList<StudyWay>()
var companyMap = ConcurrentHashMap<String,Company>()
val locations = HashMap<String,Int>()
var counts = HashMap<String,Int>()
@ -60,6 +61,7 @@ class DataSet {
val companies = companyRepo.findAll()
for(company in companies){
companyMap[company.id] = company
val locate = company.locate
var temp = ""
//只得到省或直辖市名 如:杭州-余杭区 ----> 杭州

@ -47,7 +47,7 @@ class SimpleCORSFilter : Filter {
val response = resp as HttpServletResponse
val request = req as HttpServletRequest
response.setHeader("Access-Control-Allow-Origin", "*")
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE")
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT")
response.setHeader("Access-Control-Max-Age", "3600")
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, authorization, Content-Type, Authorization, credential, X-XSRF-TOKEN")
if ("OPTIONS".equals(request.method, ignoreCase = true)) {

@ -29,37 +29,38 @@ public class AutoRecommendCtl {
private final static int TAGS_MIN = 4;
@GetMapping
public Message getRecommend(@RequestParam String username){
public Message getRecommend(@RequestParam String username) {
Message message = new Message();
ConcurrentHashMap<String, UsersEntity> userSet = dataSet.getUserMap();
UsersEntity usersEntity = userSet.get(username);
if(usersEntity == null){
if (usersEntity == null) {
message.setMsg(username + "未找到")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
ArrayList<Company> recommendCompany = new ArrayList<>();
ArrayList<String> userTags = userService.splitTags(usersEntity.getTags());
if(userTags == null){
return message.setMsg("用户"+username+"没有输入兴趣")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
for(Company company: companyRepo.findAll()){
int count = 0;
ArrayList<String> companyTags = company.getTags();
for(String tag: userTags){
if(companyTags.contains(tag)){
count++;
try {
ArrayList<String> userTags = userService.splitTags(usersEntity.getTags());
for (Company company : companyRepo.findAll()) {
int count = 0;
ArrayList<String> companyTags = company.getTags();
for (String tag : userTags) {
if (companyTags.contains(tag)) {
count++;
}
}
if (count > TAGS_MIN) {
recommendCompany.add(company);
}
}
if(count > TAGS_MIN){
recommendCompany.add(company);
}
return message.setMsg("操作成功")
.setCode(StateCode.OK)
.setData(recommendCompany);
} catch (Exception e) {
return message.setMsg("用户" + username + "没有输入兴趣")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
return message.setMsg("操作成功")
.setCode(StateCode.OK)
.setData(recommendCompany);
}
}

@ -1,17 +1,15 @@
package controller;
import database.mongo.Comment;
import database.mongo.Help;
import database.mongo.HelpRepo;
import message.Message;
import message.StateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
@Configuration
@RestController
@RequestMapping("/help")
public class HelpCtl {
@Autowired

@ -6,7 +6,6 @@ import config.EndpointContext
import database.mssql.UserRepo
import database.mssql.UsersEntity
import helper.TokenSet
import org.springframework.beans.factory.annotation.Autowired
import struct.Sessions
import top.ourfor.encoding.json.parse
import javax.websocket.*

@ -34,7 +34,6 @@ class PaySocket {
@OnClose
fun close(session: Session) {
map.remove(session.id)
for((k,v) in key) {
if(v==session.id) {
key.remove(k)

@ -1,6 +1,7 @@
package controller;
import cache.DataSet;
import database.mssql.UserRepo;
import database.mssql.UsersEntity;
import helper.MailService;
import helper.UserService;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@ -18,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class UserCtl {
private final DataSet ds;
private final UserService userService;
@Autowired
private UserRepo userRepo;
public UserCtl(DataSet ds, UserService userService) {
this.ds = ds;
this.userService = userService;
@ -81,16 +85,18 @@ public class UserCtl {
.setData(null);
}
@PutMapping
public Message update(@RequestParam String username,
public Message update(@RequestParam(required = false) String username,
@RequestParam(required = false) String openid,
@RequestParam(required = false) String email,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) Short age,
@RequestParam(required = false) String age,
@RequestParam(required = false) String sex,
@RequestParam(required = false) String city,
@RequestParam(required = false) String province,
@RequestParam(required = false) String country,
@RequestParam(required = false) String phone,
@RequestParam(required = false) ArrayList<String> tags){
@RequestParam(required = false) String tags){
Short age1 = Short.parseShort(age);
Message message = new Message();
final UsersEntity usersEntity = ds.getUserMap().get(username);
if(usersEntity == null){
@ -98,15 +104,23 @@ public class UserCtl {
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
if(openid != null) usersEntity.setOpenid(openid);
if(email != null) usersEntity.setEmail(email);
if(nickname != null) usersEntity.setNickname(nickname);
if(age != null) usersEntity.setAge(age);
if(age != null && 0 <= age1 && 200 > age1) {
usersEntity.setAge(age1);
}else if(age != null){
return message.setMsg("age参数不合法请输入0~200的数")
.setCode(StateCode.FORBIDDEN)
.setData(null);
}
if(sex != null) usersEntity.setSex(sex);
if(city != null) usersEntity.setCity(city);
if(province != null) usersEntity.setProvince(province);
if(country != null) usersEntity.setCountry(country);
if(phone != null) usersEntity.setPhone(phone);
if(tags != null) usersEntity.setTags(userService.joinTags(tags));
if(tags != null) usersEntity.setTags(tags);
ds.getUserMap().put(usersEntity.getUsername(),usersEntity);
return message.setMsg(username+"信息已修改")
.setCode(StateCode.OK)
.setData(usersEntity);
@ -138,7 +152,20 @@ public class UserCtl {
}
@GetMapping("/login")
public Message login(@RequestParam String username,
@RequestParam String password){
Message message = new Message();
UsersEntity user = ds.getUserMap().get(username);
if(user != null && user.getPassword().equals(password)){
return message.setMsg(username+"欢迎登陆!")
.setCode(StateCode.OK)
.setData(null);
}
return message.setMsg("用户名或密码错误")
.setCode(StateCode.FORBIDDEN)
.setData(null);
}
}

@ -0,0 +1,60 @@
package controller.console;
import cache.DataSet;
import database.mongo.Company;
import database.mongo.CompanyRepo;
import helper.UserService;
import message.Message;
import message.StateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/console/company")
public class CompanyCtl {
@Autowired
private DataSet dataSet;
@Autowired
private UserService userService;
@GetMapping
public Message getCompany(@RequestParam(required = false) String companyId){
Message message = new Message();
if(companyId == null){
return message.setMsg("操作成功")
.setCode(StateCode.OK)
.setData(null);
}
Company company = dataSet.getCompanyMap().get(companyId);
if(company == null){
return message.setMsg(companyId+"没有找到")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
return message.setMsg("操作成功")
.setCode(StateCode.OK)
.setData(null);
}
@PutMapping("/tags")
public Message updateTags(@RequestParam String companyId,
@RequestParam String tags){
Message message = new Message();
Company company = dataSet.getCompanyMap().get(companyId);
if(company == null){
return message.setMsg("公司"+companyId+"没有找到")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
company.setTags(userService.splitTags(tags));
dataSet.getCompanyMap().put(companyId,company);
return message.setMsg(companyId+"更新成功")
.setCode(StateCode.ACCEPTED)
.setData(null);
}
}

@ -1,35 +1,49 @@
package controller.console;
import cache.DataSet;
import database.mssql.OrderRepo;
import database.mssql.OrdersEntity;
import message.Message;
import message.StateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@RestController
@RequestMapping("/console/order")
public class OrderCtl {
@Autowired
private OrderRepo orderRepo;
private DataSet dataSet;
@GetMapping
public Message getOrders(){
Message message = new Message();
List<OrdersEntity> orders = (List<OrdersEntity>) orderRepo.findAll();
Collection<OrdersEntity> orders = dataSet.getOrderMap().values();
return message.setMsg("操作成功")
.setCode(StateCode.OK)
.setData(orders);
}
@DeleteMapping
public Message deleteOrder(@RequestParam String outTradeNo){
Message message = new Message();
ConcurrentHashMap<String,OrdersEntity> orders = dataSet.getOrderMap();
OrdersEntity order = orders.get(outTradeNo);
if(order == null){
return message.setMsg(outTradeNo + "未找到")
.setCode(StateCode.NOT_FOUND)
.setData(null);
}
orders.remove(order);
return message.setMsg("账单"+outTradeNo+"已删除")
.setCode(StateCode.ACCEPTED)
.setData(null);
}
}

@ -49,14 +49,15 @@ public class UsersCtl {
@RequestParam String email,
@RequestParam(required = false) String phone){
final Message message = new Message();
UsersEntity usersEntity = ds.getUserMap().get(username);
if(usersEntity != null){
UsersEntity user = ds.getUserMap().get(username);
if(user != null){
return message.setMsg("用户名"+username+"已存在")
.setCode(StateCode.FORBIDDEN)
.setData(null);
}
try{
user = new UsersEntity(username,password,email,phone);
ds.getUserMap().put(username,user);
return message.setCode(StateCode.CREATED)
.setMsg("操作成功")
.setData(null);

@ -2,7 +2,6 @@ package database.mssql;
import javax.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "users", schema = "dbo", catalog = "[user]")
public class UsersEntity {
@ -37,8 +36,8 @@ public class UsersEntity {
}
@Basic
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "nickname", insertable = false, updatable = false)
@Column(name = "nickname")
public String getNickname() {
return nickname;
}
@ -48,7 +47,8 @@ public class UsersEntity {
}
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", insertable = false, updatable = false)
public Long getId() {
return id;
}
@ -257,4 +257,29 @@ public class UsersEntity {
public int hashCode() {
return Objects.hash(nickname, id, username, password, age, sex, openid, city, province, country, wechatId, weiboId, qqId, phone, email, tags, reserve, inactive, stand);
}
@Override
public String toString() {
return "UsersEntity{" +
"nickname='" + nickname + '\'' +
", id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", openid='" + openid + '\'' +
", city='" + city + '\'' +
", province='" + province + '\'' +
", country='" + country + '\'' +
", wechatId='" + wechatId + '\'' +
", weiboId='" + weiboId + '\'' +
", qqId='" + qqId + '\'' +
", phone='" + phone + '\'' +
", email='" + email + '\'' +
", tags='" + tags + '\'' +
", reserve='" + reserve + '\'' +
", inactive='" + inactive + '\'' +
", stand='" + stand + '\'' +
'}';
}
}

@ -1,15 +1,10 @@
package helper
import cache.DataSet
import com.alibaba.fastjson.JSON
import database.mongo.CompanyRepo
import database.mongo.JobRepo
import database.mongo.StudyWayRepo
import database.mssql.OrderRepo
import database.mssql.UserRepo
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
@ -21,9 +16,15 @@ class Schedule {
private val ds: DataSet? = null
@Autowired
private val userRepo: UserRepo? = null
@Autowired
private val studyWayRepo: StudyWayRepo? = null
@Autowired
private val companyRepo: CompanyRepo? = null
@Autowired
private val orderRepo: OrderRepo? = null
//每隔1h将缓存数据写入数据库
@Scheduled(initialDelay = 1000 * 60L, fixedRate = 1000 * 60L)
@Scheduled(initialDelay = 1000 * 60 * 20L, fixedRate = 1000 * 60 * 20L)
fun userInfoUpdate() {
val userList = ArrayList(ds!!.userMap.values)
userRepo!!.saveAll(userList)
@ -34,7 +35,18 @@ class Schedule {
ds.userDeleteList.clear()
}
@Scheduled(initialDelay = 1000 * 60 * 60L, fixedRate = 1000 * 60 * 60L)
fun studyWayUpdate(){
studyWayRepo!!.saveAll(ds!!.wayList)
}
@Scheduled(initialDelay = 1000 * 60 * 60L, fixedRate = 1000 * 60 * 60L)
fun companyUpdate(){
companyRepo!!.saveAll(ds!!.companyMap.values)
}
@Scheduled(initialDelay = 1000 * 60 * 20L, fixedRate = 1000 * 60 * 20L)
fun orderUpdate(){
orderRepo!!.saveAll(ds!!.orderList)
}
}

@ -11,7 +11,7 @@ public class UserService {
public String joinTags(ArrayList<String> tags){
StringBuilder builder = new StringBuilder(tags.get(0));
for(int i = 1;i < tags.size();i++){
builder.append("-").append(tags.indexOf(i));
builder.append("-").append(tags.get(i));
}
return builder.toString();
}

@ -2,6 +2,8 @@ package init
import cache.DataSet
import config.AuthServerConfig
import database.mssql.UserRepo
import database.mssql.UsersEntity
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.context.ApplicationContext
@ -11,11 +13,8 @@ import org.springframework.stereotype.Component
@Order(1)
@Component
class Start: CommandLineRunner {
@Autowired
lateinit var ac: ApplicationContext
@Autowired
lateinit var ds: DataSet
override fun run(vararg args: String?) {
ds.init()
}

Loading…
Cancel
Save