|
@@ -1,28 +1,119 @@
|
|
|
package com.dk.mdm.service.sale;
|
|
package com.dk.mdm.service.sale;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
|
|
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
|
|
+import com.dk.common.response.ResponseResultUtil;
|
|
|
|
|
+import com.dk.common.response.ResponseResultVO;
|
|
|
|
|
+import com.dk.mdm.infrastructure.convert.sale.OutReturnConvert;
|
|
|
|
|
+import com.dk.mdm.infrastructure.convert.sale.OutReturnItemConvert;
|
|
|
|
|
+import com.dk.mdm.mapper.sale.OutReturnItemMapper;
|
|
|
import com.dk.mdm.model.pojo.sale.OutReturn;
|
|
import com.dk.mdm.model.pojo.sale.OutReturn;
|
|
|
|
|
+import com.dk.mdm.model.pojo.sale.OutReturnItem;
|
|
|
import com.dk.mdm.mapper.sale.OutReturnMapper;
|
|
import com.dk.mdm.mapper.sale.OutReturnMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
|
|
+import com.dk.mdm.model.vo.sale.OutReturnItemVO;
|
|
|
|
|
+import com.dk.mdm.model.vo.sale.OutReturnVO;
|
|
|
|
|
+import com.dk.mdm.service.common.CommonService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
@Service
|
|
@Service
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public class OutReturnService extends BaseService<OutReturn> {
|
|
public class OutReturnService extends BaseService<OutReturn> {
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public String getPrimaryKey() {
|
|
|
|
|
- return "return_id";
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getPrimaryKey() {
|
|
|
|
|
+ return "return_id";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BaseMapper<OutReturn> getRepository() {
|
|
|
|
|
+ return outReturnMapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutReturnMapper outReturnMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutReturnItemService outReturnItemService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutReturnItemMapper outReturnItemMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonService commonService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutReturnConvert outReturnConvert;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutReturnItemConvert outReturnItemConvert;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 新建方法
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public ResponseResultVO<?> insert(OutReturnVO outReturnVO) {
|
|
|
|
|
+
|
|
|
|
|
+ // 获取单号
|
|
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.ORDER.getName(), false);
|
|
|
|
|
+ outReturnVO.setReturnId(codeMap.get("outId").toString()).setReturnNo(codeMap.get("outNote").toString())
|
|
|
|
|
+ .setReturnType(Constant.DocumentType.OUT_RETURN.getName());
|
|
|
|
|
+ // 转化实体
|
|
|
|
|
+ OutReturn outReturn = outReturnConvert.convertToPo(outReturnVO);
|
|
|
|
|
+ // 订单总单保存
|
|
|
|
|
+ super.insert(outReturn);
|
|
|
|
|
+
|
|
|
|
|
+ // 明细保存
|
|
|
|
|
+ if (outReturnVO.getItemList() != null && outReturnVO.getItemList().size() > 0) {
|
|
|
|
|
+ for (OutReturnItemVO outReturnItemVO : outReturnVO.getItemList()) {
|
|
|
|
|
+ OutReturnItem outReturnItem = outReturnItemConvert.convertToPo(outReturnItemVO);
|
|
|
|
|
+ outReturnItem.setReturnId(outReturn.getReturnId()).setCpId(outReturn.getCpId()).setIntoStatus(Constant.IntoStatus.DAIRUKU.getName());
|
|
|
|
|
+ outReturnItemMapper.insert(outReturnItem);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public BaseMapper<OutReturn> getRepository() {
|
|
|
|
|
- return outReturnMapper;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 编辑方法
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public ResponseResultVO<Boolean> update(OutReturnVO outReturnVO) {
|
|
|
|
|
+ // 转化实体
|
|
|
|
|
+ OutReturn outReturn = outReturnConvert.convertToPo(outReturnVO);
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private OutReturnMapper outReturnMapper;
|
|
|
|
|
|
|
+ // 编辑的
|
|
|
|
|
+ List<OutReturnItemVO> editOutReturnItemVOList = outReturnVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
|
|
|
+ for (OutReturnItemVO outReturnItemVO : editOutReturnItemVOList) {
|
|
|
|
|
+ // 入库中数量不能小于入库数量
|
|
|
|
|
+ if (outReturnItemVO.getIntoingQty().compareTo(outReturnItemVO.getIntoQty()) == -1) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INTOINGQTY_NO_LESS_INTOQTY.getMessage());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ OutReturnItem outReturnItem = outReturnItemConvert.convertToPo(outReturnItemVO);
|
|
|
|
|
+ outReturnItemService.updateByUuid(outReturnItem);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ return ResponseResultUtil.success(super.update(outReturn, new UpdateWrapper<OutReturn>().lambda().eq(OutReturn::getReturnId,
|
|
|
|
|
+ UUID.fromString(outReturn.getReturnId()))));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|