readme 修改

Signed-off-by: SmileToCandy <smiletocandy@qq.com>
会员中心dcx
Dcx12138 8 months ago
parent e49504cb14
commit 259a2fe6fd

@ -35,76 +35,133 @@ import com.tamguo.util.ShiroUtils;
import com.tamguo.util.Status; import com.tamguo.util.Status;
import com.tamguo.util.UploaderMessage; import com.tamguo.util.UploaderMessage;
// 标识这是一个Spring的控制器类用于处理Web请求并返回相应的视图或数据
@Controller @Controller
public class AccountController { public class AccountController {
// 自动注入IMemberService用于处理会员相关的业务逻辑
@Autowired @Autowired
public IMemberService memberService; public IMemberService memberService;
// 通过配置文件注入文件存储路径属性值,方便后续文件保存操作使用
@Value("${file.storage.path}") @Value("${file.storage.path}")
private String fileStoragePath; private String fileStoragePath;
// 自动注入Setting可能用于获取一些系统配置相关的设置信息
@Autowired @Autowired
private Setting setting; private Setting setting;
// 自动注入CacheService用于缓存相关操作例如在生成头像编号时使用缓存来保证编号的唯一性和递增性
@Autowired @Autowired
private CacheService cacheService; private CacheService cacheService;
// 定义头像编号的默认格式化字符串,用于格式化生成的编号,保证编号格式统一
private static final String AVATOR_NO_FORMAT = "00000"; private static final String AVATOR_NO_FORMAT = "00000";
// 定义头像编号的前缀,方便识别头像文件相关的编号
private static final String AVATOR_PREFIX = "MTX"; private static final String AVATOR_PREFIX = "MTX";
// 创建日志记录器,用于记录该类中关键操作的日志信息,方便调试和问题排查
public Logger logger = LoggerFactory.getLogger(getClass()); public Logger logger = LoggerFactory.getLogger(getClass());
/**
* GET
*
* @param model ModelAndView
* @param session HttpSession
* @return ModelAndView便
*/
@RequestMapping(value = "member/account", method = RequestMethod.GET) @RequestMapping(value = "member/account", method = RequestMethod.GET)
public ModelAndView index(ModelAndView model , HttpSession session){ public ModelAndView index(ModelAndView model, HttpSession session) {
model.setViewName("member/account"); model.setViewName("member/account");
MemberEntity member = (MemberEntity) session.getAttribute("currMember"); MemberEntity member = (MemberEntity) session.getAttribute("currMember");
model.addObject("member" , memberService.findByUid(member.getUid())); model.addObject("member", memberService.findByUid(member.getUid()));
return model; return model;
} }
/**
* POSTIDID
*
* @param member MemberEntity
* @return Result
*/
@RequestMapping(value = "member/account/update", method = RequestMethod.POST) @RequestMapping(value = "member/account/update", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result updateMember(@RequestBody MemberEntity member){ public Result updateMember(@RequestBody MemberEntity member) {
member.setUid(ShiroUtils.getUserId()); member.setUid(ShiroUtils.getUserId());
memberService.updateMember(member); memberService.updateMember(member);
return Result.successResult(member); return Result.successResult(member);
} }
/**
* GET
*
* @param model ModelAndView
* @return ModelAndView便
*/
@RequestMapping(value = "member/password", method = RequestMethod.GET) @RequestMapping(value = "member/password", method = RequestMethod.GET)
public ModelAndView password(ModelAndView model){ public ModelAndView password(ModelAndView model) {
model.setViewName("member/password"); model.setViewName("member/password");
return model; return model;
} }
/**
* POST
*
* @param member MemberEntity
* @return Result
*/
@RequestMapping(value = "member/password/update", method = RequestMethod.POST) @RequestMapping(value = "member/password/update", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result updatePwd(@RequestBody MemberEntity member){ public Result updatePwd(@RequestBody MemberEntity member) {
return memberService.updatePwd(member); return memberService.updatePwd(member);
} }
/**
* POSTHttpServletRequest
*
* @param file MultipartFile
* @param request HttpServletRequest使
* @return UploaderMessage
* @throws IOException I/O
*/
@RequestMapping(value = "/member/uploadFile", method = RequestMethod.POST) @RequestMapping(value = "/member/uploadFile", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException { public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {
// 判断上传的文件是否为空,如果为空则直接返回文件为空的错误提示信息
if (!file.isEmpty()) { if (!file.isEmpty()) {
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
try { try {
// 根据当前日期构建文件存储的路径,方便按日期分类存储文件
String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd"); String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd");
File dir = new File(path); File dir = new File(path);
// 如果目录不存在,则创建相应的目录,确保文件有存储的位置
if (!dir.exists()) if (!dir.exists())
dir.mkdirs(); dir.mkdirs();
// 生成头像文件名,结合缓存获取的编号以及原文件名的后缀组成完整的文件名
String avatorName = this.getAvatorNo() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); String avatorName = this.getAvatorNo() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// 获取文件输入流,用于读取上传文件的内容
in = file.getInputStream(); in = file.getInputStream();
// 创建文件输出流,用于将读取的文件内容写入到服务器指定的存储位置
out = new FileOutputStream(path + "/" + avatorName); out = new FileOutputStream(path + "/" + avatorName);
byte[] b = new byte[1024]; byte[] b = new byte[1024];
int len = 0; int len = 0;
// 通过循环读取输入流中的文件内容,并写入到输出流中,实现文件的复制保存操作
while ((len = in.read(b)) > 0) { while ((len = in.read(b)) > 0) {
out.write(b, 0, len); out.write(b, 0, len);
} }
// 关闭输出流,释放资源
out.close(); out.close();
// 关闭输入流,释放资源
in.close(); in.close();
// 记录文件在服务器上的存储位置信息到日志中,方便后续查看和排查问题
logger.info("Server File Location=" + path + avatorName); logger.info("Server File Location=" + path + avatorName);
// 创建表示文件上传成功的消息对象,并设置相应的成功状态、提示信息、文件路径以及文件所在的域名等信息
UploaderMessage msg = new UploaderMessage(); UploaderMessage msg = new UploaderMessage();
msg.setStatus(Status.SUCCESS); msg.setStatus(Status.SUCCESS);
msg.setStatusMsg("File upload success"); msg.setStatusMsg("File upload success");
@ -112,30 +169,38 @@ public class AccountController {
msg.setFileDomain(setting.domain); msg.setFileDomain(setting.domain);
return msg; return msg;
} catch (Exception e) { } catch (Exception e) {
// 如果在文件上传过程中出现异常,创建表示文件上传失败的消息对象,并设置相应的错误状态和提示信息,然后返回该对象告知前端上传失败
UploaderMessage msg = new UploaderMessage(); UploaderMessage msg = new UploaderMessage();
msg.setStatus(Status.ERROR); msg.setStatus(Status.ERROR);
msg.setError("File upload file"); msg.setError("File upload file");
return msg; return msg;
} finally { } finally {
if (out != null) { // 在最终块中确保输出流资源被正确关闭,避免资源泄露
if (out!= null) {
out.close(); out.close();
out = null; out = null;
} }
if (in != null) { // 在最终块中确保输入流资源被正确关闭,避免资源泄露
if (in!= null) {
in.close(); in.close();
in = null; in = null;
} }
} }
} else { } else {
// 如果上传的文件为空,创建表示文件为空的错误消息对象,并设置相应的错误状态和提示信息,然后返回该对象告知前端文件为空
UploaderMessage msg = new UploaderMessage(); UploaderMessage msg = new UploaderMessage();
msg.setStatus(Status.ERROR); msg.setStatus(Status.ERROR);
msg.setError("File is empty"); msg.setError("File is empty");
return msg; return msg;
} }
} }
/**
*
*
* @return
*/
private String getAvatorNo() { private String getAvatorNo() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
String format = sdf.format(new Date()); String format = sdf.format(new Date());
@ -145,4 +210,4 @@ public class AccountController {
String avatorNo = AVATOR_PREFIX + df.format(incr); String avatorNo = AVATOR_PREFIX + df.format(incr);
return avatorNo; return avatorNo;
} }
} }

@ -19,109 +19,182 @@ import com.tamguo.service.IPaperService;
import com.tamguo.util.ExceptionSupport; import com.tamguo.util.ExceptionSupport;
import com.tamguo.util.Result; import com.tamguo.util.Result;
// 标识这是一个Spring的控制器类用于处理Web请求并返回相应的视图或数据
@Controller @Controller
public class MemberPaperController { public class MemberPaperController {
// 自动注入IPaperService用于处理试卷相关的业务逻辑比如试卷的查询、添加、修改、删除等操作
@Autowired @Autowired
private IPaperService iPaperService; private IPaperService iPaperService;
/**
* GET"member/paperList"
*
* @param model ModelAndView
* @param session HttpSession使
* @return ModelAndView便
*/
@RequestMapping(value = "/member/paper", method = RequestMethod.GET) @RequestMapping(value = "/member/paper", method = RequestMethod.GET)
public ModelAndView paper(ModelAndView model, HttpSession session){ public ModelAndView paper(ModelAndView model, HttpSession session) {
model.setViewName("member/paperList"); model.setViewName("member/paperList");
return model; return model;
} }
/**
* GETIDResult
*
* @param paperId
* @return ResultResult
*/
@RequestMapping(value = "/member/findPaper", method = RequestMethod.GET) @RequestMapping(value = "/member/findPaper", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result findPaper(String paperId) { public Result findPaper(String paperId) {
return Result.successResult(iPaperService.find(paperId)); return Result.successResult(iPaperService.find(paperId));
} }
@RequestMapping(value = "member/paper/list" , method = RequestMethod.GET) /**
* GET
* Map便jqGrid
*
* @param name
* @param page
* @param limit
* @param session HttpSession
* @return Map
*/
@RequestMapping(value = "member/paper/list", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Map<String, Object> paperList(String name , Integer page , Integer limit , HttpSession session){ public Map<String, Object> paperList(String name, Integer page, Integer limit, HttpSession session) {
MemberEntity member = ((MemberEntity)session.getAttribute("currMember")); MemberEntity member = ((MemberEntity) session.getAttribute("currMember"));
Page<PaperEntity> p = new Page<>(); Page<PaperEntity> p = new Page<>();
p.setCurrent(page); p.setCurrent(page);
p.setSize(limit); p.setSize(limit);
Page<PaperEntity> list = iPaperService.memberPaperList(name, member.getUid() , p); Page<PaperEntity> list = iPaperService.memberPaperList(name, member.getUid(), p);
return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages()); return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages());
} }
@RequestMapping(value="member/paperList/addPaperQuestionInfo",method=RequestMethod.POST) /**
* POSTJSONID
* Result
*
* @param data JSONObject
* @return Result
*/
@RequestMapping(value = "member/paperList/addPaperQuestionInfo", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result addPaperQuestionInfo(@RequestBody JSONObject data){ public Result addPaperQuestionInfo(@RequestBody JSONObject data) {
try { try {
String paperId ; String title ; String name ;String type; String paperId;
String title;
String name;
String type;
paperId = data.getString("uid"); paperId = data.getString("uid");
title = data.getString("title"); title = data.getString("title");
type = data.getString("type"); type = data.getString("type");
name = QuestionType.getQuestionType(type).getDesc(); name = QuestionType.getQuestionType(type).getDesc();
iPaperService.addPaperQuestionInfo(paperId , title , name , type); iPaperService.addPaperQuestionInfo(paperId, title, name, type);
return Result.result(0, null, "修改成功"); return Result.result(0, null, "修改成功");
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("添加questionInfo", this.getClass(), e); return ExceptionSupport.resolverResult("添加questionInfo", this.getClass(), e);
} }
} }
/**
* POSTJSONID
* Result
*
* @param data JSONObject
* @return Result
*/
@RequestMapping("member/paperList/updatePaperQuestionInfo.html") @RequestMapping("member/paperList/updatePaperQuestionInfo.html")
@ResponseBody @ResponseBody
public Result updatePaperQuestionInfo(@RequestBody JSONObject data){ public Result updatePaperQuestionInfo(@RequestBody JSONObject data) {
try { try {
String paperId ; String title ; String name ; String type ; String uid; String paperId;
String title;
String name;
String type;
String uid;
paperId = data.getString("uid"); paperId = data.getString("uid");
title = data.getString("title"); title = data.getString("title");
type = data.getString("type"); type = data.getString("type");
name = QuestionType.getQuestionType(type).getDesc(); name = QuestionType.getQuestionType(type).getDesc();
uid = data.getString("infoUid"); uid = data.getString("infoUid");
iPaperService.updatePaperQuestionInfo(paperId , title , name , type , uid); iPaperService.updatePaperQuestionInfo(paperId, title, name, type, uid);
return Result.result(0, null, "修改成功"); return Result.result(0, null, "修改成功");
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("修改questionInfo", this.getClass(), e); return ExceptionSupport.resolverResult("修改questionInfo", this.getClass(), e);
} }
} }
/**
* IDResult
*
* @param paperId
* @return Result
*/
@RequestMapping("member/paperList/deletePaper") @RequestMapping("member/paperList/deletePaper")
@ResponseBody @ResponseBody
public Result deletePaper(String paperId){ public Result deletePaper(String paperId) {
try { try {
return iPaperService.deletePaper(paperId); return iPaperService.deletePaper(paperId);
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("删除试卷", this.getClass(), e); return ExceptionSupport.resolverResult("删除试卷", this.getClass(), e);
} }
} }
/**
* ID
* Result
*
* @param paperId
* @param uid
* @return Result
*/
@RequestMapping("member/paperList/deletePaperQuestionInfoBtn") @RequestMapping("member/paperList/deletePaperQuestionInfoBtn")
@ResponseBody @ResponseBody
public Result deletePaperQuestionInfoBtn(String paperId , String uid){ public Result deletePaperQuestionInfoBtn(String paperId, String uid) {
try { try {
return iPaperService.deletePaperQuestionInfoBtn(paperId , uid); return iPaperService.deletePaperQuestionInfoBtn(paperId, uid);
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("删除子卷", this.getClass(), e); return ExceptionSupport.resolverResult("删除子卷", this.getClass(), e);
} }
} }
@RequestMapping(value="member/paperList/addPaper.html",method=RequestMethod.POST) /**
* POSTIDResult
*
*
* @param paper PaperEntity
* @param session HttpSessionID
* @return Result
*/
@RequestMapping(value = "member/paperList/addPaper.html", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result addPaper(@RequestBody PaperEntity paper,HttpSession session){ public Result addPaper(@RequestBody PaperEntity paper, HttpSession session) {
try { try {
MemberEntity member = (MemberEntity) session.getAttribute("currMember"); MemberEntity member = (MemberEntity) session.getAttribute("currMember");
paper.setCreaterId(member.getUid()); paper.setCreaterId(member.getUid());
iPaperService.addPaper(paper); iPaperService.addPaper(paper);
return Result.result(Result.SUCCESS_CODE, paper, "添加成功"); return Result.result(Result.SUCCESS_CODE, paper, "添加成功");
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("添加试卷", this.getClass(), e); return ExceptionSupport.resolverResult("添加试卷", this.getClass(), e);
} }
} }
@RequestMapping(value="member/paperList/updatePaper.html",method=RequestMethod.POST) /**
* POSTResult
*
* @param paper PaperEntity
* @return Result
*/
@RequestMapping(value = "member/paperList/updatePaper.html", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result updatePaper(@RequestBody PaperEntity paper){ public Result updatePaper(@RequestBody PaperEntity paper) {
try { try {
return iPaperService.updatePaper(paper); return iPaperService.updatePaper(paper);
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("修改试卷", this.getClass(), e); return ExceptionSupport.resolverResult("修改试卷", this.getClass(), e);
} }
} }
} }

@ -17,80 +17,146 @@ import com.tamguo.service.IQuestionService;
import com.tamguo.util.ExceptionSupport; import com.tamguo.util.ExceptionSupport;
import com.tamguo.util.Result; import com.tamguo.util.Result;
@Controller(value="memberQuestionController") // 标识这是一个Spring的控制器类名为"memberQuestionController"用于处理与会员相关的试题操作的Web请求并返回相应的视图或数据
@Controller(value = "memberQuestionController")
public class QuestionController { public class QuestionController {
// 自动注入IQuestionService用于处理试题相关的业务逻辑例如试题的添加、查询、更新、删除等操作
@Autowired @Autowired
private IQuestionService iQuestionService; private IQuestionService iQuestionService;
// 自动注入IPaperService用于获取试卷相关信息可能在试题与试卷关联等操作中会用到
@Autowired @Autowired
private IPaperService iPaperService; private IPaperService iPaperService;
/**
* GETID"member/addQuestion"
* ModelAndView便
*
* @param paperId
* @param model ModelAndView
* @return ModelAndView
*/
@RequestMapping(value = "/member/addQuestion", method = RequestMethod.GET) @RequestMapping(value = "/member/addQuestion", method = RequestMethod.GET)
public ModelAndView index(String paperId , ModelAndView model){ public ModelAndView index(String paperId, ModelAndView model) {
model.setViewName("member/addQuestion"); model.setViewName("member/addQuestion");
model.addObject("paper", iPaperService.find(paperId)); model.addObject("paper", iPaperService.find(paperId));
return model; return model;
} }
/**
* POSTResult
*
*
* @param question QuestionEntity
* @return Result
*/
@RequestMapping(value = "/member/submitQuestion", method = RequestMethod.POST) @RequestMapping(value = "/member/submitQuestion", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result submitQuestion(QuestionEntity question){ public Result submitQuestion(QuestionEntity question) {
try { try {
return iQuestionService.addQuestion(question); return iQuestionService.addQuestion(question);
} catch (Exception e) { } catch (Exception e) {
return ExceptionSupport.resolverResult("添加试题", this.getClass(), e); return ExceptionSupport.resolverResult("添加试题", this.getClass(), e);
} }
} }
/**
* GETID"member/questionList"
* ModelAndView便
*
* @param paperId
* @param model ModelAndView
* @return ModelAndView
*/
@RequestMapping(value = "/member/questionList", method = RequestMethod.GET) @RequestMapping(value = "/member/questionList", method = RequestMethod.GET)
public ModelAndView questionList(String paperId , ModelAndView model){ public ModelAndView questionList(String paperId, ModelAndView model) {
model.addObject("paper", iPaperService.find(paperId)); model.addObject("paper", iPaperService.find(paperId));
model.setViewName("member/questionList"); model.setViewName("member/questionList");
return model; return model;
} }
@RequestMapping(value = "/member/queryQuestionList" , method=RequestMethod.POST) /**
* POSTJSONID
* Map便jqGrid
*
* @param data JSONObject
* @return Map
*/
@RequestMapping(value = "/member/queryQuestionList", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Map<String, Object> queryQuestionList(@RequestBody JSONObject data){ public Map<String, Object> queryQuestionList(@RequestBody JSONObject data) {
String questionType ; String uid ; String content ; String paperId ; String questionType;
Integer page ; Integer limit; String uid;
String content;
String paperId;
Integer page;
Integer limit;
questionType = data.getString("questionType"); questionType = data.getString("questionType");
uid = data.getString("uid"); uid = data.getString("uid");
content = data.getString("content"); content = data.getString("questionContent");
paperId = data.getString("paperId"); paperId = data.getString("paperId");
page = data.getInteger("page"); page = data.getInteger("page");
limit = data.getInteger("limit"); limit = data.getInteger("limit");
Page<QuestionEntity> p = new Page<>(); Page<QuestionEntity> p = new Page<>();
p.setCurrent(page); p.setCurrent(page);
p.setSize(limit); p.setSize(limit);
Page<QuestionEntity> list = iQuestionService.queryQuestionList(questionType , uid , content , paperId , p); Page<QuestionEntity> list = iQuestionService.queryQuestionList(questionType, uid, content, paperId, p);
return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages()); return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages());
} }
/**
* GETIDID"member/editQuestion"
* IDIDModelAndView便
*
* @param paperId
* @param questionId
* @param model ModelAndViewID
* @return IDModelAndView
*/
@RequestMapping(value = "/member/editQuestion", method = RequestMethod.GET) @RequestMapping(value = "/member/editQuestion", method = RequestMethod.GET)
public ModelAndView editQuestion(String paperId , String questionId , ModelAndView model){ public ModelAndView editQuestion(String paperId, String questionId, ModelAndView model) {
model.setViewName("member/editQuestion"); model.setViewName("member/editQuestion");
model.addObject("paper", iPaperService.find(paperId)); model.addObject("paper", iPaperService.find(paperId));
model.addObject("questionId" , questionId); model.addObject("questionId", questionId);
return model; return model;
} }
/**
* GETIDResult
*
* @param questionId
* @return ResultResult
*/
@RequestMapping(value = "/member/getQuestion", method = RequestMethod.GET) @RequestMapping(value = "/member/getQuestion", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result getQuestion(String questionId) { public Result getQuestion(String questionId) {
return Result.successResult(iQuestionService.select(questionId)); return Result.successResult(iQuestionService.select(questionId));
} }
/**
* POSTResult
*
*
* @param question QuestionEntity
* @return Result
*/
@RequestMapping(value = "/member/updateQuestion", method = RequestMethod.POST) @RequestMapping(value = "/member/updateQuestion", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result updateQuestion(QuestionEntity question) { public Result updateQuestion(QuestionEntity question) {
return iQuestionService.updateQuestion(question); return iQuestionService.updateQuestion(question);
} }
/**
* GETResult
*
*
* @param uid
* @return Result
*/
@RequestMapping(value = "/member/deleteQuestion", method = RequestMethod.GET) @RequestMapping(value = "/member/deleteQuestion", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result deleteQuestion(@RequestBody String uid) { public Result deleteQuestion(@RequestBody String uid) {
return iQuestionService.delete(uid); return iQuestionService.delete(uid);
} }
} }
Loading…
Cancel
Save