基于javaweb+mysql的springboot在线拍卖竞价系统(java+springboot+freemarker+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线拍卖竞价系统(java+springboot+freemarker+mysql)
超级管理员:系统管理、用户管理(冻结等)、审批竞拍标的物管理、竞标类型管理、审批机构、个人提现管理(审核)、企业提现管理(审批)等。
普通用户:注册登录、个人信息管理(个人资料、密码修改等)、留言管理、竞价管理、竞拍收藏、订单查询(物流信息查询)、银行卡管理、提现管理等、竞拍物品展示查询(列表搜索、详情展示、报名记录、竞价记录)。
企业用户:注册登录、发布竞拍、竞拍管理、充值订单、银行卡管理、提现记录。
HttpSession session = getSession();
if(session != null){
return session.getAttribute(key);
}
return null;
}
/**
* 设置session值
* @param key
* @param object
*/
public static void set(String key,Object object){
HttpSession session = getSession();
if(session != null){
session.setAttribute(key,object);
}
}
/**
* 获取当前登录的用户
* @return
*/
public static User getLoginedUser(){
HttpSession session = getSession();
if(session != null){
Object attribute = session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
return attribute == null ? null : (User)attribute;
}
return null;
}
/**
* 获取拍卖者登录信息
* @return
*/
public static Organization getOraganization(){
HttpSession session=getSession();
if(session!=null){
Object attribute = session.getAttribute(SessionConstant.SESSION_USER_ORGANIZATION);
return attribute==null?null:(Organization) attribute;
}
return null;
}
/**
* 获取前台用户登录信息
/**
* 后台项目分类控制器
*
*/
@RequestMapping("/admin/project_category")
@Controller
public class ProjectCategoryController {
@Autowired
private ProjectCategoryService projectCategoryService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 项目分类列表
* @param model
* @param projectCategory
* @param pageBean
* @return
*/
@GetMapping("/list")
public String list(Model model, ProjectCategory projectCategory, PageBean<ProjectCategory> pageBean){
model.addAttribute("title", "商品分类列表");
model.addAttribute("name",projectCategory.getName());
model.addAttribute("pageBean", projectCategoryService.findList(projectCategory, pageBean));
return "admin/project_category/list";
}
/**
* 项目分类添加
* @param model
* @return
*/
@GetMapping("/add")
public String add(Model model){
return Result.success(true);
}
/**
* 登录成功后的系统主页
* @param model
* @return
*/
@RequestMapping(value="/index")
public String index(Model model){
model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));
model.addAttribute("userTotal", userService.total());
model.addAttribute("operatorLogTotal", operaterLogService.total());
model.addAttribute("databaseBackupTotal", 0);
model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
model.addAttribute("showTipsText", showTipsText);
model.addAttribute("showTipsUrlText", showTipsUrlText);
model.addAttribute("showTipsUtl", showTipsUtl);
model.addAttribute("showTipsBtnText", showTipsBtnText);
return "admin/system/index";
}
/**
* 注销登录
* @return
*/
@RequestMapping(value="/logout")
public String logout(){
Integer type = (Integer) SessionUtil.get("type");
if(type==(LoginType.ADMINISTRATOR.getCode())){
User loginedUser = SessionUtil.getLoginedUser();
if(loginedUser != null){
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
}
}else if(type == LoginType.ORGANIZATION.getCode()){
Organization loginedJudge = SessionUtil.getOraganization();
if(loginedJudge != null){
SessionUtil.set(SessionConstant.SESSION_USER_ORGANIZATION,null);
}
}
return "redirect:login";
}
/**
* 无权限提示页面
* @return
*/
@RequestMapping(value="/no_right")
public String noRight(){
return "admin/system/no_right";
}
/**
private OperaterLogService operaterLogService;
@Autowired
private AccountService accountService;
/**
* 商品列表
* @param model
* @param biddingProject
* @param pageBean
* @return
*/
@GetMapping("/list")
public String list(Model model, BiddingProject biddingProject, PageBean<BiddingProject> pageBean){
Organization oraganization = SessionUtil.getOraganization();
biddingProject.setOrganization(oraganization);
PageBean<BiddingProject> list = projectService.findList(biddingProject, pageBean);
model.addAttribute("pageBean",list);
model.addAttribute("title","竞价列表");
model.addAttribute("categoryList",projectCategoryService.findAll());
model.addAttribute("name",biddingProject.getName()==null?"":biddingProject.getName());
model.addAttribute("currentCategory",biddingProject.getProjectCategory()==null?-1:biddingProject.getProjectCategory().getId());
return "admin/bidding_record/list";
}
/**
* 竞价记录列表
* @param biddingRecord
* @Param pageBean
* @param model
* @return
*/
@GetMapping("/record_list")
public String recordsList(BiddingRecord biddingRecord, PageBean<BiddingRecord> pageBean,Model model){
BiddingProject biddingProject = projectService.find(biddingRecord.getBiddingProject().getId());
if(biddingProject==null){
model.addAttribute("msg","未找到该商品");
}
PageBean<BiddingRecord> biddingRecordList = biddingRecordService.findByOraganizationList(biddingProject.getId(), pageBean);
model.addAttribute("biddingRecordList",biddingRecordList);
model.addAttribute("title","竞价记录列表");
return "admin/bidding_record/bidding_record_view_list";
}
/**
* 确认交易操作
* @param rid
* @return
*/
@ResponseBody
}else if(type == LoginType.ORGANIZATION.getCode()){
Organization loginedJudge = SessionUtil.getOraganization();
if(loginedJudge != null){
SessionUtil.set(SessionConstant.SESSION_USER_ORGANIZATION,null);
}
}
return "redirect:login";
}
/**
* 无权限提示页面
* @return
*/
@RequestMapping(value="/no_right")
public String noRight(){
return "admin/system/no_right";
}
/**
* 修改用户个人信息
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
public String updateUserInfo(){
return "admin/system/update_userinfo";
}
/**
* 修改个人信息保存
* @param user
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
public String updateUserInfo(User user){
User loginedUser = SessionUtil.getLoginedUser();
loginedUser.setEmail(user.getEmail());
loginedUser.setMobile(user.getMobile());
loginedUser.setHeadPic(user.getHeadPic());
//首先保存到数据库
userService.save(loginedUser);
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return "redirect:update_userinfo";
}
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(@RequestParam(name="id",required=true)Long id,Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
Role role = roleService.find(id);
model.addAttribute("role", role);
model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
return "admin/role/edit";
}
/**
* 角色修改表单提交处理
* @param request
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
Role existRole = roleService.find(role.getId());
if(existRole == null){
return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
}
existRole.setName(role.getName());
existRole.setRemark(role.getRemark());
existRole.setStatus(role.getStatus());
existRole.setAuthorities(role.getAuthorities());
if(roleService.save(existRole) == null){
return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
}
log.info("编辑角色【"+role+"】");
operaterLogService.add("编辑角色【"+role.getName()+"】");
return Result.success(true);
}
/**
* 删除角色
@PostMapping("/login")
public Result<Boolean> login(Account account) {
if (account == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_LOGIN_ERROR);
}
if (account.getUsername() == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_USERNAME_ERROR);
}
Account byUsername = accountService.findByUsername(account.getUsername());
if (byUsername == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_NOT_EXIST_ERROR);
}
if (!byUsername.getPassword().equals(account.getPassword())) {
return Result.error(CodeMsg.HOME_ACCOUNT_PASSWORD_ERROR);
}
if (byUsername.getStatus() == Account.HOME_ACCOUNT_STATUS_UNABLE) {
return Result.error(CodeMsg.HOME_ACCOUNT_STATUS_ERROR);
}
SessionUtil.set(SessionConstant.SESSION_HOME_USER_LOGIN_KEY, byUsername);
return Result.success(true);
}
/**
* 注册用户操作
*
* @param account
* @return
*/
@ResponseBody
@PostMapping("/register")
public Result<Boolean> register(Account account) {
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(account);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//验证邮箱
if (!StringUtil.emailFormat(account.getEmail())) {
return Result.error(CodeMsg.HOME_ACCOUNT_EMAIL_ERROR);
}
//验证手机号
if (!StringUtil.isMobile(account.getMobile())) {
return Result.error(CodeMsg.HOME_ACCOUNT_PHONE_ERROR);
}
/**
* 项目通用工具类
*
*/
public class StringUtil {
/**
* 返回指定格式的日期字符串
* @param date
* @param formatter
* @return
*/
public static String getFormatterDate(Date date,String formatter){
SimpleDateFormat sdf = new SimpleDateFormat(formatter);
return sdf.format(date);
}
/**
* 判断请求是否是ajax
* @param request
* @return
*/
public static boolean isAjax(HttpServletRequest request){
String header = request.getHeader("X-Requested-With");
if("XMLHttpRequest".equals(header))return true;
return false;
}
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId() == null || user.getId().longValue() <= 0){
return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
}
if(userService.isExistUsername(user.getUsername(), user.getId())){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
//到这说明一切符合条件,进行数据库保存
User findById = userService.find(user.getId());
//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime");
if(userService.save(findById) == null){
return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
}
operaterLogService.add("编辑用户,用户名:" + user.getUsername());
return Result.success(true);
}
/**
* 删除用户
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
userService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
}
operaterLogService.add("删除用户,用户ID:" + id);
return Result.success(true);
}
}
package com.yuanlrc.base.controller.admin;
model.addAttribute("pageBean", accountService.findList(account, pageBean));
return "admin/account/list";
}
/**
* 前台用户添加
* @param model
* @return
*/
@GetMapping("/add")
public String add(Model model){
return "admin/account/add";
}
/**
* 前台用户添加操作
* @param account
* @return
*/
@ResponseBody
@PostMapping("/add")
public Result<Boolean> add(Account account){
CodeMsg validate = ValidateEntityUtil.validate(account);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(StringUtils.isEmpty(account.getPmPwd())){
return Result.error(CodeMsg.ADMIN_ACCOUNT_PMPWD_ERROR);
}
Account byUsername = accountService.findByUsername(account.getUsername());
if(byUsername!=null){
return Result.error(CodeMsg.HOME_ACCOUNT_USERNAME_EXIST);
}
//一切顺利添加到数据库
if(accountService.save(account)==null){
return Result.error(CodeMsg.ADMIN_ACCOUNT_ADD_ERROR);
}
operaterLogService.add("添加前台用户,用户名:" + account.getUsername());
return Result.success(true);
}
return Result.error(codeMsg);
}
//准备保存文件
File filePath = new File(uploadPhotoPath);
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
//判断当天日期的文件夹是否存在,若不存在,则创建
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
try {
photo.transferTo(new File(uploadPhotoPath + "/" + filename));
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
return Result.success(filename);
}
/**
* 富文本kindedit的图片上传
*
* @param request
* @param response
* @param imgFile
* @throws IOException
*/
@ResponseBody
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public void uploadFile(HttpServletRequest request, HttpServletResponse response, @RequestParam("imgFile") MultipartFile imgFile) throws IOException {
PrintWriter out = response.getWriter();
//判断文件类型是否是图片
String originalFilename = imgFile.getOriginalFilename();
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
if (biddingProject.getTransactionPrice() < money) {
//更新竞拍最高价
if (projectService.updateMaxMoney(money, pid) <= 0) {
return Result.error(CodeMsg.HOME_BIDDING_PROJECT_EDIT_MAX_MONEY_ERROR);
}
}
//添加到竞拍表
BiddingRecord biddingRecord = new BiddingRecord();
biddingRecord.setAccount(account);
biddingRecord.setBiddingProject(biddingProject);
biddingRecord.setQuantity(quantity);
biddingRecord.setBid(money);
if (biddingRecordService.save(biddingRecord) == null) {
return Result.error(CodeMsg.HOME_PROJECT_BIDDINGRECORD_ADD_ERROR);
}
return Result.success(true);
}
/**
* 查询自己的报名记录
*
* @param
* @return
*/
@GetMapping("/apply_list")
public String projectApply(Model model) {
Account account = SessionUtil.getAccount();
List<BiddingApply> applyList = biddingApplyService.findByAccountId(account.getId());
model.addAttribute("projectApplyList", applyList);
model.addAttribute("activeType", "profile");
return "home/personal/profile_apply_list";
}
/**
* 查询自己的竞价记录
*
* @param model
* @return
*/
@GetMapping("/bidding_record_list")
public String projectBiddingRecord(Model model) {
Account account = SessionUtil.getAccount();
List<BiddingRecord> recordList = biddingRecordService.findByAccountIdOrderByBidDesc(account.getId());
model.addAttribute("recordList", recordList);
model.addAttribute("activeType", "profile");
return "home/personal/profile_bidding_record_list";
}
/**
Account account = SessionUtil.getAccount();
BiddingRecord biddingRecord = biddingRecordService.find(recordId);
BiddingProject biddingProject = biddingRecord.getBiddingProject();
Organization organization = biddingProject.getOrganization();
ProjectEvaluate projectEvaluate = new ProjectEvaluate();
projectEvaluate.setAccount(account);
projectEvaluate.setBiddingProject(biddingProject);
projectEvaluate.setRate(score.intValue());
projectEvaluate.setContent(content);
if (projectEvaluateService.save(projectEvaluate) == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_PROJECT_EVALUATE_ADD_ERROR);
}
//更新竞价记录的状态
if (biddingRecordService.updateBiddingStatus(biddingRecord.getId(), BiddingRecord.BIDDING_STATUS_EVALUATED) <= 0) {
return Result.error(CodeMsg.ADMIN_ORGANIZATION_STATUS_EDIT_ERROR);
}
//更新拍卖者的信用分
organization.setRate(score);
if (organizationService.updateRate(organization) <= 0) {
return Result.error(CodeMsg.HOME_ORGANIZATION_RATE_ADD_ERROR);
}
//更新商品的评分和评论人
biddingProject.setRate(biddingProject.getRate() + score);
projectService.updateProjectRate(biddingProject.getRate(), biddingProject.getId());
return Result.success(true);
}
}
package com.yuanlrc.base.controller.common;
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
if(newPwd.length()<4){
return Result.error(CodeMsg.PASSWORD_MIN_LENGTH_ERROR);
}
if(newPwd.length() > 32){
return Result.error(CodeMsg.PASSWORD_MAX_LENGTH_ERROR);
}
loginedUser.setPassword(newPwd);
//保存数据库
userService.save(loginedUser);
//更新session
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
}else if(type == LoginType.ORGANIZATION.getCode()){
Organization loginedJudge = SessionUtil.getOraganization();
Organization find = organizationService.find(loginedJudge.getId());
if(!find.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
find.setPassword(newPwd);
CodeMsg codeMsg = ValidateEntityUtil.validate(find);
if (codeMsg.getCode() != CodeMsg.SUCCESS.getCode())
return Result.error(codeMsg);
//保存数据库
organizationService.save(find);
//更新session
loginedJudge.setPassword(newPwd);
SessionUtil.set(SessionConstant.SESSION_USER_ORGANIZATION, loginedJudge);
}
return Result.success(true);
}
/**
* 日志管理列表
* @param model
* @param operaterLog
* @param pageBean
* @return
*/
@RequestMapping(value="/operator_log_list")
public String operatorLogList(Model model,OperaterLog operaterLog,PageBean<OperaterLog> pageBean){
model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
model.addAttribute("operator", operaterLog.getOperator());
model.addAttribute("title", "日志列表");
*/
@RequestMapping("/home/project")
@Controller
public class HomeProjectController {
@Autowired
private AccountService accountService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private ProjectService projectService;
@Autowired
private ProjectCategoryService projectCategoryService;
@Autowired
private BiddingRecordService biddingRecordService;
@Autowired
private BiddingApplyService biddingApplyService;
@Autowired
private ProjectEvaluateService projectEvaluateService;
/**
* 前台商品列表
*
* @param model
* @return
*/
@GetMapping("/list")
public String index(Model model, BiddingProject biddingProject, PageBean<BiddingProject> pageBean) {
Date date = new Date();
model.addAttribute("activeType", "project");
PageBean<BiddingProject> biddingProjectPageBean = projectService.homeFindList(biddingProject, pageBean);
for (BiddingProject project : biddingProjectPageBean.getContent()) {
projectService.status(project, date);
}
//准备保存文件
File filePath = new File(uploadPhotoPath);
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
//判断当天日期的文件夹是否存在,若不存在,则创建
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
try {
photo.transferTo(new File(uploadPhotoPath + "/" + filename));
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Account account = SessionUtil.getAccount();
account.setHeadPic(filename);
accountService.updateHeadPic(filename, account.getId());
SessionUtil.set(SessionConstant.SESSION_HOME_USER_LOGIN_KEY, account);
return Result.success(filename);
}
/**
* 编辑个人信息
*
* @param account
* @return
*/
@ResponseBody
@PostMapping("/edit_profile")
public Result<Boolean> editProfile(Account account) {
Account account1 = accountService.find(account.getId());
if (account1 == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_NOT_EXIST_ERROR);
}
if (!StringUtil.emailFormat(account.getEmail())) {
return Result.error(CodeMsg.HOME_ACCOUNT_EMAIL_ERROR);
}
if (!StringUtil.isMobile(account.getMobile())) {
return Result.error(CodeMsg.HOME_ACCOUNT_PHONE_ERROR);
}
/**
* 项目通用工具类
*
*/
public class StringUtil {
/**
* 返回指定格式的日期字符串
* @param date
* @param formatter
* @return
*/
public static String getFormatterDate(Date date,String formatter){
SimpleDateFormat sdf = new SimpleDateFormat(formatter);
return sdf.format(date);
}
/**
* 判断请求是否是ajax
* @param request
* @return
*/
public static boolean isAjax(HttpServletRequest request){
String header = request.getHeader("X-Requested-With");
if("XMLHttpRequest".equals(header))return true;
return false;
}
/**
* 从流读取字符串
* @param inputStream
* @return
*/
public static String getStringFromInputStream(InputStream inputStream){
String string = "";
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"GB2312"));
String buf = null;
try {
while((buf = bufferedReader.readLine()) != null){
accountService.updateHeadPic(filename, account.getId());
SessionUtil.set(SessionConstant.SESSION_HOME_USER_LOGIN_KEY, account);
return Result.success(filename);
}
/**
* 编辑个人信息
*
* @param account
* @return
*/
@ResponseBody
@PostMapping("/edit_profile")
public Result<Boolean> editProfile(Account account) {
Account account1 = accountService.find(account.getId());
if (account1 == null) {
return Result.error(CodeMsg.HOME_ACCOUNT_NOT_EXIST_ERROR);
}
if (!StringUtil.emailFormat(account.getEmail())) {
return Result.error(CodeMsg.HOME_ACCOUNT_EMAIL_ERROR);
}
if (!StringUtil.isMobile(account.getMobile())) {
return Result.error(CodeMsg.HOME_ACCOUNT_PHONE_ERROR);
}
BeanUtils.copyProperties(account, account1, "id", "createTime", "updateTIme", "username", "password", "status", "headPic", "balance", "creditScore");
if (accountService.save(account1) == null) {
return Result.error(CodeMsg.ADMIN_ACCOUNT_EDIT_PROFILE_ERROR);
}
SessionUtil.set(SessionConstant.SESSION_HOME_USER_LOGIN_KEY, account1);
return Result.success(true);
}
/**
* 修改密码
*
* @param oldPassword
* @param newPassword
* @return
*/
@ResponseBody
@PostMapping("/edit_password")
public Result<Boolean> editPassword(@RequestParam(name = "oldPassword") String oldPassword, @RequestParam(name = "newPassword") String newPassword) {
Account account = SessionUtil.getAccount();
if (StringUtils.isEmpty(oldPassword)) {
//表示未通过
organization1.setAuditStatus(AuditStatus.AUDIT.getCode());
}
BeanUtils.copyProperties(organization,organization1,"auditStatus","password","name","role","balance","id","createTime","updateTime","rate");
SessionUtil.set(SessionConstant.SESSION_USER_ORGANIZATION,organization1);
if(organizationService.save(organization1)==null){
return Result.error(CodeMsg.ADMIN_USER_INFO_SAVE_ERROR);
}
return Result.success(true);
}
/**
* 拍卖者忘记密码
* @param email
* @param password
* @return
*/
@ResponseBody
@PostMapping("/forget_password")
public Result<Boolean> forgetPassword(@RequestParam(name = "email")String email,@RequestParam(name = "password")String password){
Organization byEmail = organizationService.findByEmail(email);
if(byEmail==null){
return Result.error(CodeMsg.HOME_ACCOUNT_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(password)){
return Result.error(CodeMsg.ADMIN_ORGANIZATION_PASSWORD_ERROR);
}
if(password.length()<4){
return Result.error(CodeMsg.PASSWORD_MIN_LENGTH_ERROR);
}
if(password.length()>32){
return Result.error(CodeMsg.PASSWORD_MAX_LENGTH_ERROR);
}
byEmail.setPassword(password);
if(organizationService.updatePassword(byEmail)<=0){
return Result.error(CodeMsg.ADMIN_ORGANIZATION_UPDATE_PASSWORD_ERROR);
}
return Result.success(true);
}
}
package com.yuanlrc.base.controller.common;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private UserService userService;
@Autowired
private OrganizationService organizationService;
@Autowired
private OrderAuthService orderAuthService;
private String showTipsText;
private String showTipsUrlText;
private String showTipsBtnText;
private String showTipsUtl;
private Logger log = LoggerFactory.getLogger(SystemController.class);
/**
* 登录页面
* @param
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model){
model.addAttribute("loginTypes", LoginType.values());
return "admin/system/login";
}
/**
* 用户登录提交表单处理方法
* @param request
* @param cpacha
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> login(HttpServletRequest request,String username,String password,String cpacha, Integer type){
if(username == null){
return Result.error(CodeMsg.ADMIN_USERNAME_EMPTY);
}
if(password == null){
return Result.error(CodeMsg.ADMIN_PASSWORD_EMPTY);
}
@ResponseBody
@PostMapping("/edit")
public Result<Boolean> edit(BiddingProject biddingProject){
Long projectId = biddingProject.getId();
BiddingProject currentProject = projectService.find(projectId);
if(currentProject==null){
return Result.error(CodeMsg.ADMIN_PROJECT_SHOPING_NOT_EXIST);
}
List<BiddingApply> byBiddingProjectId = biddingApplyService.findByBiddingProjectId(projectId);
if(byBiddingProjectId.size()<0){
return Result.error(CodeMsg.ADMIN_PROJECT_SHOPING_APPLY_ERROR);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(biddingProject);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//报名时间和当前时间比较
if(biddingProject.getStartTime().before(new Date())){
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_SIGNUP_TIME_ERROR);
}
//报名日期比较
if (!biddingProject.getStartTime().before(biddingProject.getEndTime())) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_SIGNUP_DATE_ERROR);
}
//竞拍日期比较
if (!biddingProject.getBiddingStartTime().before(biddingProject.getBiddingEndTime())) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_DATE_ERROR);
}
//竞拍日期和报名日期比较
if(!biddingProject.getStartTime().before(biddingProject.getBiddingStartTime())){
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_SIGNUP_ERROR);
}
if(!biddingProject.getEndTime().before(biddingProject.getBiddingEndTime())){
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_SIGNUP_ERROR);
}
//报名开始时间和竞拍结束时间比较
if(!biddingProject.getStartTime().before(biddingProject.getBiddingEndTime())){
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_END_DATE_ERROR);
}
String describes = biddingProject.getDescribes();
biddingProject.setDescribes(describes.trim());
BeanUtils.copyProperties(biddingProject, currentProject, "id", "createTime", "updateTime", "projectNumber", "transactionPrice", "applicantsNumber","auctionTimes","account","organization","rate","viewsNumber");
if (projectService.save(currentProject) == null) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_EDIT_ERROR);
}
/**
* 系统控制器
*
*/
@RequestMapping("/system")
@Controller
public class SystemController {
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private UserService userService;
@Autowired
private OrganizationService organizationService;
@Autowired
/**
* 商品添加操作
* @param biddingProject
* @return
*/
@ResponseBody
@PostMapping("/add")
public Result<Boolean> add(BiddingProject biddingProject){
Organization loginedOrganization = SessionUtil.getOraganization();
if (loginedOrganization == null) {
return Result.error(CodeMsg.USER_SESSION_EXPIRED);
}
CodeMsg validate = ValidateEntityUtil.validate(biddingProject);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//报名日期比较
if (!biddingProject.getStartTime().before(biddingProject.getEndTime())) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_SIGNUP_DATE_ERROR);
}
//竞拍日期比较
if (!biddingProject.getBiddingStartTime().before(biddingProject.getBiddingEndTime())) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_DATE_ERROR);
}
//报名开始时间和竞拍结束时间比较
if(!biddingProject.getStartTime().before(biddingProject.getBiddingEndTime())){
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_BIDDING_END_DATE_ERROR);
}
String projectNumber = StringUtil.gneerateSn("xm");
biddingProject.setProjectNumber(projectNumber);
biddingProject.setOrganization(loginedOrganization);
String describes = biddingProject.getDescribes();
biddingProject.setDescribes(describes.trim());
//一切顺利添加到数据库
if(projectService.save(biddingProject)==null){
return Result.error(CodeMsg.ADMIN_PROJECT_SHOPING_ADD_ERROR);
}
operaterLogService.add("添加商品成功,商品名:" + biddingProject.getName());
return Result.success(true);
}
/**
/**
* session统一操作工具类
*
*/
public class SessionUtil {
/**
* 获取请求request
* @return
*/
public static HttpServletRequest getRequest(){
ServletRequestAttributes attributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
return attributes == null ? null : attributes.getRequest();
}
/**
* 获取session
* @return
*/
public static HttpSession getSession(){
HttpServletRequest request = getRequest();
if(request != null){
return request.getSession();
}
return null;
}
/**
* 获取指定键的值
* @param key
* @return
/**
* 系统验证码公用控制器
*
*/
@Controller
@RequestMapping("/cpacha")
public class CpachaController {
private Logger log = LoggerFactory.getLogger(CpachaController.class);
/**
* 通用验证码生成器
* @param vcodeLength
* @param fontSize
* @param width
* @param height
* @param method
* @param request
* @param response
*/
@RequestMapping(value="/generate_cpacha",method=RequestMethod.GET)
public void generateCpacha(
@RequestParam(name="vl",defaultValue="4")Integer vcodeLength,//vcodeLength,验证码长度
@RequestParam(name="fs",defaultValue="21")Integer fontSize,//fontSize,验证码字体大小
@RequestParam(name="w",defaultValue="98")Integer width,//width,图片宽度
@RequestParam(name="h",defaultValue="33")Integer height,//height,图片高度
@RequestParam(name="method",defaultValue="admin_login")String method,//用来调用此方法的名称,以此名称为键,存入到session中
HttpServletRequest request,
HttpServletResponse response){
CpachaUtil cpachaUtil = new CpachaUtil(vcodeLength,fontSize,width,height);
String generatorVCode = cpachaUtil.generatorVCode();
//将生成的验证码放入session,以供放后面程序的验证使用
return Result.success(true);
}
/**
* 拍卖者忘记密码
* @param email
* @param password
* @return
*/
@ResponseBody
@PostMapping("/forget_password")
public Result<Boolean> forgetPassword(@RequestParam(name = "email")String email,@RequestParam(name = "password")String password){
Organization byEmail = organizationService.findByEmail(email);
if(byEmail==null){
return Result.error(CodeMsg.HOME_ACCOUNT_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(password)){
return Result.error(CodeMsg.ADMIN_ORGANIZATION_PASSWORD_ERROR);
}
if(password.length()<4){
return Result.error(CodeMsg.PASSWORD_MIN_LENGTH_ERROR);
}
if(password.length()>32){
return Result.error(CodeMsg.PASSWORD_MAX_LENGTH_ERROR);
}
byEmail.setPassword(password);
if(organizationService.updatePassword(byEmail)<=0){
return Result.error(CodeMsg.ADMIN_ORGANIZATION_UPDATE_PASSWORD_ERROR);
}
return Result.success(true);
}
}
package com.yuanlrc.base.controller.common;