BaseService.java 14.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.springboot.dao.mapper.*;
import cn.csbr.springboot.dao.model.*;
import cn.hutool.core.date.DateTime;
import com.csbr.util.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
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.util.CollectionUtils;

import com.csbr.mybatis.CommonMapper;
import com.csbr.util.IdUtils;

/**
 * 操作流水类
 */
@Service
public class BaseService {
    private static final Logger log = LoggerFactory.getLogger(BaseService.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 MfcubestockPickstatementMapper mfcubestockPickstatementMapper;

    @Autowired
    private MfcubestockMapper mfcubestockMapper;
    @Autowired
    private SpdWvdetailScendMapper spdWvdetailScendMapper;
    @Autowired
    private HisGoodsMapper hisGoodsMapper;
    @Autowired
    private  SysUserMapper sysUserMapper;
    @Autowired
    private SysOrgMapper sysOrgMapper;

    public synchronized int writeLog(InboundItem item, Mfcubestockdetail cubedetail, String type) {


        Mfcubestockstatement mfcubestockstatement = new Mfcubestockstatement();
        mfcubestockstatement.setGuid(IdUtils.getUUID());
        mfcubestockstatement.setDepotguid(cubedetail.getDepotGuid());
        mfcubestockstatement.setDepotname(cubedetail.getDepotName());
        mfcubestockstatement.setCubeguid(item.getAllocationGuid());
        mfcubestockstatement.setCubename(item.getAllocation());
        mfcubestockstatement.setLocguid(item.getAllocationGuid());
        mfcubestockstatement.setLocname(item.getAllocation());
        mfcubestockstatement.setLabguid(cubedetail.getLabGuid());
        mfcubestockstatement.setGoodsguid(cubedetail.getGoodsGUID());
        mfcubestockstatement.setGoodsname(cubedetail.getGoodsName());
        mfcubestockstatement.setUnit(cubedetail.getUnit());
        mfcubestockstatement.setLot(cubedetail.getLot());
        mfcubestockstatement.setProductiondate(cubedetail.getProductiondate());
        mfcubestockstatement.setExpiredate(cubedetail.getExpireDate());
        mfcubestockstatement.setCreateTime(new Date());
        mfcubestockstatement.setUpdateTime(new Date());
        mfcubestockstatement.setInputdate(new Date());
        mfcubestockstatement.setOperaterguid(item.getOperaterId());
        mfcubestockstatement.setOperatername(item.getOperaterName());
        mfcubestockstatement.setType(type);
        mfcubestockstatement.setSuppliername(cubedetail.getSupplierName());
        mfcubestockstatement.setSupplierguid(cubedetail.getSupplierGUID());
        mfcubestockstatement.setCubeDetailGuid(cubedetail.getCubeGuid());
        mfcubestockstatement.setQty(BigDecimal.ONE);
        mfcubestockstatement.setBillno(cubedetail.getRkBillNo());
        mfcubestockstatement.setBarcode(cubedetail.getLabGuid());
        mfcubestockstatement.setSts("N");
        mfcubestockstatement.setBacksts("N");

        SysUser sysUser=sysUserMapper.selectByPrimaryKey(item.getOperaterId());
        SysOrg sysOrg=sysOrgMapper.selectByPrimaryKey(sysUser.getOrgguid());
        mfcubestockstatement.setOperaterdeptguid(sysOrg.getGuid());
        mfcubestockstatement.setOperaterdeptguid(sysOrg.getOrgname());
        //暂定设置 退货的时候 加上供应商区分 ,使用varchar4字段

        Example example = new Example(HisGoods.class);

        example.createCriteria().andEqualTo("guid", cubedetail.getGoodsGUID());
        List<HisGoods> hisGoodsList = hisGoodsMapper.selectByExample(example);
        HisGoods hisGoods = hisGoodsMapper.selectByPrimaryKey(cubedetail.getGoodsGUID());


            //        Goodscode
        mfcubestockstatement.setGoodscode(hisGoods.getGoodscode());
//        Goodsspec
            mfcubestockstatement.setGoodsspec(hisGoods.getGoodsspec());
//        Manufacturer
            mfcubestockstatement.setManufacturer(hisGoods.getProducer());
//        Registkey
            mfcubestockstatement.setRegistkey(hisGoods.getRegistkey());

        mfcubestockstatement.setStoreguid(guiContext.getStoreguid());

        mfcubestockstatement.setRfiduid(item.getRfiduid());
        int insertCount = mfcubestockstatementMapper.insert(mfcubestockstatement);
      //增加取货表
        if(type.equals("2"))
        {
            MfcubestockPickstatement mfcubestockPickstatement=new MfcubestockPickstatement();
            BeanUtils.copyProperties(mfcubestockstatement,mfcubestockPickstatement);
            insertCount = mfcubestockPickstatementMapper.insert(mfcubestockPickstatement);
        }
        //跟新取货记录为已还货
        else if(type.equals("6")) {
            Example usestatementcondition = new Example(MfcubestockPickstatement.class);
            //操作的这个表数据为空,不知道有没有用到,暂时也修改一下
            //usestatementcondition.createCriteria().andEqualTo("barcode",cubedetail.getLabguid()).andEqualTo("type", "2").andEqualTo("backsts", "N");
            usestatementcondition.createCriteria().andEqualTo("rfiduid",cubedetail.getRfidUid()).andEqualTo("type", "2").andEqualTo("backsts", "N");
            List<MfcubestockPickstatement> usemfcubestockPickstatementList = mfcubestockPickstatementMapper.selectByExample(usestatementcondition);
            for (MfcubestockPickstatement mfcubestockPickstatementone : usemfcubestockPickstatementList) {
                mfcubestockPickstatementone.setBacksts("Y");
                mfcubestockPickstatementone.setBacktime(new DateTime());
                mfcubestockPickstatementone.setBackusername(item.getOperaterName());
                mfcubestockPickstatementMapper.updateByPrimaryKey(mfcubestockPickstatementone);
                Mfcubestockstatement mfcubestockstatement1=new Mfcubestockstatement();
                BeanUtils.copyProperties(mfcubestockPickstatementone,mfcubestockstatement1);
                mfcubestockstatementMapper.updateByPrimaryKey(mfcubestockstatement1);
            }
        }
        return insertCount;
    }

    public int sumNumber(InboundItem item, Mfcubestockdetail cubedetail) {
        Example condition = new Example(Mfcubestock.class);
        condition.createCriteria().andEqualTo("depotguid", guiContext.getLoginUser().getOrgGuid()).andEqualTo("cubeguid", cubedetail.getCubeGuid())
                 .andEqualTo("goodsguid", cubedetail.getGoodsGUID()).andEqualTo("lot", cubedetail.getLot()).andEqualTo("expiredate", cubedetail.getExpireDate());
//                    .andEqualTo("sterilantdate",cubedetail.getSterilantdate()).andEqualTo("sterilantexpdate",cubedetail.getSterilantexpdate())
//                    .andEqualTo("sterilantlot",cubedetail.getSterilantlot());

        //这里在汇总更新
        Example dataQ = new Example(Mfcubestockdetail.class);
        dataQ.createCriteria().andEqualTo("depotGuid", guiContext.getLoginUser().getOrgGuid()).andEqualTo("cubeGuid", item.getAllocationGuid())
             .andEqualTo("goodsGUID", item.getGoodsguid()).andEqualTo("lot", cubedetail.getLot()).andEqualTo("expireDate", cubedetail.getExpireDate());
        List<Mfcubestockdetail> details = mfcubestockdetailMapper.selectByExample(dataQ);
        BigDecimal number = new BigDecimal(0);
        for (Mfcubestockdetail mfcubestockdetail : details) {
            number = number.add(new BigDecimal(mfcubestockdetail.getNumber()));
        }
        List<Mfcubestock> mfcubestocks = mfcubestockMapper.selectByExample(condition);
        int updateCount = 0;
        if (mfcubestocks.size() > 0) {
            mfcubestocks.get(0).setStocknumber(number);

            updateCount = mfcubestockMapper.updateByPrimaryKey(mfcubestocks.get(0));
        }
        return updateCount;
    }

    public void writeLog(InboundItem item, SpdWvdetail wvdetail, String type) {


        Mfcubestockstatement mfcubestockstatement = new Mfcubestockstatement();
        mfcubestockstatement.setGuid(IdUtils.getUUID());
        mfcubestockstatement.setStoreguid(guiContext.getStoreguid());
        mfcubestockstatement.setDepotguid(wvdetail.getOrgguid());
        mfcubestockstatement.setDepotname(wvdetail.getOrgname());
        mfcubestockstatement.setCubeguid(item.getAllocationGuid());
        mfcubestockstatement.setCubename(item.getAllocation());
        mfcubestockstatement.setLocguid(item.getAllocationGuid());
        mfcubestockstatement.setLocname(item.getAllocation());
        mfcubestockstatement.setLabguid(item.getBarcode());
        mfcubestockstatement.setGoodsguid(wvdetail.getGoodsguid());
        mfcubestockstatement.setGoodsname(wvdetail.getGoodsname());
        mfcubestockstatement.setUnit(wvdetail.getUnit());
        mfcubestockstatement.setLot(wvdetail.getLot());
        mfcubestockstatement.setSupplierguid(item.getSupplierGuid());
        mfcubestockstatement.setSuppliername(item.getSupplierName());
        mfcubestockstatement.setProductiondate(wvdetail.getProductiondate());
        mfcubestockstatement.setExpiredate(wvdetail.getExpiredate());
        mfcubestockstatement.setCreateTime(new Date());
        mfcubestockstatement.setUpdateTime(new Date());
        mfcubestockstatement.setInputdate(new Date());
        mfcubestockstatement.setOperaterguid(item.getOperaterId());
        mfcubestockstatement.setOperatername(item.getOperaterName());
        mfcubestockstatement.setType(type);

        mfcubestockstatement.setQty(wvdetail.getMvqty());
        mfcubestockstatement.setBillno(item.getSrcOrderCode());
        mfcubestockstatement.setBarcode(item.getBarcode());

//        Goodscode
        mfcubestockstatement.setGoodscode(item.getGoodscode());
//        Goodsspec
        mfcubestockstatement.setGoodsspec(item.getGoodsspec());
//        Manufacturer
        mfcubestockstatement.setManufacturer(item.getManufacturer());
//        Registkey
        mfcubestockstatement.setRegistkey(item.getRegistkey());

        mfcubestockstatement.setRfiduid(item.getRfiduid());
        mfcubestockstatement.setOperaterguid(item.getOperaterId());
        mfcubestockstatement.setOperatername(item.getOperaterName());

        SysUser sysUser=sysUserMapper.selectByPrimaryKey(item.getOperaterId());
        SysOrg sysOrg=sysOrgMapper.selectByPrimaryKey(sysUser.getOrgguid());
        mfcubestockstatement.setOperaterdeptguid(sysOrg.getGuid());
        mfcubestockstatement.setOperaterdeptguid(sysOrg.getOrgname());
        mfcubestockstatementMapper.insert(mfcubestockstatement);
    }

    public void sumNumber(SpdWvdetail wvdetail, Mfcubestockdetail cubedetail) {
        Example condition = new Example(Mfcubestock.class);
        condition.createCriteria().andEqualTo("depotguid", guiContext.getLoginUser().getOrgGuid()).andEqualTo("cubeguid", cubedetail.getCubeGuid()).andEqualTo("productiondate", cubedetail.getExpireDate())
                 .andEqualTo("goodsguid", cubedetail.getGoodsGUID()).andEqualTo("lot", cubedetail.getLot()).andEqualTo("expiredate", cubedetail.getExpireDate());
//                    .andEqualTo("sterilantdate",cubedetail.getSterilantdate()).andEqualTo("sterilantexpdate",cubedetail.getSterilantexpdate())
//                    .andEqualTo("sterilantlot",cubedetail.getSterilantlot());
        int count = mfcubestockMapper.selectCountByExample(condition);
        if (count == 0) {//这里预插入一条
            Mfcubestock ms = new Mfcubestock();
            ms.setGuid(IdUtils.getUUID());
            ms.setDepotguid(guiContext.getLoginUser().getOrgGuid());
            ms.setDepotname(guiContext.getLoginUser().getOrgName());
            ms.setCubeguid(cubedetail.getCubeGuid());
            ms.setCubename(cubedetail.getCubeName());
            ms.setGoodsguid(wvdetail.getGoodsguid());
            ms.setGoodsname(wvdetail.getGoodsname());
            ms.setUnit(wvdetail.getUnit());
            ms.setLot(wvdetail.getLot());
            ms.setStocknumber(wvdetail.getMvqty());
            ms.setProductiondate(wvdetail.getProductiondate());
            ms.setExpiredate(wvdetail.getExpiredate());
//                ms.setSterilantlot(wvdetail.getSterilantlot());
//                ms.setSterilantdate(wvdetail.getSterilantdate());
//                ms.setSterilantexpdate(wvdetail.getSterilantexpdate());
            ms.setCreateTime(new Date());
            ms.setUpdateTime(new Date());
            mfcubestockMapper.insert(ms);
            return;
        }

        //这里在汇总更新
        Example dataQ = new Example(Mfcubestockdetail.class);
        condition.createCriteria().andEqualTo("depotGuid", guiContext.getLoginUser().getOrgGuid()).andEqualTo("cubeGuid", cubedetail.getCubeGuid()).andEqualTo("productiondate", cubedetail.getExpireDate())
                 .andEqualTo("goodsGUID", cubedetail.getGoodsGUID()).andEqualTo("lot", cubedetail.getLot()).andEqualTo("expireDate", cubedetail.getExpireDate());
        List<Mfcubestockdetail> details = mfcubestockdetailMapper.selectByExample(dataQ);
        BigDecimal number = new BigDecimal(0);
//        for (Mfcubestockdetail mfcubestockdetail : details) {
//            number = number.add(mfcubestockdetail.getNumber());
//        }
        List<Mfcubestock> mfcubestocks = mfcubestockMapper.selectByExample(condition);
        mfcubestocks.get(0).setUpdateTime(new Date());
        mfcubestocks.get(0).setStocknumber(mfcubestocks.get(0).getStocknumber().add(new BigDecimal(cubedetail.getNumber())));
        mfcubestockMapper.updateByPrimaryKey(mfcubestocks.get(0));
    }


    public List<Map> queryCabinetList(String orgid) {
        String sql = "select * from cabinet where sysorgguid='" + orgid + "'";

        List<Map> CabinetList = commonMapper.queryList(sql);

        return CabinetList;
    }
}