CyclecountAPIService.java 2.48 KB
package com.huaheng.api.general.service;

import com.alibaba.fastjson.JSON;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.inventory.cyclecountAdjust.domain.CyclecountAdjust;
import com.huaheng.pc.inventory.cyclecountAdjust.domain.CyclecountAdjustModel;
import com.huaheng.pc.inventory.cyclecountAdjust.mapper.CyclecountAdjustMapperAuto;
import com.huaheng.pc.inventory.cyclecountAdjust.service.ICycleconutAdjustService;
import com.huaheng.pc.inventory.cyclecountAdjustDetail.domain.CyclecountAdjustDetail;
import com.huaheng.pc.inventory.cyclecountAdjustDetail.service.ICyclecountAdjustDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *  盘点差异接口服务层
 *    @author huaheng
 *    @date 2019-1-8
 *
 *
 *
 */

@Service
public class CyclecountAPIService {

    @Resource
    private CyclecountAdjustMapperAuto cyclecountAdjustMapperAuto;
    @Resource
    private ICycleconutAdjustService cycleconutAdjustService;
    @Resource
    private ICyclecountAdjustDetailService cyclecountAdjustDetailService;

    public AjaxResult confirm(String url) {

        //查找状态为10的盘点差异主单
        CyclecountAdjust cyclecountAdjust=new CyclecountAdjust();
        cyclecountAdjust.setStatus(10);
        cyclecountAdjust=cyclecountAdjustMapperAuto.selectFirstEntity(cyclecountAdjust);
        if(cyclecountAdjust==null){
            return AjaxResult.error("没有盘点差异上传");
        }
        //通过主单id找到子单
        CyclecountAdjustDetail cyclecountAdjustDetail=new CyclecountAdjustDetail();
        cyclecountAdjustDetail.setCyclecountAdjustCode(cyclecountAdjust.getCode());
        List<CyclecountAdjustDetail> cyclecountAdjustDetails=cyclecountAdjustDetailService.selectListEntityByEqual(cyclecountAdjustDetail);

        //把主单和子单整合到一起
        CyclecountAdjustModel cyclecountAdjustModel=new CyclecountAdjustModel();
        cyclecountAdjustModel.setCyclecountAdjust(cyclecountAdjust);
        cyclecountAdjustModel.setCyclecountAdjustDetails(cyclecountAdjustDetails);

        String JsonParam = JSON.toJSONString(cyclecountAdjustModel);
        String result = HttpUtils.sendPost(url, JsonParam);
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        cyclecountAdjust.setStatus(20);
        cycleconutAdjustService.updateByModel(cyclecountAdjust);
        return ajaxResult;
    }

}