package com.dk.mdm.service.mac; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.dk.common.infrastructure.annotaiton.Pagination; import com.dk.common.infrastructure.constant.Constant; import com.dk.common.model.pojo.PageList; import com.dk.common.response.ResponseResultUtil; import com.dk.common.response.ResponseResultVO; import com.dk.mdm.infrastructure.convert.mac.OtherReceivableConvert; import com.dk.mdm.infrastructure.convert.mac.OtherReceivableItemConvert; import com.dk.mdm.mapper.mac.OtherReceivableItemMapper; import com.dk.mdm.model.pojo.mac.*; import com.dk.mdm.mapper.mac.OtherReceivableMapper; import com.dk.common.service.BaseService; import com.dk.common.mapper.BaseMapper; import com.dk.mdm.model.query.mac.OtherReceivableItemQuery; import com.dk.mdm.model.query.mac.OtherReceivableQuery; import com.dk.mdm.model.response.mac.OtherReceivableItemResponse; import com.dk.mdm.model.response.mac.OtherReceivableResponse; import com.dk.mdm.model.vo.mac.OtherReceivableItemVO; import com.dk.mdm.model.vo.mac.OtherReceivableVO; import com.dk.mdm.service.common.CommonService; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @Service @Transactional public class OtherReceivableService extends BaseService { @Override public String getPrimaryKey() { return "receivable_id"; } @Override public BaseMapper getRepository() { return otherReceivableMapper; } @Autowired private OtherReceivableMapper otherReceivableMapper; @Autowired private OtherReceivableItemMapper otherReceivableItemMapper; @Autowired private OtherReceivableItemService otherReceivableItemService; @Autowired private CommonService commonService; @Autowired private OtherReceivableConvert otherReceivableConvert; @Autowired private OtherReceivableItemConvert otherReceivableItemConvert; /** * @desc : 条件查询 * @author : 付斌 * @date : 2023/1/9 10:40 */ @Pagination public ResponseResultVO> selectByCond(OtherReceivableQuery otherReceivableQuery) { return super.mergeListWithCount(otherReceivableQuery, otherReceivableMapper.selectByCond(otherReceivableQuery), otherReceivableMapper.countByCond(otherReceivableQuery)); } /** * @desc : 查询订单明细(货物、收款、附件) * @author : 付斌 * @date : 2024-02-28 13:25 */ @Pagination public ResponseResultVO> selectOtherReceivableInfoById(String id) { Map result = new HashMap<>(); // 商品明细 List otherReceivableItem = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id)); result.put("otherReceivableItem", otherReceivableItem); // 附件 return ResponseResultUtil.success(result); } /** * @desc : 新建方法 * @author : 付斌 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO insert(OtherReceivableVO otherReceivableVO) { // 获取单号 Map codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.ORDER.getName(), false); otherReceivableVO.setReceivableId(codeMap.get("outId").toString()).setReceivableNo(codeMap.get("outNote").toString()) .setObjectType(Constant.ObjectType.CUS.getName()); // 转化实体 OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO); // 订单总单保存 super.insert(otherReceivable); // 订单明细保存 if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) { for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) { OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO); otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId()); otherReceivableItemMapper.insert(otherReceivableItem); } } return ResponseResultUtil.success(); } /** * @desc : 编辑方法 * @author : 付斌 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO update(OtherReceivableVO otherReceivableVO) { // 明细实体(避免并发,需要再查一遍) OtherReceivableItem otherReceivableItemForUpdate; // 转化实体 OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO); //删除的 List deleteOtherReceivableItemVOList = otherReceivableVO.getDeleteItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList()); if (deleteOtherReceivableItemVOList.size() > 0) { for (OtherReceivableItemVO otherReceivableItemVO : deleteOtherReceivableItemVOList) { otherReceivableItemMapper.deleteById(otherReceivableItemVO.getItemId()); } } // 新增的 List insertOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() == null).collect(Collectors.toList()); for (OtherReceivableItemVO otherReceivableItemVO : insertOtherReceivableItemVOList) { OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO); otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId()); otherReceivableItemMapper.insert(otherReceivableItem); } // 编辑的 List editOtherReceivableItemVOList = otherReceivableVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList()); for (OtherReceivableItemVO otherReceivableItemVO : editOtherReceivableItemVOList) { otherReceivableItemForUpdate = otherReceivableItemMapper.selectByIdForUpdate(otherReceivableItemVO.getItemId()); OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO); otherReceivableItemService.updateByUuid(otherReceivableItem); } return ResponseResultUtil.success(super.update(otherReceivable, new UpdateWrapper().lambda().eq(OtherReceivable::getReceivableId, UUID.fromString(otherReceivable.getReceivableId())))); } }