diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java index 2abfebf2..78af6b89 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java @@ -22,6 +22,8 @@ package cn.ysk.cashier.utils; */ public interface CacheKey { + String ONLINE_ADMIN = "ONLINE_ADMIN:"; + /** * 激活码 */ diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java index 5e78001a..134e1799 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java @@ -39,8 +39,8 @@ public class TbProductController { } @GetMapping("/isHot") - public ResponseEntity updateIsHot(@RequestParam String shopId, @RequestParam Integer id){ - tbProductService.updateIsHot(id,shopId); + public ResponseEntity updateIsHot(@RequestParam Integer isHot, @RequestParam Integer id){ + tbProductService.updateIsHot(id,isHot); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java index 6607c755..480ff91c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java @@ -1,25 +1,9 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.service.shop.TbPlussShopStaffService; import cn.ysk.cashier.dto.shop.TbPlussShopStaffQueryCriteria; -import io.swagger.models.auth.In; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -91,4 +75,15 @@ public class TbPlussShopStaffController { tbPlussShopStaffService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } + +// @ApiOperation("修改个人密码") +// @PostMapping(value = "/upPass") +// @AnonymousPostMapping +// public ResponseEntity upshopStaffPass(HttpServletRequest request, @RequestBody Map map){ +// tbShopInfoService.upShopPass(map.get("username"),map.get("password")); +// //根据token踢出用户 +// onlineUserService.logout(tokenProvider.getToken(request)); +// log.info("修改商户密码成功。"); +// return new ResponseEntity<>(HttpStatus.OK); +// } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java index 48a51f9b..a6980d50 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java @@ -72,7 +72,7 @@ public class TbShopInfoController { public ResponseEntity upShopPass(HttpServletRequest request, @RequestBody Map map) throws Exception { tbShopInfoService.upShopPass(map.get("username"),map.get("password")); //根据token踢出用户 -// onlineUserService.logout(tokenProvider.getToken(request)); + onlineUserService.logout(tokenProvider.getToken(request)); log.info("修改商户密码成功。"); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index 86bc5ffc..1da35b54 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -25,9 +25,9 @@ public interface TbProductRepository extends JpaRepository, @Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true) @Modifying void updateByStatus(List productIds); - @Query(value = "update tb_product set is_hot=1 where id = :id",nativeQuery = true) + @Query(value = "update tb_product set is_hot=:isHot where id = :id",nativeQuery = true) @Modifying - void updateIsHot(@Param("id") Integer id); + void updateIsHot(@Param("id") Integer id,@Param("isHot")Integer isHot); @Query(value = "update tb_product set is_stock=:isStock where id = :proId and shop_id=:shopId",nativeQuery = true) @Modifying diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java index f8429d07..00876641 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java @@ -1,18 +1,3 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.repository.shop; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; @@ -21,8 +6,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import java.util.List; - /** * @website https://eladmin.vip * @author lyf @@ -42,6 +25,10 @@ public interface TbPlussShopStaffRepository extends JpaRepository sysUserIds=new HashSet<>(); for (Integer id : ids) { TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(id).get(); - User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount()); + User sysUser = userRepository.findByUsername(tbPlussShopStaff.getShopId()+"@"+tbPlussShopStaff.getAccount()); tbPlussShopStaffRepository.deleteById(id); sysUserIds.add(sysUser.getId()); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java index d9e55502..3ee7c092 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java @@ -85,7 +85,7 @@ public interface TbProductService { */ void download(List all, HttpServletResponse response) throws IOException; - void updateIsHot(Integer id, String shopId); + void updateIsHot(Integer id,Integer isStock); void updateIsStock(Integer proId, String shopId, Integer isStock); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java index 625c0271..31bdb4aa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java @@ -1,18 +1,3 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.domain.vo; import lombok.Data; @@ -25,6 +10,9 @@ import lombok.Data; @Data public class UserPassVo { + //staff + private String loginType; + private String oldPass; private String newPass; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java index f54b9107..bc462c86 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java @@ -1,26 +1,15 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.rest; import cn.hutool.core.collection.CollectionUtil; +import cn.ysk.cashier.config.security.security.TokenProvider; +import cn.ysk.cashier.config.security.service.OnlineUserService; +import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository; import cn.ysk.cashier.system.domain.Dept; import cn.ysk.cashier.system.domain.User; import cn.ysk.cashier.system.domain.vo.UserPassVo; import cn.ysk.cashier.system.service.dto.UserDto; import cn.ysk.cashier.system.service.dto.UserQueryCriteria; +import cn.ysk.cashier.utils.MD5Utils; import cn.ysk.cashier.utils.PageUtil; import cn.ysk.cashier.utils.RsaUtils; import cn.ysk.cashier.utils.SecurityUtils; @@ -37,16 +26,20 @@ import cn.ysk.cashier.system.service.dto.RoleSmallDto; import cn.ysk.cashier.system.service.VerifyService; import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.utils.enums.CodeEnum; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; @@ -68,6 +61,9 @@ public class UserController { private final DeptService deptService; private final RoleService roleService; private final VerifyService verificationCodeService; + private final OnlineUserService onlineUserService; + private final TbPlussShopStaffRepository shopStaffRepository; + private final TokenProvider tokenProvider; @ApiOperation("导出用户数据") @GetMapping(value = "/download") @@ -155,17 +151,27 @@ public class UserController { @ApiOperation("修改密码") @PostMapping(value = "/updatePass") - public ResponseEntity updateUserPass(@RequestBody UserPassVo passVo) throws Exception { - String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass()); - String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass()); - UserDto user = userService.findByName(SecurityUtils.getCurrentUsername()); - if(!passwordEncoder.matches(oldPass, user.getPassword())){ + @Transactional + public ResponseEntity updateUserPass(HttpServletRequest request, @RequestBody UserPassVo passVo) throws Exception { + String currentUsername = SecurityUtils.getCurrentUsername(); + UserDto user = userService.findByName(currentUsername); + String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass()); + String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass()); + if (!passwordEncoder.matches(oldPass, user.getPassword())) { throw new BadRequestException("修改失败,旧密码错误"); } - if(passwordEncoder.matches(newPass, user.getPassword())){ + if (passwordEncoder.matches(newPass, user.getPassword())) { throw new BadRequestException("新密码不能与旧密码相同"); } + String encPass = MD5Utils.encrypt( passVo.getNewPass()); + if (StringUtils.isNotBlank(passVo.getLoginType()) && passVo.getLoginType().equals("staff")) { + String[] split = currentUsername.split("@"); + shopStaffRepository.updatePassAndShopId(split[1],split[0],encPass,System.currentTimeMillis()); + }else { + shopStaffRepository.updatePass(currentUsername,encPass,System.currentTimeMillis()); + } userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass)); + onlineUserService.logout(tokenProvider.getToken(request)); return new ResponseEntity<>(HttpStatus.OK); }