no message
							parent
							
								
									a5d73dc89f
								
							
						
					
					
						commit
						b9ef72ea63
					
				| 
						 | 
				
			
			@ -213,6 +213,18 @@ public class Item extends BaseEntity implements Serializable {
 | 
			
		|||
    @ApiModelProperty(value = "agv场景")
 | 
			
		||||
    private AgvScene agvScene;
 | 
			
		||||
 | 
			
		||||
    public Item() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Item(String code, String name, String unit,Dept dept,String sourceName,Long sourceId) {
 | 
			
		||||
        this.code = code;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.unit = unit;
 | 
			
		||||
        this.dept = dept;
 | 
			
		||||
        this.sourceName = sourceName;
 | 
			
		||||
        this.sourceId = sourceId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void copy(Item source){
 | 
			
		||||
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 | 
			
		|||
import java.util.Map;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -112,4 +113,11 @@ public interface ItemService {
 | 
			
		|||
     */
 | 
			
		||||
    Item existItem(String itemCode);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据物料编码查询物料信息
 | 
			
		||||
     * @param itemCodes
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    Map<String,Item> findByItemCodes(Set itemCodes);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -32,21 +32,19 @@ import org.springframework.stereotype.Service;
 | 
			
		|||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
import org.springframework.data.domain.Page;
 | 
			
		||||
import org.springframework.data.domain.Pageable;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import javax.persistence.EntityManager;
 | 
			
		||||
import javax.persistence.Query;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.LinkedHashMap;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.domain.Example;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author houjianlan
 | 
			
		||||
 * @website https://eladmin.vip
 | 
			
		||||
 * @description 服务实现
 | 
			
		||||
 * @author houjianlan
 | 
			
		||||
 * @date 2023-08-07
 | 
			
		||||
 **/
 | 
			
		||||
@Service
 | 
			
		||||
| 
						 | 
				
			
			@ -58,21 +56,21 @@ public class ItemServiceImpl implements ItemService {
 | 
			
		|||
    private final EntityManager entityMapper;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String,Object> queryAll(ItemQueryCriteria criteria, Pageable pageable){
 | 
			
		||||
        Page<Item> page = itemRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
 | 
			
		||||
    public Map<String, Object> queryAll(ItemQueryCriteria criteria, Pageable pageable) {
 | 
			
		||||
        Page<Item> page = itemRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
 | 
			
		||||
        return PageUtil.toPage(page.map(itemMapper::toDto));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<ItemDto> queryAll(ItemQueryCriteria criteria){
 | 
			
		||||
        return itemMapper.toDto(itemRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
 | 
			
		||||
    public List<ItemDto> queryAll(ItemQueryCriteria criteria) {
 | 
			
		||||
        return itemMapper.toDto(itemRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional
 | 
			
		||||
    public ItemDto findById(Long id) {
 | 
			
		||||
        Item item = itemRepository.findById(id).orElseGet(Item::new);
 | 
			
		||||
        ValidationUtil.isNull(item.getId(),"Item","id",id);
 | 
			
		||||
        ValidationUtil.isNull(item.getId(), "Item", "id", id);
 | 
			
		||||
        return itemMapper.toDto(item);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -82,16 +80,17 @@ public class ItemServiceImpl implements ItemService {
 | 
			
		|||
        Item item = itemRepository.findById(id).orElseGet(Item::new);
 | 
			
		||||
        return item;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional
 | 
			
		||||
    public ItemDto findByCode(String itemCode) {
 | 
			
		||||
        Item itemExample = new Item();
 | 
			
		||||
        itemExample.setCode(itemCode);
 | 
			
		||||
        Example<Item> example = Example.of(itemExample);
 | 
			
		||||
        List<Item>  its=itemRepository.findAll(example);
 | 
			
		||||
        if(its.size()>0){
 | 
			
		||||
        List<Item> its = itemRepository.findAll(example);
 | 
			
		||||
        if (its.size() > 0) {
 | 
			
		||||
            return itemMapper.toDto(its.get(0));
 | 
			
		||||
        }else {
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +105,7 @@ public class ItemServiceImpl implements ItemService {
 | 
			
		|||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void update(Item resources) {
 | 
			
		||||
        Item item = itemRepository.findById(resources.getId()).orElseGet(Item::new);
 | 
			
		||||
        ValidationUtil.isNull( item.getId(),"Item","id",resources.getId());
 | 
			
		||||
        ValidationUtil.isNull(item.getId(), "Item", "id", resources.getId());
 | 
			
		||||
        item.copy(resources);
 | 
			
		||||
        itemRepository.save(item);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -122,7 +121,7 @@ public class ItemServiceImpl implements ItemService {
 | 
			
		|||
    public void download(List<ItemDto> all, HttpServletResponse response) throws IOException {
 | 
			
		||||
        List<Map<String, Object>> list = new ArrayList<>();
 | 
			
		||||
        for (ItemDto item : all) {
 | 
			
		||||
            Map<String,Object> map = new LinkedHashMap<>();
 | 
			
		||||
            Map<String, Object> map = new LinkedHashMap<>();
 | 
			
		||||
            map.put("代码", item.getCode());
 | 
			
		||||
            map.put("名称", item.getName());
 | 
			
		||||
            map.put("规格", item.getSpecs());
 | 
			
		||||
| 
						 | 
				
			
			@ -163,14 +162,27 @@ public class ItemServiceImpl implements ItemService {
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Item existItem(String itemCode){
 | 
			
		||||
        String hql=" from Item it where it.code='"+itemCode+"' and it.enabled=true ";
 | 
			
		||||
        Query query=entityMapper.createQuery(hql);
 | 
			
		||||
        List<Item> its=query.getResultList();
 | 
			
		||||
        if(its.size()>0){
 | 
			
		||||
    public Item existItem(String itemCode) {
 | 
			
		||||
        String hql = " from Item it where it.code='" + itemCode + "' and it.enabled=true ";
 | 
			
		||||
        Query query = entityMapper.createQuery(hql);
 | 
			
		||||
        List<Item> its = query.getResultList();
 | 
			
		||||
        if (its.size() > 0) {
 | 
			
		||||
            return its.get(0);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Item> findByItemCodes(Set itemCodes) {
 | 
			
		||||
        String hql = " from Item it where it.code in (:itemCodes)  ";
 | 
			
		||||
        Query query = entityMapper.createQuery(hql);
 | 
			
		||||
        query.setParameter("itemCodes", itemCodes);
 | 
			
		||||
        List<Item> its = query.getResultList();
 | 
			
		||||
        Map<String, Item> itemMap = new HashMap<>();
 | 
			
		||||
        for (Item item : its) {
 | 
			
		||||
            itemMap.put(item.getCode(), item);
 | 
			
		||||
        }
 | 
			
		||||
        return itemMap;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,9 +19,12 @@ import com.youchain.businessdata.domain.Mo;
 | 
			
		|||
import com.youchain.businessdata.service.dto.MoDto;
 | 
			
		||||
import com.youchain.businessdata.service.dto.MoQueryCriteria;
 | 
			
		||||
import org.springframework.data.domain.Pageable;
 | 
			
		||||
import org.springframework.scheduling.annotation.Async;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -95,4 +98,25 @@ public interface MoService {
 | 
			
		|||
     * @param mo MO票
 | 
			
		||||
     */
 | 
			
		||||
    void scanMo(String mo);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据labelNos查询MO
 | 
			
		||||
     * @param labelNos labelNos集合
 | 
			
		||||
     * @return Map<String,Mo>
 | 
			
		||||
     */
 | 
			
		||||
    Map<String,Mo> findBylabelNos(Set labelNos);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 批量创建MO
 | 
			
		||||
     * @param mos MO集合
 | 
			
		||||
     */
 | 
			
		||||
    @Async
 | 
			
		||||
    void batchCreateMos(List<Mo> mos);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 批量修改MO
 | 
			
		||||
     * @param mos MO集合
 | 
			
		||||
     */
 | 
			
		||||
    @Async
 | 
			
		||||
    void batchUpdateMos(List<Mo> mos);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,10 +19,7 @@ import com.youchain.exception.handler.ApiResult;
 | 
			
		|||
import com.youchain.modules.system.domain.Dept;
 | 
			
		||||
import com.youchain.modules.system.service.DeptService;
 | 
			
		||||
import com.youchain.modules.system.service.dto.DeptDto;
 | 
			
		||||
import com.youchain.utils.BizStatus;
 | 
			
		||||
import com.youchain.utils.HttpPostUtil;
 | 
			
		||||
import com.youchain.utils.StringUtils;
 | 
			
		||||
import com.youchain.utils.UrlApi;
 | 
			
		||||
import com.youchain.utils.*;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
| 
						 | 
				
			
			@ -265,24 +262,102 @@ public class MlsServiceImpl implements MlsService {
 | 
			
		|||
        if (details == null || details.size() == 0) {
 | 
			
		||||
            throw new RuntimeException("没有获取到MO票数据!");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        List<Mo> mosToCreate = new ArrayList<>();//新增Mo集合
 | 
			
		||||
        List<Mo> mosToUpdate = new ArrayList<>();//修改Mo集合
 | 
			
		||||
 | 
			
		||||
        //获取所有物料编码
 | 
			
		||||
        Set<String> itemCodes = details.stream()
 | 
			
		||||
                .map(detail -> ((JSONObject) detail).getString("itemCode"))
 | 
			
		||||
                .collect(Collectors.toSet());
 | 
			
		||||
        //获取已存在的物料
 | 
			
		||||
        Map<String, Item> existingItems = itemService.findByItemCodes(itemCodes);
 | 
			
		||||
 | 
			
		||||
        //获取所有MO票
 | 
			
		||||
        Set<String> labelNos = details.stream()
 | 
			
		||||
                .map(detail -> ((JSONObject) detail).getString("labelNo"))
 | 
			
		||||
                .collect(Collectors.toSet());
 | 
			
		||||
        //获取已存在的MO票
 | 
			
		||||
        Map<String, Mo> existingMos = moService.findBylabelNos(labelNos);
 | 
			
		||||
 | 
			
		||||
        //循环处理每个MO票
 | 
			
		||||
        for (int i = 0; i < details.size(); i++) {
 | 
			
		||||
            JSONObject detail = details.getJSONObject(i);
 | 
			
		||||
            String labelState = detail.getString("labelState");//标签状态
 | 
			
		||||
            if ("PRINTED".equals(labelState)) {
 | 
			
		||||
                //物料编码
 | 
			
		||||
                String itemCode = detail.getString("itemCode");
 | 
			
		||||
                Item item = null;
 | 
			
		||||
                if (existingItems.containsKey(itemCode)) {
 | 
			
		||||
                    item = existingItems.get(itemCode);
 | 
			
		||||
                } else {
 | 
			
		||||
                    //新增物料
 | 
			
		||||
                    item = createItem(detail);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                //MO票
 | 
			
		||||
                String labelNo = detail.getString("labelNo");
 | 
			
		||||
                //判断是否已存在MO票
 | 
			
		||||
                if (existingMos.containsKey(labelNo)) {
 | 
			
		||||
                    Mo existingMo = existingMos.get(labelNo);
 | 
			
		||||
                    //更新MO票信息
 | 
			
		||||
                    mosToUpdate.add(updateMo(existingMo, detail));
 | 
			
		||||
                } else {
 | 
			
		||||
                    //新增MO票
 | 
			
		||||
                    mosToCreate.add(createMo(detail, item));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //批量新增Mo票
 | 
			
		||||
        if (!mosToCreate.isEmpty()) {
 | 
			
		||||
            moService.batchCreateMos(mosToCreate);
 | 
			
		||||
        }
 | 
			
		||||
        //批量更新Mo票
 | 
			
		||||
        if (!mosToUpdate.isEmpty()) {
 | 
			
		||||
            moService.batchUpdateMos(mosToUpdate);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建订单
 | 
			
		||||
     *
 | 
			
		||||
     * @param detail
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private Item createItem(JSONObject detail) {
 | 
			
		||||
 | 
			
		||||
        String itemCode = detail.getString("itemCode");//物料编码
 | 
			
		||||
        String itemDesc = detail.getString("itemDesc");//物料描述
 | 
			
		||||
        String uom = detail.getString("uom");//单位
 | 
			
		||||
        String sourceSystem = detail.getString("sourceSystem");//来源系统
 | 
			
		||||
        Long itemId = detail.getLong("itemId");//物料id
 | 
			
		||||
 | 
			
		||||
        //创建
 | 
			
		||||
        Item Item = new Item(itemCode, itemDesc, uom, UserUtils.getDept(), sourceSystem, itemId);
 | 
			
		||||
        itemService.create(Item);
 | 
			
		||||
        return Item;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建Mo票信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param detail
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    private Mo createMo(JSONObject detail, Item item) {
 | 
			
		||||
        Integer selfWorkOrderId = detail.getInteger("selfWorkOrderId");//自制件工单id
 | 
			
		||||
        String sourceSystem = detail.getString("sourceSystem");//来源系统
 | 
			
		||||
        String selfWorkOrderName = detail.getString("selfWorkOrderName");//自制件工单编号
 | 
			
		||||
            String itemCode = detail.getString("itemCode");//物料编码
 | 
			
		||||
        String labelType = detail.getString("labelType");//标签类型
 | 
			
		||||
        String goodsAreaCode = detail.getString("goodsAreaCode");//MLS货区
 | 
			
		||||
        String checkResult = detail.getString("checkResult");//检验状态
 | 
			
		||||
        String datetimeStockIn = detail.getString("datetimeStockin");//入库时间
 | 
			
		||||
        String deleteFlag = detail.getString("deleteFlag");//数据有效性;有效0,无效1
 | 
			
		||||
            String uom = detail.getString("uom");//单位
 | 
			
		||||
        String createUserCode = detail.getString("createUserCode");//创建人
 | 
			
		||||
        String mlsUpdateTime = detail.getString("updateTime");//修改时间
 | 
			
		||||
            String itemDesc = detail.getString("itemDesc");//物料描述
 | 
			
		||||
        String labelNo = detail.getString("labelNo");//MO票
 | 
			
		||||
            Long itemId = detail.getLong("itemId");//物料id
 | 
			
		||||
        String updateUserCode = detail.getString("updateUserCode");//修改人
 | 
			
		||||
        String mlsCreateTime = detail.getString("createTime");//创建时间
 | 
			
		||||
        Double qty = detail.getDouble("qty") == null ? 0 : detail.getDouble("qty");//可用数量
 | 
			
		||||
| 
						 | 
				
			
			@ -293,25 +368,6 @@ public class MlsServiceImpl implements MlsService {
 | 
			
		|||
        String goodsLocationCode = detail.getString("goodsLocationCode");//MLS货位
 | 
			
		||||
        String invCode = detail.getString("invCode");//MLS子库
 | 
			
		||||
 | 
			
		||||
            if ("PRINTED".equals(labelState)) {
 | 
			
		||||
                //判断物料是否存在;不存在新增;
 | 
			
		||||
                ItemDto itemDto = itemService.findByCode(itemCode);
 | 
			
		||||
                Item item = itemService.toEntity(itemDto);
 | 
			
		||||
                if (item == null) {
 | 
			
		||||
                    item = new Item();
 | 
			
		||||
                    item.setCode(itemCode);
 | 
			
		||||
                    item.setName(itemDesc);
 | 
			
		||||
                    item.setUnit(uom);
 | 
			
		||||
                    DeptDto deptDto = deptService.findById(7L);
 | 
			
		||||
                    Dept dept = deptService.toEntity(deptDto);
 | 
			
		||||
                    item.setDept(dept);
 | 
			
		||||
                    item.setSourceName(sourceSystem);
 | 
			
		||||
                    item.setSourceId(itemId);
 | 
			
		||||
                    itemService.create(item);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                MoDto moDto = moService.findByLabelNo(labelNo);
 | 
			
		||||
                if (moDto == null) {
 | 
			
		||||
        Mo mo = new Mo(labelNo, labelType, labelState, deliveryHeaderId, sourceSystem, qty,
 | 
			
		||||
                workOrderId, workOrderName, selfWorkOrderId, selfWorkOrderName, null, item,
 | 
			
		||||
                checkResult, Boolean.parseBoolean(deleteFlag), null, null, null, null, invCode, goodsAreaCode, goodsLocationCode,
 | 
			
		||||
| 
						 | 
				
			
			@ -320,33 +376,16 @@ public class MlsServiceImpl implements MlsService {
 | 
			
		|||
                mlsUpdateTime == null ? null : DateUtil.parse(mlsUpdateTime).toTimestamp(),
 | 
			
		||||
                createUserCode, updateUserCode
 | 
			
		||||
        );
 | 
			
		||||
                    moService.create(mo);
 | 
			
		||||
                } else {
 | 
			
		||||
                    Mo mo = moService.toEntity(moDto);
 | 
			
		||||
                    mo.setLabelType(labelType);
 | 
			
		||||
                    mo.setLabelState(labelState);
 | 
			
		||||
                    mo.setDeliveryHeaderId(deliveryHeaderId);
 | 
			
		||||
                    mo.setSourceSystem(sourceSystem);
 | 
			
		||||
                    mo.setQty(qty);
 | 
			
		||||
                    mo.setWorkOrderId(workOrderId);
 | 
			
		||||
                    mo.setWorkOrderName(workOrderName);
 | 
			
		||||
                    mo.setSelfWorkOrderId(selfWorkOrderId);
 | 
			
		||||
                    mo.setSelfWorkOrderName(selfWorkOrderName);
 | 
			
		||||
                    mo.setDatetimeStockIn(datetimeStockIn == null ? null : DateUtil.parse(datetimeStockIn).toTimestamp());
 | 
			
		||||
                    mo.setItem(item);
 | 
			
		||||
                    mo.setCheckResult(checkResult);
 | 
			
		||||
                    mo.setDeleteFlag(Boolean.parseBoolean(deleteFlag));
 | 
			
		||||
                    mo.setInvCode(invCode);
 | 
			
		||||
                    mo.setGoodsAreaCode(goodsAreaCode);
 | 
			
		||||
                    mo.setGoodsLocationCode(goodsLocationCode);
 | 
			
		||||
                    mo.setMlsUpdateTime(mlsUpdateTime == null ? null : DateUtil.parse(mlsUpdateTime).toTimestamp());
 | 
			
		||||
                    mo.setUpdateUserCode(updateUserCode);
 | 
			
		||||
                    moService.update(mo);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
        return mo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    private Mo updateMo(Mo mo, JSONObject detail) {
 | 
			
		||||
        mo.setCheckResult(detail.getString("checkResult"));
 | 
			
		||||
        mo.setDeleteFlag(Boolean.parseBoolean(detail.getString("deleteFlag")));
 | 
			
		||||
        mo.setMlsUpdateTime(detail.getString("updateTime") == null ? null : DateUtil.parse(detail.getString("updateTime")).toTimestamp());
 | 
			
		||||
        mo.setUpdateUserCode(detail.getString("updateUserCode"));
 | 
			
		||||
        return mo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,9 +15,6 @@
 | 
			
		|||
 */
 | 
			
		||||
package com.youchain.businessdata.service.impl;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.date.DateUtil;
 | 
			
		||||
import com.alibaba.fastjson.JSON;
 | 
			
		||||
import com.alibaba.fastjson.JSONObject;
 | 
			
		||||
import com.youchain.basicdata.domain.Item;
 | 
			
		||||
import com.youchain.basicdata.domain.Point;
 | 
			
		||||
import com.youchain.basicdata.domain.Stock;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,8 +24,6 @@ import com.youchain.basicdata.service.StockService;
 | 
			
		|||
import com.youchain.businessdata.domain.*;
 | 
			
		||||
import com.youchain.businessdata.service.*;
 | 
			
		||||
import com.youchain.businessdata.service.dto.OrderDto;
 | 
			
		||||
import com.youchain.exception.EntityExistException;
 | 
			
		||||
import com.youchain.exception.handler.ApiResult;
 | 
			
		||||
import com.youchain.modules.system.service.DictService;
 | 
			
		||||
import com.youchain.utils.*;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
| 
						 | 
				
			
			@ -36,21 +31,16 @@ import com.youchain.businessdata.repository.MoRepository;
 | 
			
		|||
import com.youchain.businessdata.service.dto.MoDto;
 | 
			
		||||
import com.youchain.businessdata.service.dto.MoQueryCriteria;
 | 
			
		||||
import com.youchain.businessdata.service.mapstruct.MoMapper;
 | 
			
		||||
import org.springframework.data.domain.Example;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
import org.springframework.data.domain.Page;
 | 
			
		||||
import org.springframework.data.domain.Pageable;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import javax.persistence.EntityManager;
 | 
			
		||||
import javax.persistence.Query;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author huojin
 | 
			
		||||
| 
						 | 
				
			
			@ -68,13 +58,11 @@ public class MoServiceImpl implements MoService {
 | 
			
		|||
    private final OrderService orderService;
 | 
			
		||||
    private final ItemService itemService;
 | 
			
		||||
    private final StockService stockService;
 | 
			
		||||
    private final InventoryService inventoryService;
 | 
			
		||||
    private final PointService pointService;
 | 
			
		||||
    private final AgvTaskService agvTaskService;
 | 
			
		||||
    private final TaskService taskService;
 | 
			
		||||
    private final AsnDetailService asnDetailService;
 | 
			
		||||
    private final ItemKeyService itemKeyService;
 | 
			
		||||
    private final DictService dictService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Object> queryAll(MoQueryCriteria criteria, Pageable pageable) {
 | 
			
		||||
| 
						 | 
				
			
			@ -136,20 +124,20 @@ public class MoServiceImpl implements MoService {
 | 
			
		|||
        for (MoDto mo : all) {
 | 
			
		||||
            Map<String, Object> map = new LinkedHashMap<>();
 | 
			
		||||
            map.put("送货单头ID", mo.getDeliveryHeaderId());
 | 
			
		||||
            map.put("MO票",mo.getLabelNo());
 | 
			
		||||
            map.put("物料编码",mo.getItem().getCode());
 | 
			
		||||
            map.put("物料描述",mo.getItem().getName());
 | 
			
		||||
            map.put("可用数量",mo.getQty());
 | 
			
		||||
            map.put("标签类型",mo.getLabelType());
 | 
			
		||||
            map.put("是否有效",mo.getDeleteFlag());
 | 
			
		||||
            map.put("标签状态",mo.getLabelState());
 | 
			
		||||
            map.put("检验状态",mo.getCheckResult());
 | 
			
		||||
            map.put("mls子库",mo.getInvCode());
 | 
			
		||||
            map.put("mls入库时间",mo.getDatetimeStockIn());
 | 
			
		||||
            map.put("mls修改时间",mo.getMlsUpdateTime());
 | 
			
		||||
            map.put("mls创建时间",mo.getMlsCreateTime());
 | 
			
		||||
            map.put("wms接收时间",mo.getCreateTime());
 | 
			
		||||
            map.put("wms修改时间",mo.getUpdateTime());
 | 
			
		||||
            map.put("MO票", mo.getLabelNo());
 | 
			
		||||
            map.put("物料编码", mo.getItem().getCode());
 | 
			
		||||
            map.put("物料描述", mo.getItem().getName());
 | 
			
		||||
            map.put("可用数量", mo.getQty());
 | 
			
		||||
            map.put("标签类型", mo.getLabelType());
 | 
			
		||||
            map.put("是否有效", mo.getDeleteFlag());
 | 
			
		||||
            map.put("标签状态", mo.getLabelState());
 | 
			
		||||
            map.put("检验状态", mo.getCheckResult());
 | 
			
		||||
            map.put("mls子库", mo.getInvCode());
 | 
			
		||||
            map.put("mls入库时间", mo.getDatetimeStockIn());
 | 
			
		||||
            map.put("mls修改时间", mo.getMlsUpdateTime());
 | 
			
		||||
            map.put("mls创建时间", mo.getMlsCreateTime());
 | 
			
		||||
            map.put("wms接收时间", mo.getCreateTime());
 | 
			
		||||
            map.put("wms修改时间", mo.getUpdateTime());
 | 
			
		||||
            list.add(map);
 | 
			
		||||
        }
 | 
			
		||||
        FileUtil.downloadExcel(list, response);
 | 
			
		||||
| 
						 | 
				
			
			@ -227,11 +215,55 @@ public class MoServiceImpl implements MoService {
 | 
			
		|||
        createTasks(item, stock, srcPoint, endPoint, moDto.getLabelNo(), moDto, orderDto);
 | 
			
		||||
 | 
			
		||||
        // 更新容器状态和目标点位状态
 | 
			
		||||
        updateStockAndEndPoint(stock,endPoint);
 | 
			
		||||
        updateStockAndEndPoint(stock, endPoint);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Mo> findBylabelNos(Set labelNos) {
 | 
			
		||||
        String hql = "from Mo where labelNo in (:labelNos) ";
 | 
			
		||||
        Query query = entityManager.createQuery(hql);
 | 
			
		||||
        query.setParameter("labelNos", labelNos);
 | 
			
		||||
        List<Mo> list = query.getResultList();
 | 
			
		||||
        Map<String, Mo> map = new HashMap<>();
 | 
			
		||||
        for (Mo mo : list) {
 | 
			
		||||
            map.put(mo.getLabelNo(), mo);
 | 
			
		||||
        }
 | 
			
		||||
        return map;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void batchCreateMos(List<Mo> mos) {
 | 
			
		||||
        int batchSize = 50; // 根据需求调整批处理大小
 | 
			
		||||
        for (int i = 0; i < mos.size(); i++) {
 | 
			
		||||
            entityManager.persist(mos.get(i));
 | 
			
		||||
            if (i % batchSize == 0 && i > 0) {
 | 
			
		||||
                entityManager.flush(); // 批量提交
 | 
			
		||||
                entityManager.clear(); // 清理缓存
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        entityManager.flush(); // 最后确保所有剩余的实体也被flush到数据库
 | 
			
		||||
        entityManager.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void batchUpdateMos(List<Mo> mos) {
 | 
			
		||||
        int batchSize = 50; // 根据需求调整批处理大小
 | 
			
		||||
        for (int i = 0; i < mos.size(); i++) {
 | 
			
		||||
            Mo mo = mos.get(i);
 | 
			
		||||
            entityManager.merge(mo); // 更新实体
 | 
			
		||||
            if (i % batchSize == 0 && i > 0) { // 每处理50个实体执行一次flush和clear
 | 
			
		||||
                entityManager.flush();
 | 
			
		||||
                entityManager.clear();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        entityManager.flush(); // 确保最后的更改也被写入数据库
 | 
			
		||||
        entityManager.clear(); // 清理持久化上下文以释放内存
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void createTasks(Item item, Stock stock, Point srcPoint, Point endPoint, String propC1, MoDto moDto, OrderDto orderDto) {
 | 
			
		||||
        // 生成AGV任务
 | 
			
		||||
        AgvTask agvTask = new AgvTask(BizStatus.ASN, stock.getCode(), srcPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "RACK_MOVE_FULL");
 | 
			
		||||
| 
						 | 
				
			
			@ -253,7 +285,7 @@ public class MoServiceImpl implements MoService {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // 提取更新容器状态和目标点位状态的逻辑到单独方法
 | 
			
		||||
    private  void updateStockAndEndPoint(Stock stock,Point point) {
 | 
			
		||||
    private void updateStockAndEndPoint(Stock stock, Point point) {
 | 
			
		||||
        stock.setStatus(BaseStatus.USED);
 | 
			
		||||
        stock.setPoint(point);
 | 
			
		||||
        stockService.update(stock);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -139,7 +139,7 @@ public class OrderServiceImpl implements OrderService {
 | 
			
		|||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void batchUpdateOrders(List<Order> orders) {
 | 
			
		||||
        int batchSize = 100; // 根据需求调整批处理大小
 | 
			
		||||
        int batchSize = 50; // 根据需求调整批处理大小
 | 
			
		||||
        for (int i = 0; i < orders.size(); i++) {
 | 
			
		||||
            Order order = orders.get(i);
 | 
			
		||||
            entityManager.merge(order); // 更新实体
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,16 +23,9 @@ public class moTask {
 | 
			
		|||
    public MlsService mlsService;
 | 
			
		||||
 | 
			
		||||
    public void moTask() {
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            log.info("获取mo信息");
 | 
			
		||||
        MoInfo moInfo = getMoInfo();
 | 
			
		||||
        String moJson = mlsService.getMoJson(moInfo);
 | 
			
		||||
        mlsService.getMoInfo(moJson);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("MLS异常信息:" + e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MoInfo getMoInfo() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue