| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 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<OtherReceivable> {
- @Override
- public String getPrimaryKey() {
- return "receivable_id";
- }
- @Override
- public BaseMapper<OtherReceivable> 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<PageList<OtherReceivableResponse>> selectByCond(OtherReceivableQuery otherReceivableQuery) {
- return super.mergeListWithCount(otherReceivableQuery, otherReceivableMapper.selectByCond(otherReceivableQuery),
- otherReceivableMapper.countByCond(otherReceivableQuery));
- }
- /**
- * @desc : 查询订单明细(货物、收款、附件)
- * @author : 付斌
- * @date : 2024-02-28 13:25
- */
- @Pagination
- public ResponseResultVO<Map<String, Object>> selectOtherReceivableInfoById(String id) {
- Map<String, Object> result = new HashMap<>();
- // 商品明细
- List<OtherReceivableItemResponse> 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<String, Object> 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<OtherReceivableItemVO> 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<OtherReceivableItemVO> 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<OtherReceivableItemVO> 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<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
- UUID.fromString(otherReceivable.getReceivableId()))));
- }
- }
|