| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.mapper.DeviceMapper; |
| | | import com.yuanchu.mom.mapper.ManualTechnologyMapper; |
| | | import com.yuanchu.mom.mapper.ManufactureOrderMapper; |
| | | import com.yuanchu.mom.pojo.ManualTechnology; |
| | | import com.yuanchu.mom.pojo.ManufactureOrder; |
| | | import com.yuanchu.mom.pojo.dto.ManualTechnologyDto; |
| | | import com.yuanchu.mom.service.ManualTechnologyService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.DateFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 编制工序表(ManualTechnology)表服务实现类 |
| | |
| | | ManualTechnologyMapper manualTechnologyMapper; |
| | | |
| | | @Resource |
| | | DeviceMapper deviceMapper; |
| | | ManufactureOrderMapper manufactureOrderMapper; |
| | | |
| | | |
| | | //排产-->查看 |
| | | @Override |
| | | public List<Map<String,Object>> seleDatil(Integer manOrdId) { |
| | | public List<Map<String, Object>> seleDatil(Integer manOrdId) { |
| | | return manualTechnologyMapper.seleDatil(manOrdId); |
| | | } |
| | | |
| | | //排产-->更新 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void output(String date, List<ManualTechnologyDto> manualTechnologyDtoList) throws ParseException { |
| | | //更新每个工序的设备 |
| | | List<ManualTechnology> manualTechnologies = manualTechnologyDtoList.stream().map(manualTechnologyDto -> { |
| | | ManualTechnology manualTechnology = new ManualTechnology(); |
| | | BeanUtils.copyProperties(manualTechnologyDto, manualTechnology); |
| | | return manualTechnology; |
| | | }).collect(Collectors.toList()); |
| | | //批量更新设备id |
| | | manualTechnologyMapper.updateBatchManualTechnology(manualTechnologies); |
| | | Integer manufactureOrderId = manualTechnologyMapper.selectById(manualTechnologyDtoList.get(1).getId()).getManufactureOrderId(); |
| | | List<ManualTechnology> manualTechnologyList = manualTechnologyMapper.selectList(Wrappers.<ManualTechnology>query().eq("manufacture_order_id", manufactureOrderId)); |
| | | /*赋值(最开始第一个工序的开始日期)*/ |
| | | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date parse = dateFormat.parse(date); |
| | | //将起始日期赋值给Calendar对象 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(parse); |
| | | //第一个工序 |
| | | ManualTechnology manualTechnology = manualTechnologyList.get(0); |
| | | calendar.add(Calendar.DATE, manualTechnology.getPeriod()); |
| | | manualTechnology.setStartTime(parse).setEndTime(calendar.getTime()); |
| | | //循环赋值时间 |
| | | for (int i = 0; i < manualTechnologyList.size()-1 ; i++) { |
| | | Calendar calendar1 = Calendar.getInstance(); |
| | | calendar1.setTime(manualTechnologyList.get(i).getEndTime()); |
| | | ManualTechnology technology = manualTechnologyList.get(i + 1); |
| | | calendar1.add(Calendar.DATE,1); |
| | | technology.setStartTime(calendar1.getTime()); |
| | | calendar1.add(Calendar.DATE,technology.getPeriod()); |
| | | technology.setEndTime(calendar1.getTime()); |
| | | } |
| | | //批量更新 |
| | | manualTechnologyMapper.updateBatchManualTechnology(manualTechnologyList); |
| | | //如果该产品下的所有工序都安排了,则将状态改为已排产还有待下达 |
| | | if (checkFieldExistence(manualTechnologies)) { |
| | | ManufactureOrder manufactureOrder = new ManufactureOrder(); |
| | | manufactureOrder.setId(manufactureOrderId).setType(1).setGoState(0); |
| | | manufactureOrderMapper.updateById(manufactureOrder); |
| | | } |
| | | } |
| | | |
| | | |
| | | /*判断是否所有工序全部都安排了设备*/ |
| | | public static boolean checkFieldExistence(List<ManualTechnology> dataList) { |
| | | for (ManualTechnology data : dataList) { |
| | | if (data.getDeviceId() == null) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | | |