|
@@ -0,0 +1,227 @@
|
|
|
+package com.example.storageex.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.example.storageex.mapper.IndexMapper;
|
|
|
+import com.example.storageex.service.IndexService;
|
|
|
+import com.example.storageex.utils.HttpHelper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class IndexServiceImpl extends ServiceImpl<IndexMapper, Object> implements IndexService {
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> selectDetails(Map<String, Object> condition) {
|
|
|
+ if (ObjectUtil.isNotEmpty(condition.get("beginTime"))) {
|
|
|
+
|
|
|
+ // 获取到传过来的时间
|
|
|
+ Date beginTime = DateUtil.parse(condition.get("beginTime").toString());
|
|
|
+
|
|
|
+ // 获取到传过来时间的最后一天
|
|
|
+ Date endTime = DateUtil.endOfMonth(beginTime);
|
|
|
+
|
|
|
+ if (DateUtil.betweenDay(beginTime, endTime, false) > 15) {
|
|
|
+ beginTime = DateUtil.beginOfMonth(beginTime);
|
|
|
+ endTime = DateUtil.offsetDay(beginTime, 15);
|
|
|
+ } else {
|
|
|
+ beginTime = DateUtil.offsetDay(DateUtil.beginOfMonth(beginTime), 14);
|
|
|
+ }
|
|
|
+ condition.put("beginTime", beginTime);
|
|
|
+ condition.put("endTime", endTime);
|
|
|
+ }
|
|
|
+ return baseMapper.selectDetails(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getV3PlanData(Map<String, String> condition) {
|
|
|
+
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ // 请求v3接口获取token
|
|
|
+ String tokenUrl = "http://mes.cfmfactory.com:8087/portal/getAccessTokenAction.do";
|
|
|
+ Map<String, String> getTokenMap = new HashMap<>();
|
|
|
+ getTokenMap.put("AppId", "1");
|
|
|
+ getTokenMap.put("AppSecret", "a2b1c2d3");
|
|
|
+ Map<String, Object> tokenResultMap = HttpHelper.doGet(tokenUrl, getTokenMap);
|
|
|
+ String token = tokenResultMap.get("token").toString();
|
|
|
+
|
|
|
+ // 请求v3接口获取所有人领料信息
|
|
|
+ String url = "http://mes.cfmfactory.com:8087/MesWeb/planPersonOutAction.do";
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ DateTime parse = DateUtil.parse(DateUtil.format(date, "yyyy-MM-dd 7:30:00"));
|
|
|
+
|
|
|
+ if (date.compareTo(parse) < 0) {
|
|
|
+ date = DateUtil.offsetDay(date, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("action", "list");
|
|
|
+ map.put("status", "1");
|
|
|
+ map.put("beginDate", DateUtil.formatDateTime(date));
|
|
|
+ map.put("endDate", DateUtil.formatDateTime(date));
|
|
|
+ map.put("access_token", token);
|
|
|
+ Map<String, Object> resultMap = HttpHelper.doGet(url, map);
|
|
|
+
|
|
|
+ // 接收到的消息
|
|
|
+ List<JSONObject> items = (List<JSONObject>) resultMap.get("items");
|
|
|
+
|
|
|
+ String jobNo = condition.get("jobNo");
|
|
|
+
|
|
|
+ List<Map<String, Object>> v3DataList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<Object, List<JSONObject>> v3DataMap = items.stream()
|
|
|
+ .filter(item -> item.get("distributor").toString().equals(jobNo))
|
|
|
+ .collect(Collectors.groupingBy(item -> item.get("material")));
|
|
|
+
|
|
|
+ v3DataMap.forEach((k, v) -> {
|
|
|
+ Map<String, Object> itemMap = new HashMap<>();
|
|
|
+ itemMap.put("name", k);
|
|
|
+ itemMap.put("canTakeQty", v.stream().map(item -> new BigDecimal(item.get("plantotalsquare").toString())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ v3DataList.add(itemMap);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal paperManCanTakeQty = items.stream()
|
|
|
+ .filter(item -> item.get("paperMan").toString().equals(jobNo))
|
|
|
+ .map(item -> new BigDecimal(item.get("plantotalsquare").toString()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ if (paperManCanTakeQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ HashMap<String, Object> rzMap = new HashMap<>();
|
|
|
+ rzMap.put("name", "热转印纸");
|
|
|
+ rzMap.put("canTakeQty", paperManCanTakeQty);
|
|
|
+ v3DataList.add(rzMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("v3DataList", v3DataList);
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<Object> query = Wrappers.query();
|
|
|
+
|
|
|
+ List<Map<String, Object>> allMaterialList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (v3DataList.size() > 0) {
|
|
|
+ query.gt("s.Quantity", 0);
|
|
|
+ query.and(q -> v3DataList.stream().map(item -> item.get("name").toString()).collect(Collectors.toList()).forEach(item ->
|
|
|
+ q.or().likeRight("m.`Name`", item + "-")
|
|
|
+ ));
|
|
|
+ query.and(q -> q.eq("uu.JobNo", jobNo).or().isNull("uu.JobNo"));
|
|
|
+
|
|
|
+ allMaterialList = baseMapper.selectAllMaterialList(query);
|
|
|
+ for (Map<String, Object> material : allMaterialList) {
|
|
|
+ for (Map<String, Object> stringObjectMap : v3DataList) {
|
|
|
+ if (material.get("materialName").toString().startsWith(stringObjectMap.get("name").toString())) {
|
|
|
+
|
|
|
+ BigDecimal canTakeQty = (BigDecimal) stringObjectMap.get("canTakeQty");
|
|
|
+
|
|
|
+ BigDecimal width = floatToBig((Float) material.get("width"));
|
|
|
+ BigDecimal bigDecimal = new BigDecimal("100");
|
|
|
+
|
|
|
+ BigDecimal userStockQty = (BigDecimal) material.get("userStockQty");
|
|
|
+ userStockQty = userStockQty == null ? BigDecimal.ZERO : userStockQty;
|
|
|
+
|
|
|
+ BigDecimal canTakeQtyBD = canTakeQty.subtract(userStockQty.multiply(width).divide(bigDecimal, 2, RoundingMode.HALF_UP))
|
|
|
+ .multiply(bigDecimal).divide(width, 2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ material.put("canTakeQty", canTakeQtyBD.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : canTakeQtyBD);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<Object, Object> hashMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 添加墨水
|
|
|
+ List<Map<String, Object>> inkList = baseMapper.selectInk();
|
|
|
+ for (Map<String, Object> item : inkList) {
|
|
|
+ item.put("width", 0);
|
|
|
+ item.put("canTakeQty", 16);
|
|
|
+ }
|
|
|
+ allMaterialList.addAll(inkList);
|
|
|
+
|
|
|
+
|
|
|
+ hashMap.put("list", allMaterialList);
|
|
|
+ result.put("allMaterialList", hashMap);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> contractPayment() {
|
|
|
+
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ DateTime beginOfMonth = DateUtil.beginOfMonth(date);
|
|
|
+ DateTime endOfMonth = DateUtil.endOfMonth(date);
|
|
|
+
|
|
|
+ if (DateUtil.betweenDay(date, beginOfMonth, true) > 14) {
|
|
|
+ // 上半月结束时间
|
|
|
+ String halfEndTime = DateUtil.format(endOfMonth, "yyyy-MM-15 HH:mm:ss");
|
|
|
+ // 上个账期已付
|
|
|
+ List<Map<String, Object>> paidInLastAccountingPeriod =
|
|
|
+ baseMapper.getPaidInLastAccountingPeriod(beginOfMonth, halfEndTime);
|
|
|
+ result.put("paidInLastAccountingPeriod", paidInLastAccountingPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下半月开始时间
|
|
|
+ String lowerHalfBeginTime = DateUtil.format(beginOfMonth, "yyyy-MM-16 HH:mm:ss");
|
|
|
+
|
|
|
+ // 本账期
|
|
|
+ BigDecimal currentAccountingPeriod = baseMapper.getCurrentAccountingPeriod(lowerHalfBeginTime, endOfMonth)
|
|
|
+ .setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ result.put("currentAccountingPeriod", currentAccountingPeriod);
|
|
|
+
|
|
|
+ // 已付
|
|
|
+ List<Map<String, Object>> paid = baseMapper.gerPaid(lowerHalfBeginTime, endOfMonth);
|
|
|
+ paid.forEach(item -> item.put("PayAmount", ((BigDecimal) item.get("PayAmount")).setScale(2, RoundingMode.HALF_DOWN)));
|
|
|
+ result.put("paid", paid);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> approvalRole() {
|
|
|
+ return baseMapper.approvalRole();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getInventoryRecord(Map<String, String> condition) {
|
|
|
+
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query()
|
|
|
+ .ne("sc.IsDelete", 1);
|
|
|
+
|
|
|
+ String beginTime = condition.get("beginTime");
|
|
|
+ String endTime = condition.get("endTime");
|
|
|
+ boolean NotEmptyFlag = ObjectUtil.isNotEmpty(beginTime) && ObjectUtil.isNotEmpty(endTime);
|
|
|
+ if (NotEmptyFlag) {
|
|
|
+ DateTime beginOfDay = DateUtil.beginOfDay(DateUtil.parse(beginTime));
|
|
|
+ DateTime endOfDay = DateUtil.endOfDay(DateUtil.parse(endTime));
|
|
|
+ wrapper.between("sc.CreatedTime", beginOfDay, endOfDay);
|
|
|
+ }
|
|
|
+
|
|
|
+ return baseMapper.getInventoryRecord(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private BigDecimal floatToBig(float scale) {
|
|
|
+ DecimalFormat df = new DecimalFormat("##0.00");
|
|
|
+ return new BigDecimal(df.format(scale));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|