Skip to content
网游世界
网游世界

吾生有涯,而知无涯。

  • 首页
  • PHP
    • ThinkPHP
    • FastAdmin
    • webman
  • JavaScript
    • jQuery
    • AdminLTE
  • Free Pascal
  • Java
    • JeeSite
    • 若依
    • ruoyi-vue-pro
  • 其它
    • 操作系统
    • 树莓派
    • 前端
    • Null
  • 关于
网游世界

吾生有涯,而知无涯。

JeeSite 删除数据拦截

3Vshej, 2023年12月29日 周五2023年12月29日 周五

单表操作删除时,默认框架已提供了,但有时候需要根据条件判断是否允许删除;如,客户表,如果客户信息已被使用,而不允许被删除。

方法同数据唯一性验证,查询关联表是否有引用记录,并统计数量,大于 0,则不允许删除。

CustomerDao.xml 中增加查询方法

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jeesite.modules.customer.dao.CustomerDao">
<!-- 查询数据
<select id="findList" resultType="Customer">
SELECT ${sqlMap.column.toSql()}
FROM ${sqlMap.table.toSql()}
<where>
${sqlMap.where.toSql()}
</where>
ORDER BY ${sqlMap.order.toSql()}
</select> -->
<select id="getOrderReviewNum" resultType="Long">
SELECT
count(0)
FROM
`product_order_review` a
where a.status =0 AND a.customer_code = #{customerCode}
LIMIT 1
</select>
<select id="getOrderNum" resultType="Long">
SELECT
count(0)
FROM
`product_work_order` a
where a.status =0 AND a.customer_code = #{customerCode}
LIMIT 1
</select>
<select id="getTransportNum" resultType="Long">
SELECT
count(0)
FROM
`product_transport` a
where a.customer_code = #{customerCode}
LIMIT 1
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.jeesite.modules.customer.dao.CustomerDao"> <!-- 查询数据 <select id="findList" resultType="Customer"> SELECT ${sqlMap.column.toSql()} FROM ${sqlMap.table.toSql()} <where> ${sqlMap.where.toSql()} </where> ORDER BY ${sqlMap.order.toSql()} </select> --> <select id="getOrderReviewNum" resultType="Long"> SELECT count(0) FROM `product_order_review` a where a.status =0 AND a.customer_code = #{customerCode} LIMIT 1 </select> <select id="getOrderNum" resultType="Long"> SELECT count(0) FROM `product_work_order` a where a.status =0 AND a.customer_code = #{customerCode} LIMIT 1 </select> <select id="getTransportNum" resultType="Long"> SELECT count(0) FROM `product_transport` a where a.customer_code = #{customerCode} LIMIT 1 </select> </mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jeesite.modules.customer.dao.CustomerDao">
    
    <!-- 查询数据
    <select id="findList" resultType="Customer">
        SELECT ${sqlMap.column.toSql()}
        FROM ${sqlMap.table.toSql()}
        <where>
            ${sqlMap.where.toSql()}
        </where>
        ORDER BY ${sqlMap.order.toSql()}
    </select> -->

    <select id="getOrderReviewNum" resultType="Long">
        SELECT
            count(0)
        FROM
            `product_order_review` a
        where a.status =0 AND a.customer_code = #{customerCode}
            LIMIT 1
    </select>

    <select id="getOrderNum" resultType="Long">
        SELECT
            count(0)
        FROM
            `product_work_order` a
        where a.status =0 AND a.customer_code = #{customerCode}
            LIMIT 1
    </select>

    <select id="getTransportNum" resultType="Long">
        SELECT
            count(0)
        FROM
            `product_transport` a
        where a.customer_code = #{customerCode}
            LIMIT 1
    </select>

</mapper>

CustomerDao.java 文件中,增加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Long getOrderReviewNum(String customerCode);
Long getOrderNum(String customerCode);
Long getTransportNum(String customerCode);
Long getOrderReviewNum(String customerCode); Long getOrderNum(String customerCode); Long getTransportNum(String customerCode);
    Long getOrderReviewNum(String customerCode);
    Long getOrderNum(String customerCode);
    Long getTransportNum(String customerCode);

CustomerService.java 中增加及调整 delete 方法

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@Autowired
private CustomerDao customerDao;
/**
* 删除数据
*
* @param customer
*/
@Override
@Transactional
public void delete(Customer customer) {
if (checkCustomerIsUse(customer.getCustomerCode())) {
throw new RuntimeException("客户已被使用,不能被删除");
}
super.delete(customer);
}
public Long getOrderReviewNum(String customerCode) {
return customerDao.getOrderReviewNum(customerCode);
}
public Long getOrderNum(String customerCode) {
return customerDao.getOrderNum(customerCode);
}
public Long getTransportNum(String customerCode) {
return customerDao.getTransportNum(customerCode);
}
public boolean checkCustomerIsUse(String customerCode) {
if (getOrderReviewNum(customerCode) > 0) return true;
if (getOrderNum(customerCode) > 0) return true;
if (getTransportNum(customerCode) > 0) return true;
return false;
}
@Autowired private CustomerDao customerDao; /** * 删除数据 * * @param customer */ @Override @Transactional public void delete(Customer customer) { if (checkCustomerIsUse(customer.getCustomerCode())) { throw new RuntimeException("客户已被使用,不能被删除"); } super.delete(customer); } public Long getOrderReviewNum(String customerCode) { return customerDao.getOrderReviewNum(customerCode); } public Long getOrderNum(String customerCode) { return customerDao.getOrderNum(customerCode); } public Long getTransportNum(String customerCode) { return customerDao.getTransportNum(customerCode); } public boolean checkCustomerIsUse(String customerCode) { if (getOrderReviewNum(customerCode) > 0) return true; if (getOrderNum(customerCode) > 0) return true; if (getTransportNum(customerCode) > 0) return true; return false; }
@Autowired
private CustomerDao customerDao;

/**
 * 删除数据
 *
 * @param customer
 */
@Override
@Transactional
public void delete(Customer customer) {
    if (checkCustomerIsUse(customer.getCustomerCode())) {
        throw new RuntimeException("客户已被使用,不能被删除");
    }
    super.delete(customer);
}


public Long getOrderReviewNum(String customerCode) {
    return customerDao.getOrderReviewNum(customerCode);
}

public Long getOrderNum(String customerCode) {
    return customerDao.getOrderNum(customerCode);
}

public Long getTransportNum(String customerCode) {
    return customerDao.getTransportNum(customerCode);
}

public boolean checkCustomerIsUse(String customerCode) {
    if (getOrderReviewNum(customerCode) > 0) return true;
    if (getOrderNum(customerCode) > 0) return true;
    if (getTransportNum(customerCode) > 0) return true;

    return false;
}

CustomerController.java 控制器中,调整 delete 方法

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/**
* 删除数据
*/
@RequiresPermissions("customer:customer:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(Customer customer) {
try {
customerService.delete(customer);
return renderResult(Global.TRUE, text("删除客户信息成功!"));
} catch (RuntimeException e) {
return renderResult(Global.FALSE, text(e.getMessage()));
}
}
/** * 删除数据 */ @RequiresPermissions("customer:customer:edit") @RequestMapping(value = "delete") @ResponseBody public String delete(Customer customer) { try { customerService.delete(customer); return renderResult(Global.TRUE, text("删除客户信息成功!")); } catch (RuntimeException e) { return renderResult(Global.FALSE, text(e.getMessage())); } }
/**
 * 删除数据
 */
@RequiresPermissions("customer:customer:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(Customer customer) {
    try {
        customerService.delete(customer);
        return renderResult(Global.TRUE, text("删除客户信息成功!"));
    } catch (RuntimeException e) {
        return renderResult(Global.FALSE, text(e.getMessage()));
    }
}

 

相关文章:

  1. JeeSite 列表中增加日期范围筛选 在开发中,需要进行日期范围筛选,那么可以按以下方法来进行。...
  2. JeeSite 列表中添加子列表 在 JeeSite 列表中,在业务中有需要查看子表数据。具体方法为:...
  3. JeeSite 导出数据 默认情况下,JeeSite 会自动生成导出代码,但有时候忘记了。这里介绍如何手动添加导出功能。...
  4. JeeSite 重置按钮不生效 测试人员在测试列表搜索时,设置搜索条件,点击“查询”按钮功能正常,点击“重置”按钮时,却没反应。...
Java JeeSite JeeSite 框架列表页删除

文章导航

Previous post
Next post

近期文章

  • Android Studio Gradle 配置国内镜像
  • 为什么重新发明轮子
  • ruoyi-vue-pro 匿名访问
  • VUE 中接收 code 异常
  • 关于 AI

归档

  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2024 年 7 月
  • 2024 年 6 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
除非特殊说明,本站作品采用知识共享署名 4.0 国际许可协议进行许可。
豫公网安备 41010402002622号 豫ICP备2020029609号-3
©2025 3Vshej
网游世界
  • 首页
  • PHP
    • ThinkPHP
    • FastAdmin
    • webman
  • JavaScript
    • jQuery
    • AdminLTE
  • Free Pascal
  • Java
    • JeeSite
    • 若依
    • ruoyi-vue-pro
  • 其它
    • 操作系统
    • 树莓派
    • 前端
    • Null
  • 关于