| | |
| | | package org.jeecg.modules.cms.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.cms.entity.CuttingInventory; |
| | | import org.jeecg.modules.cms.mapper.CuttingInventoryMapper; |
| | | import org.jeecg.modules.cms.mapper.CuttingToolMapper; |
| | | import org.jeecg.modules.cms.service.ICuttingInventoryService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | IPage<Map<String, Object>> result = baseMapper.statisticsByCuttingIdAndStatus(page); |
| | | return result; |
| | | } |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateStatus(List<String> ids, String status) { |
| | | if (ids != null && !ids.isEmpty() && StringUtils.isNotBlank(status)) { |
| | | // UpdateWrapper<CuttingInventory> updateWrapper = new UpdateWrapper<>(); |
| | | // updateWrapper.in("id", ids); |
| | | // updateWrapper.set("inventory_status", status); // 根据实际数据库字段名调整 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String username = "System"; // 默认用户名 |
| | | if (user != null) { |
| | | username = oConvertUtils.getString(user.getUsername(), "System"); |
| | | } |
| | | UpdateWrapper<CuttingInventory> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", ids); |
| | | updateWrapper.set("inventory_status", status); |
| | | updateWrapper.set("update_time", new Date()); |
| | | updateWrapper.set("update_by", username); |
| | | this.update(updateWrapper); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void restoreStatus(List<String> ids) { |
| | | if (ids != null && !ids.isEmpty()) { |
| | | // 获取当前登录用户信息 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String username = "System"; // 默认用户名 |
| | | if (user != null) { |
| | | username = oConvertUtils.getString(user.getUsername(), "System"); |
| | | } |
| | | |
| | | // 方式1: 查询当前状态并根据状态决定恢复到哪个状态 |
| | | List<CuttingInventory> inventoryList = this.listByIds(ids); |
| | | List<String> toRestoreIds = inventoryList.stream() |
| | | .filter(inv -> "待出库".equals(inv.getInventoryStatus())) // 只处理"待出库"状态的 |
| | | .map(CuttingInventory::getId) |
| | | .collect(Collectors.toList()); |
| | | //FIXME:在报废前有多个状态,如果报废作废,刀具库存状态如何退回原来的状态。 |
| | | if (!toRestoreIds.isEmpty()) { |
| | | UpdateWrapper<CuttingInventory> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", toRestoreIds); |
| | | updateWrapper.set("inventory_status", "正常"); |
| | | updateWrapper.set("update_time", new Date()); |
| | | updateWrapper.set("update_by", username); |
| | | this.update(updateWrapper); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |