PartServiceImpl.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.fdkankan.sale.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.sale.common.PageInfo;
  6. import com.fdkankan.sale.common.ResultCode;
  7. import com.fdkankan.sale.entity.Part;
  8. import com.fdkankan.sale.entity.PartLog;
  9. import com.fdkankan.sale.entity.Repair;
  10. import com.fdkankan.sale.exception.BusinessException;
  11. import com.fdkankan.sale.mapper.IPartMapper;
  12. import com.fdkankan.sale.service.IPartLogService;
  13. import com.fdkankan.sale.service.IPartService;
  14. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  15. import com.fdkankan.sale.vo.request.PartParam;
  16. import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * <p>
  25. * 服务实现类
  26. * </p>
  27. *
  28. * @author
  29. * @since 2022-12-07
  30. */
  31. @Service
  32. public class PartServiceImpl extends ServiceImpl<IPartMapper, Part> implements IPartService {
  33. @Autowired
  34. IPartLogService partLogService;
  35. @Override
  36. public Object pageList(PartParam param) {
  37. LambdaQueryWrapper<Part> wrapper = getWrapper(param);
  38. Page<Part> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  39. return PageInfo.PageInfo(page);
  40. }
  41. @Override
  42. public Object allList(PartParam param) {
  43. if(param.getCameraType() == null){
  44. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  45. }
  46. LambdaQueryWrapper<Part> wrapper = getWrapper(param);
  47. wrapper.eq(Part::getCameraType,0);
  48. wrapper.eq(Part::getStatus,0);
  49. return this.list(wrapper);
  50. }
  51. private LambdaQueryWrapper<Part> getWrapper(PartParam param) {
  52. LambdaQueryWrapper<Part> wrapper = new LambdaQueryWrapper<>();
  53. if(StringUtils.isNotBlank(param.getPartName())){
  54. wrapper.like(Part::getPartName,param.getPartName());
  55. }
  56. if(param.getCameraType() != null){
  57. wrapper.eq(Part::getCameraType,param.getCameraType());
  58. }
  59. wrapper.orderByDesc(Part::getCreateTime);
  60. return wrapper;
  61. }
  62. @Override
  63. public void inStock(Part part,Long userId) {
  64. if(part.getPartId() == null || part.getPartStock() == null){
  65. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  66. }
  67. LambdaUpdateWrapper<Part> wrapper = new LambdaUpdateWrapper<>();
  68. wrapper.eq(Part::getPartId,part.getPartId());
  69. wrapper.setSql("part_stock = part_stock +" + part.getPartStock());
  70. this.update(wrapper);
  71. partLogService.saveLog(part.getPartId(),part.getPartStock(),userId,0,null);
  72. }
  73. @Override
  74. public void outStock(Integer partId, Integer count,Long userId,String repairId) {
  75. LambdaUpdateWrapper<Part> wrapper = new LambdaUpdateWrapper<>();
  76. wrapper.eq(Part::getPartId,partId);
  77. wrapper.setSql("part_stock = part_stock -" + count);
  78. this.update(wrapper);
  79. partLogService.saveLog(partId,count,userId,1,repairId);
  80. }
  81. @Override
  82. public void recovery(Integer partId, Integer partCount, Long userId, String repairId) {
  83. partLogService.saveLog(partId,partCount,userId,2,repairId);
  84. }
  85. }