LoseAndOverService.java 10 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.springboot.dao.mapper.*;
import cn.csbr.springboot.dao.model.Mfcubestockcout;
import cn.csbr.springboot.dao.model.Mfcubestockdetail;
import tk.mybatis.mapper.entity.Example;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

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;
import com.csbr.util.IdUtils;

/**
 * 损益业务类
 */
@Service
public class LoseAndOverService {
    private static Logger logger = LoggerFactory.getLogger(StockCountService.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 MfcubestockcoutMapper mfcubestockcoutMapper;

    @Autowired
    private BaseService baseService;

    public synchronized List<InboundItem> queryInboundItem(String inboundNo, String goodsInfo) {
        List<String> dataTypes = new ArrayList();
        dataTypes.add("2");
        dataTypes.add("3");
        String goodsInfol = null;
        Example condition = new Example(Mfcubestockcout.class);
        Example.Criteria cr = condition.createCriteria().andEqualTo("rkbillno", inboundNo);
        cr.andEqualTo("processflag", "0");
        cr.andIn("datatype", dataTypes);
        if (!StringUtils.isEmpty(goodsInfo)) {
            goodsInfol = "%" + goodsInfo + "%";
            String sql = "  GoodsName like '" + goodsInfol + "' or LabGuid like'" + goodsInfol + "'";
            cr.andCondition("(" + sql + ")");
        }
        cr.andCondition(" CubeGuid in (select guid from  cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
        List<Mfcubestockcout> mfcubestockdetails = mfcubestockcoutMapper.selectByExample(condition);
        List<InboundItem> inboundItems = new ArrayList();
        //转换库存对象到vo
        for (Mfcubestockcout data : mfcubestockdetails) {
            InboundItem inboundItem = new InboundItem();
            inboundItems.add(inboundItem);
            inboundItem.setScanQty(data.getNumber().intValue());
            inboundItem.setSrcOrderCode(data.getRkbillno());
            inboundItem.setQty(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.setGuid(data.getGuid());
            inboundItem.setIfScand((byte) 1);
            inboundItem.setCheckType(data.getDatatype());
            inboundItem.setGuid(data.getGuid());
            inboundItem.setProductiondate(data.getProductiondate());
            inboundItem.setExpiredate(data.getExpiredate());
        }

        return inboundItems;
    }

    @Transactional
    public List<InboundItem> ActionqueryInboundItem(String cubeGuid, String rfidData) {
        String goodsInfol = "";
        // ActionBacknboundItem(cubeGuid,rfidData);
        String sql = " select * from mfcubestockdetail where billstate!='O' AND CubeGuid in (select guid from  cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "') " +
                " AND DepotGuid='" + guiContext.getLoginUser().getOrgGuid() + "' AND CubeName=" + "'" + cubeGuid + "'  AND  rfiduid  NOT 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());
            inboundItems.add(inboundItem);

        }

        return inboundItems;
    }

    public void saveBanlance(List<InboundItem> items) {

        for (InboundItem item : items) {
            Mfcubestockcout mfcubestockcout = mfcubestockcoutMapper.selectByPrimaryKey(item.getGuid());
            Mfcubestockdetail detail = null;
            String logType = "";
            System.out.println("------------------------------------item checktype:" + item.getCheckType());
            if (item.getCheckType().equals("2")) {
                System.out.println("----------------------------22222222222--------item checktype:" + item.getCheckType());
                Example condition = new Example(Mfcubestockdetail.class);
                condition.createCriteria().andEqualTo("labguid", item.getBarcode());
                List<Mfcubestockdetail> details = mfcubestockdetailMapper.selectByExample(condition);
                if (details.size() > 0) {
                    detail = details.get(0);
                    mfcubestockdetailMapper.deleteByExample(condition);

                } else {
                    detail = toMfCubstockdetail(mfcubestockcout);
                }
                logType = "5";
            } else if (item.getCheckType().equals("3")) {
                detail = toMfCubstockdetail(mfcubestockcout);
                mfcubestockdetailMapper.insert(detail);
                logType = "4";
            } else {
                continue;
            }
            baseService.writeLog(item, detail, logType);
         //   baseService.sumNumber(item, detail);
            mfcubestockcout.setProcessflag("1");
            mfcubestockcout.setProcessoperaterguid(guiContext.getLoginUser().getOrgGuid());
            mfcubestockcout.setProcessoperatername(guiContext.getLoginUser().getRealName());
            mfcubestockcout.setProcessTime(new Date());
            mfcubestockcoutMapper.updateByPrimaryKey(mfcubestockcout);
        }

    }

    private Mfcubestockdetail toMfCubstockdetail(Mfcubestockcout cubedetail) {
        Mfcubestockdetail cubedetailout = new Mfcubestockdetail();
        cubedetailout.setDepotGuid(cubedetail.getDepotguid());
        cubedetailout.setDepotName(cubedetail.getDepotname());
        cubedetailout.setCubeGuid(cubedetail.getCubeguid());
        cubedetailout.setCubeName(cubedetail.getCubename());
        cubedetailout.setLocGuid(cubedetail.getLocguid());
        cubedetailout.setLocName(cubedetail.getLocname());
        cubedetailout.setLabGuid(cubedetail.getLabguid());
        cubedetailout.setGoodsGUID(cubedetail.getGoodsguid());
        cubedetailout.setGoodsName(cubedetail.getGoodsname());
        cubedetailout.setUnit(cubedetail.getUnit());
        cubedetailout.setLot(cubedetail.getLot());
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(cubedetail.getProductiondate());
        String time2 = df.format(cubedetail.getExpiredate());
        String time3 = df.format(cubedetail.getSterilantdate());
        String time4 = df.format(cubedetail.getSterilantexpdate());
        cubedetailout.setProductiondate(Timestamp.valueOf(time));
        cubedetailout.setExpireDate(Timestamp.valueOf(time2));
        cubedetailout.setSterilantLot(cubedetail.getSterilantlot());
        cubedetailout.setSterilantDate(Timestamp.valueOf(time3));
        cubedetailout.setSterilantEXPDate(Timestamp.valueOf(time4));
        cubedetailout.setNumber(cubedetail.getNumber().toString());
        cubedetailout.setSupplierGUID(cubedetail.getSupplierguid());
        cubedetailout.setSupplierName(cubedetail.getSuppliername());
        cubedetailout.setRkBillNo(cubedetail.getRkbillno());
        cubedetailout.setPriceBuy(cubedetail.getPricebuy().toString());
        cubedetailout.setAmountBuy(cubedetail.getAmountbuy().toString());
        cubedetailout.setCreateTime(new Timestamp(System.currentTimeMillis()));
        cubedetailout.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        cubedetailout.setGuid(IdUtils.getUUID());

        return cubedetailout;
    }
}