BackService.java 10.1 KB
package cn.csbr.app.service;

import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.model.InboundItem;
import cn.csbr.app.model.RfidDataModel;
import cn.csbr.springboot.dao.mapper.MfcubestockMapper;
import cn.csbr.springboot.dao.mapper.MfcubestockdetailMapper;
import cn.csbr.springboot.dao.mapper.MfcubestockstatementMapper;
import cn.csbr.springboot.dao.mapper.SpdWvdetailMapper;
import cn.csbr.springboot.dao.model.Cabinet;
import cn.csbr.springboot.dao.model.Mfcubestockdetail;
import cn.csbr.springboot.dao.model.SpdWvdetail;
import cn.hutool.core.date.DateTime;
import tk.mybatis.mapper.entity.Example;

import java.sql.Timestamp;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.csbr.mybatis.CommonMapper;

/**
 * 还货类
 */
@Service
public class BackService {
    private static Logger log = LoggerFactory.getLogger(BackService.class);
    @Autowired
    private CommonMapper commonMapper;
    @Autowired
    private CabinetService cabinetService;
    @Autowired
    private GUIContext guiContext;
    @Autowired
    private SpdWvdetailMapper spdWvdetailMapper;
    @Autowired
    private FxConfigure fxConfigure;
    @Autowired
    private MfcubestockdetailMapper mfcubestockdetailMapper;
    @Autowired
    private MfcubestockstatementMapper mfcubestockstatementMapper;
    @Autowired
    private MfcubestockMapper mfcubestockMapper;
    @Autowired
    private BaseService baseService;

    public synchronized List<InboundItem> queryInboundItem(String inboundNo, Map<Cabinet, List<String>> scanData, String goodsInfo) {
        String goodsInfol = null;
        String sql = "SELECT A.GUID,A.BillNo,A.RowNo,A.GoodsGuid,A.GoodsCode,A.GoodsName,A.GoodsSpec,A.Unit,A.Price,A.RegistKey,A.Manufacturer,A.SupplierGUID,A.SupplierName,A.GoodsType,1 MVQty,A.PRICE * 1 Amount,A.Lot,A.ProductionDate,A.ExpireDate,A.SterilantLot,A.SterilantDate,A.SterilantEXPDate,A.Cargoposition,A.MvDate,A.Memo,A.OrgGUID,A.OrgName, b.rfiduid AS temprfiduid, b.barcode AS barcode FROM Spd_wvdetail a INNER JOIN spd_wvdetail_scend b ON a.guid = b.rdguid AND a.rowno = b.RowNo "
                + "  where b.BarCode in (select labguid from mfcubestockdetail c where c.rkbillno = a.BillNo and c.billstate='O') "
                + " and a.billno in (select billno from spd_wv d where d.billno=a.billno and d.MedDeptGuid='"
                + guiContext.getLoginUser().getOrgGuid() + "') ";

        if (!StringUtils.isEmpty(goodsInfo)) {
            goodsInfol = "%" + goodsInfo + "%";
            sql += " and (a.goodscode like '" + goodsInfol + "' or a.GoodsName like '" + goodsInfol
                    + "' or b.BarCode like '" + goodsInfol + "')";
        }
        sql += " order by a.mvdate";
        List<Map> maps = commonMapper.queryList(sql);

        // List<SpdWvdetail> spdWvdetails =
        // spdWvdetailMapper.selectByExample(condition);

        List<InboundItem> inboundItems = new ArrayList<>();
        Set<Cabinet> cabinets = scanData.keySet();
        for (Map map : maps) {
            InboundItem inboundItem = new InboundItem();

            SpdWvdetail data = JSON.parseObject(JSON.toJSONString(map), SpdWvdetail.class);

            inboundItem.setRowNo(data.getRowno());
            inboundItem.setScanQty(data.getMvqty().intValue());
            inboundItem.setSrcOrderCode(data.getBillno());
            inboundItem.setQty(data.getAmount().intValue());
            inboundItem.setGoodsguid(data.getGoodsguid());
            inboundItem.setGoodscode(data.getGoodscode());
            inboundItem.setGoodsname(data.getGoodsname());
            inboundItem.setGoodsspec(data.getGoodsspec());
            inboundItem.setUnit(data.getUnit());
            inboundItem.setIfScand((byte) 0);
            inboundItem.setSupplierName(data.getSuppliername());
            inboundItem.setSupplierGuid(data.getSupplierguid());
            inboundItem.setBacthCode(data.getLot());
            inboundItem.setSrcInboundDate(data.getMvdate());
            inboundItem.setTraceCode(data.getBarcode());
            inboundItem.setBarcode(data.getBarcode());
            inboundItem.setRfiduid(data.getTemprfiduid());
            inboundItem.setGuid(data.getGuid());
            inboundItem.setRegistkey(data.getRegistkey());
            inboundItem.setManufacturer(data.getManufacturer());
            inboundItem.setProductiondate(data.getProductiondate());
            inboundItem.setExpiredate(data.getExpiredate());
            for (Cabinet cabinet : cabinets) {
                List<String> results = scanData.get(cabinet);
                if (results.contains(inboundItem.getRfiduid())) {
                    inboundItem.setAllocation(cabinet.getCabinetcode());
                    inboundItem.setAllocationGuid(cabinet.getGuid());
                    inboundItem.setIfInCabinet((byte) 1);
                    inboundItem.setIfScand((byte) 1);

                    inboundItems.add(inboundItem);
                }
            }
        }
        return inboundItems;
    }

    @Transactional
    public synchronized List<InboundItem> ActionqueryInboundItem(RfidDataModel rfidDataModel, String rfidData) {
        String goodsInfol = "";
        //设置操作人人是从柜子柜子对象中取得
        String cubeGuid = rfidDataModel.getCabinetCd();
        String operaterId = rfidDataModel.getUserCd();
        String operaterName = rfidDataModel.getUserName();
        if(operaterId.isEmpty()||operaterId==null)
        {
            operaterId=guiContext.getLoginUser().getGuid();
            operaterName=guiContext.getLoginUser().getRealName();
        }
        log.info("获取用户"+operaterId+","+operaterName);
        String sql = " select * from mfcubestockdetail where  CubeGuid in (select guid from  cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "') " +
                " AND DepotGuid='" + guiContext.getLoginUser().getOrgGuid() + " '  AND  rfiduid   IN (" + rfidData + ")";
        List<Map> maps = commonMapper.queryList(sql);

        List<InboundItem> inboundItems = new ArrayList<>();

        for (Map map : maps) {
            InboundItem inboundItem = new InboundItem();
            Mfcubestockdetail data = JSON.parseObject(JSON.toJSONString(map), Mfcubestockdetail.class);
            inboundItem.setScanQty(Double.valueOf(data.getNumber()).intValue());
            inboundItem.setSrcOrderCode(data.getRkBillNo());
            inboundItem.setQty(Double.valueOf(data.getNumber()).intValue());
            inboundItem.setGoodsguid(data.getGoodsGUID());
            inboundItem.setGoodsname(data.getGoodsName());
            inboundItem.setUnit(data.getUnit());
            inboundItem.setIfScand((byte) 0);
            inboundItem.setSupplierName(data.getSupplierName());
            inboundItem.setSupplierGuid(data.getSupplierGUID());
            inboundItem.setBacthCode(data.getLot());
            inboundItem.setTraceCode(data.getLabGuid());
            inboundItem.setBarcode(data.getLabGuid());
            inboundItem.setGuid(data.getGuid());

            inboundItem.setAllocation(data.getCubeName());
            inboundItem.setAllocationGuid(data.getCubeGuid());
            inboundItem.setIfInCabinet((byte) 1);
            inboundItem.setIfScand((byte) 1);
            inboundItem.setProductiondate(data.getProductiondate());
            inboundItem.setExpiredate(data.getExpireDate());
            inboundItem.setRfiduid(data.getRfidUid());
            inboundItem.setOperaterId(operaterId);
            inboundItem.setOperaterName(operaterName);
            if (!data.getCubeName().equals(cubeGuid)) {
                for (Cabinet cabinet : guiContext.getCabinets()) {
                    if (cabinet.getCabinetcode().equals(cubeGuid)) {
                        data.setLocGuid(cabinet.getGuid());
                        inboundItem.setAllocation(cabinet.getCabinetcode());
                        inboundItem.setAllocationGuid(cabinet.getGuid());
                        data.setLocName(cabinet.getCabinetcode());
                        data.setCubeName(cabinet.getCabinetcode());
                        data.setCubeGuid(cabinet.getGuid());
                        mfcubestockdetailMapper.updateByPrimaryKeySelective(data);
                        break;

                    }

                }
            }
            if (data.getBillState().equals("O")) {
                inboundItems.add(inboundItem);
            }
        }

        return inboundItems;
    }

    public synchronized List<InboundItem> queryRejectItem() {
        Random r = new Random(100);
        List<InboundItem> inboundItems = new ArrayList();
        for (int i = 0; i <= 20; i++) {
            InboundItem inboundItem = new InboundItem();
            inboundItem.setSrcOrderCode("入库单00" + i);
            inboundItem.setGoods(null);
            inboundItem.setQty(i);
            inboundItem.setScanQty(i);
            inboundItem.setAllocation("002:" + i + ":" + Math.random() * 100);
            if (i % 2 == 0) {
                inboundItem.setIfInCabinet((byte) 1);
            }
            inboundItems.add(inboundItem);
        }
        return inboundItems;
    }


    public void saveInCabinetInfo(List<InboundItem> inboundItems) {
        for (InboundItem item : inboundItems) {
            if (item.getIfInCabinet() == null || item.getIfInCabinet() != 1) {
                continue;
            }
            Mfcubestockdetail cubedetail = mfcubestockdetailMapper.selectByPrimaryKey(item.getGuid());
            cubedetail.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            cubedetail.setBillState("Y");
            cubedetail.setBackTime(new DateTime());
            cubedetail.setBackUsername(item.getOperaterName());
            cubedetail.setStoreguid(guiContext.getStoreguid());
            cubedetail.setStorename(guiContext.getStorename());
            mfcubestockdetailMapper.updateByPrimaryKeySelective(cubedetail);
            baseService.writeLog(item, cubedetail, "6");    //还货
        }
    }
}