装备管理 youhua
This commit is contained in:
parent
336468164d
commit
7e07867d96
|
|
@ -11,6 +11,7 @@ import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
|||
import com.bonus.material.equipment.domain.DeptConfigRateSummary;
|
||||
import com.bonus.material.equipment.domain.DeptConfigTypeSummary;
|
||||
import com.bonus.material.equipment.domain.DeptEquipmentConfig;
|
||||
import com.bonus.material.equipment.domain.EquipmentDetail;
|
||||
import com.bonus.material.equipment.service.ISysDeptService;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
|
|
@ -58,7 +59,6 @@ public class SysDeptController extends BaseController {
|
|||
@SysLog(title = "装备列表", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "查询装备列表")
|
||||
public TableDataInfo listRate(DeptConfigRateSummary user) {
|
||||
try {
|
||||
startPage();
|
||||
List<DeptConfigRateSummary> list = service.selectDeptConfigRatePivot(user);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -90,4 +90,15 @@ public class SysDeptController extends BaseController {
|
|||
}
|
||||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
@PostMapping("/detailsInfo")
|
||||
@SysLog(title = "公司装备详情页面", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "公司装备详情页面")
|
||||
public TableDataInfo detailsInfo(@RequestBody EquipmentDetail equipmentDetail) {
|
||||
try {
|
||||
List<EquipmentDetail> list = service.detailsInfo(equipmentDetail);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
package com.bonus.material.equipment.domain;
|
||||
|
||||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class DeptConfigRateSummary {
|
||||
public class DeptConfigRateSummary extends BaseEntity {
|
||||
|
||||
/** 部门ID */
|
||||
private Long deptId;
|
||||
|
||||
private String deptName;
|
||||
//公司
|
||||
private String companyName;
|
||||
|
||||
/** 配置类型A的装备配置率累计值 */
|
||||
private BigDecimal valueA;
|
||||
|
|
@ -20,4 +23,13 @@ public class DeptConfigRateSummary {
|
|||
|
||||
/** 配置类型C的装备配置率累计值 */
|
||||
private BigDecimal valueC;
|
||||
|
||||
/** 配置类型D的装备配置率累计值 新型装备 */
|
||||
private BigDecimal valueD;
|
||||
private BigDecimal configType;
|
||||
private BigDecimal companyId;
|
||||
private BigDecimal configValue;
|
||||
//装备配置率赋值
|
||||
private BigDecimal configRate;
|
||||
private BigDecimal orderCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.bonus.material.equipment.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 装备配置详情实体类
|
||||
*/
|
||||
@Data
|
||||
public class EquipmentDetail {
|
||||
|
||||
/** 序号 */
|
||||
private Integer index;
|
||||
|
||||
/** 工序 */
|
||||
private String process;
|
||||
|
||||
/** 装备名称 */
|
||||
private String name;
|
||||
|
||||
/** 基本配置标准(台/套) */
|
||||
private String standard;
|
||||
|
||||
/** 装备种类 */
|
||||
private String type;
|
||||
|
||||
/** 配置说明 */
|
||||
private String desc;
|
||||
|
||||
/** 装备配置率赋值 */
|
||||
private String value;
|
||||
|
||||
/** 自有装备数量 */
|
||||
private Integer own;
|
||||
|
||||
/** 租赁装备数量 */
|
||||
private Integer rent;
|
||||
|
||||
/** 装备实际配置率 */
|
||||
private String actual;
|
||||
|
||||
/** 特殊装备配置率 */
|
||||
private String special;
|
||||
|
||||
/** 特殊装备原因 */
|
||||
private String reason;
|
||||
//公司
|
||||
private String companyId;
|
||||
private String configType;
|
||||
/*是否存在新型装备的标识
|
||||
* 是 → status = 1,否 → status = 0
|
||||
*
|
||||
* */
|
||||
private String ifExist;
|
||||
private String orderCount;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -24,4 +24,6 @@ public interface SysDeptMapper {
|
|||
List<DeptConfigTypeSummary> selectDeptConfigTypeSummary(DeptConfigTypeSummary entity);
|
||||
|
||||
List<DeptTreeSelect> getTree();
|
||||
|
||||
List<EquipmentDetail> detailsInfo(EquipmentDetail equipmentDetail);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,6 @@ public interface ISysDeptService {
|
|||
List<DeptConfigRateSummary> selectDeptConfigRatePivot(DeptConfigRateSummary entity);
|
||||
|
||||
List<DeptConfigTypeSummary> selectDeptConfigTypeSummary(DeptConfigTypeSummary entity);
|
||||
|
||||
List<EquipmentDetail> detailsInfo(EquipmentDetail equipmentDetail);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import com.bonus.common.security.utils.SecurityUtils;
|
|||
import com.bonus.material.equipment.domain.*;
|
||||
import com.bonus.material.equipment.mapper.SysDeptMapper;
|
||||
import com.bonus.material.equipment.service.ISysDeptService;
|
||||
import com.bonus.material.owner.domain.Ownerdomin;
|
||||
import com.bonus.material.owner.mapper.OwnerMapper;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
|
@ -20,9 +22,11 @@ import org.springframework.beans.BeanUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -32,6 +36,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
@Autowired
|
||||
private SysDeptMapper mapper;
|
||||
|
||||
@Resource
|
||||
private OwnerMapper ownerMapper;
|
||||
|
||||
@Override
|
||||
public List<DeptTreeSelect> selectDeptTreeList(SysDept dept) {
|
||||
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
|
||||
|
|
@ -67,15 +74,100 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DeptConfigRateSummary> selectDeptConfigRatePivot(DeptConfigRateSummary entity) {
|
||||
return mapper.selectDeptConfigRatePivot(entity);
|
||||
public List<DeptConfigRateSummary> selectDeptConfigRatePivot(DeptConfigRateSummary entity){
|
||||
// 1. 获取配置率数据(包含公司、设备类型、满分值、基本配置数量、设备名称)
|
||||
List<DeptConfigRateSummary> configList = mapper.selectDeptConfigRatePivot(entity);
|
||||
|
||||
// 2. 获取所有设备数据(包含设备名称、来源、自有数量)
|
||||
List<Ownerdomin> ownList = ownerMapper.list(null);
|
||||
|
||||
// 3. 构建索引:设备名称 → List<设备记录>
|
||||
Map<String, List<Ownerdomin>> ownIndex = ownList.stream()
|
||||
.collect(Collectors.groupingBy(Ownerdomin::getMaName));
|
||||
|
||||
// 4. 构建公司 → 汇总结果 Map
|
||||
Map<String, DeptConfigRateSummary> companyMap = new LinkedHashMap<>();
|
||||
|
||||
for (DeptConfigRateSummary config : configList) {
|
||||
String company = config.getCompanyName();
|
||||
String type = config.getConfigType().toPlainString();
|
||||
String maName = config.getDeptName();
|
||||
BigDecimal orderCount = config.getOrderCount();
|
||||
// 获取所有匹配该设备名称的记录
|
||||
List<Ownerdomin> matchedDevices = ownIndex.getOrDefault(maName, Collections.emptyList());
|
||||
|
||||
// 计算评分
|
||||
BigDecimal score = computeScoreByMaName(orderCount,matchedDevices, config);
|
||||
|
||||
// 获取或创建该公司对应的评分对象
|
||||
DeptConfigRateSummary dto = companyMap.computeIfAbsent(company, k -> {
|
||||
DeptConfigRateSummary d = new DeptConfigRateSummary();
|
||||
d.setDeptName(company);
|
||||
d.setCompanyId(config.getCompanyId());
|
||||
d.setCompanyName(company);
|
||||
return d;
|
||||
});
|
||||
|
||||
// 设置对应类型得分字段
|
||||
switch (type) {
|
||||
case "0": dto.setValueA(score); break; // 线路
|
||||
case "1": dto.setValueB(score); break; // 电缆
|
||||
case "2": dto.setValueC(score); break; // 变电
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 返回结果列表
|
||||
return new ArrayList<>(companyMap.values());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private BigDecimal computeScoreByMaName(BigDecimal ordercount,List<Ownerdomin> owns, DeptConfigRateSummary config) {
|
||||
if (config == null || owns == null || owns.isEmpty()) return BigDecimal.ZERO;
|
||||
|
||||
BigDecimal ownedTotal = BigDecimal.ZERO;
|
||||
BigDecimal leasedTotal = BigDecimal.ZERO;
|
||||
|
||||
for (Ownerdomin own : owns) {
|
||||
BigDecimal num = new BigDecimal(own.getMaNum());
|
||||
if ("2".equals(own.getType())) {
|
||||
ownedTotal = ownedTotal.add(num); // 自有
|
||||
} else {
|
||||
leasedTotal = leasedTotal.add(num); // 租赁
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal base = config.getConfigValue(); // 基本配置数量
|
||||
BigDecimal score = config.getConfigRate(); // 满分值
|
||||
|
||||
if (base == null || base.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO;
|
||||
|
||||
|
||||
// 计算比例 = (自有 + 租赁×0.6 + 订单×0.9) / 基本配置数
|
||||
BigDecimal rate = ownedTotal
|
||||
.add(leasedTotal.multiply(new BigDecimal("0.6")))
|
||||
.add(ordercount.multiply(new BigDecimal("0.9")))
|
||||
.divide(base, 4, RoundingMode.HALF_UP);
|
||||
|
||||
|
||||
// 判断是否超过满分
|
||||
if (rate.compareTo(BigDecimal.ONE) > 0) {
|
||||
return score.setScale(2, RoundingMode.HALF_UP);
|
||||
} else {
|
||||
return rate.multiply(score).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptConfigTypeSummary> selectDeptConfigTypeSummary(DeptConfigTypeSummary entity) {
|
||||
return mapper.selectDeptConfigTypeSummary(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EquipmentDetail> detailsInfo(EquipmentDetail equipmentDetail) {
|
||||
return mapper.detailsInfo(equipmentDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ public class OwnerController extends BaseController {
|
|||
@ApiOperation(value = "自有装备管理新增")
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody Ownerdomin ownerdomin) throws UnsupportedEncodingException {
|
||||
if(ownerdomin.getMaNameId() != null){
|
||||
ownerdomin.setMaName(ownerdomin.getMaNameId());
|
||||
}
|
||||
Integer i = ownerService.add(ownerdomin);
|
||||
if (i > 0){
|
||||
return AjaxResult.success("新增成功");
|
||||
|
|
|
|||
|
|
@ -52,5 +52,7 @@ public class Ownerdomin {
|
|||
@ApiModelProperty(value = "备注")
|
||||
@Excel(name = "备注")
|
||||
private String remark;
|
||||
@ApiModelProperty(value = "装备名称id")
|
||||
private String maNameId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,15 +104,39 @@
|
|||
<select id="selectDeptConfigRatePivot"
|
||||
resultType="com.bonus.material.equipment.domain.DeptConfigRateSummary">
|
||||
SELECT
|
||||
sd.dept_name AS deptName,
|
||||
SUM( CASE WHEN mdc.config_type = '0' THEN CAST( mdc.config_rate AS DECIMAL ( 10, 2 )) ELSE 0 END ) AS valueA,
|
||||
SUM( CASE WHEN mdc.config_type = '1' THEN CAST( mdc.config_rate AS DECIMAL ( 10, 2 )) ELSE 0 END ) AS valueB,
|
||||
SUM( CASE WHEN mdc.config_type = '2' THEN CAST( mdc.config_rate AS DECIMAL ( 10, 2 )) ELSE 0 END ) AS valueC
|
||||
my.type_name AS deptName,
|
||||
sd.dept_name AS companyName,
|
||||
mdc.dept_id AS companyId,
|
||||
mdc.config_type AS configType,
|
||||
mdc.config_value AS configValue,
|
||||
mdc.config_rate AS configRate,
|
||||
IFNULL(order_stat.order_count, 0) AS orderCount
|
||||
FROM
|
||||
ma_dept_config mdc
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = mdc.dept_id
|
||||
GROUP BY
|
||||
mdc.dept_id
|
||||
LEFT JOIN ma_type my ON my.type_id = mdc.type_id
|
||||
|
||||
-- 设备订单数量子查询
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
sd.dept_id AS dept_id,
|
||||
mt2.type_id AS parent_type_id,
|
||||
COUNT(md.ma_id) AS order_count
|
||||
FROM
|
||||
ma_order_details md
|
||||
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
||||
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
|
||||
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
|
||||
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
|
||||
GROUP BY sd.dept_id, mt2.type_id
|
||||
) order_stat
|
||||
ON order_stat.dept_id = mdc.dept_id
|
||||
AND order_stat.parent_type_id = mdc.type_id
|
||||
|
||||
WHERE 1 = 1;
|
||||
|
||||
|
||||
</select>
|
||||
<select id="selectDeptConfigTypeSummary"
|
||||
resultType="com.bonus.material.equipment.domain.DeptConfigTypeSummary">
|
||||
|
|
@ -125,6 +149,67 @@
|
|||
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
||||
WHERE mdc.dept_id = #{deptId}
|
||||
</select>
|
||||
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
|
||||
SELECT
|
||||
d.dept_id AS companyId,
|
||||
mt.type_name AS NAME,
|
||||
d.config_description as `desc`,
|
||||
d.config_rate as `value`,
|
||||
|
||||
(
|
||||
SELECT
|
||||
CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END
|
||||
FROM ma_dept_config d2
|
||||
WHERE d2.dept_id = d.dept_id AND d2.config_type = '3'
|
||||
) AS ifExist,
|
||||
|
||||
(
|
||||
SELECT COUNT(md.ma_id)
|
||||
FROM ma_order_details md
|
||||
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
|
||||
LEFT JOIN ma_type mt1 ON mdi.type_id = mt1.type_id
|
||||
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
||||
WHERE
|
||||
moi.buyer_company = d.dept_id AND
|
||||
mt2.type_id = d.type_id
|
||||
) AS orderCount,
|
||||
|
||||
SUM(CAST(d.config_value AS DECIMAL(10, 2))) AS standard,
|
||||
MAX(own_count) AS own,
|
||||
MAX(rent_count) AS rent
|
||||
|
||||
FROM
|
||||
ma_dept_config d
|
||||
LEFT JOIN (
|
||||
SELECT ma_name, SUM(ma_num) AS own_count
|
||||
FROM ma_own_manage
|
||||
WHERE type = '2' AND is_active = '0'
|
||||
GROUP BY ma_name
|
||||
) own ON CAST(d.type_id AS CHAR) = own.ma_name
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT ma_name, SUM(ma_num) AS rent_count
|
||||
FROM ma_own_manage
|
||||
WHERE type = '1' AND is_active = '0'
|
||||
GROUP BY ma_name
|
||||
) rent ON CAST(d.type_id AS CHAR) = rent.ma_name
|
||||
|
||||
LEFT JOIN ma_type mt ON mt.type_id = d.type_id
|
||||
WHERE
|
||||
1=1
|
||||
<if test="companyId != null">
|
||||
AND d.dept_id = #{companyId}
|
||||
</if>
|
||||
<if test="configType != null">
|
||||
AND d.config_type = #{configType}
|
||||
</if>
|
||||
|
||||
GROUP BY
|
||||
d.dept_id,
|
||||
d.config_type,
|
||||
d.type_id;
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<update id="edit">
|
||||
update ma_own_manage set
|
||||
ma_type = #{maType},
|
||||
ma_name = #{maName},
|
||||
ma_name = #{maNameId},
|
||||
model_id = #{modelId},
|
||||
ma_model = #{maModel},
|
||||
ma_num = #{maNum},
|
||||
|
|
@ -29,6 +29,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="list" resultType="com.bonus.material.owner.domain.Ownerdomin">
|
||||
SELECT
|
||||
m.id,
|
||||
m.type,
|
||||
t.type_id as maNameId,
|
||||
m.ma_type AS maType,
|
||||
t.type_name AS maName,
|
||||
m.model_id AS modelId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue