基于javaweb+mysql的springboot在线拍卖竞价系统(java+springboot+freemarker+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot在线拍卖竞价系统(java+springboot+freemarker+mysql+maven)
超级管理员:系统管理、用户管理(冻结等)、审批竞拍标的物管理、竞标类型管理、审批机构、个人提现管理(审核)、企业提现管理(审批)等。
普通用户:注册登录、个人信息管理(个人资料、密码修改等)、留言管理、竞价管理、竞拍收藏、订单查询(物流信息查询)、银行卡管理、提现管理等、竞拍物品展示查询(列表搜索、详情展示、报名记录、竞价记录)。
企业用户:注册登录、发布竞拍、竞拍管理、充值订单、银行卡管理、提现记录。
/**
* 角色添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(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));
return "admin/role/add";
}
/**
* 角色添加表单提交处理
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(roleService.save(role) == null){
return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
}
log.info("添加角色【"+role+"】");
operaterLogService.add("添加角色【"+role.getName()+"】");
return Result.success(true);
}
/**
* 角色编辑页面
* @param id
* @param model
* @return
*/
@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";
//竞拍日期比较
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);
}
operaterLogService.add("编辑商品,商品名称:" + biddingProject.getName());
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 {
projectService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_BIDDING_PROJECT_DELETE_ERROR);
}
operaterLogService.add("删除竞拍商品,竞拍商品ID:" + id);
return Result.success(true);
}
/**
* 查看商品详情页面
* @param id
* @param model
* @return
*/
@GetMapping("/project_detail")
public String projectDetail(@RequestParam("id")Long id,Model model){
return Result.success(true);
}
/**
* 确定拍价
*
* @param pid
* @param quantity
* @param money
* @return
*/
@ResponseBody
@PostMapping("/auction_price")
public Result<Boolean> auctionPrice(@RequestParam(name = "id", required = true) Long pid, @RequestParam(name = "quantity", required = true) int quantity, @RequestParam(name = "money", required = true) int money) {
Account account = SessionUtil.getAccount();
//首先要根据项目id找到项目
BiddingProject biddingProject = projectService.find(pid);
if (biddingProject == null) {
return Result.error(CodeMsg.ADMIN_PROJECT_SHOPING_NOT_EXIST);
}
//查询有没有报名
BiddingApply biddingApply = biddingApplyService.findByBiddingProjectIdAndAccountId(pid, account.getId());
if (biddingApply == null) {
return Result.error(CodeMsg.HOME_SIGN_UP_NOT_EXIST_ERROR);
}
if (quantity > biddingProject.getQuantity()) {
return Result.error(CodeMsg.HOME_PROJECT_QUANTITY_ERROR);
}
if (money < biddingProject.getStartPrice()) {
return Result.error(CodeMsg.HOME_PROJECT_MINMONEY_ERROR);
}
//更新竞拍次数
if (projectService.updateAuctionTimes(biddingProject.getAuctionTimes() + 1, pid) <= 0) {
return Result.error(CodeMsg.HOME_BIDDING_PROJECT_AUCTIONTIMES_ADD_ERROR);
}
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) {
/**
* 商品列表
* @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
@PostMapping("/transaction")
public Result<Boolean> transaction(@RequestParam(name = "rid",required = true)Long rid){
BiddingRecord biddingRecord = biddingRecordService.find(rid);
if(biddingRecord==null){
return Result.error(CodeMsg.ADMIN_PROJECT_BIDDINGRECORD_NOT_EXIST);
}
//清空本次商品的所有竞拍记录
return biddingRecordService.updateRecordTransaction(biddingRecord);
}
* 菜单编辑页面表单提交处理
* @param request
* @param menu
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Menu menu){
if(menu == null){
Result.error(CodeMsg.DATA_ERROR);
}
if(menu.getId() == null){
Result.error(CodeMsg.ADMIN_MENU_ID_EMPTY);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(menu);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(menu.getParent() != null){
if(menu.getParent().getId() == null){
menu.setParent(null);
}
}
Menu existMenu = menuService.find(menu.getId());
if(existMenu == null){
Result.error(CodeMsg.ADMIN_MENU_ID_ERROR);
}
//表示验证都通过,开始添加数据库
existMenu.setIcon(menu.getIcon());
existMenu.setName(menu.getName());
existMenu.setParent(menu.getParent());
existMenu.setSort(menu.getSort());
existMenu.setUrl(menu.getUrl());
existMenu.setButton(menu.isButton());
existMenu.setShow(menu.isShow());
if(menuService.save(existMenu) == null){
Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
}
//数据库添加操作成功,记录日志
if(projectEvaluateService.updateReplay(rid, content)<=0){
return Result.error(CodeMsg.ADMIN_PROJECT_SHOPING_RATE_REPLY_ERROR);
}
return Result.success(true);
}
}
/**
* 系统控制器
*
*/
@RequestMapping("/system")
@Controller
public class SystemController {
@Autowired
private OperaterLogService operaterLogService;
}
if (imgFile.getSize() / 1024 > uploadPhotoMaxSize) {
CodeMsg codeMsg = CodeMsg.UPLOAD_PHOTO_ERROR;
codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
out.write(String.valueOf(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 {
imgFile.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);
response.setContentType("application/json; charset=UTF-8");
JSONObject obj = new JSONObject();
obj.put("error", 0);
obj.put("url", "/photo/view?filename=" + "/" + filename);
out.println(obj.toJSONString());
}
}
{
FileInputStream fis = null;
try
{
File file = new File(filePath);
if (!file.exists())
{
throw new FileNotFoundException(filePath);
}
fis = new FileInputStream(file);
byte[] b = new byte[1024];
int length;
while ((length = fis.read(b)) > 0)
{
os.write(b, 0, length);
}
}
catch (IOException e)
{
throw e;
}
finally
{
if (os != null)
{
try
{
os.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
if (fis != null)
{
try
{
fis.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
}
}
}
return Result.success(true);
}
/**
* 验证订单
* @param orderSn
* @param phone
* @return
*/
@RequestMapping(value="/auth_order",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
if(orderSn.length() < 18){
return Result.error(CodeMsg.ORDER_SN_ERROR);
}
if(phone.length() < 11){
return Result.error(CodeMsg.PHONE_ERROR);
}
if(!StringUtil.authOrder(orderSn, phone)){
return Result.error(CodeMsg.ORDER_AUTH_ERROR);
}
OrderAuth orderAuth = new OrderAuth();
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
//判断用户名是否存在
if(userService.isExistUsername(user.getUsername(), 0l)){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
//到这说明一切符合条件,进行数据库新增
if(userService.save(user) == null){
return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
}
operaterLogService.add("添加用户,用户名:" + user.getUsername());
return Result.success(true);
}
/**
* 用户编辑页面
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("roles", roleService.findAll());
model.addAttribute("user", userService.find(id));
return "admin/user/edit";
}
/**
* 编辑用户信息表单提交处理
* @param user
* @return
*/
@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对象中,该方法会覆盖新字段内容
* 商品添加操作
* @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);
}
/**
* 商品编辑页面
* @param id
* @param model
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
/**
* 前台商品控制器
*
*/
@RequestMapping("/home/project")
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);
}
/**
* 前台用户编辑页面
* @param id
* @param model
* @return
*/
@GetMapping("/edit")
public String edit(@RequestParam(name = "id",required = true)Long id,Model model){
Account account = accountService.find(id);
model.addAttribute("account",account);
return "admin/account/edit";
}
/**
* 前台用户编辑操作
* @param account
* @return
*/
@ResponseBody
@PostMapping("/edit")
public Result<Boolean> edit(Account account){
CodeMsg validate = ValidateEntityUtil.validate(account);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
* @param projectCategory
* @return
*/
@ResponseBody
@PostMapping("/add")
public Result<Boolean> add(ProjectCategory projectCategory){
CodeMsg validate = ValidateEntityUtil.validate(projectCategory);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
ProjectCategory byName = projectCategoryService.findByName(projectCategory.getName());
if(byName!=null){
return Result.error(CodeMsg.ADMIN_PROJECT_CATEGORY_NAME_EXIST);
}
//一切顺利添加到数据库
if(projectCategoryService.save(projectCategory)==null){
return Result.error(CodeMsg.ADMIN_PROJECT_CATEGORY_ADD_ERROR);
}
operaterLogService.add("添加项目分类,分类名:" + projectCategory.getName());
return Result.success(true);
}
/**
* 项目分类编辑页面
* @param id
* @param model
* @return
*/
@GetMapping("/edit")
public String edit(@RequestParam(name = "id",required = true)Long id,Model model){
ProjectCategory projectCategory = projectCategoryService.find(id);
model.addAttribute("projectCategory",projectCategory);
model.addAttribute("categoryList",CategoryStatus.values());
return "admin/project_category/edit";
}
/**
* 项目分类编辑操作
* @param projectCategory
* @return
*/
@ResponseBody
@PostMapping("/edit")
public Result<Boolean> edit(ProjectCategory projectCategory){
CodeMsg validate = ValidateEntityUtil.validate(projectCategory);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
}
/**
* 项目分类添加
* @param model
* @return
*/
@GetMapping("/add")
public String add(Model model){
model.addAttribute("categoryList",CategoryStatus.values());
return "admin/project_category/add";
}
/**
* 项目分类添加操作
* @param projectCategory
* @return
*/
@ResponseBody
@PostMapping("/add")
public Result<Boolean> add(ProjectCategory projectCategory){
CodeMsg validate = ValidateEntityUtil.validate(projectCategory);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
ProjectCategory byName = projectCategoryService.findByName(projectCategory.getName());
if(byName!=null){
return Result.error(CodeMsg.ADMIN_PROJECT_CATEGORY_NAME_EXIST);
}
//一切顺利添加到数据库
if(projectCategoryService.save(projectCategory)==null){
return Result.error(CodeMsg.ADMIN_PROJECT_CATEGORY_ADD_ERROR);
}
operaterLogService.add("添加项目分类,分类名:" + projectCategory.getName());
return Result.success(true);
}
/**
* 项目分类编辑页面
* @param id
* @param model
* @return
/**
* 前台首页控制器
*
*/
@RequestMapping("/home/index")
@Controller
public class HomeIndexController {
@Autowired
private AccountService accountService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private ProjectService projectService;
@Autowired
private ProjectCategoryService projectCategoryService;
@Autowired
private RechargeRecordService rechargeRecordService;
@Autowired
private BiddingRecordService biddingRecordService;
@Autowired
private ProjectEvaluateService projectEvaluateService;
@Autowired
private OrganizationService organizationService;
private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";
private long uploadPhotoMaxSize = 10240;
private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/";//文件保存位置
/**
* 前台首页
/**
* 公用的上传类
*
*/
@RequestMapping("/upload")
@Controller
public class UploadController {
private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";
private long uploadPhotoMaxSize = 10240;
private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/";//文件保存位置
private Logger log = LoggerFactory.getLogger(UploadController.class);
/**
* 图片统一上传类
*
* @param photo
* @return
*/
@RequestMapping(value = "/upload_photo", method = RequestMethod.POST)
@ResponseBody
public Result<String> uploadPhoto(@RequestParam(name = "photo", required = true) MultipartFile photo) {
//判断文件类型是否是图片
String originalFilename = photo.getOriginalFilename();
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
if (!uploadPhotoSufix.contains(suffix.toLowerCase())) {
return Result.error(CodeMsg.UPLOAD_PHOTO_SUFFIX_ERROR);
}
if (photo.getSize() / 1024 > uploadPhotoMaxSize) {
CodeMsg codeMsg = CodeMsg.UPLOAD_PHOTO_ERROR;
codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
return Result.error(codeMsg);
}
//准备保存文件
File filePath = new File(uploadPhotoPath);
if (!filePath.exists()) {
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
//判断当天日期的文件夹是否存在,若不存在,则创建