|
|
@@ -1,13 +1,39 @@
|
|
|
package com.dk.mdm.service.mac;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
+import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
+import com.dk.common.model.pojo.PageList;
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
+import com.dk.common.response.ResponseResultUtil;
|
|
|
+import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.mdm.infrastructure.convert.mac.OtherPayableConvert;
|
|
|
+import com.dk.mdm.infrastructure.convert.mac.OtherPayableItemConvert;
|
|
|
+import com.dk.mdm.mapper.mac.OtherPayableItemMapper;
|
|
|
import com.dk.mdm.model.pojo.mac.OtherPayable;
|
|
|
import com.dk.mdm.mapper.mac.OtherPayableMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
+import com.dk.mdm.model.pojo.mac.OtherPayable;
|
|
|
+import com.dk.mdm.model.pojo.mac.OtherPayableItem;
|
|
|
+import com.dk.mdm.model.query.mac.OtherPayableItemQuery;
|
|
|
+import com.dk.mdm.model.query.mac.OtherPayableQuery;
|
|
|
+import com.dk.mdm.model.response.mac.OtherPayableItemResponse;
|
|
|
+import com.dk.mdm.model.response.mac.OtherPayableResponse;
|
|
|
+import com.dk.mdm.model.vo.mac.OtherPayableItemVO;
|
|
|
+import com.dk.mdm.model.vo.mac.OtherPayableVO;
|
|
|
+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.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class OtherPayableService extends BaseService<OtherPayable> {
|
|
|
@@ -25,4 +51,155 @@ public class OtherPayableService extends BaseService<OtherPayable> {
|
|
|
@Autowired
|
|
|
private OtherPayableMapper otherPayableMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OtherPayableItemMapper otherPayableItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountService accountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OtherPayableConvert otherPayableConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OtherPayableItemConvert otherPayableItemConvert;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2023/1/9 10:40
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<OtherPayableResponse>> selectByCond(OtherPayableQuery otherPayableQuery) {
|
|
|
+ return super.mergeListWithCount(otherPayableQuery, otherPayableMapper.selectByCond(otherPayableQuery),
|
|
|
+ otherPayableMapper.countByCond(otherPayableQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 查询明细(货物、收款、附件)
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2024-02-28 13:25
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<Map<String, Object>> selectOtherPayableInfoById(String id) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ // 商品明细
|
|
|
+ List<OtherPayableItemResponse> otherPayableItem = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
|
|
|
+ result.put("otherPayableItem", otherPayableItem);
|
|
|
+
|
|
|
+ // 附件
|
|
|
+ return ResponseResultUtil.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建方法
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<?> insert(OtherPayableVO otherPayableVO) {
|
|
|
+
|
|
|
+ // 获取单号
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.ORDER.getName(), false);
|
|
|
+ otherPayableVO.setPayableId(codeMap.get("outId").toString()).setPayableNo(codeMap.get("outNote").toString())
|
|
|
+ .setObjectType(Constant.ObjectType.CUS.getName());
|
|
|
+ // 转化实体
|
|
|
+ OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
|
|
|
+ // 总单保存
|
|
|
+ super.insert(otherPayable);
|
|
|
+
|
|
|
+ // 明细保存
|
|
|
+ if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
|
|
|
+ for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
|
|
|
+ OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
|
|
|
+ otherPayableItem.setPayableId(otherPayable.getPayableId()).setCpId(otherPayable.getCpId());
|
|
|
+ otherPayableItemMapper.insert(otherPayableItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应收记账
|
|
|
+ accountService.accPayable(otherPayable.getPayableId(),"t_mac_other_payable");
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 编辑方法
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<?> update(OtherPayableVO otherPayableVO) {
|
|
|
+
|
|
|
+ // 先更新收款单总表,否则id又更错了
|
|
|
+ OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
|
|
|
+ super.update(otherPayable, new UpdateWrapper<OtherPayable>().lambda().eq(OtherPayable::getPayableId,
|
|
|
+ UUID.fromString(otherPayable.getPayableId())));
|
|
|
+
|
|
|
+ // 应收反记账
|
|
|
+ accountService.reversePayable(otherPayableVO.getPayableId(),"t_mac_other_payable");
|
|
|
+
|
|
|
+ // 将之前的明细全部删除
|
|
|
+ List<OtherPayableItem> otherPayableItemOriginalList = otherPayableItemMapper.selectByZIdForUpdate(otherPayableVO.getPayableId());
|
|
|
+ for (OtherPayableItem otherPayableItem : otherPayableItemOriginalList) {
|
|
|
+ otherPayableItemMapper.deleteById(otherPayableItem.getItemId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 明细保存
|
|
|
+ if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
|
|
|
+ for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
|
|
|
+ OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
|
|
|
+ otherPayableItem.setItemId(null).setPayableId(otherPayableVO.getPayableId()).setCpId(otherPayableVO.getCpId());
|
|
|
+ otherPayableItemMapper.insert(otherPayableItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应收记账
|
|
|
+ accountService.accPayable(otherPayableVO.getPayableId(),"t_mac_other_payable");
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 获取信息(编辑用)
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2024-03-02 17:27
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> getOtherPayableForUpdate(String id) {
|
|
|
+ Map<String, Object> dataInfo = new HashMap<>();
|
|
|
+ OtherPayableResponse otherPayableResponse = otherPayableMapper.selectById(id);
|
|
|
+ dataInfo.put("data", otherPayableResponse);
|
|
|
+
|
|
|
+ // 商品明细
|
|
|
+ List<OtherPayableItemResponse> otherPayableItemResponse = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
|
|
|
+ dataInfo.put("dataItem", otherPayableItemResponse);
|
|
|
+ return ResponseResultUtil.success(dataInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 作废
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2024-03-08 16:38
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> invalid(String id) {
|
|
|
+ OtherPayable otherPayableForUpdate = otherPayableMapper.selectByIdForUpdate(id);
|
|
|
+ // 并发校验
|
|
|
+ if (!otherPayableForUpdate.getFlgValid()) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
|
|
|
+ }
|
|
|
+ // 如果所在月份已结账,则不能作废 todo
|
|
|
+
|
|
|
+ // 应收反记账
|
|
|
+ accountService.reversePayable(id,"t_mac_other_payable");
|
|
|
+
|
|
|
+ // 作废
|
|
|
+ OtherPayable otherPayableUpdate = new OtherPayable();
|
|
|
+ otherPayableUpdate.setFlgValid(false).setPayableId(id);
|
|
|
+ super.updateByUuid(otherPayableUpdate);
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
}
|