|
@@ -0,0 +1,300 @@
|
|
|
+package com.platform.service.yongyou.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.enums.DataFilterTypeEnum;
|
|
|
+import com.platform.common.model.UserInfo;
|
|
|
+import com.platform.common.util.*;
|
|
|
+import com.platform.common.yongyou.request.*;
|
|
|
+import com.platform.common.yongyou.response.*;
|
|
|
+import com.platform.dao.bean.MyPage;
|
|
|
+import com.platform.dao.bean.MyVOPage;
|
|
|
+import com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO;
|
|
|
+import com.platform.dao.dto.store.SparePickDetailDTO;
|
|
|
+import com.platform.dao.dto.store.SparePickFormDTO;
|
|
|
+import com.platform.dao.dto.store.SpareRestoreFormDTO;
|
|
|
+import com.platform.dao.entity.store.*;
|
|
|
+import com.platform.dao.enums.SparePickFormStatusEnum;
|
|
|
+import com.platform.dao.mapper.sqarepartmanage.SparePartInfoMapper;
|
|
|
+import com.platform.dao.mapper.store.SparePickDetailMapper;
|
|
|
+import com.platform.dao.mapper.store.SparePickFormMapper;
|
|
|
+import com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO;
|
|
|
+import com.platform.dao.vo.query.store.SparePickDetailVO;
|
|
|
+import com.platform.dao.vo.query.store.SparePickFormVO;
|
|
|
+import com.platform.dao.vo.query.store.SpareRestoreDetailVO;
|
|
|
+import com.platform.dao.vo.query.store.SpareRestoreFormVO;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.store.*;
|
|
|
+import com.platform.service.yongyou.YongyouService;
|
|
|
+import handler.yongyou.GetCurrentStockHandler;
|
|
|
+import handler.yongyou.LoginHandler;
|
|
|
+import handler.yongyou.OtherOutHandler;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 用友 service 实现类
|
|
|
+ * @Author liuyu
|
|
|
+ * @Date 2020-06-09 10:50:37
|
|
|
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service("yongyouService")
|
|
|
+public class YongyouServiceImpl implements YongyouService {
|
|
|
+ private SparePickFormService sparePickFormService;
|
|
|
+ private SparePickDetailService sparePickDetailService;
|
|
|
+ private SpareRestoreFormService spareRestoreFormService;
|
|
|
+ private SpareRestoreDetailService spareRestoreDetailService;
|
|
|
+ private String token_key = "yongyou-token";
|
|
|
+
|
|
|
+ private String geToken() {
|
|
|
+ String token = RedisUtils.getString(token_key);
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ LoginHandler handler = new LoginHandler();
|
|
|
+ LoginRequest req = new LoginRequest();
|
|
|
+ req.setCSrv("");
|
|
|
+ req.setPAccId("");
|
|
|
+ req.setCSrv("");
|
|
|
+ req.setPUserId("");
|
|
|
+ req.setPPassword("");
|
|
|
+ req.setPDate(DateUtils.dateToString(LocalDate.now(), DateUtils.PATTERN_YMD));
|
|
|
+ handler.setRequest(req);
|
|
|
+ R r = handler.handler();
|
|
|
+ LoginResponse loginResponse = (LoginResponse) r.getData();
|
|
|
+ Login login = loginResponse.getData();
|
|
|
+ token = login.getToken();
|
|
|
+ RedisUtils.setString(token_key, token);
|
|
|
+ return token;
|
|
|
+ } else {
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询存量分页
|
|
|
+ *
|
|
|
+ * @param record
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AbstractPageResultBean<SparePartInfoVO> selectPageList(SparePartInfoDTO record, int pageNum, int pageSize) {
|
|
|
+ // 已生成情况,直接推送
|
|
|
+ GetCurrentStockHandler handler = new GetCurrentStockHandler();
|
|
|
+ GetCurrentStockRequest req = new GetCurrentStockRequest();
|
|
|
+ req.setToken(geToken());
|
|
|
+ req.setConn("");
|
|
|
+ req.setPageNum(pageNum);
|
|
|
+ req.setPageSize(pageSize);
|
|
|
+ req.setStcWhere("");
|
|
|
+ handler.setRequest(req);
|
|
|
+ R r = handler.handler();
|
|
|
+ GetCurrentStockResponse response = (GetCurrentStockResponse) r.getData();
|
|
|
+ List<GetCurrentStock> datas = response.getData();
|
|
|
+ List<SparePartInfoVO> partInfoVOS = new ArrayList<>();
|
|
|
+ for (GetCurrentStock stockResponse : datas) {
|
|
|
+ SparePartInfoVO partInfoVO = new SparePartInfoVO();
|
|
|
+ partInfoVO.setId(stockResponse.getPartId() + "");
|
|
|
+ partInfoVO.setName(stockResponse.getCInvName());
|
|
|
+ partInfoVO.setGgxh(stockResponse.getCInvStd());
|
|
|
+ partInfoVO.setNum(stockResponse.getIQuantity());
|
|
|
+ partInfoVOS.add(partInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ MyVOPage<SparePartInfoVO> myVOPage = new MyVOPage<>();
|
|
|
+ myVOPage.setPageNum(pageNum);
|
|
|
+ myVOPage.setPageSize(pageSize);
|
|
|
+ Page page = new Page(pageNum, pageSize);
|
|
|
+ page.setTotal(response.getTotal());
|
|
|
+ myVOPage.setPages(page.getPages());
|
|
|
+ myVOPage.setTotal(Long.valueOf(response.getTotalNum()));
|
|
|
+ myVOPage.setRows(partInfoVOS);
|
|
|
+ return myVOPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交领用单到出库单
|
|
|
+ *
|
|
|
+ * @param id 领用单id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addOutForm(String id) {
|
|
|
+ SparePickFormVO sparePickFormVO = sparePickFormService.getDetail(id);
|
|
|
+ OtherOutVouch otherOutVouch = new OtherOutVouch();
|
|
|
+ OtherOutMain otherOutMain = new OtherOutMain();
|
|
|
+ List<OtherOutDetail> otherOutDetail = new ArrayList<>();
|
|
|
+ otherOutVouch.setOtherOutMain(otherOutMain);
|
|
|
+ otherOutVouch.setOtherOutDetail(otherOutDetail);
|
|
|
+ otherOutMain.setBrdflag(0);
|
|
|
+ otherOutMain.setCvouchtype("0");
|
|
|
+ otherOutMain.setCbustype("其他出库");
|
|
|
+ otherOutMain.setCwhcode("034");
|
|
|
+ otherOutMain.setDdate(DateUtils.dateToString(LocalDateTime.now()));
|
|
|
+ otherOutMain.setVt_id("85");
|
|
|
+ otherOutMain.setBisstqc(false);
|
|
|
+ otherOutMain.setCcode("0000000006");
|
|
|
+ otherOutMain.setCrdcode("2a");
|
|
|
+ otherOutMain.setCsource("库存");
|
|
|
+
|
|
|
+ otherOutMain.setCdefine1(sparePickFormVO.getId());// 保存设备系统的id
|
|
|
+ otherOutMain.setCmaker(sparePickFormVO.getCreatedUserName());// 申请人名称
|
|
|
+ List<SparePickDetailVO> detailVOS = sparePickFormVO.getDetailList();
|
|
|
+ for (SparePickDetailVO vo : detailVOS) {
|
|
|
+ OtherOutDetail detail = new OtherOutDetail();
|
|
|
+ detail.setId(vo.getSpareId());
|
|
|
+ detail.setCinvcode(vo.getNo());
|
|
|
+ detail.setIquantity(vo.getNum());
|
|
|
+ detail.setIunitcost(vo.getPrice());
|
|
|
+ detail.setIprice(vo.getTotalPrice());
|
|
|
+ otherOutDetail.add(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 推送数据
|
|
|
+ OtherOutHandler handler = new OtherOutHandler();
|
|
|
+ OtherOutAddRequest req = new OtherOutAddRequest();
|
|
|
+ req.setCAcc_ID("");
|
|
|
+ req.setOtherOutVouch(otherOutVouch);
|
|
|
+ req.setToken(geToken());
|
|
|
+ req.setConn("");
|
|
|
+ handler.setRequest(req);
|
|
|
+ R r = handler.handler();
|
|
|
+ OtherOutAddResponse response = (OtherOutAddResponse) r.getData();
|
|
|
+ String data = response.getData();
|
|
|
+
|
|
|
+ // 保存用友出库单数据
|
|
|
+ sparePickFormService.updateModelByIdYongyou(sparePickFormVO.getId(), data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 领用单用友回调,回写实际数量和状态
|
|
|
+ *
|
|
|
+ * @param jsonStr
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void backOutForm(String jsonStr) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonStr);
|
|
|
+ String id = (String) jsonObject.get("id");
|
|
|
+ String status = (String) jsonObject.get("status");
|
|
|
+ String time = (String) jsonObject.get("time");
|
|
|
+ JSONArray detailList = (JSONArray) jsonObject.get("detailList");
|
|
|
+
|
|
|
+ for (Iterator<Object> iterator = detailList.iterator(); iterator.hasNext(); ) {
|
|
|
+ JSONObject next = (JSONObject) iterator.next();
|
|
|
+ String spareId = next.getString("spareId");
|
|
|
+ String spareNum = next.getString("spareNum");
|
|
|
+ String detailId = next.getString("detailId");
|
|
|
+ String spareGGXH = next.getString("spareGGXH");
|
|
|
+ SparePickDetail sparePickDetail = new SparePickDetail();
|
|
|
+ sparePickDetail.setId(detailId);
|
|
|
+ sparePickDetail.setNum(new BigDecimal(spareNum));
|
|
|
+ sparePickDetail.setSpareGgxh(spareGGXH);
|
|
|
+ sparePickDetailService.modModelByPrimaryKey(sparePickDetail);
|
|
|
+ }
|
|
|
+ SparePickForm sparePickForm = new SparePickForm();
|
|
|
+ sparePickForm.setStatus(2);
|
|
|
+ sparePickForm.setId(id);
|
|
|
+ sparePickFormService.modModelByPrimaryKey(sparePickForm);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交退库单到出库单
|
|
|
+ *
|
|
|
+ * @param id 领用单id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addRestoreForm(String id) {
|
|
|
+ SpareRestoreFormVO sparePickFormVO = spareRestoreFormService.getDetail(id);
|
|
|
+ OtherOutVouch otherOutVouch = new OtherOutVouch();
|
|
|
+ OtherOutMain otherOutMain = new OtherOutMain();
|
|
|
+ List<OtherOutDetail> otherOutDetail = new ArrayList<>();
|
|
|
+ otherOutVouch.setOtherOutMain(otherOutMain);
|
|
|
+ otherOutVouch.setOtherOutDetail(otherOutDetail);
|
|
|
+ otherOutMain.setBrdflag(0);
|
|
|
+ otherOutMain.setCvouchtype("0");
|
|
|
+ otherOutMain.setCbustype("其他出库");
|
|
|
+ otherOutMain.setCwhcode("034");
|
|
|
+ otherOutMain.setDdate(DateUtils.dateToString(LocalDateTime.now()));
|
|
|
+ otherOutMain.setVt_id("85");
|
|
|
+ otherOutMain.setBisstqc(false);
|
|
|
+ otherOutMain.setCcode("0000000006");
|
|
|
+ otherOutMain.setCrdcode("2a");
|
|
|
+ otherOutMain.setCsource("库存");
|
|
|
+
|
|
|
+ otherOutMain.setCdefine1(sparePickFormVO.getId());// 保存设备系统的id
|
|
|
+ otherOutMain.setCmaker(sparePickFormVO.getCreatedUserName());// 申请人名称
|
|
|
+ List<SpareRestoreDetailVO> detailVOS = sparePickFormVO.getDetailList();
|
|
|
+ for (SpareRestoreDetailVO vo : detailVOS) {
|
|
|
+ OtherOutDetail detail = new OtherOutDetail();
|
|
|
+ detail.setId(vo.getSpareId());
|
|
|
+ detail.setIquantity(vo.getNum().negate() );// 取负数
|
|
|
+ otherOutDetail.add(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 推送数据
|
|
|
+ OtherOutHandler handler = new OtherOutHandler();
|
|
|
+ OtherOutAddRequest req = new OtherOutAddRequest();
|
|
|
+ req.setCAcc_ID("");
|
|
|
+ req.setOtherOutVouch(otherOutVouch);
|
|
|
+ req.setToken(geToken());
|
|
|
+ req.setConn("");
|
|
|
+ handler.setRequest(req);
|
|
|
+ R r = handler.handler();
|
|
|
+ OtherOutAddResponse response = (OtherOutAddResponse) r.getData();
|
|
|
+ String data = response.getData();
|
|
|
+
|
|
|
+ // 保存用友出库单数据
|
|
|
+ spareRestoreFormService.updateModelByIdYongyou(sparePickFormVO.getId(), data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退库单用友回调
|
|
|
+ *
|
|
|
+ * @param jsonStr
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void backRestoreForm(String jsonStr) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonStr);
|
|
|
+ String id = (String) jsonObject.get("id");
|
|
|
+ String status = (String) jsonObject.get("status");
|
|
|
+ String time = (String) jsonObject.get("time");
|
|
|
+ JSONArray detailList = (JSONArray) jsonObject.get("detailList");
|
|
|
+
|
|
|
+ for (Iterator<Object> iterator = detailList.iterator(); iterator.hasNext(); ) {
|
|
|
+ JSONObject next = (JSONObject) iterator.next();
|
|
|
+ String spareId = next.getString("spareId");
|
|
|
+ String spareNum = next.getString("spareNum");
|
|
|
+ String detailId = next.getString("detailId");
|
|
|
+ String spareGGXH = next.getString("spareGGXH");
|
|
|
+ SpareRestoreDetail sparePickDetail = new SpareRestoreDetail();
|
|
|
+ sparePickDetail.setId(detailId);
|
|
|
+ sparePickDetail.setNum(new BigDecimal(spareNum));
|
|
|
+ sparePickDetail.setSpareGgxh(spareGGXH);
|
|
|
+ spareRestoreDetailService.modModelByPrimaryKey(sparePickDetail);
|
|
|
+ }
|
|
|
+ SpareRestoreForm sparePickForm = new SpareRestoreForm();
|
|
|
+ sparePickForm.setStatus(2);
|
|
|
+ sparePickForm.setId(id);
|
|
|
+ spareRestoreFormService.modModelByPrimaryKey(sparePickForm);
|
|
|
+ }
|
|
|
+}
|