基于javaweb+mysql的ssm农产品水果店销售管理系统(java+jsp+ssm+javabean+mysql+tomcat)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
农产品店、水果店等管理产品与销售、进货等信息
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL EasyUI JavaScript
基于javaweb+mysql的SSM农产品水果店销售管理系统(java+jsp+ssm+javabean+mysql+tomcat)
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
@Autowired
private LogService logService;
/**
* 系统登录后的主页
* @param model
* @return
*/
@RequestMapping(value="/index",method=RequestMethod.GET)
public ModelAndView index(ModelAndView model,HttpServletRequest request){
List<Menu> userMenus = (List<Menu>)request.getSession().getAttribute("userMenus");
model.addObject("topMenuList", MenuUtil.getAllTopMenu(userMenus));
model.addObject("secondMenuList", MenuUtil.getAllSecondMenu(userMenus));
model.setViewName("system/index");
return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
}
/**
* 系统登录后的欢迎页
* @param model
* @return
*/
@RequestMapping(value="/welcome",method=RequestMethod.GET)
public ModelAndView welcome(ModelAndView model){
model.setViewName("system/welcome");
return model;
}
/**
* 登陆页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView login(ModelAndView model){
model.setViewName("system/login");
return model;
}
/**
* 登录表单提交处理控制器
* @param user
* @param cpacha
/**
* 菜单管理控制器
*
*/
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
/**
* 菜单管理列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.addObject("topList", menuService.findTopList());
model.setViewName("menu/list");
return model;
}
/**
* 获取菜单列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getMenuList(Page page,
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
* 供应商管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("supplier/list");
return model;
}
/**
* 模糊搜索分页获取供应商信息
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(
@RequestParam(name="name",defaultValue="") String name,Page page
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("total", supplierService.getTotal(queryMap));
ret.put("rows", supplierService.findList(queryMap));
return ret;
}
/**
* 添加供应商信息
* @param supplier
* @return
*/
@RequestMapping(value="add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Supplier supplier){
Map<String, String> ret = new HashMap<String, String>();
if(supplier == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的供应商信息!");
return ret;
}
if(StringUtils.isEmpty(supplier.getName())){
ret.put("type", "error");
ret.put("msg", "请填写供应商名称!");
@ResponseBody
public Map<String, String> edit(Sell sell){
Map<String, String> ret = new HashMap<String, String>();
if(sell == null){
ret.put("type", "error");
ret.put("msg", "请选择正确的销售单信息!");
return ret;
}
sell.setStatus(1);
if(sellService.edit(sell) <= 0){
ret.put("type", "error");
ret.put("msg", "编辑失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "编辑成功!");
return ret;
}
/**
* 商品库存调整
* @param stockList
*/
private void updateStock(List<Stock> stockList){
for(Stock stock : stockList){
Stock existStock = stockService.findByProductId(stock.getProductId());
if(existStock!= null){
//更新商品库存数量及销售数量
existStock.setProductNum(existStock.getProductNum() - stock.getProductNum());
existStock.setSellNum(existStock.getSellNum() + stock.getProductNum());
if(existStock.getProductNum() < 0){
existStock.setProductNum(0);
}
stockService.edit(existStock);
}
}
}
}
try {
Double priceDouble = row.getCell(5).getNumericCellValue();
float price = Float.valueOf(priceDouble+"");
product.setPrice(price);
} catch (Exception e) {
// TODO: handle exception
msg += "第" + (rowIndex+1) + "行商品价格格式错误,跳过!\n";
continue;
}
product.setRemark(row.getCell(6) == null ? "" : row.getCell(6).getStringCellValue());
product.setSupplierId(supplierId);
if(productService.add(product) <= 0){
msg += "第" + (rowIndex+1) + "行商品添加失败!\n";
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return msg;
}
}
sellDetail.setProductNum(jsonObject.getInt("productNum"));
sellDetail.setPrice(Float.valueOf(jsonObject.getString("price")));
sellDetail.setMoney(sellDetail.getPrice() * sellDetail.getProductNum());
sell.getSellDetailList().add(sellDetail);
money += sellDetail.getMoney();
num += sellDetail.getProductNum();
Stock stock = new Stock();
stock.setProductId(Long.valueOf(jsonObject.getInt("id")+""));
stock.setProductNum(sellDetail.getProductNum());
stock.setCreateTime(new Date());
stockList.add(stock);
}
sell.setMoney(money);
sell.setProductNum(num);
User admin = (User)request.getSession().getAttribute("admin");
sell.setOperator(admin.getUsername());
sell.setCreateTime(new Date());
if(sellService.add(sell) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
//进行库存调整操作
updateStock(stockList);
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 编辑销售单信息
* @param product
* @return
*/
@RequestMapping(value="edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Sell sell){
Map<String, String> ret = new HashMap<String, String>();
if(sell == null){
ret.put("type", "error");
ret.put("msg", "请选择正确的销售单信息!");
return ret;
}
sell.setStatus(1);
if(sellService.edit(sell) <= 0){
}
}
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
/**
* 系统操作类控制器
*
*/
@Controller
@RequestMapping("/system")
public class SystemController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户管理控制器
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
if(excelFile == null){
ret.put("type", "error");
ret.put("msg", "请选择上传的文件!");
return ret;
}
if(excelFile.getSize() > 5000000){
ret.put("type", "error");
ret.put("msg", "文件大小超过5M,请上传不大于5M的文件");
return ret;
}
//获取文件后缀
String suffix = excelFile.getOriginalFilename().substring(excelFile.getOriginalFilename().lastIndexOf(".")+1,excelFile.getOriginalFilename().length());
if(!"xlsx,xls".contains(suffix)){
ret.put("type", "error");
ret.put("msg", "请上传xlsx或xls格式的文件!");
return ret;
}
String msg = "";
try {
msg = addProductByFile(supplierId,excelFile.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if("".equals(msg)){
msg = "全部导入成功";
}
ret.put("type", "success");
ret.put("msg", msg);
return ret;
}
private String addProductByFile(Long supplierId,InputStream inputStream){
String msg = "";
try {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream);
HSSFSheet sheetAt = hssfWorkbook.getSheetAt(0);
//去掉表头,送第二行开始读
if(sheetAt.getLastRowNum() <= 0){
msg = "文件内容为空!";
}
System.out.println(sheetAt.getLastRowNum());
@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
@RequestParam(name="w",required=false,defaultValue="100") Integer width,
@RequestParam(name="h",required=false,defaultValue="30") Integer height,
@RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,
HttpServletRequest request,
HttpServletResponse response){
CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
String generatorVCode = cpachaUtil.generatorVCode();
request.getSession().setAttribute(cpachaType, generatorVCode);
BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
try {
ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 用户管理控制器
* 商品管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("offset", 0);
queryMap.put("pageSize", 9999);
model.addObject("supplierList", supplierService.findList(queryMap));
model.setViewName("product/list");
return model;
}
/**
* 模糊搜索分页获取商品信息
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(
@RequestParam(name="supplierId",required=false) Long supplierId,
@RequestParam(name="name",defaultValue="") String name,Page page
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
if(supplierId != null){
queryMap.put("supplierId", supplierId);
}
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("total", productService.getTotal(queryMap));
ret.put("rows", productService.findList(queryMap));
return ret;
}
/**
* 添加商品信息
* @param product
* @return
*/
@RequestMapping(value="add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Product product){
Map<String, String> ret = new HashMap<String, String>();
if(product == null){
ret.put("type", "error");
JSONObject jsonObject = productArray.getJSONObject(i);
SellRebackDetail sellDetail = new SellRebackDetail();
sellDetail.setProductName(jsonObject.getString("name"));
sellDetail.setProductNum(jsonObject.getInt("productNum"));
sellDetail.setPrice(Float.valueOf(jsonObject.getString("price")));
sellDetail.setMoney(sellDetail.getPrice() * sellDetail.getProductNum());
sell.getSellRebackDetailList().add(sellDetail);
money += sellDetail.getMoney();
num += sellDetail.getProductNum();
Stock stock = new Stock();
stock.setProductId(Long.valueOf(jsonObject.getInt("id")+""));
stock.setProductNum(sellDetail.getProductNum());
stock.setCreateTime(new Date());
stockList.add(stock);
}
sell.setMoney(money);
sell.setProductNum(num);
User admin = (User)request.getSession().getAttribute("admin");
sell.setOperator(admin.getUsername());
sell.setCreateTime(new Date());
if(sellRebackService.add(sell) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
//进行库存调整操作
updateStock(stockList);
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 编辑销售退货单信息
* @param product
* @return
*/
@RequestMapping(value="edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(SellReback sell){
Map<String, String> ret = new HashMap<String, String>();
if(sell == null){
ret.put("type", "error");
ret.put("msg", "请选择正确的销售退货单信息!");
return ret;
}
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
ret.put("type", "error");
ret.put("msg", "请填写正确的进货单信息!");
return ret;
}
JSONArray productArray = JSONArray.fromObject(productList);
float money = 0;
int num = 0;
List<Stock> stockList = new ArrayList<Stock>();
for(int i = 0; i < productArray.size(); i++){
JSONObject jsonObject = productArray.getJSONObject(i);
OrderInDetail orderInDetail = new OrderInDetail();
orderInDetail.setProductName(jsonObject.getString("name"));
orderInDetail.setProductNum(jsonObject.getInt("productNum"));
orderInDetail.setPrice(Float.valueOf(jsonObject.getString("price")));
orderInDetail.setMoney(orderInDetail.getPrice() * orderInDetail.getProductNum());
orderIn.getOrderInDetailList().add(orderInDetail);
money += orderInDetail.getMoney();
num += orderInDetail.getProductNum();
Stock stock = new Stock();
stock.setProductId(Long.valueOf(jsonObject.getInt("id")+""));
stock.setProductNum(orderInDetail.getProductNum());
stock.setCreateTime(new Date());
stock.setSellNum(0);
stockList.add(stock);
}
orderIn.setMoney(money);
orderIn.setProductNum(num);
User admin = (User)request.getSession().getAttribute("admin");
orderIn.setOperator(admin.getUsername());
orderIn.setCreateTime(new Date());
if(orderInService.add(orderIn) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
//进行入库操作
addStock(stockList);
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 编辑进货单信息
* @param product
* @return
*/
@RequestMapping(value="edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(OrderIn orderIn){
*/
@RequestMapping(value="add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(String productList,OrderIn orderIn,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(productList)){
ret.put("type", "error");
ret.put("msg", "请至少选择一个商品信息!");
return ret;
}
if(orderIn == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的进货单信息!");
return ret;
}
JSONArray productArray = JSONArray.fromObject(productList);
float money = 0;
int num = 0;
List<Stock> stockList = new ArrayList<Stock>();
for(int i = 0; i < productArray.size(); i++){
JSONObject jsonObject = productArray.getJSONObject(i);
OrderInDetail orderInDetail = new OrderInDetail();
orderInDetail.setProductName(jsonObject.getString("name"));
orderInDetail.setProductNum(jsonObject.getInt("productNum"));
orderInDetail.setPrice(Float.valueOf(jsonObject.getString("price")));
orderInDetail.setMoney(orderInDetail.getPrice() * orderInDetail.getProductNum());
orderIn.getOrderInDetailList().add(orderInDetail);
money += orderInDetail.getMoney();
num += orderInDetail.getProductNum();
Stock stock = new Stock();
stock.setProductId(Long.valueOf(jsonObject.getInt("id")+""));
stock.setProductNum(orderInDetail.getProductNum());
stock.setCreateTime(new Date());
stock.setSellNum(0);
stockList.add(stock);
}
orderIn.setMoney(money);
orderIn.setProductNum(num);
User admin = (User)request.getSession().getAttribute("admin");
orderIn.setOperator(admin.getUsername());
/**
* 获取菜单列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getMenuList(Page page,
@RequestParam(name="name",required=false,defaultValue="") String name
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
queryMap.put("name", name);
List<Menu> findList = menuService.findList(queryMap);
ret.put("rows", findList);
ret.put("total", menuService.getTotal(queryMap));
return ret;
}
/**
* 获取指定目录下的系统icon集合
* @param request
* @return
*/
@RequestMapping(value="/get_icons",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getIconList(HttpServletRequest request){
Map<String, Object> ret = new HashMap<String, Object>();
String realPath = request.getServletContext().getRealPath("/");
File file = new File(realPath + "\\resources\\admin\\easyui\\css\\icons");
List<String> icons = new ArrayList<String>();
if(!file.exists()){
ret.put("type", "error");
ret.put("msg", "文件目录不存在!");
return ret;
}
File[] listFiles = file.listFiles();
for(File f:listFiles){
if(f!= null && f.getName().contains("png")){
icons.add("icon-" + f.getName().substring(0, f.getName().indexOf(".")).replace("_", "-"));
}
}
ret.put("type", "success");
ret.put("content", icons);
return ret;