This commit is contained in:
Vindicator645 2020-03-14 17:30:51 +08:00
parent c1a23adaba
commit 205b7e2602
6 changed files with 139 additions and 8 deletions

View File

@ -0,0 +1,71 @@
package com.codesdream.ase.controller;
import com.alibaba.fastjson.JSONObject;
import com.codesdream.ase.component.datamanager.JSONParameter;
import com.codesdream.ase.component.json.respond.FailedSONRespond;
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
import com.codesdream.ase.component.permission.ASEUsernameEncoder;
import com.codesdream.ase.component.json.request.UserLeaveChecker;
import com.codesdream.ase.component.json.respond.UserLeaveCheckerJSONRespond;
import com.codesdream.ase.service.LeavesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
/**
* 登录界面控制器类
*/
@Slf4j
@Controller
public class LeavesController {
@Resource
private JSONParameter jsonParameter;
@Resource
private LeavesService leavesService;
@Resource
private ASEUsernameEncoder usernameEncoder;
@RequestMapping(value = "/")
String printLeave(Model model) {
return "Leave";
}
@RequestMapping(value = "/Leave/check", method = RequestMethod.POST)
@ResponseBody
String checkLeave(HttpServletRequest request){
// 检查是否为JSON
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond());
UserLeaveChecker LeaveChecker = json.get().toJavaObject(UserLeaveChecker.class);
// 检查类型
if(LeaveChecker.getCheckType().equals("UsernameExistChecker")){
// 根据学号计算用户名
String user = usernameEncoder.encode(LeaveChecker.getUsername()) ;
// 查询用户名存在状态
boolean existStatus = userService.checkIfUserExists(user).getKey();
// 构造返回对象
UserLeaveCheckerJSONRespond respond = new UserLeaveCheckerJSONRespond();
respond.setUserExist(existStatus);
return jsonParameter.getJSONString(respond);
}
else {
// 返回失败对象
return jsonParameter.getJSONString(new JSONBaseRespondObject());
}
}
}

View File

@ -6,7 +6,7 @@ import java.util.*;
import javax.persistence.*;
@Data
@Entity
@Table(name = "leaves_archive")
@Table(name = "leave")
public class Leave {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -1,7 +0,0 @@
package com.codesdream.ase.model.leaves;
/**
请假信息的管理系统
*/
public class LeavesSystem {
}

View File

@ -0,0 +1,6 @@
package com.codesdream.ase.repository.leaves;
import org.springframework.data.repository.CrudRepository;
public interface LeaveRepository extends CrudRepository{
}

View File

@ -0,0 +1,4 @@
package com.codesdream.ase.service;
public interface ILeavesService {
}

View File

@ -0,0 +1,57 @@
package com.codesdream.ase.service;
import com.codesdream.ase.model.leaves.Leave;
import com.codesdream.ase.repository.leaves.LeaveRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Optional;
@Service
public class LeavesService implements ILeavesService {
@Resource
private LeaveRepository leaveRepository;
@Override
public Optional<Leave> findLeaveByTitle(String title) {
return LeaveRepository.findByTitle(title);
}
@Override
public Optional<leave> findLeaveByCreator(String creatorName) {
return LeaveRepository.findByCreator(creatorName);
}
@Override
public Leave save(Leave Leave) {
return LeaveRepository.save(Leave);
}
@Override
public Leave addReport(Leave Leave, Report report) {
Leave.setReport(report);
return update(Leave);
}
@Override
public void delete(Leave Leave) {
LeaveRepository.delete(Leave);
}
@Override
public Leave update(Leave Leave) {
return LeaveRepository.save(Leave);
}
@Override
public Leave createLeave(Leave Leave) {
return LeaveRepository.save(Leave);
}
/*@Override
public Leave findActivitiesInTheCharge(User user) {
}*/
}