基于javaweb+ssm的农资采购销售系统(java+SSM+Easyui+maven+Mysql)
项目描述:
一个完整的农资采购销售系统,系统分为前台会员注册登陆,农资信息浏览,农资详情信息查看,加入购物车,提交订单,付款购买农资等;后台管理员对人员信息的管理,首页图片管理(系统可配置化),农资订单管理,图标统计,农资信息管理
运行环境:
jdk8+tomca8+mysql+IntelliJ IDEA+maven
项目技术:
spring+spring mvc+mybatis+jquery+jquery.easyui.min.js
前端登录:http://localhost:8080/snack/shop/index
后台登录:http://localhost:8080/snack//admin/login/adminLogin
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
![](https://i-blog.csdnimg.cn/blog_migrate/7a7585bc77ea31dc78392dcc90880030.png)
/**
* 取消订单
* @param model
* @param id
* @return
*/
@RequestMapping("/qx")
public String itemOrderqx(Model model,Integer id){
ItemOrder obj = itemOrderService.getById(id);
obj.setStatus(1);
itemOrderService.updateById(obj);
model.addAttribute("obj",obj);
return "redirect:/itemOrder/my.action";
}
/**
* 后台发货
* @param id
* @return
*/
@RequestMapping("/fh")
public String itemOrderfh(Integer id){
ItemOrder obj = itemOrderService.getById(id);
obj.setStatus(2);
itemOrderService.updateById(obj);
}
//生成订单表
List<Integer> ids = new ArrayList<Integer>();
// Double b = 0.0; //价格
BigDecimal b = new BigDecimal(0);
for (CarDto carDto:list){
ids.add(carDto.getId());
Car car = carService.getById(carDto.getId());
// b+=car.getPrice()*carDto.getNum();
b =b.add(new BigDecimal(car.getPrice()).multiply(new BigDecimal(carDto.getNum())));
}
ItemOrder itemOrder = new ItemOrder();
itemOrder.setUserId(id);
/**
* 取消订单
* @param model
* @param id
* @return
*/
@RequestMapping("/qx")
public String itemOrderqx(Model model,Integer id){
ItemOrder obj = itemOrderService.getById(id);
obj.setStatus(1);
itemOrderService.updateById(obj);
model.addAttribute("obj",obj);
public String addItem(Model model) {
String sql = "select * from item_category where isDelete = 0 and pid is not null order by id";
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("types", pagers);
return "item/addItem";
}
/**
* 执行添加操作
*
* @param item
* @param files CommonsMultipartFile用于文件上传
* @return
*/
@RequestMapping("/exadd")
public String exaddItem(Item item, @RequestParam("file") CommonsMultipartFile[] files, HttpServletRequest request) throws IOException {
itemCommon(item, files, request);
item.setGmNum(0);
item.setIsDelete(0);
item.setScNum(0);
itemService.insert(item);
return "redirect:/item/findbysql.action";
}
/**
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
staff.setPassword(newPwd);
CodeMsg codeMsg = ValidateEntityUtil.validate(staff);
if (codeMsg.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(codeMsg);
}
loginedStaff.setPassword(newPwd);
//保存数据库
staffService.save(loginedStaff);
//更新session
SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY, loginedStaff);
}
return Result.success(true);
}
/**
* 日志管理列表
* @param model
if (s == 3) {
item.setUrl4(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
if (s == 4) {
item.setUrl5(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
}
}
ItemCategory byId = itemCategoryService.getById(item.getCategoryIdTwo());
item.setCategoryIdOne(byId.getPid());
/**
* 进入商品评价页面
* @param id
* @param model
* @return
*/
@RequestMapping("/pj")
public String itemOrderpj(Integer id,Model model,Integer orderId){
model.addAttribute("id",id);
model.addAttribute("orderId",orderId);
return "itemOrder/pj";
Pager<Item> itemList = itemService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", itemList);
model.addAttribute("obj", item);
return "item/itemList";
}
/**
* 转到添加商品页面
*
* @param model
* @return
*/
@RequestMapping("/add")
public String addItem(Model model) {
String sql = "select * from item_category where isDelete = 0 and pid is not null order by id";
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("types", pagers);
return "item/addItem";
}
/**
* 执行添加操作
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
}
//检查用户所属角色状态是否可用
if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
}
//检查用户所属角色的权限是否存在
if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
}
//检查一切符合,可以登录,将用户信息存放至session
/**
* 无权限提示页面
* @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
*/
//查询已发货订单
String sql3 = "select * from item_order where isDelete=0 and status=2 and user_id="+id+" order by id";
// Pager<ItemOrder> itemOrder2 = itemOrderService.findBySqlRerturnEntity(sql);
List<ItemOrder> itemOrder2 = itemOrderService.listBySqlReturnEntity(sql3);
//查询已收货订单
String sql4 = "select * from item_order where isDelete=0 and status=3 and user_id="+id+" order by id";
// Pager<ItemOrder> itemOrder3 = itemOrderService.findBySqlRerturnEntity(sql);
List<ItemOrder> itemOrder3 = itemOrderService.listBySqlReturnEntity(sql4);
//查询已评价订单
String sql5 = "select * from item_order where isDelete=0 and status=4 and user_id="+id+" order by id";
// Pager<ItemOrder> itemOrder4 = itemOrderService.findBySqlRerturnEntity(sql);
List<ItemOrder> itemOrder4 = itemOrderService.listBySqlReturnEntity(sql5);
/*request.setAttribute("add",itemOrderAll);
request.setAttribute("add0",itemOrder0);
request.setAttribute("add1",itemOrder1);
request.setAttribute("add2",itemOrder2);
request.setAttribute("add3",itemOrder3);
request.setAttribute("add4",itemOrder4);*/
* @return
*/
@RequestMapping("/view")
public String view(Item item ,HttpServletRequest request){
Item itemObj = itemService.getById(item.getId());
request.setAttribute("obj",itemObj);
return "item/viewlist";
}
}
订单管理代码:
/**
* 订单controller
*/
@Controller
@RequestMapping("/itemOrder")
public class ItemOrderController extends BaseController {
@Autowired
private ItemOrderService itemOrderService;
@Autowired
private UserService userService;
@Autowired
private ItemService itemService;
@Autowired
private CarService carService;
sql+=" order by id desc";
Pager<ItemOrder> data = itemOrderService.findBySqlRerturnEntity(sql);
request.setAttribute("pagers",data);
request.setAttribute("obj",itemOrder);
return "/itemOrder/itemOrderList";
}
@RequestMapping("/my")
public String my(HttpServletRequest request, Model model){
//判断当前用户是否登录
Object userId = request.getSession().getAttribute("userId");
if(userId==null){
return "login/uLogin";
}
//检查一切符合,可以登录,将用户信息存放至session
request.getSession().setAttribute(SessionConstant.SESSION_STAFF_LOGIN_KEY, byJobNumber);
request.getSession().setAttribute("loginType",type);
//销毁session中的验证码
request.getSession().setAttribute("admin_login", null);
//将登陆记录写入日志库
operaterLogService.add("用户【"+username+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
log.info("员工成功登录,user = " + byJobNumber);
}
return Result.success(true);
}
/**
* 登录成功后的系统主页
* @param model
* @return
*/
@RequestMapping(value="/index")
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 删除操作日志,可删除多个
* @param ids
* @return
*/
@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(String ids){
if(!StringUtils.isEmpty(ids)){
String[] splitIds = ids.split(",");
for(String id : splitIds){
operaterLogService.delete(Long.valueOf(id));
@RequestMapping("/sh")
public String itemOrdersh(Integer id){
ItemOrder obj = itemOrderService.getById(id);
obj.setStatus(3);
itemOrderService.updateById(obj);
return "redirect:/itemOrder/my.action";
}
/**
* 进入商品评价页面
* @param id
* @param model
* @return
*/
orderDetail.setNum(load.getNum());
orderDetail.setTotal(String.valueOf(carDto.getNum()*load.getPrice()));
orderDetailService.insert(orderDetail);
//修改商品成交数
Item item = itemService.getById(load.getItemId());
item.setGmNum(item.getGmNum()+carDto.getNum());
//删除购物车
carService.deleteById(carDto.getId());
}
}
json.put(Consts.RES,1);
return json.toJSONString();
}
/**
* 取消订单
* @param model
* @param id
* @return
*/
@RequestMapping("/qx")
public String itemOrderqx(Model model,Integer id){
ItemOrder obj = itemOrderService.getById(id);
orderDetail.setItemId(load.getItemId());
orderDetail.setOrderId(itemOrder.getId());
orderDetail.setStatus(0);
orderDetail.setNum(load.getNum());
orderDetail.setTotal(String.valueOf(carDto.getNum()*load.getPrice()));
orderDetailService.insert(orderDetail);
//修改商品成交数
Item item = itemService.getById(load.getItemId());
item.setGmNum(item.getGmNum()+carDto.getNum());
//删除购物车
carService.deleteById(carDto.getId());
model.addAttribute("operatorLogTotal", operaterLogService.total());
model.addAttribute("databaseBackupTotal", databaseBakService.total());
model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
return "admin/system/index";
}
/**
* 注销登录
* @return
*/
@RequestMapping(value="/logout")
public String logout(){
Integer loginType = (Integer) SessionUtil.get("loginType");
if(loginType == LoginType.ADMINISTRATOR.getCode()){
User loginedUser = SessionUtil.getLoginedUser();
if(loginedUser != null){
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
}
}else if(loginType == LoginType.STAFF.getCode()){
Staff loginedStaff = SessionUtil.getLoginedStaff();
if(loginedStaff != null){
SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,null);
}
//表示密码正确,接下来判断用户状态是否可用
if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
}
//检查用户所属角色状态是否可用
if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
}
//检查用户所属角色的权限是否存在
if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
public String updatePwd(){
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
* @param oldPwd
* @param newPwd
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
itemCommon(item, files, request);
itemService.updateById(item);
return "redirect:/item/findbysql.action";
}
/**
* 商品下架
* @param id
* @return
*/
@RequestMapping("/remove")
public String removeItem(Integer id) {
String sql = "update item set isDelete = 1 where id=";
String sql1 = Integer.toString(id) ;
itemService.updateBysql(sql+sql1);
return "redirect:/item/findbysql.action";
}
/**
* 上传文件的公共方法
*
* @param item
* @param files
* @param request
//判断是否为空
if(findByUsername == null){
return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
}
//表示用户存在,进一步对比密码是否正确
if(!findByUsername.getPassword().equals(password)){
return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
}
//表示密码正确,接下来判断用户状态是否可用
if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
}
//检查用户所属角色状态是否可用
if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
}
//检查用户所属角色的权限是否存在
if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
return "admin/system/index";
}
/**
* 注销登录
* @return
*/
@RequestMapping(value="/logout")
public String logout(){
Integer loginType = (Integer) SessionUtil.get("loginType");
if(loginType == LoginType.ADMINISTRATOR.getCode()){
User loginedUser = SessionUtil.getLoginedUser();
if(loginedUser != null){
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
}
}else if(loginType == LoginType.STAFF.getCode()){
Staff loginedStaff = SessionUtil.getLoginedStaff();
if(loginedStaff != null){
SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,null);
}
if (s == 1) {
item.setUrl2(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
if (s == 2) {
item.setUrl3(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
if (s == 3) {
item.setUrl4(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
if (s == 4) {
item.setUrl5(request.getContextPath() + "\\resource\\ueditor\\upload\\" + n + files[s].getOriginalFilename());
}
}
}
ItemCategory byId = itemCategoryService.getById(item.getCategoryIdTwo());
item.setCategoryIdOne(byId.getPid());
String sql4 = "select * from item_order where isDelete=0 and status=3 and user_id="+id+" order by id";
// Pager<ItemOrder> itemOrder3 = itemOrderService.findBySqlRerturnEntity(sql);
List<ItemOrder> itemOrder3 = itemOrderService.listBySqlReturnEntity(sql4);
//查询已评价订单
String sql5 = "select * from item_order where isDelete=0 and status=4 and user_id="+id+" order by id";
// Pager<ItemOrder> itemOrder4 = itemOrderService.findBySqlRerturnEntity(sql);
List<ItemOrder> itemOrder4 = itemOrderService.listBySqlReturnEntity(sql5);
/*request.setAttribute("add",itemOrderAll);
request.setAttribute("add0",itemOrder0);
request.setAttribute("add1",itemOrder1);
request.setAttribute("add2",itemOrder2);
request.setAttribute("add3",itemOrder3);
request.setAttribute("add4",itemOrder4);*/
model.addAttribute("add",itemOrderAll);
model.addAttribute("add0",itemOrder0);
model.addAttribute("add1",itemOrder1);
Car car = carService.getById(carDto.getId());
// b+=car.getPrice()*carDto.getNum();
b =b.add(new BigDecimal(car.getPrice()).multiply(new BigDecimal(carDto.getNum())));
}
ItemOrder itemOrder = new ItemOrder();
itemOrder.setUserId(id);
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmss");
itemOrder.setCode(sd.format(new Date()));
itemOrder.setAddTime(new Date());
itemOrder.setTotal(b.setScale(2,BigDecimal.ROUND_HALF_UP).toString());
适用
课程设计,大作业,毕业设计,项目练习,学习演示等