12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.fdkankan.sale.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.sale.common.PageInfo;
- import com.fdkankan.sale.common.ResultCode;
- import com.fdkankan.sale.entity.Part;
- import com.fdkankan.sale.entity.PartLog;
- import com.fdkankan.sale.entity.Repair;
- import com.fdkankan.sale.exception.BusinessException;
- import com.fdkankan.sale.mapper.IPartMapper;
- import com.fdkankan.sale.service.IPartLogService;
- import com.fdkankan.sale.service.IPartService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.sale.vo.request.PartParam;
- import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-12-07
- */
- @Service
- public class PartServiceImpl extends ServiceImpl<IPartMapper, Part> implements IPartService {
- @Autowired
- IPartLogService partLogService;
- @Override
- public Object pageList(PartParam param) {
- LambdaQueryWrapper<Part> wrapper = getWrapper(param);
- Page<Part> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- return PageInfo.PageInfo(page);
- }
- @Override
- public Object allList(PartParam param) {
- if(param.getCameraType() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaQueryWrapper<Part> wrapper = getWrapper(param);
- wrapper.eq(Part::getCameraType,0);
- wrapper.eq(Part::getStatus,0);
- return this.list(wrapper);
- }
- private LambdaQueryWrapper<Part> getWrapper(PartParam param) {
- LambdaQueryWrapper<Part> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getPartName())){
- wrapper.like(Part::getPartName,param.getPartName());
- }
- if(param.getCameraType() != null){
- wrapper.eq(Part::getCameraType,param.getCameraType());
- }
- wrapper.orderByDesc(Part::getCreateTime);
- return wrapper;
- }
- @Override
- public void inStock(Part part,Long userId) {
- if(part.getPartId() == null || part.getPartStock() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaUpdateWrapper<Part> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(Part::getPartId,part.getPartId());
- wrapper.setSql("part_stock = part_stock +" + part.getPartStock());
- this.update(wrapper);
- partLogService.saveLog(part.getPartId(),part.getPartStock(),userId,0,null);
- }
- @Override
- public void outStock(Integer partId, Integer count,Long userId,String repairId) {
- LambdaUpdateWrapper<Part> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(Part::getPartId,partId);
- wrapper.setSql("part_stock = part_stock -" + count);
- this.update(wrapper);
- partLogService.saveLog(partId,count,userId,1,repairId);
- }
- @Override
- public void recovery(Integer partId, Integer partCount, Long userId, String repairId) {
- partLogService.saveLog(partId,partCount,userId,2,repairId);
- }
- }
|