共计 12608 个字符,预计需要花费 32 分钟才能阅读完成。
前端模板框架为 Bootstrap, 零碎分为前台和后盾。后盾次要为管理员角色,性能有:
商品类型治理、商品治理、订单治理、会员治理、管理员治理等。前台用户性能有:登录、注册、查看商品、退出购物车、付款、查看订单、集体核心等。该零碎总共 9 张表
运行环境:windows/linux、jdk1.8、mysql5.x、maven3.5\3.6、tomcat7.0
前端商品控制器:
/**
* <p>
* 前端控制器
* </p>
*/
@RestController
@RequestMapping("/goods")
public class GoodsController {
@Autowired
private GoodsService goodsService;
@Autowired
private ProviderService providerService;
@Autowired
private CategoryService categoryService;
/**
* 商品含糊查问
*
* @param
* @return
*/
@SysLog("商品查问操作")
@RequestMapping("/goodsList")
public DataGridViewResult goodsList(GoodsVO goodsVO) {
// 创立分页信息 参数 1 当前页 参数 2 每页显示条数
IPage<Goods> page = new Page<>(goodsVO.getPage(), goodsVO.getLimit());
QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(goodsVO.getProviderid() != null && goodsVO.getProviderid() != 0, "providerid", goodsVO.getProviderid());
queryWrapper.like(!StringUtils.isEmpty(goodsVO.getGname()), "gname", goodsVO.getGname());
IPage<Goods> goodsIPage = goodsService.page(page, queryWrapper);
List<Goods> records = goodsIPage.getRecords();
for (Goods goods : records) {Provider provider = providerService.getById(goods.getProviderid());
if (null != provider) {goods.setProvidername(provider.getProvidername());
}
}
return new DataGridViewResult(goodsIPage.getTotal(), records);
}
/**
* 增加商品信息
*
* @param goods
* @return
*/
@SysLog("商品增加操作")
@PostMapping("/addgoods")
public Result addGoods(Goods goods) {String id = RandomStringUtils.randomAlphanumeric(8);
if (goods.getGoodsimg()!=null&&goods.getGoodsimg().endsWith("_temp")){String newName = AppFileUtils.renameFile(goods.getGoodsimg());
goods.setGoodsimg(newName);
}
goods.setGnumbering(id);
boolean bool = goodsService.save(goods);
if (bool) {return Result.success(true, "200", "增加胜利!");
}
return Result.error(false, null, "增加失败!");
}
/**
* 批改商品信息
*
* @param goods
* @return
*/
@SysLog("商品批改操作")
@PostMapping("/updategoods")
public Result updateGoods(Goods goods) {
// 商品图片不是默认图片
if (!(goods.getGoodsimg()!=null&&goods.getGoodsimg().equals(Constast.DEFAULT_IMG))){if (goods.getGoodsimg().endsWith("_temp")){String newName = AppFileUtils.renameFile(goods.getGoodsimg());
goods.setGoodsimg(newName);
// 删除原先的图片
String oldPath = goodsService.getById(goods.getGid()).getGoodsimg();
AppFileUtils.removeFileByPath(oldPath);
}
}
boolean bool = goodsService.updateById(goods);
if (bool) {return Result.success(true, "200", "批改胜利!");
}
return Result.error(false, null, "批改失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("商品删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {boolean bool = goodsService.removeById(id);
if (bool) {return Result.success(true, "200", "删除胜利!");
}
return Result.error(false, null, "删除失败!");
}
/**
* 依据 id 查问以后商品领有的类别
*
* @param id
* @return
*/
@RequestMapping("/initGoodsByCategoryId")
public DataGridViewResult initGoodsByCategoryId(int id) {
List<Map<String, Object>> mapList = null;
try {
// 查问所有类别列表
mapList = categoryService.listMaps();
// 依据商品 id 查问商品领有的类别
Set<Integer> cateIdList = categoryService.findGoodsByCategoryId(id);
for (Map<String, Object> map : mapList) {
// 定义标记 默认不选中
boolean flag = false;
int cateId = (int) map.get("cateid");
for (Integer cid : cateIdList) {if (cid == cateId) {
flag = true;
break;
}
}
map.put("LAY_CHECKED", flag);
}
} catch (Exception e) {e.printStackTrace();
}
return new DataGridViewResult(Long.valueOf(mapList.size()), mapList);
}
/**
* 依据商品 id 加载商品信息
* @param goodsid
* @return
*/
@GetMapping("/loadGoodsById")
public DataGridViewResult loadGoodsById(int goodsid) {QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
goodsQueryWrapper.eq(goodsid != 0, "gid", goodsid);
Goods goods = goodsService.getById(goodsid);
return new DataGridViewResult(goods);
}
/**
* 为商品调配类别
*
* @param categoryids
* @param goodsid
* @return
*/
@SysLog("类别增加操作")
@RequestMapping("/saveGoodsCategory")
public Result saveGoodsCategory(String categoryids, int goodsid) {
try {if (goodsService.saveGoodsCategory(goodsid, categoryids)) {return Result.success(true, null, "调配胜利");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "调配失败");
}
/**
* 加载下拉框
*
* @return
*/
@RequestMapping("/loadAllGoods")
public DataGridViewResult loadAllGoods() {QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
List<Goods> list = goodsService.list(queryWrapper);
return new DataGridViewResult(list);
}
/**
* 依据供应商查商品下拉框
*
* @param providerid
* @return
*/
@RequestMapping("/loadGoodsByProvidreId")
public DataGridViewResult loadGoodsByProvidreId(Integer providerid) {QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
goodsQueryWrapper.eq(providerid != null, "providerid", providerid);
List<Goods> list = goodsService.list(goodsQueryWrapper);
for (Goods goods : list) {Provider provider = providerService.getById(goods.getProviderid());
if (null != provider) {goods.setProvidername(provider.getProvidername());
}
}
return new DataGridViewResult(list);
}
}
前端销售控制器:
/**
* <p>
* 前端控制器
* </p>
*/
@RestController
@RequestMapping("/sale")
public class SaleController {
@Autowired
private SaleService saleService;
@Autowired
private GoodsService goodsService;
@Autowired
private CustomerService customerService;
/**
* 销售查问
*
* @param
* @return
*/
@SysLog("销售查问操作")
@RequestMapping("/saleList")
public DataGridViewResult saleList(SaleVO saleVO) {
// 创立分页信息 参数 1 当前页 参数 2 每页显示条数
IPage<Sale> page = new Page<>(saleVO.getPage(), saleVO.getLimit());
QueryWrapper<Sale> queryWrapper = new QueryWrapper<>();
queryWrapper.like(!StringUtils.isEmpty(saleVO.getNumbering()),"numbering", saleVO.getNumbering());
queryWrapper.eq(saleVO.getGid() != null && saleVO.getGid() != 0, "gid", saleVO.getGid());
queryWrapper.ge(saleVO.getStartTime() != null, "buytime", saleVO.getStartTime());
queryWrapper.le(saleVO.getEndTime() != null, "buytime", saleVO.getEndTime());
queryWrapper.orderByDesc("buytime");
IPage<Sale> saleIPage = saleService.page(page, queryWrapper);
List<Sale> records = saleIPage.getRecords();
for (Sale sale : records) {sale.setAllmoney(sale.getMoney()*sale.getBuyquantity());
Customer customer = customerService.getById(sale.getCustid());
if (null != customer) {sale.setCustomervip(customer.getCustvip());
sale.setCustomername(customer.getCustname());
}
Goods goods = goodsService.getById(sale.getGid());
if (null != goods) {sale.setGoodsname(goods.getGname());
sale.setGnumbering(goods.getGnumbering());
}
}
return new DataGridViewResult(saleIPage.getTotal(), records);
}
/**
* 增加销售单信息
*
* @param sale
* @return
*/
@SysLog("销售增加操作")
@PostMapping("/addsale")
public Result addsale(Sale sale, HttpSession session) {if (sale.getGid()==0){return Result.error(false, null, "增加失败!未选商品");
}
Goods goods = goodsService.getById(sale.getGid());
Integer gquantity = goods.getGquantity();
if(gquantity<sale.getBuyquantity()){return Result.error(false, null, "增加失败!库存有余, 库存为:"+gquantity);
}
User user = (User) session.getAttribute("username");
String num = RandomStringUtils.randomAlphanumeric(7);
sale.setNumbering(num);
sale.setPerson(user.getUsername());
sale.setBuytime(new Date());
sale.setRealnumber(sale.getBuyquantity());
boolean bool = saleService.save(sale);
if (bool) {return Result.success(true, "200", "增加胜利!");
}
return Result.error(false, null, "增加失败!库存有余");
}
/**
* 批改销售单信息
*
* @param sale
* @return
*/
@SysLog("销售批改操作")
@PostMapping("/updatesale")
public Result updatesale(Sale sale, HttpSession session) {User user = (User) session.getAttribute("username");
sale.setPerson(user.getUsername());
sale.setBuytime(new Date());
boolean bool = saleService.updateById(sale);
if (bool) {return Result.success(true, "200", "批改胜利!");
}
return Result.error(false, null, "批改失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("销售删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {boolean bool = saleService.removeById(id);
if (bool) {return Result.success(true, "200", "删除胜利!");
}
return Result.error(false, null, "删除失败!");
}
}
前端用户控制器:
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 登录
*
* @param username 用户名
* @param password 明码
* @param request
* @return
*/
@SysLog("登陆操作")
@PostMapping("/login")
public Result login(String username, String password, HttpServletRequest request) {
try {
// 获取以后登录主体对象
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
subject.login(token);
LoginUserVO userDTO = (LoginUserVO) subject.getPrincipal();
request.getSession().setAttribute("username", userDTO.getUser());
return Result.success(true, "200", "登录胜利");
} catch (UnknownAccountException e) {e.printStackTrace();
return Result.error(false, "400", "登录失败, 用户名不存在");
}catch (IncorrectCredentialsException e) {e.printStackTrace();
return Result.error(false, "400", "登录失败, 明码谬误");
}catch (AuthenticationException e) {e.printStackTrace();
return Result.error(false, "400", "登录失败, 账户禁用");
}
}
/**
* 失去登陆验证码
* @param response
* @param session
* @throws IOException
*/
@RequestMapping("/getCode")
public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36,4,5);
session.setAttribute("code",lineCaptcha.getCode());
try {ServletOutputStream outputStream = response.getOutputStream();
lineCaptcha.write(outputStream);
outputStream.close();} catch (IOException e) {e.printStackTrace();
}
}
/**
* 查问所有用户信息
*
* @param userVO
* @return
*/
@SysLog("用户查问操作")
@RequestMapping("/userList")
public DataGridViewResult userList(UserVO userVO) {
// 分页构造函数
IPage<User> page = new Page<>(userVO.getPage(), userVO.getLimit());
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.like(!StringUtils.isEmpty(userVO.getUsername()), "username", userVO.getUsername());
queryWrapper.like(!StringUtils.isEmpty(userVO.getUname()), "uname", userVO.getUname());
/**
* 翻页查问
* @param page 翻页对象
* @param queryWrapper 实体对象封装操作类
*/
IPage<User> userIPage = userService.page(page, queryWrapper);
return new DataGridViewResult(userIPage.getTotal(), userIPage.getRecords());
}
/**
* 增加用户信息
*
* @param user
* @return
*/
@SysLog("用户增加操作")
@PostMapping("/adduser")
public Result addRole(User user) {user.setUcreatetime(new Date());
String salt = UUIDUtil.randomUUID();
user.setPassword(PasswordUtil.md5("000000", salt, 2));
user.setSalt(salt);
user.setType(1);
boolean bool = userService.save(user);
try {if (bool) {return Result.success(true, "200", "增加胜利!");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "增加失败!");
}
/**
* 校验用户名是否存在
*
* @param username
* @return
*/
@RequestMapping("/checkUserName")
public String checkUserName(String username) {Map<String, Object> map = new HashMap<>();
try {QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username", username);
User user = userService.getOne(queryWrapper);
if (user != null) {map.put("exist", true);
map.put("message", "用户名已存在");
} else {map.put("exist", false);
map.put("message", "用户名能够应用");
}
} catch (Exception e) {e.printStackTrace();
}
return JSON.toJSONString(map);
}
/**
* 批改用户信息
*
* @param user
* @return
*/
@SysLog("用户批改操作")
@PostMapping("/updateuser")
public Result updateUser(User user) {boolean bool = userService.updateById(user);
try {if (bool) {return Result.success(true, "200", "批改胜利!");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "批改失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("用户删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {boolean bool = userService.removeById(id);
try {if (bool) {return Result.success(true, "200", "删除胜利!");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "删除失败!");
}
/**
* 重置明码
*
* @param id
* @return
*/
@SysLog("用户批改操作")
@PostMapping("/resetPwd")
public Result resetPwd(int id) {User user = new User();
String salt = UUIDUtil.randomUUID();
user.setUid(id);
user.setPassword(PasswordUtil.md5("000000", salt, 2));
user.setSalt(salt);
boolean bool = userService.updateById(user);
try {if (bool) {return Result.success(true, "200", "重置胜利!");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "重置失败!");
}
/**
* 依据 id 查问以后用户领有的角色
*
* @param id
* @return
*/
@RequestMapping("/initRoleByUserId")
public DataGridViewResult initRoleByUserId(int id) {
List<Map<String, Object>> mapList = null;
try {
// 查问所有角色列表
mapList = roleService.listMaps();
// 依据用户 id 查问用户领有的角色
Set<Integer> roleIdList = userService.findRoleByUserId(id);
for (Map<String, Object> map : mapList) {
// 定义标记 默认不选中
boolean flag = false;
int roleId = (int) map.get("roleid");
for (Integer rid : roleIdList) {if (rid == roleId) {
flag = true;
break;
}
}
map.put("LAY_CHECKED", flag);
}
} catch (Exception e) {e.printStackTrace();
}
return new DataGridViewResult(Long.valueOf(mapList.size()), mapList);
}
/**
* 为用户调配角色
*
* @param roleids
* @param userid
* @return
*/
@SysLog("用户增加操作")
@RequestMapping("/saveUserRole")
public Result saveUserRole(String roleids, int userid) {
try {if (userService.saveUserRole(userid, roleids)) {return Result.success(true, null, "调配胜利");
}
} catch (Exception e) {e.printStackTrace();
}
return Result.error(false, null, "调配失败");
}
/**
* 批改明码
*
* @param newPassWord1
* @param newPassWord2
* @return
*/
@RequestMapping("/updateUserPassWord")
public Result updateUserPassWord(String newPassWord1, String newPassWord2,HttpSession session) {User sessionUser = (User) session.getAttribute("username");
if (newPassWord1.equals(newPassWord2)){User user = new User();
String salt = UUIDUtil.randomUUID();
user.setUid(sessionUser.getUid());
user.setPassword(PasswordUtil.md5(newPassWord1, salt, 2));
user.setSalt(salt);
boolean bool = userService.updateById(user);
if (bool){return Result.success(true,null,"批改胜利");
}else {return Result.error(false,null,"批改失败!");
}
}else {return Result.error(false,null,"批改失败,两次明码不统一!");
}
}
}
正文完