最近几周挺忙的,又要准备面试又要参加学校的实习什么的,而且还要准备web课的结课项目,说是老师帮助我们优秀的项目组申请软件著作权,所以这个在线支付的项目我还是比较重视的,在功能的实现上面下了比较多的功夫,因为不会真的上线有的功能能模拟就模拟了。算是比较满意的了,平时成绩100,结课项目评委分数92(说是前端页面不够美观,不然能给95加吧),综合成绩96,还行,不辜负我整个大三下的自学,大四即将到来,实习单位也找到了,七月份正式上班,最近几天能划水就划划水吧。
本次采取的开发框架还是比较容易上手的微服务springboot开发框架,因为涉及到支付,采用另一个微服务负责支付端的响应。
- @Data
- public class Good{
- private int goodId;
- private String goodName;
- private int goodInPrice;
- private int goodOutPrice;
- private int goodReserve;
- private String goodProduct;
- private String goodExTime;
- private int goodShopId;
- }
- @Data
- public class Older implements Serializable {
- private int olderId;
- private int olderUserId;
- private int olderGoodId;
- private int olderShopId;
- private int olderGoodNumber;
- private String olderAddress;
- private String olderGoHomeTime;
- private boolean olderState;
- private String olderDate;
- }
- @Data
- public class Shop {
- private int shopId;
- private String shopNickname;
- private String shopAddress;
- private String shopOwner;
- private String shopPhone;
- private String shopInfo;
- private String password;
- }
- @Data
- public class User {
- private int userId;
- private String userNickname;
- private char userSex;
- private String userHead;
- private String userBrith;
- private String userAddress;
- private String userRegister;
- private String userPhone;
- private String password;
- }
- @Mapper
- public interface ShopMapper extends BaseMapper<Good> {
-
- @Select("SELECT * FROM ncds.shop WHERE shopPhone=#{shopPhone} AND password=#{password}")
- boolean loginShop(@Param("shopPhone") String shop_phone, @Param("password") String password);
-
-
- @Insert("INSERT INTO ncds.shop (shopPhone,password) VALUE (#{shopPhone},#{password})")
- boolean registerShop(@Param("shopPhone") String shopPhone, @Param("password") String password);
-
-
- @Update("UPDATE ncds.shop SET shopNickname=#{shopNickname},shopAddress=#{shopAddress},shopOwner=#{shopOwner},shopInfo=#{shopInfo} WHERE shopId=#{shopId}")
- boolean refineShop(@Param("shopNickname") String shopNickname, @Param("shopAddress") String shopAddress, @Param("shopOwner") String shopOwner, @Param("shopInfo") String shopInfo, @Param("shopId") int shopId);
-
-
- @Update("UPDATE ncds.shop SET password=#{password} WHERE shopId=#{shopId}")
- boolean updateShopPassword(@Param("shopId") int shopId, @Param("password") String password);
-
-
- @Select("SELECT * FROM ncds.good WHERE goodId=#{goodId}")
- List<Good> findHostGood(@Param("goodId") int goodId);
-
-
- @Insert("INSERT INTO ncds.good (goodName,goodInPrice,goodOutPrice,goodReserve,goodExTime,goodProduct,goodShopId) " +
- "VALUE (#{goodName},#{goodInPrice},#{goodOutPrice},#{goodReserve},#{goodExTime},#{goodProduct},#{goodShopId})")
- boolean saveGood(@Param("goodName") String goodName, @Param("goodInPrice") int goodInPrice, @Param("goodOutPrice") int goodOutPrice,
- @Param("goodReserve") int goodReserve, @Param("goodExTime") String goodExTime, @Param("goodProduct") String goodProduct, @Param("goodShopId") int goodShopId);
-
- @Delete("DELETE FROM ncds.good WHERE goodId=#{goodId}")
- boolean deleteGood(@Param("goodId") int goodId);
-
- @Update("UPDATE ncds.good SET goodReserve=#{goodNumber} WHERE goodId=#{goodId} AND goodName=#{goodName}")
- boolean addGood_number(@Param("goodId") int goodId, @Param("goodNumber") int goodNumber, @Param("goodName") String goodName);
-
- @Update("UPDATE ncds.good SET goodOutPrice=#{price} WHERE goodId=#{goodId}")
- boolean inSuPriceByGood_id(@Param("goodId") int goodId, @Param("price") int price);
-
-
- @Select("SELECT * FROM ncds.older WHERE olderShopId=#{olderShopId}")
- List<Older> findOlderByShopId(int olderShopId);
-
- @Select("SELECT * FROM ncds.older WHERE olderUserId=#{userId}")
- List<Older> findOlderByUserId(int userId);
-
-
- @Select("SELECT * FROM ncds.shop WHERE shopId=#{shopId}")
- Shop findShopById(@Param("shopId") int shopId);
-
-
- @Select("SELECT * FROM ncds.good WHERE goodShopId=#{goodShopId}")
- List<Good> findGoodByShopId(int goodShopId);
-
-
- @Select("SELECT shopId FROM ncds.shop WHERE shopPhone=#{shopPhone}")
- int findShopIdByShopPhone(String shopPhone);
-
-
- @Select("SELECT goodShopId FROM ncds.good WHERE goodId=#{goodId}")
- int findShopIdByGoodId(@Param("goodId") int goodId);
-
- @Select("SELECT shopPhone FROM ncds.shop WHERE shopId=#{shopId}")
- String findShopPhoneByShopId(@Param("shopId") int shopId);
-
- }
- @Mapper
- public interface UserMapper {
- /*1.登录*/
- @Select("SELECT * FROM ncds.user WHERE userPhone=#{userPhone} AND password=#{password}")
- boolean loginUser(@Param("userPhone") String userPhone, @Param("password") String password);
-
- /*2.注册*/
- @Insert("INSERT INTO ncds.user(userPhone,password) VALUE (#{userPhone},#{password})")
- boolean registerUser(@Param("userPhone") String userPhone, @Param("password") String password);
-
- /*补全信息(最开始注册仅仅按照电话与id以及密码 注册)*/
-
- /**
- * @param userId
- * @param userNickname
- * @param userSex
- * @param userHead 采取的是longblob的mysql数据库格式,利用load_file(文件磁盘路径)的方式
- * 只需要传入一个路径参数即可实现图片或者视频的存储。我们规定文件路径为D:/ncds/img/...
- * @param userBrith
- * @param userAddress
- * @param userRegister
- * @return boolean
- */
- @Update("UPDATE ncds.user SET userNickname=#{userNickname},userSex=#{userSex},userHead=load_file(#{userHead}),userBrith=#{userBrith},userAddress=#{userAddress},userRegister=#{userRegister},password=#{password} WHERE userId=#{userId}")
- boolean refineUser(@Param("userId") int userId, @Param("userNickname") String userNickname, @Param("userSex") char userSex,
- @Param("userHead") String userHead, @Param("userBrith") String userBrith, @Param("userAddress") String userAddress, @Param("userRegister") String userRegister, @Param("password") String password);
-
-
- /*4.查看热门商品(需要redis数据库查询返回的id排序)*/
- @Select("SELECT * FROM ncds.good WHERE goodId=#{goodId}")
- Good findHostGood(int goodId);
-
- /*5.搜素商家(分为两种,按照id查与按照name查)*/
- @Select("SELECT * FROM ncds.shop WHERE shopId=#{shopId}")
- Shop findShopById(int shopId);
-
- @Select("SELECT * FROM ncds.shop WHERE shopNickname=#{shopNickname}")
- Shop findShopByName(String shopNickname);
- /*6.模糊查询,搜索商品(可能不为一个商品)*/
-
- /**
- * @param goodName 注意测试时需要将传入的参数拼接为“%${goodName}%”的形式
- * @return List<Good>
- */
- @Select("SELECT * FROM ncds.good WHERE goodName LIKE #{goodName}")
- List<Good> findGoodByName(String goodName);
-
- @Insert("INSERT INTO ncds.older (olderUserId,olderGoodId,olderGoodNumber,olderAddress,olderGoHomeTime,olderState,olderDate,olderShopId)" +
- "VALUE (#{olderUserId},#{olderGoodId},#{olderGoodNumber},#{olderAddress},#{olderGoHomeTime},#{olderState},#{olderDate},#{olderShopId})")
- boolean saveOlder(@Param("olderUserId") int olderUserId, @Param("olderGoodId") int olderGoodId, @Param("olderGoodNumber") int olderGoodNumber, @Param("olderAddress") String olderAddress, @Param("olderGoHomeTime") String olderGoHomeTime, @Param("olderState") boolean olderState, @Param("olderDate") String olderDate, @Param("olderShopId") int olderShopId);
-
- /*8.支付*/
- @Update("UPDATE ncds.older SET olderState=TRUE WHERE olderId=#{olderId}")
- boolean updateOlderState(@Param("older_id") int olderId);
-
- /*9.退货处理(就是删除订单,商家的货物退还,计算退款资金)*/
- @Select("SELECT olderUserId FROM ncds.older WHERE olderId=#{olderId}")
- int findUserIdByOlderId(@Param("olderId") Integer olderId);
-
- @Delete("DELETE FROM ncds.older WHERE olderId=#{olderId}")
- boolean deleteOlder(int olderId);
-
- @Update("UPDATE ncds.good SET goodReserve=goodReserve+#{olderGoodNumber} WHERE goodShopId=#{shopId}")
- boolean addGood(int shopId, int olderGoodNumber);
-
- /*11.查询个人信息*/
- @Select("SELECT userPhone FROM ncds.user WHERE userId=#{userId}")
- String findUserPhoneByUserId(@Param("userId") Integer userId);
-
- @Select("SELECT * FROM ncds.user WHERE userId=#{userId}")
- User findUserById(@Param("userId") int userId);
-
- @Select("SELECT userId FROM ncds.user WHERE userPhone=#{userPhone}")
- int findUserIdByUserPhone(@Param("userPhone") String userPhone);
-
- /*13.查询全部商品*/
- @Select("SELECT * FROM ncds.good")
- List<Good> findAllGood();
- }
- public interface ShopService {
-
- boolean loginShop(String shop_phone, String password);
-
- boolean registerShop(String shop_phone, String password);
-
- boolean refineShop(String shop_nickname, String shop_address, String shop_owner, String shop_info, int shopId);
-
- boolean updateShopPassword(int shop_id, String password);
-
- boolean saveGood(String goodName, int goodInPrice, int goodOutPrice, int goodReserve, String goodExTime, String goodProduct, int goodShopId);
-
- boolean deleteGood(int good_id);
-
- boolean addGood_number(int good_id, int good_number, String goodName);
-
- boolean inSuPriceByGood_id(int good_id, int price);
-
- List<Older> findOlderByShopId(int shopId);
-
- List<Older> findOlderByUserId(int userId);
-
- Shop findShopById(int shop_id);
-
- List<Good> findGoodByShopId(int goodShopId);
-
- int findShopIdByShopPhone(String shopPhone);
-
- boolean saveGoodByFile(MultipartFile file);
-
- int findShopIdByGoodId(int goodId);
-
- String findShopPhoneByShopId(int shopId);
- }
-
- @Service("ShopService")
- public class ShopServiceImpl implements ShopService {
- @Autowired
- private ShopMapper shopMapper;
-
- @Autowired
- private FileOption fileOption;
-
- @Override
- public boolean loginShop(String shop_phone, String password) {
- return shopMapper.loginShop(shop_phone, password);
- }
-
- @Override
- public boolean registerShop(String shop_phone, String password) {
- return shopMapper.registerShop(shop_phone, password);
- }
-
- @Override
- public boolean refineShop(String shop_nickname, String shop_address, String shop_owner, String shop_info, int shopId) {
- return shopMapper.refineShop(shop_nickname, shop_address, shop_owner, shop_info, shopId);
- }
-
- @Override
- public boolean updateShopPassword(int shop_id, String password) {
- return shopMapper.updateShopPassword(shop_id, password);
- }
-
-
- @Override
- public boolean saveGood(String goodName, int goodInPrice, int goodOutPrice, int goodReserve, String goodExTime, String goodProduct, int goodShopId) {
- return shopMapper.saveGood(goodName, goodInPrice, goodOutPrice, goodReserve, goodExTime, goodProduct, goodShopId);
- }
-
-
- @Override
- public boolean deleteGood(int good_id) {
- return shopMapper.deleteGood(good_id);
- }
-
- @Override
- public boolean addGood_number(int good_id, int good_number, String goodName) {
- return shopMapper.addGood_number(good_id, good_number, goodName);
- }
-
- @Override
- public boolean inSuPriceByGood_id(int good_id, int price) {
- return shopMapper.inSuPriceByGood_id(good_id, price);
- }
-
-
- @Override
- public List<Older> findOlderByShopId(int shopId) {
- return shopMapper.findOlderByShopId(shopId);
- }
-
- @Override
- public List<Older> findOlderByUserId(int userId) {
- return shopMapper.findOlderByUserId(userId);
- }
-
-
- @Override
- public Shop findShopById(int shop_id) {
- return shopMapper.findShopById(shop_id);
- }
-
- @Override
- public List<Good> findGoodByShopId(int goodShopId) {
- return shopMapper.findGoodByShopId(goodShopId);
- }
-
- @Override
- public int findShopIdByShopPhone(String shopPhone) {
- return shopMapper.findShopIdByShopPhone(shopPhone);
- }
-
- @Override
- public boolean saveGoodByFile(MultipartFile file) {
- boolean flag = true;
- List<Good> goodList = fileOption.fileOptions(file);
- for (Good good : goodList) {
- flag = saveGood(good.getGoodName(), good.getGoodInPrice(), good.getGoodOutPrice(),
- good.getGoodReserve(), good.getGoodExTime(), good.getGoodProduct()
- , good.getGoodShopId());
- }
- return flag;
- }
-
- @Override
- public int findShopIdByGoodId(int goodId) {
- return shopMapper.findShopIdByGoodId(goodId);
- }
-
- @Override
- public String findShopPhoneByShopId(int shopId) {
- return shopMapper.findShopPhoneByShopId(shopId);
- }
- }
- public interface UserService {
- /*1.登录*/
- boolean loginUser(String user_phone, String password);
-
- /*2.注册*/
- boolean registerUser(String user_phone, String password);
-
- /*补全信息(最开始注册仅仅按照电话与id以及密码 注册)*/
- boolean refineUser(int user_id, String user_nickname, char user_sex,
- String user_head, String user_brith, String user_address, String user_register,String password);
-
- /*4.查看热门商品(需要redis数据库查询返回的id排序)*/
- Good findHostGood(int good_id);
-
- /*5.搜素商家(分为两种,按照id查与按照name查)*/
- Shop findShopById(int shop_id);
-
- Shop findShopByName(String shop_nickname);
- /*6.模糊查询,搜索商品(可能不为一个商品)*/
-
- /**
- * @param good_name 注意测试时需要将传入的参数拼接为“%${good_name}%”的形式
- * @return List<Good>
- */
- List<Good> findGoodByName(String good_name);
-
- boolean updateOlderState(int older_id);
-
- String findUserPhoneByUserId(Integer userId);
-
- boolean deleteOlder(int older_id);
-
- boolean addGood(int shop_id, int older_good_number);
-
- User findUserById(int user_id);
- int findUserIdByOlderId(Integer olderId);
-
- int findUserIdByUserPhone(String userPhone);
- List<Good> findAllGood();
-
- boolean saveOlder(int olderUserId,int olderGoodId,int olderGoodNumber,String olderAddress,String olderGoHomeTime,boolean olderState,String olderDate, int olderShopId);
- }
- @Service("UserService")
- public class UserServiceImpl implements UserService {
- @Autowired
- private UserMapper userMapper;
-
- @Override
- public boolean loginUser(String user_phone, String password) {
- return userMapper.loginUser(user_phone,password);
- }
-
- @Override
- public boolean registerUser(String user_phone, String password) {
- return userMapper.registerUser(user_phone,password);
- }
-
- @Override
- public boolean refineUser(int user_id, String user_nickname, char user_sex, String user_head, String user_brith, String user_address, String user_register,String password) {
- return userMapper.refineUser(user_id,user_nickname,user_sex,user_head,user_brith,user_address,user_register,password);
- }
-
- @Override
- public Good findHostGood(int good_id) {
- return userMapper.findHostGood(good_id);
- }
-
- @Override
- public Shop findShopById(int shop_id) {
- return userMapper.findShopById(shop_id);
- }
-
- @Override
- public Shop findShopByName(String shop_nickname) {
- return userMapper.findShopByName(shop_nickname);
- }
-
- @Override
- public List<Good> findGoodByName(String good_name) {
- return userMapper.findGoodByName(good_name);
- }
-
-
- @Override
- public boolean updateOlderState(int older_id) {
- return userMapper.updateOlderState(older_id);
- }
-
- @Override
- public String findUserPhoneByUserId(Integer userId) {
- return userMapper.findUserPhoneByUserId(userId);
- }
-
- @Override
- public boolean deleteOlder(int older_id) {
- return userMapper.deleteOlder(older_id);
- }
-
- @Override
- public boolean addGood(int shop_id, int older_good_number) {
- return userMapper.addGood(shop_id,older_good_number);
- }
-
- @Override
- public User findUserById(int user_id) {
- return userMapper.findUserById(user_id);
- }
-
- @Override
- public int findUserIdByOlderId(Integer olderId) {
- return userMapper.findUserIdByOlderId(olderId);
- }
-
- @Override
- public int findUserIdByUserPhone(String userPhone) {
- return userMapper.findUserIdByUserPhone(userPhone);
- }
-
-
- @Override
- public List<Good> findAllGood() {
- return userMapper.findAllGood();
- }
-
- @Override
- public boolean saveOlder(int olderUserId, int olderGoodId, int olderGoodNumber, String olderAddress, String olderGoHomeTime, boolean olderState, String olderDate, int olderShopId) {
- return userMapper.saveOlder(olderUserId,olderGoodId,olderGoodNumber,olderAddress,olderGoHomeTime,olderState,olderDate,olderShopId);
- }
- }
-
- @RequestMapping("User")
- @RestController
- public class UserController {
-
- @Autowired
- private UserService userService;
- @Autowired
- private ShopService shopService;
- @Autowired
- private JedisFactory jedisFactory;
-
- /*注册*/
- @RequestMapping("register")
- public ModelAndView registerF() {
- return new ModelAndView("/register/register_user");
- }
-
- @PostMapping("register_user")
- public ModelAndView registerUser(String userPhone, String password) {
- boolean registerUser = userService.registerUser(userPhone, password);
- if (registerUser) {
- loginF();
- }
- return registerF();
- }
-
- /*登录*/
- @RequestMapping("login")
- public ModelAndView loginF() {
- return new ModelAndView("/login/login_user");
- }
-
- @PostMapping("login_user")
- public ModelAndView loginUser(String userPhone, String password) {
- boolean loginKey = jedisFactory.selectLoginKey(userPhone, password);
- if (loginKey) {
- return index_user(userPhone);
- } else {
- boolean loginUser = userService.loginUser(userPhone, password);
- if (loginUser) {
- return index_user(userPhone);
- }
- }
- return loginF();
- }
-
- /*主页*/
- @RequestMapping("index_user")
- public ModelAndView index_user(String userPhone) {
- List<Good> goodList = userService.findAllGood();
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("goodList", goodList);
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.setViewName("/index/user/index");
- return modelAndView;
- }
-
- @RequestMapping("index_user_return/{userPhone}")
- public ModelAndView index_user_return(@PathVariable("userPhone") String userPhone) {
- List<Good> goodList = userService.findAllGood();
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("goodList", goodList);
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.setViewName("/index/user/index");
- return modelAndView;
- }
-
- /*用户查看个人信息*/
- @RequestMapping("find_user/{userPhone}")
- public ModelAndView find_user(@PathVariable("userPhone") String userPhone) {
- int id = userService.findUserIdByUserPhone(userPhone);
- User user = userService.findUserById(id);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("User", user);
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.setViewName("/index/user/find_user");
- return modelAndView;
- }
-
- /*用户修改个人信息*/
- @RequestMapping("update_userF/{userPhone}")
- public ModelAndView update_userF(@PathVariable("userPhone") String userPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.setViewName("index/user/update_user");
- return modelAndView;
- }
-
- @RequestMapping("update_user/{userPhone}")
- public ModelAndView update_user(@PathVariable("userPhone") String userPhone, @RequestParam("userNickname") String userNickname, @RequestParam("userSex") char userSex,
- @RequestParam("userHead") String userHead, @RequestParam("userBrith") String userBrith,
- @RequestParam("userAddress") String userAddress, @RequestParam("userRegister") String userRegister, @RequestParam("password") String password) {
- int id = userService.findUserIdByUserPhone(userPhone);
- boolean flag = userService.refineUser(id, userNickname, userSex, userHead, userBrith, userAddress, userRegister, password);
- if (flag)
- return find_user(userPhone);
- else
- return update_userF(userPhone);
- }
-
- /*查看订单*/
- @RequestMapping("older_user_list/{userPhone}")
- public ModelAndView older_user_list(@PathVariable("userPhone") String userPhone) {
- int id = userService.findUserIdByUserPhone(userPhone);
- List<Older> olderList = shopService.findOlderByUserId(id);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.addObject("olderList", olderList);
- modelAndView.setViewName("/List/older_user_list");
- return modelAndView;
- }
-
- /*用户下单弹窗*/
- @RequestMapping("older_user_addF/{userPhone}")
- public ModelAndView older_user_addF(@PathVariable("userPhone") String userPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("userPhone", userPhone);
- modelAndView.setViewName("/index/user/older_user_add");
- return modelAndView;
- }
-
- @RequestMapping("older_user_add/{userPhone}")
- public ModelAndView older_user_add(@PathVariable("userPhone") String userPhone,
- @RequestParam("olderGoodId") int olderGoodId, @RequestParam("olderGoodNumber") int olderGoodNumber,
- @RequestParam("olderAddress") String olderAddress, @RequestParam("olderGoHomeTime") String olderGoHomeTime, @RequestParam("date") String date) {
- int shopId = shopService.findShopIdByGoodId(olderGoodId);
- int userId = userService.findUserIdByUserPhone(userPhone);
- boolean state = false;
- boolean saveOlder = userService.saveOlder(userId, olderGoodId, olderGoodNumber, olderAddress, olderGoHomeTime, state, date, shopId);
- if (saveOlder)
- return older_user_list(userPhone);
- else
- return older_user_addF(userPhone);
- }
-
- /*用户取消订单*/
- @RequestMapping("del_older_user/{olderId}")
- public ModelAndView del_older_user(@PathVariable("olderId") Integer olderId) {
- int userId = userService.findUserIdByOlderId(olderId);
- String userPhone = userService.findUserPhoneByUserId(userId);
- boolean deleteOlder = userService.deleteOlder(olderId);
- if (deleteOlder)
- return older_user_list(userPhone);
- else
- return older_user_list(userPhone);
- }
- /*用户确认付款(跳转网址定位http://192.168.10.105:8081/order/form)*/
-
- /*用户查询商品按照商品名称,模糊查询*/
- /*用户查询订单按照日期查询*/
- }
- @RestController
- @RequestMapping("Shop")
- public class ShopController {
-
- @Autowired
- private ShopService shopService;
- @Autowired
- private UserService userService;
- @Autowired
- private JedisFactory jedisFactory;
-
- /*注册*/
- @RequestMapping("register")
- public ModelAndView registerF() {
- return new ModelAndView("register/register_shop");
- }
-
- @PostMapping("register_shop")
- public ModelAndView registerShop(String shopPhone, String password) {
- boolean registerShop = shopService.registerShop(shopPhone, password);
- if (registerShop)
- return loginF();
- return registerF();
- }
-
- /*登录*/
- @RequestMapping("login")
- public ModelAndView loginF() {
- return new ModelAndView("login/login_shop");
- }
-
- @PostMapping("login_shop")
- public ModelAndView loginShop(String shopPhone, String password) {
- boolean loginKey = jedisFactory.selectLoginKey(shopPhone, password);
- if (loginKey) {
- return index_shop(shopPhone);
- } else {
- boolean loginShop = shopService.loginShop(shopPhone, password);
- if (loginShop)
- return index_shop(shopPhone);
- }
- return loginF();
-
- }
-
- /*商家主页数据加载与渲染*/
- @RequestMapping("index_shop")
- public ModelAndView index_shop(String shopPhone) {
- int id = shopService.findShopIdByShopPhone(shopPhone);
- List<Good> goodList = shopService.findGoodByShopId(id);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.addObject("goodList", goodList);
- modelAndView.setViewName("index/shop/index");
- return modelAndView;
- }
-
- /*跳转返回主页用,时刻拿着一个令牌*/
- @RequestMapping("index_shop_return/{shopPhone}")
- public ModelAndView index_shop_return(@PathVariable("shopPhone") String shopPhone) {
- List<Good> goodList = shopService.findGoodByShopId(shopService.findShopIdByShopPhone(shopPhone));
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.addObject("goodList", goodList);
- modelAndView.setViewName("index/shop/index");
- return modelAndView;
- }
-
- /*主页面添加商品*/
- @RequestMapping("add_goodF/{shopPhone}")
- public ModelAndView add_goodF(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.setViewName("index/shop/add_good");
- return modelAndView;
- }
-
- /*单个商品添加*/
- @RequestMapping("add_good/{shopPhone}")
- public ModelAndView add_good(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodName") String goodName, @RequestParam("goodInPrice") Integer goodInPrice, @RequestParam("goodOutPrice") Integer goodOutPrice, @RequestParam("goodReserve") Integer goodReserve, @RequestParam("goodExTime") String goodExTime, @RequestParam("goodProduct") String goodProduct, @RequestParam("goodShopId") Integer goodShopId) {
- boolean saveGood = shopService.saveGood(goodName, goodInPrice, goodOutPrice, goodReserve, goodExTime, goodProduct, goodShopId);
- if (saveGood) {
- return index_shop(shopPhone);
- }
- return good_shop_list(shopPhone);
- }
-
- /*文件导入添加*/
- @RequestMapping("add_good_file/{shopPhone}")
- public ModelAndView add_good_file(@RequestParam("file") MultipartFile file, @PathVariable("shopPhone") String shopPhone) {
- boolean saveGoodByFile = shopService.saveGoodByFile(file);
- if (saveGoodByFile) {
- return index_shop(shopPhone);
- }
- return good_shop_list(shopPhone);
- }
-
- /*商家货架数据加载与渲染*/
- @RequestMapping("good_shop_list/{shopPhone}")
- public ModelAndView good_shop_list(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- int id = shopService.findShopIdByShopPhone(shopPhone);
- List<Good> goodList = shopService.findGoodByShopId(id);
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.addObject("goodList", goodList);
- modelAndView.setViewName("List/good_shop_list");
- return modelAndView;
- }
-
- /*删除商品*/
- @RequestMapping("delete_good/{goodId}")
- public ModelAndView delete_good(@PathVariable("goodId") Integer goodId) {
- int shopId = shopService.findShopIdByGoodId(goodId);
- boolean deleteGood = shopService.deleteGood(goodId);
- String shopPhone = shopService.findShopPhoneByShopId(shopId);
- /*这里需要加上一个删除失败的跳转逻辑*/
- return good_shop_list(shopPhone);
- }
-
- /*商家订单统计页面的查看*/
- @RequestMapping("older_shop_list/{shopPhone}")
- public ModelAndView older_shop_list(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- int id = shopService.findShopIdByShopPhone(shopPhone);
- List<Older> olderList = shopService.findOlderByShopId(id);
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.addObject("olderList", olderList);
- modelAndView.setViewName("List/older_shop_list");
- return modelAndView;
- }
-
- /*商家查询自己的商品按照商品名称查询*/
- @RequestMapping("shop_findGoodByGoodName/{shopPhone}")
- public ModelAndView shop_shop_findGoodByName(@RequestParam("goodName") String goodName, @PathVariable("shopPhone") String shopPhone) {
- /*模糊查询,手动拼接*/
- List<Good> goodList = userService.findGoodByName("%" + goodName + "%");
- if (goodList != null) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("goodList", goodList);
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.setViewName("List/good_shop_list");
- return modelAndView;
- }
- return index_shop(shopPhone);
- }
-
- /*商家搜索订单按照用户ID*/
- @RequestMapping("older_shop_list_select/{shopPhone}")
- public ModelAndView shop_findOlderByUserId(@RequestParam("userId") Integer userId, @PathVariable("shopPhone") String shopPhone) {
- List<Older> olderList = shopService.findOlderByUserId(userId);
- if (olderList != null) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("olderList", olderList);
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.setViewName("List/older_shop_list");
- return modelAndView;
- }
- return older_shop_list(shopPhone);
- }
-
- /*商家调整价格窗口的弹出*/
- @RequestMapping("update_good_priceF/{shopPhone}")
- public ModelAndView update_good_priceF(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.setViewName("index/shop/update_good_price");
- return modelAndView;
- }
-
- @RequestMapping("update_good_price/{shopPhone}")
- public ModelAndView update_good_price(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodId") Integer goodId, @RequestParam("goodName") String goodName, @RequestParam("goodPrice") Integer goodPrice) {
- boolean inSuPriceByGoodId = shopService.inSuPriceByGood_id(goodId, goodPrice);
- if (inSuPriceByGoodId)
- return good_shop_list(shopPhone);
- return update_good_priceF(shopPhone);
- }
-
- /*商家进货窗口弹出*/
- @RequestMapping("add_good_numberF/{shopPhone}")
- public ModelAndView add_good_numberF(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("shopPhone", shopPhone);
- modelAndView.setViewName("index/shop/add_good_number");
- return modelAndView;
- }
-
- @RequestMapping("add_good_number/{shopPhone}")
- public ModelAndView add_good_number(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodId") Integer goodId, @RequestParam("goodName") String goodName, @RequestParam("goodNumber") Integer goodNumber) {
- boolean addGoodNumber = shopService.addGood_number(goodId, goodNumber, goodName);
- if (addGoodNumber)
- return good_shop_list(shopPhone);
- System.out.println("----------------进货操作失败-------------------");
- return add_good_numberF(shopPhone);
- }
-
- /*商家查看自家店铺信息*/
- @RequestMapping("find_shop/{shopPhone}")
- public ModelAndView find_shop(@PathVariable("shopPhone") String shopPhone) {
- int id = shopService.findShopIdByShopPhone(shopPhone);
- Shop shop = shopService.findShopById(id);
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("Shop", shop);
- modelAndView.setViewName("index/shop/find_shop");
- return modelAndView;
- }
-
- @RequestMapping("update_shopF/{shopPhone}")
- public ModelAndView update_shopF(@PathVariable("shopPhone") String shopPhone) {
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.setViewName("index/shop/update_shop");
- modelAndView.addObject("shopPhone", shopPhone);
- return modelAndView;
- }
-
- @RequestMapping("update_shop/{shopPhone}")
- public ModelAndView update_shopInfo(@PathVariable("shopPhone") String shopPhone, @RequestParam("shopNickname") String shopNickname
- , @RequestParam("shopAddress") String shopAddress, @RequestParam("shopOwner") String shopOwner
- , @RequestParam("password") String password, @RequestParam("shopInfo") String shopInfo) {
- int id = shopService.findShopIdByShopPhone(shopPhone);
- boolean refineShop = shopService.refineShop(shopNickname, shopAddress, shopOwner, shopInfo, id);
- boolean updateShopPassword = shopService.updateShopPassword(id, password);
- if (refineShop && updateShopPassword) {
- return index_shop(shopPhone);
- }
- return update_shopF(shopPhone);
- }
-
- /*注销商家*/
-
- }
1、jedisUtils
- /*redis生成连接池JedisPool的配置工具*/
- public class JedisUntil {
-
- private static JedisPool jedisPool = null;
-
- public static JedisPool getJedisPoolFactory() {
-
- if (jedisPool == null) {
- synchronized (JedisUntil.class) {
- if (jedisPool == null) {
- JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
- jedisPoolConfig.setMaxIdle(32);
- jedisPoolConfig.setMaxTotal(200);
- jedisPoolConfig.setTestOnBorrow(false);
- jedisPoolConfig.setBlockWhenExhausted(true);
-
- jedisPool = new JedisPool(jedisPoolConfig, "192.168.20.150", 6379);
- }
- }
- }
- return jedisPool;
- }
-
- public void release(Jedis jedis, JedisPool jedisPool) {
- if (jedisPool != null) {
- jedis.close();
- }
- }
- }
2、jedisFactory
- /*创建jedis生成工厂为我们创建jedis对象并操作redis数据库*/
- @Component
- public class JedisFactory {
-
- static JedisPool jedisPool = JedisUntil.getJedisPoolFactory();
- static Jedis jedis = jedisPool.getResource();
-
- /*登录走redis,第一次登录即将它加入redis数据库(用 phone-password 键值对存储)*/
- public void addLoginKey(String shopPhone, String password) {
- jedis.auth("hlc");
- jedis.setex(shopPhone, 120, password);
- jedis.close();
- }
-
- public boolean selectLoginKey(String shopPhone, String password) {
- jedis.auth("hlc");
- String V = jedis.get(shopPhone);
- if (V != null) {
- System.out.println("走缓存登录");
- jedis.close();
- return true;
- } else {
- addLoginKey(shopPhone, password);
- selectLoginKey(shopPhone, password);
- }
- jedis.close();
- return false;
- }
-
- public boolean addGoodHostKey(int goodId) {
- Long i = null;
- jedis.auth("hlc");
- i = jedis.zadd("hostGood", Double.parseDouble("1"), String.valueOf(goodId));
- jedis.close();
- return i != null;
- }
-
- /*访问一次就给该商品的热度增加1*/
- public boolean incrGoodHostKeyValue(int goodId) {
- jedis.auth("hlc");
- Long i = null;
- i = jedis.zrank("hostGood", String.valueOf(goodId));
- if (i != null) {
- jedis.zincrby("hostGood", 1, String.valueOf(goodId));
- jedis.close();
- return true;
- }
- return addGoodHostKey(goodId);
- }
-
- /*当商品下架时要删除热度*/
- public boolean delGoodHostKey(int goodId) {
- jedis.auth("hlc");
- Long i = null;
- i = jedis.zrem("host", String.valueOf(goodId));
- jedis.close();
- return i != null;
- }
-
- /*c查询热度在10以上的商品排行*/
- public List<Integer> selectHostGoodKey() {
- jedis.auth("hlc");
- Set<String> set = jedis.zrangeByScore("hostGood", 10, 1000);
- List<Integer> hostList = new ArrayList<>();
- for (String i : set) {
- hostList.add(Integer.valueOf(i));
- }
- jedis.close();
- System.out.println("走缓存查看热度商品");
- return hostList;
- }
- }
- /*文件导入解析数据实现货物的批量导入*/
- @Component
- public class FileOption {
-
- public List<Good> fileOptions(MultipartFile file) {
-
- List<Good> goodArrayList = new ArrayList<>();
-
- /*获取文件名*/
- String fileName = file.getOriginalFilename();
- /*获取文件后缀*/
- String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
- /*创建文件输入流对象*/
- InputStream ins = null;
- try {
- ins = file.getInputStream();
- } catch (IOException e) {
- System.out.println("文件导入异常");
- e.printStackTrace();
- }
- /*获取工作薄对象*/
- Workbook wb = null;
- try {
- /*根据文件类型将文件输入流对象给到工作薄对象的内容里去*/
- if (suffix.equals("xlsx")) {
- wb = new XSSFWorkbook(ins);
- } else {
- wb = new HSSFWorkbook(ins);
- }
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("文件版本识别异常");
- }
-
- /*获取excel表单*/
- Sheet sheet = wb.getSheetAt(0);
-
- /* line = 2 :从表的第三行开始获取记录*/
- if (null != sheet) {
- for (int line = 2; line <= sheet.getLastRowNum(); line++) {
- /*创建对象,封装数据*/
- Good good = new Good();
- /*创建行对象,便于逐行操作单元格*/
- Row row = sheet.getRow(line);
- if (null == row) {
- continue;
- }
- /* 判断单元格类型是否为文本类型 */
- if (1 != row.getCell(0).getCellType()) {
- System.out.println("单元格类型不是文本类型");
- }
- /*获取第一个单元格的内容并设置对象的属性*/
- row.getCell(0).setCellType(Cell.CELL_TYPE_NUMERIC);
- Integer good_id = (int) row.getCell(0).getNumericCellValue();
- good.setGoodId(good_id);
- /* 获取第二个单元格的内容并设置对象的属性*/
- row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
- String good_name = row.getCell(1).getStringCellValue();
- good.setGoodName(good_name);
- /*获取第三个单元格内容并设置对象的属性*/
- row.getCell(2).setCellType(Cell.CELL_TYPE_NUMERIC);
- Integer good_inPrice = (int) row.getCell(2).getNumericCellValue();
- good.setGoodInPrice(good_inPrice);
- /*获取第四行数据并设置对象属性*/
- row.getCell(3).setCellType(Cell.CELL_TYPE_NUMERIC);
- Integer good_outPrice = (int) row.getCell(3).getNumericCellValue();
- good.setGoodOutPrice(good_outPrice);
- /*获取第五单元格并设置对象属性*/
- row.getCell(4).setCellType(Cell.CELL_TYPE_NUMERIC);
- Integer good_reserve = (int) row.getCell(4).getNumericCellValue();
- good.setGoodReserve(good_reserve);
- /*获取第六单元格并设置对象属性*/
- String good_product = String.valueOf(row.getCell(5).getDateCellValue());
- good.setGoodProduct(good_product);
- /*获取第七单元格并设置对象属性*/
- String good_exTime = String.valueOf(row.getCell(6).getDateCellValue());
- good.setGoodExTime(good_exTime);
- /*获取第八单元格并设置对象属性*/
- Integer good_shop_id = (int) row.getCell(7).getNumericCellValue();
- good.setGoodShopId(good_shop_id);
- /*将这个对象插入List容器里*/
- goodArrayList.add(good);
- }
- }
- return goodArrayList;
- }
- }
- /*加密算法:MD5加密的使用,主要是二次加密加盐的技术*/
- @Component
- public class MD5 {
-
- public static String slat = "1a2b3c4d";
-
- public String md5_hlc(String src) {
- return DigestUtils.md5Hex(src);
- }
-
- /*前端加密的步骤与这一样,注意盐的位置与盐的值*/
- public String inputPassToFromPass(String inputPass) {
- String slat = "java_secKill";
- String str = slat.charAt(0) +
- slat.charAt(1) + inputPass +
- slat.charAt(2);
- return md5_hlc(str);
- }
-
- public String PassToDbPass(String FromPass, String slat) {
- String str = slat.charAt(2) +
- slat.charAt(1) + FromPass +
- slat.charAt(0);
- return md5_hlc(str);
-
- }
-
- public String inputPassToDbPass(String inputPass) {
- String fromPass = inputPassToFromPass(inputPass);
- return PassToDbPass(fromPass, slat);
- }
-
- /*测试加密技术*/
- /*444bcbf09f10ee179b8c8d52bf834033(数据库昵称:小年 的实体密码 / 前端加密出现的加密后密码)*/
- /*经过加密之后的密码因该不是这个,原始的密码经过MD5加密之后就发生了加密变化*/
- // public static void main(String[] args) {
- // MD5 m1 = new MD5();
- // System.out.println(m1.inputPassToFromPass("hlc123"));
- // System.out.println(m1.PassToDbPass(m1.inputPassToFromPass("hlc123"), slat));
- //
- // }
-
- }
- /*
- * 日期矫正组件:java提取系统时间可能会减少8小时,由于时区问题,所以需要将时区调整到东八区,
- * 另外数据库日期格式可能与java封装工具包可能存在差异,所以需要转换格式。
- * */
- @Component
- public class TimeC {
-
- public String getSystemTime() throws ParseException {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
- sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
- Date date = sdf.parse(sdf.format(new Date()));
- return date.toString();
- }
-
- }
需要的评论区留言我会回复的。
- spring:
- application:
- #应用名
- name: SecKill
- datasource:
- name: defaultDataSource
- driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://localhost:3306/ncds?serverTimezone=UTC
- username: root
- password: 123456
- #数据库连接池
- druid:
- name: NCDS
- min-idle: 32
- max-active: 100
- default-auto-commit: true
- max-wait: 3000
- mvc:
- static-path-pattern: /static/**
-
- thymeleaf:
- #是否利用缓存
- cache: false
- mode: HTML5
- redis:
- host: 192.168.20.150
- port: 6379
- password: hlc
- database: 1
- jedis:
- pool:
- max-idle: 32
- max-wait: 3000
- min-idle: 8
- max-active: 20
-
- server:
- port: 8080
-
- <dependencies>
- <!--跳转模板引擎-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-thymeleaf</artifactId>
- </dependency>
- <!--springMVC-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!--mybatis plus 依赖与代码生成器依赖-->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.5.2</version>
- </dependency>
- <!--mysql数据库驱动-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <!--数据库连接池-->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid-spring-boot-starter</artifactId>
- <version>1.2.8</version>
- </dependency>
- <!--lombok开发插件-->
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <!--测试-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <!--md5依赖-->
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.12.0</version>
- </dependency>
- <!--redis数据库-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-pool2</artifactId>
- <version>2.11.1</version>
- </dependency>
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- </dependency>
- <!--文件导入依赖-->
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.15</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml</artifactId>
- <version>3.15</version>
- </dependency>
- <dependency>
- <groupId>commons-fileupload</groupId>
- <artifactId>commons-fileupload</artifactId>
- <version>1.3.1</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- </dependency>
- </dependencies>
支付端口呢?当然是在我上一篇文章里了!那个就是解决支付实现的模块代码。