|
@@ -1,10 +1,33 @@
|
|
|
package com.kxs.product.biz.service.impl;
|
|
package com.kxs.product.biz.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.kxs.common.core.constant.SecurityConstants;
|
|
|
|
|
+import com.kxs.common.core.constant.enums.ErrorTypeEnum;
|
|
|
|
|
+import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
|
|
+import com.kxs.common.core.util.R;
|
|
|
|
|
+import com.kxs.common.core.util.RetOps;
|
|
|
|
|
+import com.kxs.common.security.util.SecurityUtils;
|
|
|
|
|
+import com.kxs.product.api.dto.kxsapp.machine.*;
|
|
|
|
|
+import com.kxs.product.api.model.*;
|
|
|
|
|
+import com.kxs.product.api.vo.kxsapp.machine.*;
|
|
|
|
|
+import com.kxs.product.biz.constant.enums.MachineTypeEnum;
|
|
|
|
|
+import com.kxs.product.biz.constant.enums.ProductErrorTypeEnum;
|
|
|
|
|
+import com.kxs.product.biz.mapper.KxsBrandMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsMachineMapper;
|
|
import com.kxs.product.biz.mapper.KxsMachineMapper;
|
|
|
-import com.kxs.product.api.model.KxsMachine;
|
|
|
|
|
|
|
+import com.kxs.product.biz.mapper.KxsMachineTrackMapper;
|
|
|
|
|
+import com.kxs.product.biz.mapper.KxsMachineTransferMapper;
|
|
|
import com.kxs.product.biz.service.KxsMachineService;
|
|
import com.kxs.product.biz.service.KxsMachineService;
|
|
|
|
|
+import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
|
|
+import com.kxs.user.api.model.KxsUser;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 客小爽机具表(KxsMachine)表服务实现类
|
|
* 客小爽机具表(KxsMachine)表服务实现类
|
|
@@ -13,7 +36,171 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2023-12-20 10:09:35
|
|
* @since 2023-12-20 10:09:35
|
|
|
*/
|
|
*/
|
|
|
@Service("kxsMachineService")
|
|
@Service("kxsMachineService")
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
public class KxsMachineServiceImpl extends ServiceImpl<KxsMachineMapper, KxsMachine> implements KxsMachineService {
|
|
public class KxsMachineServiceImpl extends ServiceImpl<KxsMachineMapper, KxsMachine> implements KxsMachineService {
|
|
|
|
|
|
|
|
|
|
+ private final KxsBrandMapper kxsBrandMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final KxsMachineTrackMapper kxsMachineTrackMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final KxsMachineTransferMapper kxsMachineTransferMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final RemoteKxsUserService remoteKxsUserService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineStoreListVO> machineStoreList(Page<MachineStoreListVO> page, MachineStoreListDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.machineStoreList(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineStoreListVO> searchStoreMachine(Page<MachineStoreListVO> page, MachineStoreListDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.machineStoreList(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<RecycleMachinesVO> recycleMachinesPage(Page<RecycleMachinesVO> page, Integer brandId) {
|
|
|
|
|
+
|
|
|
|
|
+ Long userId = SecurityUtils.getUser().getId();
|
|
|
|
|
+
|
|
|
|
|
+ //查询品牌
|
|
|
|
|
+ KxsBrand kxsBrand = kxsBrandMapper.selectById(brandId);
|
|
|
|
|
+ List<KxsBrand> brands = kxsBrandMapper.selectList(Wrappers.<KxsBrand>lambdaQuery().eq(KxsBrand::getBrandType, kxsBrand.getBrandType()));
|
|
|
|
|
+ List<Integer> brandIds = brands.stream().map(KxsBrand::getId).toList();
|
|
|
|
|
+
|
|
|
|
|
+ IPage<RecycleMachinesVO> recycleMachines = baseMapper.recycleMachinesPage(page, userId, brandId);
|
|
|
|
|
+
|
|
|
|
|
+ recycleMachines.getRecords().forEach(item -> item.setBrandList(brandIds));
|
|
|
|
|
+
|
|
|
|
|
+ return recycleMachines;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineUnBindListVO> machineUnBindListPage(Page<MachineUnBindListVO> page, MachineUserListDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ param.setUserId(SecurityUtils.getUser().getId().intValue());
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.machineUnBindListPage(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineBindListVO> machineBindList(Page<MachineBindListVO> page, MachineUserListDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ param.setUserId(SecurityUtils.getUser().getId().intValue());
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.machineBindList(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineUserListVO> getByPage(Page<MachineUserListVO> page, MachineUserListDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ param.setUserId(SecurityUtils.getUser().getId().intValue());
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.getByPage(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public MachineApplyRemarkVO applyRemark() {
|
|
|
|
|
+
|
|
|
|
|
+ Integer userId = SecurityUtils.getUser().getId().intValue();
|
|
|
|
|
+
|
|
|
|
|
+ //兑换机 激活数量
|
|
|
|
|
+ Long actCount = baseMapper.selectCount(Wrappers.<KxsMachine>lambdaQuery()
|
|
|
|
|
+ .eq(KxsMachine::getUserId, userId)
|
|
|
|
|
+ .eq(KxsMachine::getMachineType, MachineTypeEnum.M_TYPE_SN.getType())
|
|
|
|
|
+ .eq(KxsMachine::getIsAct, MachineTypeEnum.ACT.getType()));
|
|
|
|
|
+
|
|
|
|
|
+ //过期的循环机数量,兑换机循环时间结束
|
|
|
|
|
+ Long pastCount = baseMapper.selectCount(Wrappers.<KxsMachine>lambdaQuery()
|
|
|
|
|
+ .eq(KxsMachine::getUserId, userId)
|
|
|
|
|
+ .eq(KxsMachine::getMachineType, MachineTypeEnum.M_TYPE_SN.getType())
|
|
|
|
|
+ .lt(KxsMachine::getRecycleEndTime, LocalDateTime.now()));
|
|
|
|
|
+
|
|
|
|
|
+ return MachineApplyRemarkVO.builder()
|
|
|
|
|
+ .actCount(actCount)
|
|
|
|
|
+ .pastCount(pastCount)
|
|
|
|
|
+ .maxCount(actCount - pastCount)
|
|
|
|
|
+ .minCount(actCount - pastCount > 0 ? 1 : 0)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public R machineTransferUser(MachineTransferDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ Integer userId = SecurityUtils.getUser().getId().intValue();
|
|
|
|
|
+ R<KxsUser> result = remoteKxsUserService.loadUserByCode(param.getUserCode(), SecurityConstants.FROM_IN);
|
|
|
|
|
+ KxsUser toUser = RetOps.of(result)
|
|
|
|
|
+ .getData()
|
|
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
|
|
+
|
|
|
|
|
+ String pidPath = toUser.getPidPath();
|
|
|
|
|
+ //判断是否是下级
|
|
|
|
|
+ boolean contains = pidPath.contains("," + userId + ",");
|
|
|
|
|
+ if(!contains){
|
|
|
|
|
+ return R.failed(ProductErrorTypeEnum.USER_IS_NOT_FIND.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (String sn : param.getSnList()) {
|
|
|
|
|
+ KxsMachine machine = baseMapper.selectOne(Wrappers.<KxsMachine>lambdaQuery()
|
|
|
|
|
+ .eq(KxsMachine::getUserId, userId)
|
|
|
|
|
+ .eq(KxsMachine::getPosSn, sn));
|
|
|
|
|
+ if (machine == null) {
|
|
|
|
|
+ throw new GlobalCustomerException(sn + ProductErrorTypeEnum.MACHINE_NOT_FOUND.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(machine.getBindStatus().equals(MachineTypeEnum.BIND.getType())){
|
|
|
|
|
+ throw new GlobalCustomerException(sn + ProductErrorTypeEnum.MACHINE_BIND.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!machine.getUserId().equals(userId)){
|
|
|
|
|
+ throw new GlobalCustomerException(sn + ProductErrorTypeEnum.MACHINE_NOT_USER.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+ //循环机不可划拨
|
|
|
|
|
+ if (machine.getMachineType().equals(MachineTypeEnum.M_TYPE_RE.getType())) {
|
|
|
|
|
+ throw new GlobalCustomerException(sn + ProductErrorTypeEnum.MACHINE_TRANSFER_NO.getDescription());
|
|
|
|
|
+ }
|
|
|
|
|
+ //机具轨迹路径
|
|
|
|
|
+ String allotPath = machine.getAllotPath() == null ? "0," : machine.getAllotPath();
|
|
|
|
|
+ machine.setAllotPath(allotPath + machine.getUserId() + ",");
|
|
|
|
|
+ machine.setUserId(toUser.getId());
|
|
|
|
|
+ //修改机具所属
|
|
|
|
|
+ baseMapper.updateById(machine);
|
|
|
|
|
+
|
|
|
|
|
+ //添加机具划拨记录
|
|
|
|
|
+ KxsMachineTransfer machineTransfer = new KxsMachineTransfer();
|
|
|
|
|
+ //拨出用户
|
|
|
|
|
+ machineTransfer.setSendUserId(userId);
|
|
|
|
|
+ //拨入用户
|
|
|
|
|
+ machineTransfer.setToUserId(toUser.getId());
|
|
|
|
|
+ machineTransfer.setToUserName(toUser.getUsername());
|
|
|
|
|
+ machineTransfer.setToUserCode(toUser.getUserCode());
|
|
|
|
|
+ machineTransfer.setMachineSn(machine.getPosSn());
|
|
|
|
|
+ machineTransfer.setMachineId(machine.getId());
|
|
|
|
|
+ machineTransfer.setBrandId(machine.getBrandId());
|
|
|
|
|
+ kxsMachineTransferMapper.insert(machineTransfer);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<SearchUserMachineVO> searchUserMachine(Page<SearchUserMachineVO> page, SearchUserMachineDTO param) {
|
|
|
|
|
+
|
|
|
|
|
+ param.setUserId(SecurityUtils.getUser().getId().intValue());
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.searchUserMachine(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public IPage<MachineRecycleListVO> recycleList(Page<MachineRecycleListVO> page, RecycleMachineQuery param) {
|
|
|
|
|
+
|
|
|
|
|
+ Long userId = SecurityUtils.getUser().getId();
|
|
|
|
|
+ param.setUserId(userId.intValue());
|
|
|
|
|
+
|
|
|
|
|
+ return baseMapper.recyclePageList(page, param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|