|
@@ -1,6 +1,10 @@
|
|
|
package org.jeecg.modules.system.app.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
@@ -22,72 +26,178 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
|
|
|
|
|
|
/**
|
|
|
* @Description: 商户场所表
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2025-07-09
|
|
|
+ * @Date: 2025-07-09
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Service
|
|
|
public class AppSitePlaceServiceImpl extends ServiceImpl<AppSitePlaceMapper, AppSitePlace> implements IAppSitePlaceService {
|
|
|
@Resource
|
|
|
- AppSitePriceRulesMapper appSitePriceRulesMapper;
|
|
|
+ private AppSitePriceRulesMapper appSitePriceRulesMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean saveWitchPriceRules(AppSitePlaceDTO placeDTO) {
|
|
|
-// AppSitePlaceCuDTO appSitePlaceCuDTO = placeDTO.getAppSitePlaceCuDTO();
|
|
|
-// LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
-// if (null == appSitePlaceCuDTO.getSiteId()) throw new JeecgBootException("商户补充信息id不能为空", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
-// AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
-// BeanUtils.copyProperties(appSitePlaceCuDTO, appSitePlace);
|
|
|
-// appSitePlace.setOrgCode(sysUser.getOrgCode());
|
|
|
-// appSitePlace.setTenantId(sysUser.getOrgId());
|
|
|
-// appSitePlace.setSiteId(appSitePlaceCuDTO.getSiteId());
|
|
|
-// int insert = baseMapper.insert(appSitePlace);
|
|
|
-// if (insert<1) {
|
|
|
-// throw new JeecgBootException("商户场所保存失败");
|
|
|
-// }
|
|
|
-// placeDTO.getSiteRuleDTOS().forEach(rule -> {
|
|
|
-// AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
-// BeanUtils.copyProperties(rule, appSitePriceRules);
|
|
|
-// appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
-// appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
-// appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
-// int savePriceResult = baseMapper.insert(appSitePriceRules);
|
|
|
-// });
|
|
|
+ AppSitePlaceCuDTO appSitePlaceCuDTO = placeDTO.getAppSitePlaceCuDTO();
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ if (null == appSitePlaceCuDTO.getSiteId())
|
|
|
+ throw new JeecgBootException("商户补充信息id不能为空", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
+ BeanUtils.copyProperties(appSitePlaceCuDTO, appSitePlace);
|
|
|
+ appSitePlace.setOrgCode(sysUser.getOrgCode());
|
|
|
+ appSitePlace.setTenantId(sysUser.getOrgId());
|
|
|
+ appSitePlace.setSiteId(appSitePlaceCuDTO.getSiteId());
|
|
|
+ int insert = baseMapper.insert(appSitePlace);
|
|
|
+ if (insert < 1) {
|
|
|
+ throw new JeecgBootException("商户场所保存失败");
|
|
|
+ }
|
|
|
+ placeDTO.getSiteRuleDTOS().forEach(rule -> {
|
|
|
+ AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
+ BeanUtils.copyProperties(rule, appSitePriceRules);
|
|
|
+ appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
+ appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
+ appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
+ int savePriceResult = appSitePriceRulesMapper.insert(appSitePriceRules);
|
|
|
+ if (savePriceResult < 1) {
|
|
|
+ throw new JeecgBootException("场所价格规则保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- return null;
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean editWitchPriceRules(AppSitePlaceDTO placeDTO) {
|
|
|
- return null;
|
|
|
+ AppSitePlaceCuDTO appSitePlaceCuDTO = placeDTO.getAppSitePlaceCuDTO();
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ if (null == appSitePlaceCuDTO.getSiteId())
|
|
|
+ throw new JeecgBootException("商户补充信息id不能为空", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppSitePlace dbPlace = baseMapper.selectById(appSitePlaceCuDTO.getSiteId());
|
|
|
+ if (null == dbPlace) throw new JeecgBootException("数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ //部门校验
|
|
|
+// checkPermission(dbPlace, sysUser);
|
|
|
+ AppSitePlace appSitePlace = new AppSitePlace();
|
|
|
+ BeanUtils.copyProperties(appSitePlaceCuDTO, appSitePlace);
|
|
|
+ //不许更改项赋值
|
|
|
+ appSitePlace.setOrgCode(sysUser.getOrgCode());
|
|
|
+ appSitePlace.setTenantId(sysUser.getOrgId());
|
|
|
+ appSitePlace.setSiteId(appSitePlaceCuDTO.getSiteId());
|
|
|
+ int update = baseMapper.updateById(appSitePlace);
|
|
|
+ if (update < 1) {
|
|
|
+ throw new JeecgBootException("商户场所保存失败");
|
|
|
+ }
|
|
|
+ List<AppSitePriceRules> dbRulesList = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId()));
|
|
|
+ List<AppSiteRuleDTO> siteRuleDTOS = placeDTO.getSiteRuleDTOS();
|
|
|
+ //删除
|
|
|
+ List<AppSitePriceRules> deleteList = dbRulesList.stream().filter(
|
|
|
+ dbRule -> dbRule.getId() != null && siteRuleDTOS.stream().noneMatch(rule -> dbRule.getId().equals(rule.getId()))).collect(Collectors.toList());
|
|
|
+ deleteList.forEach(
|
|
|
+ dbRule -> {
|
|
|
+ int deleteResult = appSitePriceRulesMapper.deleteById(dbRule.getId());
|
|
|
+ if (deleteResult < 1) {
|
|
|
+ throw new JeecgBootException("场所价格规则删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ //保存
|
|
|
+ List<AppSitePriceRules> addList = siteRuleDTOS.stream().filter(rule -> rule.getId() == null).map(ruleDTO -> {
|
|
|
+ AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
+ BeanUtils.copyProperties(ruleDTO, appSitePriceRules);
|
|
|
+ appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
+ appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
+ appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
+ return appSitePriceRules;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ addList.forEach(appSitePriceRules -> {
|
|
|
+ int saveResult = appSitePriceRulesMapper.insert(appSitePriceRules);
|
|
|
+ if (saveResult < 1) {
|
|
|
+ throw new JeecgBootException("场所价格规则保存失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //更新
|
|
|
+ List<AppSitePriceRules> updateList = siteRuleDTOS.stream().filter(
|
|
|
+ rule -> rule.getId() != null && dbRulesList.stream().anyMatch(
|
|
|
+ dbRule -> dbRule.getId().equals(rule.getId()))).map(ruleDto -> {
|
|
|
+ AppSitePriceRules appSitePriceRules = new AppSitePriceRules();
|
|
|
+ BeanUtils.copyProperties(ruleDto, appSitePriceRules);
|
|
|
+ appSitePriceRules.setSitePlaceId(appSitePlace.getId());
|
|
|
+ appSitePriceRules.setOrgCode(appSitePlace.getOrgCode());
|
|
|
+ appSitePriceRules.setTenantId(appSitePlace.getTenantId());
|
|
|
+ return appSitePriceRules;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ updateList.forEach(rule -> {
|
|
|
+ int updateById = appSitePriceRulesMapper.updateById(rule);
|
|
|
+ if (updateById < 1) {
|
|
|
+ throw new JeecgBootException("场所价格规则更新失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AppSitePlaceCuDTO queryWitchPriceRulesById(String id) {
|
|
|
- return null;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public AppSitePlaceDTO queryWitchPriceRulesById(String id) {
|
|
|
+ AppSitePlace appSitePlace = baseMapper.selectById(id);
|
|
|
+ if (null == appSitePlace) throw new JeecgBootException("数据不存在", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ AppSitePlaceCuDTO appSitePlaceCuDTO = new AppSitePlaceCuDTO();
|
|
|
+ BeanUtils.copyProperties(appSitePlace, appSitePlaceCuDTO);
|
|
|
+ List<AppSiteRuleDTO> collect = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
+ .eq(AppSitePriceRules::getSitePlaceId, appSitePlace.getId())).stream().map(
|
|
|
+ appSitePriceRules -> {
|
|
|
+ AppSiteRuleDTO appSiteRuleDTO = new AppSiteRuleDTO();
|
|
|
+ BeanUtils.copyProperties(appSitePriceRules, appSiteRuleDTO);
|
|
|
+ return appSiteRuleDTO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new AppSitePlaceDTO(appSitePlaceCuDTO, collect);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean deleteWitchPriceRulesById(String id) {
|
|
|
- return null;
|
|
|
+ AppSitePlace dbPlace = baseMapper.selectById(id);
|
|
|
+ if (null==dbPlace) throw new JeecgBootException("未找到对应数据", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+// checkPermission(dbPlace,sysUser);
|
|
|
+ int deleteById = baseMapper.deleteById(id);
|
|
|
+ if (deleteById < 1) throw new JeecgBootException("删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ int deletePriceResult = appSitePriceRulesMapper.delete(Wrappers.<AppSitePriceRules>lambdaQuery().eq(AppSitePriceRules::getSitePlaceId, id));
|
|
|
+ if (deletePriceResult<1) throw new JeecgBootException("场地价格规则删除失败", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public IPage<AppSitePlaceCuDTO> queryWitchPriceRulesPage(AppSitePlacePageDTO dto) {
|
|
|
- return null;
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Page<AppSitePlace> page = new Page<>(dto.getPageNum(), dto.getPageSize());
|
|
|
+ LambdaQueryWrapper<AppSitePlace> wrapper = Wrappers.<AppSitePlace>lambdaQuery()
|
|
|
+ .like(StringUtils.isNotBlank(dto.getName()), AppSitePlace::getName, dto.getName());
|
|
|
+// .eq(AppSitePlace::getOrgCode, loginUser.getOrgCode());
|
|
|
+ IPage<AppSitePlace> resultPage = baseMapper.selectPage(page, wrapper);
|
|
|
+ return resultPage.convert(record -> {
|
|
|
+ AppSitePlaceCuDTO cuDTO = new AppSitePlaceCuDTO();
|
|
|
+ BeanUtils.copyProperties(record,cuDTO);
|
|
|
+ return cuDTO;
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 权限校验
|
|
|
+ *
|
|
|
* @param place
|
|
|
* @param sysUser
|
|
|
*/
|
|
|
- private void checkPermission(AppSitePlace place, LoginUser sysUser ){
|
|
|
- if (!sysUser.getOrgCode().equals(place.getOrgCode())) throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
+ private void checkPermission(AppSitePlace place, LoginUser sysUser) {
|
|
|
+ if (!sysUser.getOrgCode().equals(place.getOrgCode()))
|
|
|
+ throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
|
|
|
}
|
|
|
}
|