|
@@ -1,10 +1,37 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alipay.sofa.runtime.api.annotation.SofaReference;
|
|
|
+import com.baomidou.mybatisplus.plugins.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.winsea.svc.base.base.entity.CommonRoleResource;
|
|
|
+import com.winsea.svc.base.base.service.ICommonRoleResourceService;
|
|
|
+import com.winsea.svc.base.security.entity.User;
|
|
|
+import com.winsea.svc.base.security.util.AuthSecurityUtils;
|
|
|
+import com.winsea.svc.base.workflow.entity.Workflow;
|
|
|
+import com.yh.saas.common.support.util.IdGenerator;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.NumberConstant;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.CollectionWarehousingRecord;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.SalePlanInfo;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.SalesDeliveryReport;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.exception.YException;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.exception.YExceptionEnum;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.CollectionWarehousingRecordMapper;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.service.ICollectionWarehousingRecordService;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.service.INewWorkflowService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +44,200 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CollectionWarehousingRecordServiceImpl extends ServiceImpl<CollectionWarehousingRecordMapper, CollectionWarehousingRecord> implements ICollectionWarehousingRecordService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private INewWorkflowService workflowService;
|
|
|
+ @SofaReference
|
|
|
+ private ICommonRoleResourceService roleResourceService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销售出库统计列表
|
|
|
+ *
|
|
|
+ * @param collectionWarehousingRecord
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<CollectionWarehousingRecord> selectCollectionWarehousingRecordPage(CollectionWarehousingRecord collectionWarehousingRecord) {
|
|
|
+ Map<String, Object> pageView = new HashMap<>();
|
|
|
+ pageView.put("startRecord", (collectionWarehousingRecord.getCurrentPage() - 1)
|
|
|
+ * collectionWarehousingRecord.getPageSize());
|
|
|
+ List<String> businessKeys = null;
|
|
|
+ if ("2".equals(collectionWarehousingRecord.getSearchType())) {
|
|
|
+ businessKeys = workflowService.getTaskBusinessKeysByCode("COLLECTION-WAREHOUSING-RECORD");
|
|
|
+ }
|
|
|
+ List<String> statusSet = new ArrayList<>();
|
|
|
+ List<String> resourceIdList = this.getResourceIdList();
|
|
|
+ if (resourceIdList.contains("saleOutReport-Edit")) { // 填写,提交 权限做完以后替换
|
|
|
+ List<String> statusList = Lists.newArrayList(StatusEnum.PUR_RETURN.getFlag());
|
|
|
+ statusSet.addAll(statusList);
|
|
|
+ }
|
|
|
+ //公司id
|
|
|
+ pageView.put("compId", collectionWarehousingRecord.getCompId());
|
|
|
+ pageView.put("searchKeyWord", collectionWarehousingRecord.getSearchKeyWord());
|
|
|
+ pageView.put("searchType", collectionWarehousingRecord.getSearchType());
|
|
|
+ pageView.put("pageSize", collectionWarehousingRecord.getPageSize());
|
|
|
+ pageView.put("currentPage", collectionWarehousingRecord.getCurrentPage());
|
|
|
+ pageView.put("contractNo", collectionWarehousingRecord.getContractNo());
|
|
|
+ pageView.put("businessKeys", businessKeys);
|
|
|
+ pageView.put("statusSet", statusSet);
|
|
|
+ // 查询总数
|
|
|
+ Integer dataCount = baseMapper.getCountByCondition(pageView);
|
|
|
+ List<CollectionWarehousingRecord> dataList = baseMapper.getListByCondition(pageView);
|
|
|
+ if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
+ dataList.forEach(collectionWarehousingRecord1 -> {
|
|
|
+
|
|
|
+ String taskId = "";
|
|
|
+ // 只有待审核状态才有taskId
|
|
|
+ if (StringUtils.isNotBlank(collectionWarehousingRecord1.getWorkflowId())) {
|
|
|
+ JSONObject jsonObject = workflowService.getActiveTask(Lists.newArrayList(collectionWarehousingRecord1.getWorkflowId()), collectionWarehousingRecord1.getId());
|
|
|
+ taskId = jsonObject.getString("taskId");
|
|
|
+ collectionWarehousingRecord1.setTaskId(taskId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ Page<CollectionWarehousingRecord> page = new Page<>();
|
|
|
+ page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
|
|
|
+ page.setTotal(dataCount == null ? 0 : dataCount);
|
|
|
+ page.setCurrent(collectionWarehousingRecord.getCurrentPage());
|
|
|
+ page.setSize(collectionWarehousingRecord.getPageSize());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<String> getResourceIdList() {
|
|
|
+ User currentUser = AuthSecurityUtils.getCurrentUserInfo();
|
|
|
+ // 当前登录人主要角色
|
|
|
+ return roleResourceService.getBindResourcesByUserId(currentUser.getUserId()).stream()
|
|
|
+ .map(CommonRoleResource::getResourceId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加代售合同入库记录
|
|
|
+ *
|
|
|
+ * @param collectionWarehousingRecord
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String insertCollectionWarehousingRecord(CollectionWarehousingRecord collectionWarehousingRecord) {
|
|
|
+
|
|
|
+ List<CollectionWarehousingRecord> collectionWarehousingRecord1 = collectionWarehousingRecord.getCollectionWarehousingRecords();
|
|
|
+ if(!CollectionUtils.isEmpty(collectionWarehousingRecord1)){
|
|
|
+ for(int i =0;i<collectionWarehousingRecord1.size();i++){
|
|
|
+ CollectionWarehousingRecord warehousingRecord = collectionWarehousingRecord1.get(i);
|
|
|
+ //新增主键id
|
|
|
+ warehousingRecord.setId(IdGenerator.generateUUID());
|
|
|
+ this.insert(warehousingRecord);
|
|
|
+
|
|
|
+ boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(warehousingRecord.getWorkflowId());
|
|
|
+ // 不是退回的单子
|
|
|
+ if (isStartWorkflow) {
|
|
|
+ Workflow workflow = workflowService
|
|
|
+ .findLatestWorkflowByBusinessCodeByApp(warehousingRecord.getCompId(), "COLLECTION-WAREHOUSING-RECORD");
|
|
|
+ // 没配置审核流程,直接结束并处理信息
|
|
|
+ if (workflow == null) {
|
|
|
+ throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
|
|
|
+ }
|
|
|
+ // 开启审核流
|
|
|
+ else {
|
|
|
+
|
|
|
+ // 设置状态 已提交审核
|
|
|
+ warehousingRecord.setWorkflowId(workflow.getId());
|
|
|
+ this.updateById(warehousingRecord);
|
|
|
+ workflowService.startInstance(workflow.getId(), warehousingRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 退回的单子 再启用
|
|
|
+ else {
|
|
|
+
|
|
|
+ this.updateById(warehousingRecord);
|
|
|
+ workflowService.activateInstance(warehousingRecord.getWorkflowId(), warehousingRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+// // 插入操作历史
|
|
|
+// String staffName = this.billOperateHisService.getStaffAndName();
|
|
|
+ // 插入操作历史
|
|
|
+// this.billOperateHisService.saveBillOperateHis(salePlanInfo.getId(), NumberConstant.CONSTANT_PURCHASE, staffName, null,
|
|
|
+// salePlanInfo.getStatus(), null, "");
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteCollectionWarehousingRecord(String id) {
|
|
|
+ //查询销售计划信息
|
|
|
+ CollectionWarehousingRecord collectionWarehousingRecord = this.selectById(id);
|
|
|
+ if (collectionWarehousingRecord != null) {
|
|
|
+ //删除销售计划信息
|
|
|
+ this.deleteById(collectionWarehousingRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param collectionWarehousingRecord
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String editCollectionWarehousingRecord(CollectionWarehousingRecord collectionWarehousingRecord) {
|
|
|
+ boolean one = this.updateById(collectionWarehousingRecord);
|
|
|
+ if (collectionWarehousingRecord.getStatusFlag().equals(StatusEnum.TASK_RETURN.getFlag())) {
|
|
|
+ boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(collectionWarehousingRecord.getWorkflowId());
|
|
|
+ // 不是退回的单子
|
|
|
+ if (isStartWorkflow) {
|
|
|
+ Workflow workflow = workflowService
|
|
|
+ .findLatestWorkflowByBusinessCodeByApp(collectionWarehousingRecord.getCompId(), "COLLECTION-WAREHOUSING-RECORD");
|
|
|
+ // 没配置审核流程,直接结束并处理信息
|
|
|
+ if (workflow == null) {
|
|
|
+ throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
|
|
|
+ }
|
|
|
+ // 开启审核流
|
|
|
+ else {
|
|
|
+
|
|
|
+ // 设置状态 已提交审核
|
|
|
+ collectionWarehousingRecord.setWorkflowId(workflow.getId());
|
|
|
+ this.updateById(collectionWarehousingRecord);
|
|
|
+ workflowService.startInstance(workflow.getId(), collectionWarehousingRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 退回的单子 再启用
|
|
|
+ else {
|
|
|
+
|
|
|
+ this.updateById(collectionWarehousingRecord);
|
|
|
+ workflowService.activateInstance(collectionWarehousingRecord.getWorkflowId(), collectionWarehousingRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (one) {
|
|
|
+ return "OK";
|
|
|
+ } else {
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看销售计划
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CollectionWarehousingRecord getCollectionWarehousingRecord(String id) {
|
|
|
+ //查看销售计划信息
|
|
|
+ CollectionWarehousingRecord collectionWarehousingRecord = this.selectById(id);
|
|
|
+ return collectionWarehousingRecord;
|
|
|
+ }
|
|
|
+
|
|
|
}
|