| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | |
| | | List<DeviceSpare> deviceSpares = mapper.selectList(query); |
| | | return new Response<List<DeviceSpare>>().set(1,deviceSpares); |
| | | } |
| | | |
| | | public void add(List<DeviceSpare> spareList) { |
| | | mapper.insertBatchSomeColumn(spareList); |
| | | } |
| | | |
| | | public void addOrUpdate(List<DeviceSpare> spareList) { |
| | | //查询库中是否存在该设备,存在则增加数量. |
| | | for (DeviceSpare spare : spareList) { |
| | | QueryWrapper<DeviceSpare> query = Wrappers.query(); |
| | | query.eq("name",spare.getName()); |
| | | query.eq("model",spare.getModel()); |
| | | query.eq("version",spare.getVersion()); |
| | | query.eq("brand",spare.getBrand()); |
| | | query.eq("type",spare.getType()); |
| | | query.eq("supplier",spare.getSupplier()); |
| | | query.last(" limit 1"); |
| | | DeviceSpare spareInDB = mapper.selectOne(query); |
| | | if(spareInDB != null){ |
| | | spareInDB.setQuantity(spareInDB.getQuantity()+spare.getQuantity()); |
| | | mapper.updateById(spareInDB); |
| | | |
| | | }else{ |
| | | //不存在则新增 |
| | | mapper.insert(spare); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public void outBound(List<DeviceSpare> spareList) { |
| | | mapper.outBound(spareList); |
| | | } |
| | | } |