package com.yuanchu.limslaboratory.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.yuanchu.limslaboratory.pojo.Standards;
|
import com.yuanchu.limslaboratory.mapper.StandardsMapper;
|
import com.yuanchu.limslaboratory.pojo.User;
|
import com.yuanchu.limslaboratory.service.*;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.limslaboratory.utils.MyUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.ObjectUtils;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @author 江苏鵷雏网络科技有限公司
|
* @since 2023-07-11
|
*/
|
@Service
|
public class StandardsServiceImpl extends ServiceImpl<StandardsMapper, Standards> implements StandardsService {
|
|
@Resource
|
private StandardsMapper standardsMapper;
|
|
@Autowired
|
private UserService userService;
|
|
@Lazy
|
@Autowired
|
private SerialNumberService serialNumberService;
|
|
@Lazy
|
@Autowired
|
private SpecificationsService specificationsService;
|
|
@Autowired
|
private MaterialService materialService;
|
|
@Autowired
|
private ProductService productService;
|
|
@Override
|
public Integer addStandardsInformation(Standards standards) {
|
Boolean userIsNull = userService.userIsNull(standards.getUserId());
|
if (userIsNull){
|
return standardsMapper.insert(standards);
|
}
|
return 0;
|
}
|
|
@Override
|
public List<Map<String, Object>> listStandardsInformation() {
|
LambdaQueryWrapper<Standards> wrapper = new LambdaQueryWrapper<>();
|
wrapper.select(Standards::getId, Standards::getName);
|
List<Map<String, Object>> maps = standardsMapper.selectMaps(wrapper);
|
for (Map<String, Object> map : maps){
|
String id = map.get("id").toString();
|
List<Map<String, Object>> serialNumberList = serialNumberService.selectIdSerialNumberInformation(id);
|
if (ObjectUtils.isEmpty(serialNumberList)){
|
map.put("serialNumber", null);
|
} else {
|
map.put("serialNumber", serialNumberList);
|
}
|
}
|
return maps;
|
}
|
|
@Override
|
public Boolean standardsIsNull(String Id) {
|
LambdaQueryWrapper<Standards> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(Standards::getId, Id);
|
Standards standardsIsNull = standardsMapper.selectOne(wrapper);
|
return !ObjectUtils.isEmpty(standardsIsNull);
|
}
|
|
@Override
|
public IPage<Map<String, Object>> listPageStandardsInformation(Page<Object> page, String idOrNameOfStandards) {
|
return standardsMapper.listPageStandardsInformation(page, idOrNameOfStandards);
|
}
|
|
@Override
|
public Integer updateStandardsInformation(Standards standards) {
|
return standardsMapper.updateById(standards);
|
}
|
|
@Override
|
public Integer deleteStandardsInformation(String standardsId) {
|
LambdaUpdateWrapper<Standards> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.eq(Standards::getId, standardsId);
|
updateWrapper.set(Standards::getState, 0);
|
int isDeleteSuccess = standardsMapper.update(new Standards(), updateWrapper);
|
if (isDeleteSuccess == 1){
|
List<String> deleteSerialNumberId = serialNumberService.StandardsIdDeleteSerialNumber(standardsId);
|
if (!ObjectUtils.isEmpty(deleteSerialNumberId)){
|
List<Integer> deleteSpecificationsId = specificationsService.SerialNumberIdDeleteSpecifications(deleteSerialNumberId);
|
if (!ObjectUtils.isEmpty(deleteSpecificationsId)){
|
List<String> deleteMaterialId = materialService.specificationsIdDeleteMaterial(deleteSpecificationsId);
|
if (!ObjectUtils.isEmpty(deleteMaterialId)){
|
productService.MaterialIdDeleteProduct(deleteMaterialId);
|
}
|
}
|
}
|
return 1;
|
}
|
return 0;
|
}
|
}
|