master:档口子角色功能;

pull/1121/head
liujiang 2025-04-06 16:41:09 +08:00
parent 9756e5cc23
commit dcf52e2611
15 changed files with 434 additions and 331 deletions

View File

@ -4,25 +4,18 @@ import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.XktBaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.xkt.vo.store.StoreUpdateVO;
import com.ruoyi.xkt.domain.Store;
import com.ruoyi.xkt.dto.store.StoreCreateDTO;
import com.ruoyi.xkt.dto.store.StoreUpdateDTO;
import com.ruoyi.xkt.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Controller
*
@ -59,59 +52,4 @@ public class StoreController extends XktBaseController {
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:store:list')")
@GetMapping("/list")
public TableDataInfo list(Store store) {
startPage();
List<Store> list = storeService.selectStoreList(store);
return getDataTable(list);
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:store:export')")
@Log(title = "档口", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Store store) {
List<Store> list = storeService.selectStoreList(store);
ExcelUtil<Store> util = new ExcelUtil<Store>(Store.class);
util.exportExcel(response, list, "档口数据");
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:store:query')")
@GetMapping(value = "/{storeId}")
public R getInfo(@PathVariable("storeId") Long storeId) {
return success(storeService.selectStoreByStoreId(storeId));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:store:remove')")
@Log(title = "档口", businessType = BusinessType.DELETE)
@DeleteMapping("/{storeIds}")
public R remove(@PathVariable Long[] storeIds) {
return success(storeService.deleteStoreByStoreIds(storeIds));
}
}

View File

@ -1,18 +1,25 @@
package com.ruoyi.web.controller.xkt;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.XktBaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.xkt.domain.StoreRole;
import com.ruoyi.web.controller.xkt.vo.storeRole.StoreRolePageVO;
import com.ruoyi.web.controller.xkt.vo.storeRole.StoreRoleUpdateStatusVO;
import com.ruoyi.web.controller.xkt.vo.storeRole.StoreRoleVO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRolePageDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleResDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleUpdateStatusDTO;
import com.ruoyi.xkt.service.IStoreRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -21,71 +28,66 @@ import java.util.List;
* @author ruoyi
* @date 2025-03-26
*/
@Api(tags = "档口子角色")
@RequiredArgsConstructor
@RestController
@RequestMapping("/rest/v1/store-roles")
public class StoreRoleController extends XktBaseController {
@Autowired
private IStoreRoleService storeRoleService;
final IStoreRoleService storeRoleService;
/**
*
*
*/
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/list")
public TableDataInfo list(StoreRole storeRole) {
startPage();
List<StoreRole> list = storeRoleService.selectStoreRoleList(storeRole);
return getDataTable(list);
@PreAuthorize("@ss.hasPermi('system:role:add')")
@ApiOperation(value = "新增档口子角色", httpMethod = "POST", response = R.class)
@Log(title = "新增档口子角色", businessType = BusinessType.INSERT)
@PostMapping
public R<Integer> add(@Validated @RequestBody StoreRoleVO storeRoleVO) {
return R.ok(storeRoleService.insertStoreRole(BeanUtil.toBean(storeRoleVO, StoreRoleDTO.class)));
}
/**
*
*
*/
@PreAuthorize("@ss.hasPermi('system:role:export')")
@Log(title = "档口子角色", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, StoreRole storeRole) {
List<StoreRole> list = storeRoleService.selectStoreRoleList(storeRole);
ExcelUtil<StoreRole> util = new ExcelUtil<StoreRole>(StoreRole.class);
util.exportExcel(response, list, "档口子角色数据");
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@ApiOperation(value = "编辑档口子角色", httpMethod = "PUT", response = R.class)
@Log(title = "编辑档口子角色", businessType = BusinessType.UPDATE)
@PutMapping
public R<Integer> edit(@Validated @RequestBody StoreRoleVO storeRoleVO) {
return R.ok(storeRoleService.update(BeanUtil.toBean(storeRoleVO, StoreRoleDTO.class)));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:role:query')")
@ApiOperation(value = "获取档口子角色详细信息", httpMethod = "GET", response = R.class)
@GetMapping(value = "/{storeRoleId}")
public R getInfo(@PathVariable("storeRoleId") Long storeRoleId) {
return success(storeRoleService.selectStoreRoleByStoreRoleId(storeRoleId));
public R<StoreRoleVO> getInfo(@PathVariable("storeRoleId") Long storeRoleId) {
return R.ok(BeanUtil.toBean(storeRoleService.selectByStoreRoleId(storeRoleId), StoreRoleVO.class));
}
/**
*
*
*/
@PreAuthorize("@ss.hasPermi('system:role:add')")
@Log(title = "档口子角色", businessType = BusinessType.INSERT)
@PostMapping
public R add(@RequestBody StoreRole storeRole) {
return success(storeRoleService.insertStoreRole(storeRole));
@PreAuthorize("@ss.hasPermi('system:role:list')")
@ApiOperation(value = "查询档口销售出库列表", httpMethod = "POST", response = R.class)
@PostMapping("/list")
public R<List<StoreRoleResDTO>> list(@Validated @RequestBody StoreRolePageVO rolePageVO) {
return R.ok(storeRoleService.list(BeanUtil.toBean(rolePageVO, StoreRolePageDTO.class)));
}
/**
*
* /
*/
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "档口子角色", businessType = BusinessType.UPDATE)
@PutMapping
public R edit(@RequestBody StoreRole storeRole) {
return success(storeRoleService.updateStoreRole(storeRole));
@ApiOperation(value = "停用/启用档口子角色", httpMethod = "PUT", response = R.class)
@Log(title = "停用/启用档口子角色", businessType = BusinessType.UPDATE)
@PutMapping("/status")
public R<Integer> updateRoleStatus(@Validated @RequestBody StoreRoleUpdateStatusVO roleUpdateStatusVO) {
return R.ok(storeRoleService.updateRoleStatus(BeanUtil.toBean(roleUpdateStatusVO, StoreRoleUpdateStatusDTO.class)));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:role:remove')")
@Log(title = "档口子角色", businessType = BusinessType.DELETE)
@DeleteMapping("/{storeRoleIds}")
public R remove(@PathVariable Long[] storeRoleIds) {
return success(storeRoleService.deleteStoreRoleByStoreRoleIds(storeRoleIds));
}
}

View File

@ -0,0 +1,25 @@
package com.ruoyi.web.controller.xkt.vo.storeRole;
import com.ruoyi.web.controller.xkt.vo.BasePageVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("档口子角色分页查询入参")
@Data
public class StoreRolePageVO extends BasePageVO {
@NotNull(message = "档口ID不能为空")
@ApiModelProperty(value = "档口ID", required = true)
private Long storeId;
}

View File

@ -0,0 +1,28 @@
package com.ruoyi.web.controller.xkt.vo.storeRole;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口子角色停用启用")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreRoleUpdateStatusVO {
@ApiModelProperty(value = "档口子角色ID", required = true)
@NotNull(message = "档口子角色ID不能为空!")
private Long storeRoleId;
@ApiModelProperty(value = "档口子角色状态,启用传:0停用传:2", required = true)
@NotBlank(message = "档口子角色状态不能为空!")
private String delFlag;
}

View File

@ -0,0 +1,37 @@
package com.ruoyi.web.controller.xkt.vo.storeRole;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口子角色")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreRoleVO {
@ApiModelProperty(value = "档口ID", required = true)
@NotNull(message = "档口ID不能为空!")
private Long storeId;
@ApiModelProperty(value = "档口ID新增为空 编辑必传")
private Long storeRoleId;
@ApiModelProperty(value = "角色名称")
@NotBlank(message = "角色名称不能为空!")
@Size(min = 1, max = 30, message = "角色名称长度不能超过30个字!")
private String roleName;
@ApiModelProperty(value = "档口子角色备注")
private String remark;
@ApiModelProperty(value = "档口子角色菜单权限名称列表")
List<String> menuList;
}

View File

@ -1,7 +1,6 @@
package com.ruoyi.xkt.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.XktBaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -28,22 +27,37 @@ public class StoreRole extends XktBaseEntity {
/**
* store.id
*/
@Excel(name = "store.id")
private Long storeId;
/**
* 0 1
*
*/
@Excel(name = "档口角色状态", readConverterExp = "0=正常,1=停用")
private String roleStatus;
private String roleName;
/**
* ID
*/
private Long roleId;
/**
*
*/
private String remark;
/**
* ID
*/
private Long operatorId;
/**
*
*/
private String operatorName;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("storeId", getStoreId())
.append("roleStatus", getRoleStatus())
.append("version", getVersion())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())

View File

@ -5,6 +5,7 @@ import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.XktBaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -16,6 +17,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
public class StoreRoleMenu extends XktBaseEntity {
private static final long serialVersionUID = 1L;
@ -43,13 +45,6 @@ public class StoreRoleMenu extends XktBaseEntity {
@Excel(name = "菜单名称")
private String menuName;
/**
* 使0 1
*/
@Excel(name = "菜单使用状态", readConverterExp = "0=正常,1=停用")
private String menuStatus;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@ -57,7 +52,6 @@ public class StoreRoleMenu extends XktBaseEntity {
.append("storeRoleId", getStoreRoleId())
.append("storeId", getStoreId())
.append("menuName", getMenuName())
.append("menuStatus", getMenuStatus())
.append("version", getVersion())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())

View File

@ -0,0 +1,33 @@
package com.ruoyi.xkt.dto.storeRole;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口子角色")
@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreRoleDTO {
@ApiModelProperty(value = "档口ID")
private Long storeId;
@ApiModelProperty(value = "档口ID新增为空 编辑必传")
private Long storeRoleId;
@ApiModelProperty(value = "角色名称")
private String roleName;
@ApiModelProperty(value = "档口子角色备注")
private String remark;
@ApiModelProperty(value = "档口子角色菜单权限名称列表")
List<String> menuList;
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.xkt.dto.storeRole;
import com.ruoyi.xkt.dto.BasePageDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("档口子角色分页查询入参")
@Data
public class StoreRolePageDTO extends BasePageDTO {
@ApiModelProperty(value = "档口ID")
private Long storeId;
}

View File

@ -0,0 +1,37 @@
package com.ruoyi.xkt.dto.storeRole;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口子角色列表数据")
@Data
@Accessors(chain = true)
public class StoreRoleResDTO {
@ApiModelProperty(value = "档口ID")
private Long storeId;
@ApiModelProperty(value = "档口ID新增为空 编辑必传")
private Long storeRoleId;
@ApiModelProperty(value = "角色名称")
private String roleName;
@ApiModelProperty(value = "档口子角色备注")
private String remark;
@ApiModelProperty(value = "停用启用状态")
private Integer delFlag;
@ApiModelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@ApiModelProperty(value = "操作人名称")
private String operatorName;
}

View File

@ -0,0 +1,23 @@
package com.ruoyi.xkt.dto.storeRole;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("档口子角色停用启用")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StoreRoleUpdateStatusDTO {
@ApiModelProperty(value = "档口子角色ID")
private Long storeRoleId;
@ApiModelProperty(value = "档口子角色状态")
private String delFlag;
}

View File

@ -1,6 +1,9 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.domain.StoreRole;
import com.ruoyi.xkt.dto.storeRole.StoreRoleDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRolePageDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleResDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleUpdateStatusDTO;
import java.util.List;
@ -11,51 +14,45 @@ import java.util.List;
* @date 2025-03-26
*/
public interface IStoreRoleService {
/**
*
*
* @param storeRoleId
* @return
*/
public StoreRole selectStoreRoleByStoreRoleId(Long storeRoleId);
/**
*
*
* @param storeRole
* @return
*/
public List<StoreRole> selectStoreRoleList(StoreRole storeRole);
/**
*
*
* @param storeRole
* @param storeRoleDTO
* @return
*/
public int insertStoreRole(StoreRole storeRole);
public int insertStoreRole(StoreRoleDTO storeRoleDTO);
/**
*
*
*
* @param storeRole
* @return
* @param storeRoleDTO
* @return
*/
public int updateStoreRole(StoreRole storeRole);
Integer update(StoreRoleDTO storeRoleDTO);
/**
*
*
*
* @param storeRoleIds
* @return
* @param storeRoleId ID
* @return
*/
public int deleteStoreRoleByStoreRoleIds(Long[] storeRoleIds);
StoreRoleDTO selectByStoreRoleId(Long storeRoleId);
/**
*
*
*
* @param storeRoleId
* @return
* @param pageDTO
* @return
*/
public int deleteStoreRoleByStoreRoleId(Long storeRoleId);
List<StoreRoleResDTO> list(StoreRolePageDTO pageDTO);
/**
*
*
* @param updateStatusDTO
* @return
*/
Integer updateRoleStatus(StoreRoleUpdateStatusDTO updateStatusDTO);
}

View File

@ -1,11 +1,8 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.domain.Store;
import com.ruoyi.xkt.dto.store.StoreCreateDTO;
import com.ruoyi.xkt.dto.store.StoreUpdateDTO;
import java.util.List;
/**
* Service
*
@ -16,68 +13,18 @@ public interface IStoreService {
/**
*
*
* @param storeUpdateDTO
* @return int
*/
public int updateStore(StoreUpdateDTO storeUpdateDTO);
public int updateStore(StoreUpdateDTO storeUpdateDTO);
/**
*
*
* @param createDTO DTO
* @return int
*/
public int create(StoreCreateDTO createDTO);
/**
*
*
* @param storeId
* @return
*/
public Store selectStoreByStoreId(Long storeId);
/**
*
*
* @param store
* @return
*/
public List<Store> selectStoreList(Store store);
/**
*
*
* @param store
* @return
*/
public int insertStore(Store store);
/**
*
*
* @param storeIds
* @return
*/
public int deleteStoreByStoreIds(Long[] storeIds);
/**
*
*
* @param storeId
* @return
*/
public int deleteStoreByStoreId(Long storeId);
}

View File

@ -1,14 +1,32 @@
package com.ruoyi.xkt.service.impl;
import com.ruoyi.common.utils.DateUtils;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.xkt.domain.StoreRole;
import com.ruoyi.xkt.domain.StoreRoleAccount;
import com.ruoyi.xkt.domain.StoreRoleMenu;
import com.ruoyi.xkt.dto.storeRole.StoreRoleDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRolePageDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleResDTO;
import com.ruoyi.xkt.dto.storeRole.StoreRoleUpdateStatusDTO;
import com.ruoyi.xkt.mapper.StoreRoleAccountMapper;
import com.ruoyi.xkt.mapper.StoreRoleMapper;
import com.ruoyi.xkt.mapper.StoreRoleMenuMapper;
import com.ruoyi.xkt.service.IStoreRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Service
@ -17,79 +35,146 @@ import java.util.List;
* @date 2025-03-26
*/
@Service
@RequiredArgsConstructor
public class StoreRoleServiceImpl implements IStoreRoleService {
@Autowired
private StoreRoleMapper storeRoleMapper;
/**
*
*
* @param storeRoleId
* @return
*/
@Override
public StoreRole selectStoreRoleByStoreRoleId(Long storeRoleId) {
return storeRoleMapper.selectStoreRoleByStoreRoleId(storeRoleId);
}
final StoreRoleMapper storeRoleMapper;
final StoreRoleMenuMapper storeRoleMenuMapper;
final StoreRoleAccountMapper storeRoleAccMapper;
/**
*
*
* @param storeRole
* @return
*/
@Override
public List<StoreRole> selectStoreRoleList(StoreRole storeRole) {
return storeRoleMapper.selectStoreRoleList(storeRole);
}
/**
*
*
* @param storeRole
* @param storeRoleDTO
* @return
*/
@Override
@Transactional
public int insertStoreRole(StoreRole storeRole) {
storeRole.setCreateTime(DateUtils.getNowDate());
return storeRoleMapper.insertStoreRole(storeRole);
public int insertStoreRole(StoreRoleDTO storeRoleDTO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
StoreRole storeRole = BeanUtil.toBean(storeRoleDTO, StoreRole.class);
// TODO 暂时列为-1
// TODO 暂时列为-1
// TODO 暂时列为-1
storeRole.setRoleId(1000L);
storeRole.setOperatorId(loginUser.getUserId());
storeRole.setOperatorName(loginUser.getUsername());
int count = this.storeRoleMapper.insert(storeRole);
// 新增档口子角色菜单
List<StoreRoleMenu> roleMenuList = storeRoleDTO.getMenuList().stream().map(menuName -> {
StoreRoleMenu storeRoleMenu = new StoreRoleMenu();
return storeRoleMenu.setStoreId(storeRoleDTO.getStoreId())
.setStoreRoleId(storeRole.getId()).setMenuName(menuName);
}).collect(Collectors.toList());
this.storeRoleMenuMapper.insert(roleMenuList);
return count;
}
/**
*
*
*
* @param storeRole
* @return
* @param storeRoleDTO
* @return
*/
@Override
@Transactional
public int updateStoreRole(StoreRole storeRole) {
storeRole.setUpdateTime(DateUtils.getNowDate());
return storeRoleMapper.updateStoreRole(storeRole);
public Integer update(StoreRoleDTO storeRoleDTO) {
Optional.ofNullable(storeRoleDTO.getStoreRoleId()).orElseThrow(() -> new ServiceException("档口角色ID不能为空!", HttpStatus.ERROR));
StoreRole storeRole = Optional.ofNullable(this.storeRoleMapper.selectOne(new LambdaQueryWrapper<StoreRole>()
.eq(StoreRole::getId, storeRoleDTO.getStoreRoleId()).eq(StoreRole::getDelFlag, Constants.UNDELETED)
.eq(StoreRole::getStoreId, storeRoleDTO.getStoreId())))
.orElseThrow(() -> new ServiceException("档口角色不存在!", HttpStatus.ERROR));
BeanUtil.copyProperties(storeRoleDTO, storeRole);
int count = this.storeRoleMapper.updateById(storeRole);
// 将旧的子角色菜单置为无效
List<StoreRoleMenu> menuList = this.storeRoleMenuMapper.selectList(new LambdaQueryWrapper<StoreRoleMenu>()
.eq(StoreRoleMenu::getStoreRoleId, storeRoleDTO.getStoreRoleId()).eq(StoreRoleMenu::getDelFlag, Constants.UNDELETED)
.eq(StoreRoleMenu::getStoreId, storeRoleDTO.getStoreId()));
if (CollectionUtils.isNotEmpty(menuList)) {
menuList.forEach(x -> x.setDelFlag(Constants.DELETED));
this.storeRoleMenuMapper.updateById(menuList);
}
// 新增档口子角色菜单
List<StoreRoleMenu> roleMenuList = storeRoleDTO.getMenuList().stream().map(menuName -> {
StoreRoleMenu storeRoleMenu = new StoreRoleMenu();
return storeRoleMenu.setStoreId(storeRoleDTO.getStoreId())
.setStoreRoleId(storeRole.getId()).setMenuName(menuName);
}).collect(Collectors.toList());
this.storeRoleMenuMapper.insert(roleMenuList);
return count;
}
/**
*
*
*
* @param storeRoleIds
* @return
* @param storeRoleId ID
* @return
*/
@Override
@Transactional
public int deleteStoreRoleByStoreRoleIds(Long[] storeRoleIds) {
return storeRoleMapper.deleteStoreRoleByStoreRoleIds(storeRoleIds);
@Transactional(readOnly = true)
public StoreRoleDTO selectByStoreRoleId(Long storeRoleId) {
StoreRole storeRole = Optional.ofNullable(this.storeRoleMapper.selectOne(new LambdaQueryWrapper<StoreRole>()
.eq(StoreRole::getId, storeRoleId).eq(StoreRole::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口子角色不存在!", HttpStatus.ERROR));
// 找到档口子角色菜单
List<StoreRoleMenu> menuList = this.storeRoleMenuMapper.selectList(new LambdaQueryWrapper<StoreRoleMenu>()
.eq(StoreRoleMenu::getStoreRoleId, storeRoleId).eq(StoreRoleMenu::getDelFlag, Constants.UNDELETED)
.eq(StoreRoleMenu::getStoreId, storeRole.getStoreId()));
return BeanUtil.toBean(storeRole, StoreRoleDTO.class)
.setMenuList(menuList.stream().map(StoreRoleMenu::getMenuName).collect(Collectors.toList()));
}
/**
*
*
*
* @param storeRoleId
* @return
* @param pageDTO
* @return
*/
@Override
@Transactional(readOnly = true)
public List<StoreRoleResDTO> list(StoreRolePageDTO pageDTO) {
List<StoreRole> storeRoleList = this.storeRoleMapper.selectList(new LambdaQueryWrapper<StoreRole>()
.eq(StoreRole::getStoreId, pageDTO.getStoreId()).eq(StoreRole::getDelFlag, Constants.UNDELETED));
return storeRoleList.stream().map(x -> BeanUtil.toBean(x, StoreRoleResDTO.class).setStoreRoleId(x.getId()))
.collect(Collectors.toList());
}
/**
*
*
* @param updateStatusDTO
* @return
*/
@Override
@Transactional
public int deleteStoreRoleByStoreRoleId(Long storeRoleId) {
return storeRoleMapper.deleteStoreRoleByStoreRoleId(storeRoleId);
public Integer updateRoleStatus(StoreRoleUpdateStatusDTO updateStatusDTO) {
StoreRole storeRole = Optional.ofNullable(this.storeRoleMapper.selectOne(new LambdaQueryWrapper<StoreRole>()
.eq(StoreRole::getId, updateStatusDTO.getStoreRoleId()).eq(StoreRole::getDelFlag, Constants.UNDELETED)))
.orElseThrow(() -> new ServiceException("档口角色不存在!", HttpStatus.ERROR));
storeRole.setDelFlag(updateStatusDTO.getDelFlag());
// 如果是启用变为停用,则还需将子角色菜单置为无效,子角色账号置为无效
if (Objects.equals(updateStatusDTO.getDelFlag(), Constants.DELETED)) {
List<StoreRoleMenu> menuList = this.storeRoleMenuMapper.selectList(new LambdaQueryWrapper<StoreRoleMenu>()
.eq(StoreRoleMenu::getStoreRoleId, updateStatusDTO.getStoreRoleId()).eq(StoreRoleMenu::getDelFlag, Constants.UNDELETED)
.eq(StoreRoleMenu::getStoreId, storeRole.getStoreId()));
if (CollectionUtils.isNotEmpty(menuList)) {
menuList.forEach(x -> x.setDelFlag(Constants.DELETED));
this.storeRoleMenuMapper.updateById(menuList);
}
// 找到子角色账号,并置为无效
List<StoreRoleAccount> accountList = this.storeRoleAccMapper.selectList(new LambdaQueryWrapper<StoreRoleAccount>()
.eq(StoreRoleAccount::getStoreRoleId, updateStatusDTO.getStoreRoleId()).eq(StoreRoleAccount::getDelFlag, Constants.UNDELETED)
.eq(StoreRoleAccount::getStoreId, storeRole.getStoreId()));
if (CollectionUtils.isNotEmpty(accountList)) {
accountList.forEach(x -> x.setDelFlag(Constants.DELETED));
this.storeRoleAccMapper.updateById(accountList);
}
}
return this.storeRoleMapper.updateById(storeRole);
}
}

View File

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.xkt.domain.Store;
import com.ruoyi.xkt.dto.store.StoreCreateDTO;
import com.ruoyi.xkt.dto.store.StoreUpdateDTO;
@ -19,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@ -52,7 +50,7 @@ public class StoreServiceImpl implements IStoreService {
// 当前时间往后推1年为试用期时间
Date oneYearAfter = Date.from(LocalDate.now().plusYears(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
store.setTrialEndTime(oneYearAfter);
return this.storeMapper.insert(store);
return this.storeMapper.insert(store);
}
/**
@ -76,81 +74,4 @@ public class StoreServiceImpl implements IStoreService {
return storeMapper.updateById(store);
}
/**
*
*
* @param store
* @return
*/
@Override
@Transactional
public int insertStore(Store store) {
store.setCreateTime(DateUtils.getNowDate());
return storeMapper.insertStore(store);
}
/**
*
*
* @param storeId
* @return
*/
@Override
@Transactional(readOnly = true)
public Store selectStoreByStoreId(Long storeId) {
return storeMapper.selectStoreByStoreId(storeId);
}
/**
*
*
* @param store
* @return
*/
@Override
@Transactional(readOnly = true)
public List<Store> selectStoreList(Store store) {
return storeMapper.selectStoreList(store);
}
/**
*
*
* @param storeIds
* @return
*/
@Override
@Transactional
public int deleteStoreByStoreIds(Long[] storeIds) {
return storeMapper.deleteStoreByStoreIds(storeIds);
}
/**
*
*
* @param storeId
* @return
*/
@Override
@Transactional
public int deleteStoreByStoreId(Long storeId) {
return storeMapper.deleteStoreByStoreId(storeId);
}
}