Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
SongZhang 2024-07-26 18:10:38 +08:00
commit ff1be0554a
3 changed files with 24 additions and 1 deletions

View File

@ -21,6 +21,8 @@ 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,4 +44,8 @@ public interface TbPlussShopStaffRepository extends JpaRepository<TbPlussShopSta
@Query("select staff from TbPlussShopStaff as staff where staff.account = :account")
TbPlussShopStaff queryByAccount(String account);
@Modifying
@Query("update TbPlussShopStaff set name=:name where shopId = :shopId and type='master'")
void updateNameById(String name, String shopId);
}

View File

@ -16,6 +16,7 @@
package cn.ysk.cashier.service.impl.shopimpl;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.exception.EntityExistException;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import cn.ysk.cashier.system.domain.Dept;
import cn.ysk.cashier.system.domain.Job;
@ -129,6 +130,9 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
job.setId(10L);
jobs.add(job);
user.setJobs(jobs);
if (userRepository.findByUsername(user.getUsername()) != null) {
throw new BadRequestException("员工账号已存在");
}
userRepository.save(user);
return tbPlussShopStaffMapper.toDto(tbPlussShopStaffRepository.save(resources));
}
@ -136,7 +140,16 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbPlussShopStaff resources) {
if (StringUtils.isBlank(resources.getPassword())) {
resources.setPassword(null);
}
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(resources.getId()).orElseGet(TbPlussShopStaff::new);
User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount());
if(!tbPlussShopStaff.getAccount().equals(resources.getAccount())){
if (userRepository.findByUsername(resources.getAccount()) != null) {
throw new BadRequestException("员工账号不可重复");
}
}
resources.setUpdatedAt(Instant.now().toEpochMilli());
ValidationUtil.isNull( tbPlussShopStaff.getId(),"TbPlussShopStaff","id",resources.getId());
tbPlussShopStaff.copy(resources);
@ -145,11 +158,11 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
}
tbPlussShopStaffRepository.save(tbPlussShopStaff);
//修改 sysUser账号
User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount());
Set<Role> roles = new HashSet<>();
Role role = new Role();
role.setId(resources.getRoleId());
roles.add(role);
sysUser.setUsername(resources.getAccount());
sysUser.setRoles(roles);
sysUser.setNickName(resources.getName());
if (StringUtils.isNotBlank(resources.getPassword())) {

View File

@ -203,6 +203,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
TbPlussShopStaff tbPlussShopStaff = new TbPlussShopStaff();
tbPlussShopStaff.setShopId(String.valueOf(save.getId()));
tbPlussShopStaff.setType("master");
tbPlussShopStaff.setName(resources.getShopName());
tbPlussShopStaff.setAccount(resources.getAccount());
tbPlussShopStaff.setPassword(MD5Utils.encrypt(resources.getPassword()));
tbPlussShopStaff.setStatus(1);
@ -237,6 +238,9 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
@Transactional(rollbackFor = Exception.class)
public void update(TbShopInfo resources) {
TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new);
if (!resources.getShopName().equals(tbShopInfo.getShopName())) {
shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString());
}
ValidationUtil.isNull( tbShopInfo.getId(),"TbShopInfo","id",resources.getId());
tbShopInfo.copy(resources);
tbShopInfo.setUpdatedAt(Instant.now().toEpochMilli());