Java项目:农资采购销售系统(java+SSM+Easyui+maven+Mysql)

Java项目:农资采购销售系统(java+SSM+Easyui+maven+Mysql),第1张

Java项目:农资采购销售系统(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

 

 

 

商品参数管理代码:
@Controller
@RequestMapping("/item")
public class ItemController extends baseController {
    @Autowired
    private ItemService itemService;
    @Autowired
    private ItemCategoryService itemCategoryService;

    @RequestMapping("/findbysql")
    public String findBySql(Model model, Item item) {
        String sql = "select * from item where 1=1  and isDelete = 0";
        if (!isEmpty(item.getName())) {
            sql += " and name like '%" + item.getName() + "%' ";
        }
        sql += " order by id";
        Pager itemList = itemService.findBySqlRerturnEntity(sql);
        model.addAttribute("pagers", itemList);
        model.addAttribute("obj", item);
        return "item/itemList";
    }

    
    @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 pagers = itemCategoryService.findBySqlRerturnEntity(sql);
        model.addAttribute("types", pagers);
        return "item/addItem";
    }

    
    @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";
    }

    
    @RequestMapping("/update")
    public String updateItem(Integer id, Model model) {
        Item obj = itemService.load(id);
        String sql = "select * from item_category where isDelete = 0 and pid is not null order by id";
        List listBySqlReturnEntity = itemCategoryService.listBySqlReturnEntity(sql);
        model.addAttribute("types", listBySqlReturnEntity);
        model.addAttribute("obj", obj);
        return "/item/updateItem";
    }

    
    @RequestMapping("exUpdateItem")
    public String exUpdateItem(Item item, @RequestParam("file") CommonsMultipartFile[] files, HttpServletRequest request) throws IOException {
        itemCommon(item, files, request);
        itemService.updateById(item);
        return "redirect:/item/findbysql.action";
    }

    
    @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";
    }

    
    private void itemCommon(Item item, @RequestParam("file") CommonsMultipartFile[] files, HttpServletRequest request) throws IOException {
        if (files.length > 0) {
            for (int s = 0; s < files.length; s++) {
                String n = UUIDUtils.create();
                String path = SystemContext.getRealPath() + "\resource\ueditor\upload\" + n + files[s].getOriginalFilename();
                File newFile = new File(path);
                //通过CommonsMultipartFile的方法直接写文件
                files[s].transferTo(newFile);
                if (s == 0) {
                    item.setUrl1(request.getContextPath() + "\resource\ueditor\upload\" + n + files[s].getOriginalFilename());
                }
                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());
    }
    @RequestMapping("/shoplist")
    public String shoplist(String condition ,Item item,Model model,String price,String gmNum){
        String sql = "select * from item where isDelete=0";
        if(!isEmpty(item.getCategoryIdTwo())){
            sql+=" and category_id_two="+item.getCategoryIdTwo();
        }
        if(!isEmpty(condition)){
            sql+=" and name like '%"+condition+"%'";
        }
        if(!isEmpty(price)){
            sql+=" order by (price+0) ";
        }
        if(!isEmpty(gmNum)){
            sql+=" order by gmNum desc";
        }
        Pager itemList = itemService.findBySqlRerturnEntity(sql);
        model.addAttribute("pagers",itemList);
        model.addAttribute("obj",item);
       // model.addAttribute()
        return "/item/shoplist";
    }

    
    @RequestMapping("/view")
    public String view(Item item ,HttpServletRequest request){
        Item itemObj = itemService.getById(item.getId());
        request.setAttribute("obj",itemObj);
        return "item/viewlist";
    }
}

订单管理代码:
@Controller
@RequestMapping("/itemOrder")
public class ItemOrderController extends baseController {
    @Autowired
    private ItemOrderService itemOrderService;
    @Autowired
    private UserService userService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private CarService carService;
    @Autowired
    private OrderDetailService orderDetailService;
    @RequestMapping("/findBySql")
    public String itemOrderList(HttpServletRequest request,ItemOrder itemOrder){
        String sql = "select * from item_order where isDelete=0";
        if (!isEmpty(itemOrder.getCode())){
            sql+=" and code like '%"+itemOrder.getCode()+"%'";
        }
        sql+=" order by id desc";
        Pager 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";
        }
        Integer id = Integer.valueOf(userId.toString());
        //查询全部订单
        String sql = "select * from item_order where isDelete=0 and user_id="+id+" order by id";
        //Pager itemOrderAll = itemOrderService.findBySqlRerturnEntity(sql);
         List itemOrderAll = itemOrderService.listBySqlReturnEntity(sql);

        //查询待发货订单
        String sql1 = "select * from item_order where isDelete=0 and status=0 and user_id="+id+" order by id";
        //Pager itemOrder0 = itemOrderService.findBySqlRerturnEntity(sql);
        List itemOrder0 = itemOrderService.listBySqlReturnEntity(sql1);

        //查询已取消订单
        String sql2 = "select * from item_order where isDelete=0  and status=1  and user_id="+id+" order by id";
       // Pager itemOrder1 = itemOrderService.findBySqlRerturnEntity(sql);
        List itemOrder1 = itemOrderService.listBySqlReturnEntity(sql2);

        //查询已发货订单
        String sql3 = "select * from item_order where isDelete=0 and status=2  and user_id="+id+" order by id";
       // Pager itemOrder2 = itemOrderService.findBySqlRerturnEntity(sql);
        List itemOrder2 = itemOrderService.listBySqlReturnEntity(sql3);

        //查询已收货订单
        String sql4 = "select * from item_order where isDelete=0 and status=3  and user_id="+id+" order by id";
       // Pager itemOrder3 = itemOrderService.findBySqlRerturnEntity(sql);
        List itemOrder3 = itemOrderService.listBySqlReturnEntity(sql4);

        //查询已评价订单
        String sql5 = "select * from item_order where isDelete=0 and status=4 and user_id="+id+" order by id";
       // Pager itemOrder4 = itemOrderService.findBySqlRerturnEntity(sql);
        List itemOrder4 = itemOrderService.listBySqlReturnEntity(sql5);

        
        model.addAttribute("add",itemOrderAll);
        model.addAttribute("add0",itemOrder0);
        model.addAttribute("add1",itemOrder1);
        model.addAttribute("add2",itemOrder2);
        model.addAttribute("add3",itemOrder3);
        model.addAttribute("add4",itemOrder4);
        return "/item/view";
    }

    
    @RequestMapping("/exAdd")
    @ResponseBody
    public String repairStart(@RequestBody List list,HttpServletRequest request) {
        //判断是否登录,没有登录返回0
        Object userId = request.getSession().getAttribute("userId");
        JSonObject json = new JSonObject();
        if (userId == null) {
            json.put(Consts.RES, 0);
            return json.toJSonString();
        }
        //判断用户是否填写了地址
        Integer id = Integer.valueOf(userId.toString());
        User user = userService.getById(id);
        if(StringUtil.isEmpty(user.getAddress())){
            json.put(Consts.RES,2);
        }
        //生成订单表
        List ids = new ArrayList();
      //  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);
        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());
        itemOrder.setIsDelete(0);
        itemOrder.setStatus(0);
        itemOrderService.insert(itemOrder);

        //生成订单详情表
        if(!CollectionUtils.isEmpty(ids)){
        for (CarDto carDto:list){
            Car load = carService.load(carDto.getId());
            OrderDetail orderDetail = new OrderDetail();
            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());
        }
        }
        json.put(Consts.RES,1);
        return json.toJSonString();
    }

    
    @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";
    }

    
    @RequestMapping("/fh")
    public String itemOrderfh(Integer id){
        ItemOrder obj = itemOrderService.getById(id);
        obj.setStatus(2);
        itemOrderService.updateById(obj);
        return "redirect:/itemOrder/findBySql.action";
    }

    
    @RequestMapping("/sh")
    public String itemOrdersh(Integer id){
        ItemOrder obj = itemOrderService.getById(id);
        obj.setStatus(3);
        itemOrderService.updateById(obj);
        return "redirect:/itemOrder/my.action";
    }

    
    @RequestMapping("/pj")
    public String itemOrderpj(Integer id,Model model,Integer orderId){
        model.addAttribute("id",id);
        model.addAttribute("orderId",orderId);
        return "itemOrder/pj";
    }
}

 

系统控制器用户 登录、注销、修改等:
@RequestMapping("/system")
@Controller
public class SystemController {

	
	
	@Autowired
	private OperaterLogService operaterLogService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private DatabaseBakService databaseBakService;

	@Autowired
	private StaffService staffService;
	@Autowired
	private OrderAuthService orderAuthService;

	private Logger log = LoggerFactory.getLogger(SystemController.class);
	
	
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login(Model model){
		model.addAttribute("loginTypes", LoginType.values());
		return "admin/system/login";
	}
	
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public Result login(HttpServletRequest request,String username,String password,String cpacha,Integer type){
		if(StringUtils.isEmpty(username)){
			return Result.error(CodeMsg.ADMIN_USERNAME_EMPTY);
		}
		if(StringUtils.isEmpty(password)){
			return Result.error(CodeMsg.ADMIN_PASSWORD_EMPTY);
		}

		//表示实体信息合法,开始验证验证码是否为空
		if(StringUtils.isEmpty(cpacha)){
			return Result.error(CodeMsg.CPACHA_EMPTY);
		}
		//说明验证码不为空,从session里获取验证码
		Object attribute = request.getSession().getAttribute("admin_login");
		if(attribute == null){
			return Result.error(CodeMsg.SESSION_EXPIRED);
		}
		//表示session未失效,进一步判断用户填写的验证码是否正确
		if(!cpacha.equalsIgnoreCase(attribute.toString())){
			return Result.error(CodeMsg.CPACHA_ERROR);
		}

		if(type == LoginType.ADMINISTRATOR.getCode()){
			//表示验证码正确,开始查询数据库,检验密码是否正确
			User findByUsername = userService.findByUsername(username);
			//判断是否为空
			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);
			}
			//检查一切符合,可以登录,将用户信息存放至session
			request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername);
			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 = " + findByUsername);
		}else{
			Staff byJobNumber = staffService.findByNameAndIsStatus(username);
			//判断是否为空
			if(byJobNumber == null){
				return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
			}

			//表示用户存在,进一步对比密码是否正确
			if(!byJobNumber.getPassword().equals(password)){
				return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
			}

			//检查用户所属角色状态是否可用
			if(byJobNumber.getRole() == null || byJobNumber.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
			}

			//检查用户所属角色的权限是否存在
			if(byJobNumber.getRole().getAuthorities() == null || byJobNumber.getRole().getAuthorities().size() == 0){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
			}
			//检查一切符合,可以登录,将用户信息存放至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);
	}
	
	
	@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", databaseBakService.total());
		model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
		return "admin/system/index";
	}
	
	
	@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);
			}
		}
		return "redirect:login";
	}
	
	
	@RequestMapping(value="/no_right")
	public String noRight(){
		return "admin/system/no_right";
	}
	
	
	@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
	public String updateUserInfo(){
		return "admin/system/update_userinfo";
	}
	
	
	@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="/update_pwd",method=RequestMethod.GET)
	public String updatePwd(){
		return "admin/system/update_pwd";
	}
	
	
	@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
	@ResponseBody
	public Result updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
			@RequestParam(name="newPwd",required=true)String newPwd
			){
		Integer loginType = (Integer) SessionUtil.get("loginType");
		if(loginType == LoginType.ADMINISTRATOR.getCode()){
			User loginedUser = SessionUtil.getLoginedUser();
			if(!loginedUser.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);
			}
			if(newPwd.length()<4 || newPwd.length()>32){
				return Result.error(CodeMsg.ADMIN_USER_PWD_LENGTH_ERROR);
			}
			loginedUser.setPassword(newPwd);
			//保存数据库
			userService.save(loginedUser);
			//更新session
			SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
		}else{
			Staff loginedStaff = SessionUtil.getLoginedStaff();

			Staff staff = staffService.find(loginedStaff.getId());
			if(!staff.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);
			}

			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);
	}
	
	
	@RequestMapping(value="/operator_log_list")
	public String operatorLogList(Model model,OperaterLog operaterLog,PageBean pageBean){
		model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
		model.addAttribute("operator", operaterLog.getOperator());
		model.addAttribute("title", "日志列表");
		return "admin/system/operator_log_list";
	}
	
	@RequestMapping(value="/auth_order",method=RequestMethod.POST)
	@ResponseBody
	public Result authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){

		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);
	}

	
	@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
	@ResponseBody
	public Result delete(String ids){
		if(!StringUtils.isEmpty(ids)){
			String[] splitIds = ids.split(",");
			for(String id : splitIds){
				operaterLogService.delete(Long.valueOf(id));
			}
		}
		return Result.success(true);
	}
	
	
	@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
	@ResponseBody
	public Result deleteAll(){
		operaterLogService.deleteAll();
		return Result.success(true);
	}
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5562712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存