| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.micrometer.common.util.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.entity.MachineSpec; |
| | | import org.springblade.mdm.basesetting.machine.mapper.MachineMapper; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineQueryVO; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineSaveVO; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.FileSystemUtils; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.InvalidPathException; |
| | |
| | | |
| | | @Transactional |
| | | public void saveMachine(MachineSaveVO vo){ |
| | | //TODO |
| | | checkMachine(vo); |
| | | if(existsByCode(vo.getCode(),null)){ |
| | | throw new ServiceException("机床编码已存在:"+vo.getCode()); |
| | | } |
| | | |
| | | Machine machine = new Machine(); |
| | | BeanUtil.copyProperties(vo, machine); |
| | | machine.setId(null); |
| | | this.save(machine); |
| | | } |
| | | |
| | | /** |
| | | * 检查机床录入数据 |
| | | * @param vo 录入的表单数据VO |
| | | */ |
| | | void checkMachine(MachineSaveVO vo){ |
| | | if(Func.isEmpty(vo.getCode())){ |
| | | throw new ServiceException("机床编码不能为空"); |
| | | } |
| | | |
| | | if(Func.isEmpty(vo.getName())){ |
| | | throw new ServiceException("机床类型不能为空"); |
| | | } |
| | | |
| | | if(Func.isEmpty(vo.getMachineGroupCode())){ |
| | | throw new ServiceException("所属组织不能为空"); |
| | | } |
| | | |
| | | if(Func.isEmpty(vo.getMachineSpec())){ |
| | | throw new ServiceException("机床类型不能为空"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据机床编码判断机床是否存在 |
| | | * @param code 机床编码 |
| | | * @param excludeId 排除id |
| | | * @return 是否存在 |
| | | */ |
| | | boolean existsByCode(String code,Long excludeId){ |
| | | return this.lambdaQuery().eq(Machine::getCode, code).ne(excludeId!=null,Machine::getId, excludeId).count()>0; |
| | | } |
| | | |
| | | public boolean updateMachine(MachineSaveVO vo) { |
| | | |
| | | checkMachine(vo); |
| | | if(existsByCode(vo.getCode(),vo.getId())){ |
| | | throw new ServiceException("机床编码已存在:"+vo.getCode()); |
| | | } |
| | | |
| | | Machine machine = this.getById(vo.getId()); |
| | | |
| | | machine.setMachineSpec(vo.getMachineSpec()); |
| | |
| | | |
| | | //queryWrapper.and(StringUtils.isNotEmpty(keys), wrapper -> wrapper.like(Machine::getCode, keys).or().like(Machine::getName, keys)); |
| | | IPage<MachineVO> page = this.getBaseMapper().pageQuery(Condition.getPage(query),query); |
| | | |
| | | //MachineSpec.valueOf() |
| | | for (MachineVO record : page.getRecords()) { |
| | | if(record.getMachineSpec() != null){ |
| | | MachineSpec spec = MachineSpec.valueOf(record.getMachineSpec()); |
| | | record.setMachineSpecName(spec.getText()); |
| | | } |
| | | |
| | | } |
| | | return page; |
| | | } |
| | | |