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

@ -19,109 +19,182 @@ import com.tamguo.service.IPaperService;
import com.tamguo.util.ExceptionSupport;
import com.tamguo.util.Result;
// 标识这是一个Spring的控制器类用于处理Web请求并返回相应的视图或数据
@Controller
public class MemberPaperController {
// 自动注入IPaperService用于处理试卷相关的业务逻辑比如试卷的查询、添加、修改、删除等操作
@Autowired
private IPaperService iPaperService;
/**
* GET"member/paperList"
*
* @param model ModelAndView
* @param session HttpSession使
* @return ModelAndView便
*/
@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");
return model;
}
/**
* GETIDResult
*
* @param paperId
* @return ResultResult
*/
@RequestMapping(value = "/member/findPaper", method = RequestMethod.GET)
@ResponseBody
public Result findPaper(String 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
public Map<String, Object> paperList(String name , Integer page , Integer limit , HttpSession session){
MemberEntity member = ((MemberEntity)session.getAttribute("currMember"));
public Map<String, Object> paperList(String name, Integer page, Integer limit, HttpSession session) {
MemberEntity member = ((MemberEntity) session.getAttribute("currMember"));
Page<PaperEntity> p = new Page<>();
p.setCurrent(page);
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());
}
@RequestMapping(value="member/paperList/addPaperQuestionInfo",method=RequestMethod.POST)
/**
* POSTJSONID
* Result
*
* @param data JSONObject
* @return Result
*/
@RequestMapping(value = "member/paperList/addPaperQuestionInfo", method = RequestMethod.POST)
@ResponseBody
public Result addPaperQuestionInfo(@RequestBody JSONObject data){
public Result addPaperQuestionInfo(@RequestBody JSONObject data) {
try {
String paperId ; String title ; String name ;String type;
String paperId;
String title;
String name;
String type;
paperId = data.getString("uid");
title = data.getString("title");
type = data.getString("type");
name = QuestionType.getQuestionType(type).getDesc();
iPaperService.addPaperQuestionInfo(paperId , title , name , type);
iPaperService.addPaperQuestionInfo(paperId, title, name, type);
return Result.result(0, null, "修改成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("添加questionInfo", this.getClass(), e);
}
}
/**
* POSTJSONID
* Result
*
* @param data JSONObject
* @return Result
*/
@RequestMapping("member/paperList/updatePaperQuestionInfo.html")
@ResponseBody
public Result updatePaperQuestionInfo(@RequestBody JSONObject data){
public Result updatePaperQuestionInfo(@RequestBody JSONObject data) {
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");
title = data.getString("title");
type = data.getString("type");
name = QuestionType.getQuestionType(type).getDesc();
uid = data.getString("infoUid");
iPaperService.updatePaperQuestionInfo(paperId , title , name , type , uid);
iPaperService.updatePaperQuestionInfo(paperId, title, name, type, uid);
return Result.result(0, null, "修改成功");
} catch (Exception e) {
return ExceptionSupport.resolverResult("修改questionInfo", this.getClass(), e);
}
}
/**
* IDResult
*
* @param paperId
* @return Result
*/
@RequestMapping("member/paperList/deletePaper")
@ResponseBody
public Result deletePaper(String paperId){
public Result deletePaper(String paperId) {
try {
return iPaperService.deletePaper(paperId);
} catch (Exception e) {
return ExceptionSupport.resolverResult("删除试卷", this.getClass(), e);
}
}
/**
* ID
* Result
*
* @param paperId
* @param uid
* @return Result
*/
@RequestMapping("member/paperList/deletePaperQuestionInfoBtn")
@ResponseBody
public Result deletePaperQuestionInfoBtn(String paperId , String uid){
public Result deletePaperQuestionInfoBtn(String paperId, String uid) {
try {
return iPaperService.deletePaperQuestionInfoBtn(paperId , uid);
return iPaperService.deletePaperQuestionInfoBtn(paperId, uid);
} catch (Exception 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
public Result addPaper(@RequestBody PaperEntity paper,HttpSession session){
public Result addPaper(@RequestBody PaperEntity paper, HttpSession session) {
try {
MemberEntity member = (MemberEntity) session.getAttribute("currMember");
paper.setCreaterId(member.getUid());
iPaperService.addPaper(paper);
return Result.result(Result.SUCCESS_CODE, paper, "添加成功");
return Result.result(Result.SUCCESS_CODE, paper, "添加成功");
} catch (Exception 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
public Result updatePaper(@RequestBody PaperEntity paper){
public Result updatePaper(@RequestBody PaperEntity paper) {
try {
return iPaperService.updatePaper(paper);
} catch (Exception 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.Result;
@Controller(value="memberQuestionController")
// 标识这是一个Spring的控制器类名为"memberQuestionController"用于处理与会员相关的试题操作的Web请求并返回相应的视图或数据
@Controller(value = "memberQuestionController")
public class QuestionController {
// 自动注入IQuestionService用于处理试题相关的业务逻辑例如试题的添加、查询、更新、删除等操作
@Autowired
private IQuestionService iQuestionService;
// 自动注入IPaperService用于获取试卷相关信息可能在试题与试卷关联等操作中会用到
@Autowired
private IPaperService iPaperService;
/**
* GETID"member/addQuestion"
* ModelAndView便
*
* @param paperId
* @param model ModelAndView
* @return ModelAndView
*/
@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.addObject("paper", iPaperService.find(paperId));
return model;
}
/**
* POSTResult
*
*
* @param question QuestionEntity
* @return Result
*/
@RequestMapping(value = "/member/submitQuestion", method = RequestMethod.POST)
@ResponseBody
public Result submitQuestion(QuestionEntity question){
public Result submitQuestion(QuestionEntity question) {
try {
return iQuestionService.addQuestion(question);
} catch (Exception 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)
public ModelAndView questionList(String paperId , ModelAndView model){
public ModelAndView questionList(String paperId, ModelAndView model) {
model.addObject("paper", iPaperService.find(paperId));
model.setViewName("member/questionList");
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
public Map<String, Object> queryQuestionList(@RequestBody JSONObject data){
String questionType ; String uid ; String content ; String paperId ;
Integer page ; Integer limit;
public Map<String, Object> queryQuestionList(@RequestBody JSONObject data) {
String questionType;
String uid;
String content;
String paperId;
Integer page;
Integer limit;
questionType = data.getString("questionType");
uid = data.getString("uid");
content = data.getString("content");
content = data.getString("questionContent");
paperId = data.getString("paperId");
page = data.getInteger("page");
limit = data.getInteger("limit");
Page<QuestionEntity> p = new Page<>();
p.setCurrent(page);
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());
}
/**
* GETIDID"member/editQuestion"
* IDIDModelAndView便
*
* @param paperId
* @param questionId
* @param model ModelAndViewID
* @return IDModelAndView
*/
@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.addObject("paper", iPaperService.find(paperId));
model.addObject("questionId" , questionId);
model.addObject("questionId", questionId);
return model;
}
/**
* GETIDResult
*
* @param questionId
* @return ResultResult
*/
@RequestMapping(value = "/member/getQuestion", method = RequestMethod.GET)
@ResponseBody
public Result getQuestion(String questionId) {
return Result.successResult(iQuestionService.select(questionId));
}
/**
* POSTResult
*
*
* @param question QuestionEntity
* @return Result
*/
@RequestMapping(value = "/member/updateQuestion", method = RequestMethod.POST)
@ResponseBody
public Result updateQuestion(QuestionEntity question) {
return iQuestionService.updateQuestion(question);
}
/**
* GETResult
*
*
* @param uid
* @return Result
*/
@RequestMapping(value = "/member/deleteQuestion", method = RequestMethod.GET)
@ResponseBody
public Result deleteQuestion(@RequestBody String uid) {
return iQuestionService.delete(uid);
}
}
}
Loading…
Cancel
Save