问题修改

This commit is contained in:
jiang 2025-12-18 18:45:39 +08:00
parent 5848fcdde7
commit 3b2c631e69
15 changed files with 611 additions and 200 deletions

View File

@ -28,7 +28,7 @@ import com.bonus.common.core.web.page.TableDataInfo;
/**
* 企业信息Controller
*
*
* @author xsheng
* @date 2024-12-16
*/
@ -58,7 +58,7 @@ public class BmCompanyAddressController extends BaseController {
@ApiOperation(value = "导出企业信息列表")
@PreventRepeatSubmit
//@RequiresPermissions("basic:address:export")
@SysLog(title = "企业信息", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出企业信息")
@SysLog(title = "企业信息", businessType = OperaType.EXPORT, logType = 1, module = "仓储管理->导出企业信息")
@PostMapping("/export")
public void export(HttpServletResponse response, BmCompanyAddress bmCompanyAddress) {
List<BmCompanyAddress> list = bmCompanyAddressService.selectBmCompanyAddressList(bmCompanyAddress);
@ -82,7 +82,7 @@ public class BmCompanyAddressController extends BaseController {
@ApiOperation(value = "新增企业信息")
@PreventRepeatSubmit
//@RequiresPermissions("basic:address:add")
@SysLog(title = "企业信息", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增企业信息")
@SysLog(title = "企业信息", businessType = OperaType.INSERT, logType = 1, module = "仓储管理->新增企业信息")
@PostMapping
public AjaxResult add(@RequestBody BmCompanyAddress bmCompanyAddress) {
try {
@ -98,7 +98,7 @@ public class BmCompanyAddressController extends BaseController {
@ApiOperation(value = "修改企业信息")
//@PreventRepeatSubmit
//@RequiresPermissions("basic:address:edit")
@SysLog(title = "企业信息", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改企业信息")
@SysLog(title = "企业信息", businessType = OperaType.UPDATE, logType = 1, module = "仓储管理->修改企业信息")
@PostMapping("/edit")
public AjaxResult edit(@NotNull @RequestBody BmCompanyAddress bmCompanyAddress) {
if (bmCompanyAddress == null || bmCompanyAddress.getId() == null) {
@ -118,9 +118,21 @@ public class BmCompanyAddressController extends BaseController {
@ApiOperation(value = "删除企业信息")
@PreventRepeatSubmit
//@RequiresPermissions("basic:address:remove")
@SysLog(title = "企业信息", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除企业信息")
@PostMapping("/del/{ids}")
@SysLog(title = "企业信息", businessType = OperaType.DELETE, logType = 1, module = "仓储管理->删除企业信息")
@PostMapping("/del/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(bmCompanyAddressService.deleteBmCompanyAddressByIds(ids));
}
@ApiOperation(value = "删除企业信息")
@PreventRepeatSubmit
//@RequiresPermissions("basic:address:remove")
@SysLog(title = "企业信息", businessType = OperaType.DELETE, logType = 1, module = "仓储管理->删除企业信息")
@PostMapping("/delAddress")
public AjaxResult delAddress(Long id) {
return toAjax(bmCompanyAddressService.deleteBmCompanyAddressById(id));
}
}

View File

@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -294,4 +295,7 @@ public interface DevChangeMapper {
Integer orderOutCancelAll(CsDeviceDetails entity);
List<CsDeviceDetails> getOrderOutAllList(CsDeviceDetails entity);
BigDecimal getToolNum(CsDeviceDetails entity);
}

View File

@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@ -536,6 +537,18 @@ public class DevChangeServiceImpl implements DevChangeService {
if (entity.getDevType().equals("1")) {
mapper.updateZb(entity);
} else {
BigDecimal toolNum = mapper.getToolNum(entity);
// BigDecimal 比较库存 < 出库数量
if (toolNum.compareTo(entity.getOutNum()) < 0) {
// 库存不足计算差额
BigDecimal shortage = entity.getOutNum().subtract(toolNum);
return AjaxResult.error(String.format(
"库存不足!当前可用:%s需要出库%s短缺%s",
toolNum.stripTrailingZeros().toPlainString(),
entity.getOutNum().stripTrailingZeros().toPlainString(),
shortage.stripTrailingZeros().toPlainString()
));
}
mapper.updateGj(entity);
}
Integer out = mapper.out(entity);
@ -584,25 +597,51 @@ public class DevChangeServiceImpl implements DevChangeService {
*/
@Override
public AjaxResult outAll(CsDeviceDetails entity) {
try {
// 1. 首先查询需要出库的所有物品
List<CsDeviceDetails> outAllList = mapper.getOutAllList(entity);
Integer out = mapper.outAll(entity);
if (out > 0) {
outAllList.forEach(item -> {
if (item.getDevType().equals("1")) {
mapper.updateZb(item);
} else {
mapper.updateGj(item);
// 2. 先检查所有工器具的库存是否充足
for (CsDeviceDetails item : outAllList) {
if (!item.getDevType().equals("1")) {
// 工器具需要检查库存
BigDecimal toolNum = mapper.getToolNum(item); // 注意参数应该是 item
BigDecimal outNum = item.getOutNum();
if (toolNum.compareTo(outNum) < 0) {
BigDecimal shortage = outNum.subtract(toolNum);
return AjaxResult.error(String.format(
"库存不足!工具:%s当前可用%s需要出库%s短缺%s",
item.getTypeName(),
toolNum.stripTrailingZeros().toPlainString(),
outNum.stripTrailingZeros().toPlainString(),
shortage.stripTrailingZeros().toPlainString()
));
}
});
}
}
return out > 0 ? AjaxResult.success("出库成功") : AjaxResult.error("出库失败");
// 3. 所有库存检查通过后执行出库
Integer out = mapper.outAll(entity);
if (out <= 0) {
return AjaxResult.error("出库失败");
}
// 4. 更新库存
for (CsDeviceDetails item : outAllList) {
if (item.getDevType().equals("1")) {
// 装备类型
mapper.updateZb(item);
} else {
// 工器具类型 - 此时库存肯定是充足的
mapper.updateGj(item);
}
}
return AjaxResult.success("出库成功");
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("出库失败");
log.error("批量出库失败", e);
throw new RuntimeException("出库失败:" + e.getMessage());
}
}
@ -671,6 +710,18 @@ public class DevChangeServiceImpl implements DevChangeService {
if (entity.getDevType().equals("1")) {
mapper.updateOrderZb(entity);
} else {
BigDecimal toolNum = mapper.getToolNum(entity);
// BigDecimal 比较库存 < 出库数量
if (toolNum.compareTo(entity.getOutNum()) < 0) {
// 库存不足计算差额
BigDecimal shortage = entity.getOutNum().subtract(toolNum);
return AjaxResult.error(String.format(
"库存不足!当前可用:%s需要出库%s短缺%s",
toolNum.stripTrailingZeros().toPlainString(),
entity.getOutNum().stripTrailingZeros().toPlainString(),
shortage.stripTrailingZeros().toPlainString()
));
}
mapper.updateOrderGj(entity);
}
Integer out = mapper.orderOut(entity);
@ -686,23 +737,53 @@ public class DevChangeServiceImpl implements DevChangeService {
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult orderOutAll(CsDeviceDetails entity) {
try {
// 1. 首先查询需要出库的所有物品
List<CsDeviceDetails> outAllList = mapper.getOrderOutAllList(entity);
Integer out = mapper.orderOutAll(entity);
if (out > 0) {
outAllList.forEach(item -> {
if (item.getDevType().equals("0")) {
mapper.updateOrderZb(item);
} else {
mapper.updateOrderGj(item);
// 2. 先检查所有工器具的库存是否充足
for (CsDeviceDetails item : outAllList) {
if (!item.getDevType().equals("0")) {
// 工器具需要检查库存
BigDecimal toolNum = mapper.getToolNum(item); // 注意参数应该是 item
BigDecimal outNum = item.getOutNum();
if (toolNum.compareTo(outNum) < 0) {
BigDecimal shortage = outNum.subtract(toolNum);
return AjaxResult.error(String.format(
"库存不足!工具:%s当前可用%s需要出库%s短缺%s",
item.getTypeName(),
toolNum.stripTrailingZeros().toPlainString(),
outNum.stripTrailingZeros().toPlainString(),
shortage.stripTrailingZeros().toPlainString()
));
}
});
}
}
return out > 0 ? AjaxResult.success("出库成功") : AjaxResult.error("出库失败");
// 3. 所有库存检查通过后执行出库
Integer out = mapper.orderOutAll(entity);
if (out <= 0) {
return AjaxResult.error("出库失败");
}
// 4. 更新库存
for (CsDeviceDetails item : outAllList) {
if (item.getDevType().equals("0")) {
// 装备类型
mapper.updateOrderZb(item);
} else {
// 工器具类型 - 此时库存肯定是充足的
mapper.updateOrderGj(item);
}
}
return AjaxResult.success("出库成功");
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("出库失败");
log.error("批量出库失败", e);
throw new RuntimeException("出库失败:" + e.getMessage());
}
}

View File

@ -47,7 +47,7 @@ public class ToolLedgerAllEntity implements Serializable {
* 建议后续用枚举
*/
@Excel(name = "管理模式", sort = 12)
private Integer manageMode;
private String manageMode;
/**
* 装备原值仅编码设备

View File

@ -133,6 +133,12 @@ public class ToolLedgerServiceImpl implements ToolLedgerService {
*/
@Override
public List<ToolLedgerEntity> getToolByTypeId(ToolLedgerEntity entity) {
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
Long userId = SecurityUtils.getLoginUser().getUserid();
// 管理员和省公司可查看所有数据
if (!userId.equals(ADMIN_ID) || !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
entity.setCompanyId(deptId);
}
return mapper.getToolByTypeId(entity);
}
@ -142,6 +148,12 @@ public class ToolLedgerServiceImpl implements ToolLedgerService {
*/
@Override
public List<ToolLedgerEntity> getToolByPro(ToolLedgerEntity entity) {
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
Long userId = SecurityUtils.getLoginUser().getUserid();
// 管理员和省公司可查看所有数据
if (!userId.equals(ADMIN_ID) || !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
entity.setCompanyId(deptId);
}
return mapper.getToolByPro(entity);
}
}

View File

@ -1,5 +1,6 @@
package com.bonus.material.toolProcess.domain;
import com.bonus.material.devchange.domain.MaDevFile;
import com.bonus.material.tool.domain.ToolEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -8,6 +9,7 @@ import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Data
@AllArgsConstructor
@ -72,4 +74,26 @@ public class ToolApplyDetailsEntity extends ToolEntity {
private String status;
private String supplierName;
/**
* 合格证
* 说明装备合格证的URL列表存储合格证扫描件或照片
*/
private List<MaDevFile> certificates;
/**
* 定期检验报告
* 说明装备定期检验报告的URL列表
*/
private List<MaDevFile> inspectionReports;
/**
* 采购发票
* 说明装备采购发票的URL列表存储发票扫描件或照片
*/
private List<MaDevFile> purchaseInvoices;
}

View File

@ -48,7 +48,7 @@ public interface ToolApplyMapper {
* @return 结果
*/
Integer addDetail(List<ToolApplyDetailsEntity> entity);
Integer addDetail(ToolApplyDetailsEntity entity);
/**
* 工具录入申请单表格

View File

@ -2,6 +2,8 @@ package com.bonus.material.toolProcess.service.Impl;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.devchange.mapper.MaDevInfoMapper;
import com.bonus.material.device.mapper.DevMergeMapper;
import com.bonus.material.tool.domain.ToolEntity;
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
import com.bonus.material.toolLedger.mapper.ToolLedgerMapper;
@ -11,6 +13,7 @@ import com.bonus.material.toolProcess.mapper.ToolApplyMapper;
import com.bonus.material.toolProcess.service.ToolApplyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -29,6 +32,10 @@ public class ToolApplyServiceImpl implements ToolApplyService {
private ToolApplyMapper toolApplyMapper;
@Resource
private ToolLedgerMapper toolLedgerMapper;
@Resource
private DevMergeMapper devMergeMapper;
@Autowired
private MaDevInfoMapper maDevInfoMapper;
/**
* 工具申请单表格
@ -123,8 +130,36 @@ public class ToolApplyServiceImpl implements ToolApplyService {
@Override
public AjaxResult addDetail(List<ToolApplyDetailsEntity> entity) {
try {
Integer num = toolApplyMapper.addDetail(entity);
return num > 0 ? AjaxResult.success(entity) : AjaxResult.error("新增失败");
for (ToolApplyDetailsEntity detail : entity) {
Integer num = toolApplyMapper.addDetail(detail);
if (num > 0) {
detail.getCertificates().forEach(item -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
item.setFileType(2);
item.setMaId(detail.getId() + 200000);
item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(item);
});
detail.getInspectionReports().forEach(item -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
item.setFileType(3);
item.setMaId(detail.getId() + 200000);
item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(item);
});
detail.getPurchaseInvoices().forEach(item -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
item.setFileType(4);
item.setMaId(detail.getId() + 200000);
item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(item);
});
}
}
return AjaxResult.success("新增成功");
} catch (Exception e) {
log.error(e.getMessage());
return AjaxResult.error("新增失败");
@ -200,6 +235,7 @@ public class ToolApplyServiceImpl implements ToolApplyService {
private void addToolLedger(List<ToolApplyDetailsEntity> toolApplyDetailsEntities) {
toolApplyDetailsEntities.forEach(item -> {
if (item.getManageType().equals("0")) {
ToolLedgerEntity toolLedgerEntity = new ToolLedgerEntity();
toolLedgerEntity.setTypeId(item.getTypeId());
@ -214,6 +250,35 @@ public class ToolApplyServiceImpl implements ToolApplyService {
toolLedgerEntity.setToolCode(toolLedgerMapper.getCode());
toolLedgerMapper.add(toolLedgerEntity);
toolLedgerEntity.setCertificates(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 2));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 2);
toolLedgerEntity.setInspectionReports(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 3));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 3);
toolLedgerEntity.setPurchaseInvoices(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 4));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 4);
toolLedgerEntity.getCertificates().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(2);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
toolLedgerEntity.getInspectionReports().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(3);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
toolLedgerEntity.getPurchaseInvoices().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(4);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
} else {
ToolLedgerEntity byType = toolLedgerMapper.getByType(item.getTypeId());
if (byType != null) {
@ -237,7 +302,38 @@ public class ToolApplyServiceImpl implements ToolApplyService {
toolLedgerEntity.setTotalNum(item.getApplyNum());
toolLedgerEntity.setAvailableNum(item.getApplyNum());
toolLedgerEntity.setOriginCost(item.getToolPrice());
toolLedgerMapper.add(toolLedgerEntity);
toolLedgerEntity.setCertificates(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 2));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 2);
toolLedgerEntity.setInspectionReports(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 3));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 3);
toolLedgerEntity.setPurchaseInvoices(maDevInfoMapper.getFileList(Math.toIntExact(item.getId() + 200000L), 4));
maDevInfoMapper.delFileList(Math.toIntExact(item.getId() + 200000L), 4);
toolLedgerEntity.getCertificates().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(2);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
toolLedgerEntity.getInspectionReports().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(3);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
toolLedgerEntity.getPurchaseInvoices().forEach(file -> {
// 这里编写对每个 image 的处理逻辑比如打印处理等
file.setFileType(4);
file.setMaId(Math.toIntExact(toolLedgerEntity.getId() + 100000L));
file.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid()));
devMergeMapper.interFile(file);
});
}
}
});

View File

@ -738,6 +738,14 @@
END, ''
) AS id,
cdcd.dev_type AS devType,
COALESCE(
CASE
WHEN cdcd.dev_type = '1' THEN CONCAT(a.device_name, '')
WHEN cdcd.dev_type = '2' THEN CONCAT(tt1.type_name, '')
ELSE ''
END, ''
) AS typeName,
COALESCE(cdcd.num, 0) - COALESCE(cdcd.real_num, 0) AS outNum
FROM cs_device_change_details cdcd
@ -749,6 +757,8 @@
ON cdcd.dev_type = '2'
AND cdcd.dev_type_id = b.type_id
AND (cdcd.dev_code = '/' OR cdcd.dev_code = b.tool_code)
LEFT JOIN tool_type tt ON tt.type_id = b.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
WHERE cdcd.del_flag = 0
AND cdcd.dev_type IN ('1', '2')
AND cdcd.is_finished != '1'
@ -1064,6 +1074,11 @@
AND cdcd.ma_id = b.id
WHERE cdcd.order_id = #{id}
</select>
<select id="getToolNum" resultType="java.math.BigDecimal">
SELECT available_num
FROM tool_ledger
WHERE id = #{id}
</select>
<insert id="addChangeInfoNew" keyProperty="id" useGeneratedKeys="true">

View File

@ -409,6 +409,13 @@
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue == null">
and mdi.buy_price = #{minOriginalValue}
</if>
<if test="maxOriginalValue != null and maxOriginalValue != '' and minOriginalValue == null">
and mdi.buy_price = #{maxOriginalValue}
</if>
<if test="startProductionDate != null and startProductionDate != '' and endProductionDate != null and endProductionDate != ''">
and DATE_FORMAT(mdi.production_date,'%Y-%m-%d') between #{startProductionDate} and #{endProductionDate}
</if>
@ -630,6 +637,14 @@
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue == null">
and mdi.buy_price = #{minOriginalValue}
</if>
<if test="maxOriginalValue != null and maxOriginalValue != '' and minOriginalValue == null ">
and mdi.buy_price = #{maxOriginalValue}
</if>
<if test="startProductionDate != null and startProductionDate != '' and endProductionDate != null and endProductionDate != ''">
and DATE_FORMAT(mdi.production_date,'%Y-%m-%d') between #{startProductionDate} and #{endProductionDate}
</if>

View File

@ -49,7 +49,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectDevInfoList" parameterType="com.bonus.material.device.domain.vo.DevInfoVo" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
<!-- 注意UNION ALL 组合查询时,需给每个子查询加括号,且单个子查询的 order by 需配合 limit否则可能失效 -->
SELECT
t.picUrl,
t.proType,
t.mainGx,
t.childGx,
t.devCategory,
t.devSubcategory,
t.devName,
t.devType,
t.manageMode,
t.maId,
t.code,
t.identifyCode,
t.deviceName,
t.deviceCount,
t.typeId,
t.maStatus,
t.brand,
t.productionDate,
t.workingHours,
t.person,
t.personPhone,
t.createTime,
t.updateTime,
t.companyId,
t.companyName,
t.operateAddress,
t.dayLeasePrice
-- 注意:外层只查询业务需要的字段,去掉子查询中新增的辅助字段
FROM (
-- 第一个子查询:设备表数据
(
SELECT
IFNULL(mdf.file_url, bfi.url) AS picUrl,
@ -60,25 +90,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mtv.devSubcategory,
mtv.devName,
'0' AS devType,
'0' AS manageMode, -- 第一部分的 manageMode第9列
d.ma_id AS maId, -- 第10列
d.code AS `code`, -- 第11列
d.identify_code AS identifyCode, -- 第12列
d.device_name AS deviceName, -- 第13列
d.device_count AS deviceCount, -- 第14列
d.type_id AS typeId, -- 第15列
d.ma_status AS maStatus, -- 第16列
d.brand AS brand, -- 第17列
d.production_date AS productionDate, -- 第18列
d.working_hours AS workingHours, -- 第19列
sd.leader AS person, -- 20. 对应 person
sd.phone AS personPhone, -- 21. 对应 personPhone
d.create_time AS createTime, -- 第22列
d.update_time AS updateTime, -- 第23列
d.on_company AS companyId, -- 第24列
sd.dept_name AS companyName, -- 第25列
c.operate_address AS operateAddress, -- 第26列
COALESCE(d.lease_price, mt.lease_price) AS dayLeasePrice
'0' AS manageMode,
d.ma_id AS maId,
d.code AS `code`,
d.identify_code AS identifyCode,
d.device_name AS deviceName,
d.device_count AS deviceCount,
d.type_id AS typeId,
d.ma_status AS maStatus,
d.brand AS brand,
d.production_date AS productionDate,
d.working_hours AS workingHours,
sd.leader AS person,
sd.phone AS personPhone,
d.create_time AS createTime,
d.update_time AS updateTime,
d.on_company AS companyId,
sd.dept_name AS companyName,
c.operate_address AS operateAddress,
COALESCE(d.lease_price, mt.lease_price) AS dayLeasePrice,
-- 辅助字段:用于外层筛选(原表字段映射,无业务意义)
d.location AS location,
d.province_id AS provinceId,
d.city_id AS cityId,
d.area_id AS areaId,
mtv.maxTypeId AS maType,
null AS toolType,
c.company_name AS companyNameOrigin,
d.production_date AS productionDateOrigin,
d.working_hours AS workingHoursOrigin,
d.update_time AS updateTimeOrigin -- 用于外层时间筛选和排序
FROM
ma_dev_info d
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
@ -87,127 +129,225 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
LEFT JOIN bm_file_info bfi ON d.ma_id = bfi.model_id AND bfi.file_type = '0' AND bfi.task_type = '17'
LEFT JOIN ma_dev_file mdf ON d.ma_id = mdf.ma_id AND mdf.file_type = '1' AND mdf.is_active = '1'
<where>
<if test="maId != null ">and d.ma_id = #{maId}</if>
<if test="code != null and code != ''">and d.code = #{code}</if>
<if test="deviceName != null and deviceName != ''">
and d.device_name like concat('%',#{deviceName},'%')
</if>
<if test="maStatus != null">and (d.ma_status = 1 or d.ma_status = 2 or d.ma_status = 3)</if>
<if test="leaseScope != null ">and d.lease_scope = #{leaseScope}</if>
<if test="location != null and location != ''">and d.location = #{location}</if>
<if test="provinceId != null and provinceId != ''">and d.province_id = #{provinceId}</if>
<if test="cityId != null and cityId != ''">and d.city_id = #{cityId}</if>
<if test="areaId != null and areaId != ''">and d.area_id = #{areaId}</if>
<if test="brand != null and brand != ''">and d.brand = #{brand}</if>
<if test="ageMin != null and ageMax != null">
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &gt;= #{ageMin}
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &lt;= #{ageMax}
</if>
<if test="ageMin == null and ageMax != null">
<!-- 原逻辑可能有误ageMax 应该是“小于等于”?如果是“大于等于”请保留,否则改为 &lt;= -->
and TIMESTAMPDIFF(YEAR, d.production_date, NOW()) &lt;= #{ageMax}
</if>
<if test="workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != ''">
and d.working_hours &gt;= #{workingHoursMin} and d.working_hours &lt;= #{workingHoursMax}
</if>
<if test="description != null and description != ''">and d.description = #{description}</if>
<if test="gpsCode != null and gpsCode != ''">and d.gps_code = #{gpsCode}</if>
<if test="companyId != null and companyId != ''">and d.on_company = #{companyId}</if>
<if test="specification != null ">and d.specification = #{specification}</if>
<if test="deposit != null ">and d.deposit = #{deposit}</if>
<if test="startTime != null and endTime != null">
and d.update_time between #{startTime} and #{endTime}
</if>
<if test="keyWord != null and keyWord != ''">
and (
locate(#{keyWord},mtv.mainGx) > 0
or locate(#{keyWord},mtv.childGx) > 0
or locate(#{keyWord},mtv.devCategory) > 0
or locate(#{keyWord},mtv.devSubcategory) > 0
or locate(#{keyWord},mtv.devName) > 0
or locate(#{keyWord},c.company_name) > 0
or locate(#{keyWord},d.device_name) > 0
or locate(#{keyWord},d.identify_code) > 0
)
</if>
<if test="maType != null and maType != ''">
and mtv.maxTypeId = #{maType}
</if>
and d.is_active='1'
and d.up_down_status ='1'
</where>
order by
d.is_active
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'ASC'">
,d.create_time ASC
</if>
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'DESC'">
,d.create_time DESC
</if>
-- 子查询加 limit 避免 order by 失效MySQL 特性)
LIMIT 1000000 -- 根据实际数据量调整,确保覆盖所有符合条件的数据
WHERE
d.is_active = '1'
AND d.up_down_status = '1'
)
UNION ALL
-- 第二个子查询:工具表数据
(
SELECT
SUBSTRING_INDEX(tt.fileList, ',', 1) AS picUrl, -- 1. 对应第一部分 picUrl
'' AS proType, -- 2. 对应 proType
'' AS mainGx, -- 3. 对应 mainGx
'' AS childGx, -- 4. 对应 childGx
'' AS devCategory, -- 5. 对应 devCategory
'' AS devSubcategory, -- 6. 对应 devSubcategory
tt.type_name AS devName, -- 7. 对应 devName
'1' AS devType, -- 8. 对应 devType
tl.manage_mode AS manageMode, -- 9. 对应 manageMode与第一部分位置一致
tl.id AS maId, -- 10. 对应 maId
tl.tool_code AS `code`, -- 11. 对应 code
tl.identify_code AS identifyCode, -- 12. 对应 identifyCode
tt1.type_name AS deviceName, -- 13. 对应 deviceName
tl.available_num AS deviceCount, -- 14. 对应 deviceCount
tl.type_id AS typeId, -- 15. 对应 typeId
tl.STATUS AS maStatus, -- 16. 对应 maStatus
'' AS brand, -- 17. 对应 brand
tl.production_date AS productionDate, -- 18. 对应 productionDate
0 AS workingHours, -- 19. 对应 workingHours
sd.leader AS person, -- 20. 对应 person
sd.phone AS personPhone, -- 21. 对应 personPhone
tl.create_time AS createTime, -- 22. 对应 createTime
tl.update_time AS updateTime, -- 23. 对应 updateTime
tl.company_id AS companyId, -- 24. 对应 companyId
sd.dept_name AS companyName, -- 25. 对应 companyName
c.operate_address AS operateAddress, -- 26. 对应 operateAddress列数对齐
COALESCE(tl.lease_price, tt.lease_price) AS dayLeasePrice
SUBSTRING_INDEX(tt.fileList, ',', 1) AS picUrl,
'' AS proType,
'' AS mainGx,
'' AS childGx,
'' AS devCategory,
'' AS devSubcategory,
tt.type_name AS devName,
'1' AS devType,
tl.manage_mode AS manageMode,
tl.id AS maId,
tl.tool_code AS `code`,
tl.identify_code AS identifyCode,
tt1.type_name AS deviceName,
tl.available_num AS deviceCount,
tl.type_id AS typeId,
tl.STATUS AS maStatus,
'' AS brand,
tl.production_date AS productionDate,
0 AS workingHours,
sd.leader AS person,
sd.phone AS personPhone,
tl.create_time AS createTime,
tl.update_time AS updateTime,
tl.company_id AS companyId,
sd.dept_name AS companyName,
c.operate_address AS operateAddress,
COALESCE(tl.lease_price, tt.lease_price) AS dayLeasePrice,
-- 辅助字段与设备表对齐筛选条件需要无则设为NULL/''/0
NULL AS location,
NULL AS provinceId,
NULL AS cityId,
NULL AS areaId,
null AS maType, -- 工具表的maType对应tt4.type_id
tt4.type_id AS toolType, -- 工具表的maType对应tt4.type_id
c.company_name AS companyNameOrigin,
tl.production_date AS productionDateOrigin,
0 AS workingHoursOrigin, -- 工具表工时固定为0
tl.update_time AS updateTimeOrigin -- 用于外层时间筛选和排序
FROM
tool_ledger tl
LEFT JOIN sys_dept sd ON tl.company_id = sd.dept_id
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id -- 确保 tt 有 parent_id否则可能查不到数据
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id -- 确保 tt 有 parent_id否则可能查不到数据
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id -- 确保 tt 有 parent_id否则可能查不到数据
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id -- 确保 tt 有 parent_id否则可能查不到数据
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
WHERE
tl.up_down_status = '1'
-- 工具表也可添加动态筛选条件(如需),示例:
<if test="companyId != null and companyId != ''">
and tl.company_id = #{companyId}
)
) t
-- 外层筛选条件:所有动态和固定筛选条件集中在这里
WHERE
-- 1. 基础筛选条件
<if test="maId != null ">
t.maId = #{maId}
</if>
<if test="code != null and code != ''">
<if test="maId != null ">AND</if>
t.code = #{code}
</if>
<if test="deviceName != null and deviceName != ''">
<if test="maId != null or code != null and code != ''">AND</if>
t.deviceName LIKE CONCAT('%', #{deviceName}, '%')
</if>
<if test="maStatus != null">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != ''">AND</if>
t.maStatus IN (1, 2, 3)
</if>
<if test="leaseScope != null ">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null">
AND
</if>
t.leaseScope = #{leaseScope}
</if>
<if test="location != null and location != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null">
AND
</if>
t.location = #{location}
</if>
<if test="provinceId != null and provinceId != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != ''">
AND
</if>
t.provinceId = #{provinceId}
</if>
<if test="cityId != null and cityId != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != ''">
AND
</if>
t.cityId = #{cityId}
</if>
<if test="areaId != null and areaId != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != ''">
AND
</if>
t.areaId = #{areaId}
</if>
<if test="brand != null and brand != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != ''">
AND
</if>
t.brand = #{brand}
</if>
-- 2. 设备年龄筛选(工具表无生产时间则自动过滤,不影响)
<if test="ageMin != null and ageMax != null">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != ''">
AND
</if>
TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) >= #{ageMin}
AND TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) &lt;= #{ageMax}
</if>
<if test="ageMin == null and ageMax != null">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null and ageMax != null)">
AND
</if>
TIMESTAMPDIFF(YEAR, t.productionDateOrigin, NOW()) &lt;= #{ageMax}
</if>
-- 3. 工时筛选工具表工时为0可根据需求调整
<if test="workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null)">
AND
</if>
t.workingHoursOrigin >= #{workingHoursMin}
AND t.workingHoursOrigin &lt;= #{workingHoursMax}
</if>
-- 4. 其他基础筛选
<if test="description != null and description != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '')">
AND
</if>
t.description = #{description}
</if>
<if test="gpsCode != null and gpsCode != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != ''">
AND
</if>
t.gpsCode = #{gpsCode}
</if>
<if test="companyId != null and companyId != ''">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != '' or gpsCode != null and gpsCode != ''">
AND
</if>
t.companyId = #{companyId}
</if>
<if test="specification != null ">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != '' or gpsCode != null and gpsCode != '' or companyId != null and companyId != ''">
AND
</if>
t.specification = #{specification}
</if>
<if test="deposit != null ">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != '' or gpsCode != null and gpsCode != '' or companyId != null and companyId != '' or specification != null">
AND
</if>
t.deposit = #{deposit}
</if>
-- 5. 时间范围筛选
<if test="startTime != null and endTime != null">
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != '' or gpsCode != null and gpsCode != '' or companyId != null and companyId != '' or specification != null or deposit != null">
AND
</if>
t.updateTimeOrigin BETWEEN #{startTime} AND #{endTime}
</if>
-- 6. 关键字模糊筛选(覆盖设备和工具的所有关键字段)
<if test="keyWord != null and keyWord != ''">
and (
locate(#{keyWord}, tt.type_name) > 0
or locate(#{keyWord}, tt1.type_name) > 0
or locate(#{keyWord}, tl.identify_code) > 0
or locate(#{keyWord}, sd.dept_name) > 0
<if test="maId != null or code != null and code != '' or deviceName != null and deviceName != '' or maStatus != null or leaseScope != null or location != null and location != '' or provinceId != null and provinceId != '' or cityId != null and cityId != '' or areaId != null and areaId != '' or brand != null and brand != '' or (ageMin != null or ageMax != null) or (workingHoursMin != null and workingHoursMin != '' and workingHoursMax != null and workingHoursMax != '') or description != null and description != '' or gpsCode != null and gpsCode != '' or companyId != null and companyId != '' or specification != null or deposit != null or (startTime != null and endTime != null)">
AND
</if>
(
-- 设备表关键字段
LOCATE(#{keyWord}, t.mainGx) > 0
OR LOCATE(#{keyWord}, t.childGx) > 0
OR LOCATE(#{keyWord}, t.devCategory) > 0
OR LOCATE(#{keyWord}, t.devSubcategory) > 0
OR LOCATE(#{keyWord}, t.devName) > 0
OR LOCATE(#{keyWord}, t.companyNameOrigin) > 0
OR LOCATE(#{keyWord}, t.deviceName) > 0
OR LOCATE(#{keyWord}, t.identifyCode) > 0
-- 工具表关键字段(复用设备表字段别名,已在子查询中映射)
OR LOCATE(#{keyWord}, t.devName) > 0 -- 对应tt.type_name
OR LOCATE(#{keyWord}, t.deviceName) > 0 -- 对应tt1.type_name
OR LOCATE(#{keyWord}, t.companyName) > 0 -- 对应sd.dept_name
)
</if>
<if test="toolType != null and toolType != ''">
and tt4.type_id = #{toolType}
-- 7. 设备类型筛选(设备表=mtv.maxTypeId工具表=tt4.type_id
<if test="maType != null and maType != ''">
AND t.maType = #{maType}
</if>
-- 子查询加 limit 避免 order by 问题(如果工具表也需要排序,可在这里加)
LIMIT 1000000
)
-- 可选:整体排序(如果需要合并后统一排序,取消下面注释)
-- 8. 工具类型筛选仅对工具表生效设备表该字段为NULL自动过滤
<if test="toolType != null and toolType != ''">
AND t.toolType = #{toolType}
</if>
<if test="updateTimeOrderBy == null">
ORDER BY t.updateTime DESC
</if>
<if test="updateTimeOrderBy != null">
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'ASC'">
ORDER BY
t.updateTime ASC
</if>
<if test="updateTimeOrderBy != null and updateTimeOrderBy == 'DESC'">
ORDER BY
t.updateTime DESC
</if>
</if>
</select>
<select id="selectDevInfoHotList" parameterType="com.bonus.material.device.domain.vo.DevInfoVo" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
@ -638,7 +778,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM
sys_dept sd
LEFT JOIN bm_company_info b ON sd.dept_id = b.company_id
WHERE sd.parent_id = 0
WHERE sd.del_flag = 0
<if test="companyId != null">
and sd.dept_id = #{companyId}
</if>

View File

@ -478,6 +478,13 @@
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue == null">
and mdi.buy_price = #{minOriginalValue}
</if>
<if test="maxOriginalValue != null and maxOriginalValue != '' and minOriginalValue == null">
and mdi.buy_price = #{maxOriginalValue}
</if>
<!-- 生产日期范围 -->
<if test="startProductionDate != null and endProductionDate != null ">
and mdi.production_date &gt;= #{startProductionDate}
@ -583,6 +590,13 @@
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue != null and maxOriginalValue != ''">
and mdi.buy_price &gt;= #{minOriginalValue} and mdi.buy_price &lt;= #{maxOriginalValue}
</if>
<if test="minOriginalValue != null and minOriginalValue != '' and maxOriginalValue == null">
and mdi.buy_price = #{minOriginalValue}
</if>
<if test="maxOriginalValue != null and maxOriginalValue != '' and minOriginalValue == null">
and mdi.buy_price = #{maxOriginalValue}
</if>
<!-- 生产日期范围 -->
<if test="startProductionDate != null and endProductionDate != null ">
and mdi.production_date &gt;= #{startProductionDate}

View File

@ -152,7 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
up.dept_name AS czcompanyName,
mdi.person AS person,
sd.phone AS personPhone,
dept.phone AS phoneNumber,
su.phonenumber AS phoneNumber,
su.nick_name as buyerName,
sd.dept_name as sellerName,
moi.address,

View File

@ -31,6 +31,7 @@
<if test="upDownStatus != null and upDownStatus != ''">up_down_status,</if>
<if test="companyId != null">company_id,</if>
<if test="remark != null and remark != ''">remark,</if>
<!-- 兜底:至少保留一个必填字段(根据你的业务,选一个非空字段,比如 typeId -->
<if test="typeId == null">type_id</if> <!-- 避免字段列表为空,若 typeId 是必填则可省略此兜底 -->
</trim>
@ -93,25 +94,21 @@
AND tt2.del_flag = '0'
AND tt3.del_flag = '0'
AND tt4.del_flag = '0'
<if test="fourthParentId != null and fourthParentId != ''">
AND tt4.type_id =#{fourthParentId}
<if test="typeId != null and typeId != ''">
AND (tt1.type_id = #{typeId} or tt2.type_id = #{typeId} or tt3.type_id =
#{typeId} or tt4.type_id =#{typeId})
</if>
<if test="greatGrandparentId != null and greatGrandparentId != ''">
AND tt3.type_id = #{greatGrandparentId}
</if>
<if test="grandparentTypeId != null and grandparentTypeId != ''">
AND tt2.type_id = #{grandparentTypeId}
</if>
<if test="parentTypeId != null and parentTypeId != ''">
AND tt1.type_id = #{parentTypeId}
<if test="manageMode != null and manageMode != ''">
AND tt.manage_type = #{manageMode}
</if>
<if test="companyId != null">
AND (tl.company_id = #{companyId} OR tl.company_id IS NULL)
</if>
<if test="typeName != null and typeName != ''">
AND tt.type_name LIKE CONCAT('%', #{typeName}, '%')
</if>
GROUP BY tt.type_id
GROUP BY tl.type_id
ORDER BY
tl.create_time DESC
</select>
@ -281,26 +278,29 @@
a.typeName,
a.parentTypeName
FROM (
SELECT tl.tool_code AS toolCode,
SELECT tl.tool_code AS toolCode,
tl.available_num AS totalNum,
tt.type_name AS typeName,
tt1.type_name AS parentTypeName
tt.type_name AS typeName,
tt1.type_name AS parentTypeName
FROM tool_ledger tl
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
INNER JOIN tool_type tt1 ON tt1.type_id = tt.parent_id
WHERE tl.status = #{status}
AND tl.type_id = #{typeId}
AND tl.manage_mode = #{type}
) a
WHERE 1=1
<if test="keyWord != null and keyWord != ''">
AND (
a.toolCode LIKE CONCAT('%', #{keyWord}, '%')
OR a.typeName LIKE CONCAT('%', #{keyWord}, '%')
OR a.parentTypeName LIKE CONCAT('%', #{keyWord}, '%')
)
<if test="companyId != null">
AND (tl.company_id = #{companyId} OR tl.company_id IS NULL)
</if>
) a
<where>
<if test="keyWord != null and keyWord != ''">
AND (
a.toolCode LIKE CONCAT('%', #{keyWord}, '%')
OR a.typeName LIKE CONCAT('%', #{keyWord}, '%')
OR a.parentTypeName LIKE CONCAT('%', #{keyWord}, '%')
)
</if>
</where>
</select>
<select id="getToolByPro" resultType="com.bonus.material.toolLedger.domain.ToolLedgerEntity">
SELECT cdc.pro_name AS proName, -- 工程名称
@ -309,7 +309,7 @@
tt1.type_name AS parentTypeName,
IFNULL(
SUM(CASE
WHEN cdc.type = '2' AND cdcd.is_finished = '1' THEN IFNULL(cdcd.real_num, 0)
WHEN cdc.type = '2' AND cdcd.is_finished in ('1', '2') THEN IFNULL(cdcd.real_num, 0)
ELSE 0 END),
0
) - IFNULL(SUM(CASE WHEN cdc.type = '1' THEN IFNULL(cdcd.real_num, 0) ELSE 0 END), 0) -

View File

@ -18,7 +18,7 @@
)
), #{createBy}, now(), #{companyId})
</insert>
<insert id="addDetail" parameterType="java.util.List">
<insert id="addDetail" parameterType="com.bonus.material.toolProcess.domain.ToolApplyEntity" useGeneratedKeys="true" keyProperty="id">
INSERT INTO tool_apply_details (
apply_id,
type_id,
@ -30,18 +30,16 @@
identify_code
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.applyId},
#{item.typeId},
#{item.supplierId},
#{item.applyNum},
#{item.originCost},
#{item.productionDate},
#{item.code},
#{item.identifyCode}
#{applyId},
#{typeId},
#{supplierId},
#{applyNum},
#{originCost},
#{productionDate},
#{code},
#{identifyCode}
)
</foreach>
</insert>
<update id="delete">
UPDATE tool_apply
@ -135,12 +133,12 @@
tt.parent_id AS parentId,
tt.unit_name AS unitName,
tt.manage_type AS manageType,
tt.level AS level,
tl.origin_cost as origin_cost
tt.LEVEL AS LEVEL,
tl.origin_cost AS origin_cost
FROM tool_type tt
left join tool_ledger tl on tt.type_id=tl.type_id
WHERE del_flag = '0'
and (manage_type = #{manageType} OR manage_type is null)
LEFT JOIN tool_ledger tl ON tt.type_id = tl.type_id and tl.manage_mode = '1'
WHERE tt.del_flag = '0'
and (tt.manage_type = #{manageType} OR tt.manage_type is null)
</select>
<select id="listByApplyId" resultType="com.bonus.material.toolProcess.domain.ToolApplyDetailsEntity">