客户管理bug修改

This commit is contained in:
ll
2026-02-09 21:57:19 +08:00
parent 7dbe337a93
commit b84c35fe65
4 changed files with 134 additions and 27 deletions

View File

@@ -1,27 +1,44 @@
package com.zhyc.module.sale.controller; package com.zhyc.module.sale.controller;
import java.util.List; import java.util.List;
import java.util.Date; // 【修改点1】新增导入Date包
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhyc.common.annotation.Log; import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController; import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult; import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType; import com.zhyc.common.enums.BusinessType;
import com.zhyc.module.sale.domain.SxCustomer; import com.zhyc.module.sale.domain.SxCustomer;
import com.zhyc.module.sale.domain.SxCustomerExport; // 新增导入 import com.zhyc.module.sale.domain.SxCustomerExport;
import com.zhyc.module.sale.service.ISxCustomerService; import com.zhyc.module.sale.service.ISxCustomerService;
import com.zhyc.common.utils.poi.ExcelUtil; import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo; import com.zhyc.common.core.page.TableDataInfo;
/**
* 客户管理Controller
*
* @author ruoyi
* @date 2025-08-18
*/
@RestController @RestController
@RequestMapping("/customer/customer") @RequestMapping("/customer/customer")
public class SxCustomerController extends BaseController { public class SxCustomerController extends BaseController {
@Autowired @Autowired
private ISxCustomerService sxCustomerService; private ISxCustomerService sxCustomerService;
/**
* 查询客户管理列表
*/
@PreAuthorize("@ss.hasPermi('customer:customer:list')") @PreAuthorize("@ss.hasPermi('customer:customer:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SxCustomer sxCustomer) { public TableDataInfo list(SxCustomer sxCustomer) {
@@ -30,6 +47,9 @@ public class SxCustomerController extends BaseController {
return getDataTable(list); return getDataTable(list);
} }
/**
* 导出客户管理列表
*/
@PreAuthorize("@ss.hasPermi('customer:customer:export')") @PreAuthorize("@ss.hasPermi('customer:customer:export')")
@Log(title = "客户管理", businessType = BusinessType.EXPORT) @Log(title = "客户管理", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
@@ -41,14 +61,22 @@ public class SxCustomerController extends BaseController {
SxCustomerExport exportItem = new SxCustomerExport(); SxCustomerExport exportItem = new SxCustomerExport();
exportItem.setName(customer.getName()); exportItem.setName(customer.getName());
exportItem.setPhone(customer.getPhone()); exportItem.setPhone(customer.getPhone());
// 拼接完整地址
exportItem.setFullAddress( // 拼接所在地区 (省 + 市 + 区)
(customer.getProvince() != null ? customer.getProvince() : "") + String area = (customer.getProvince() != null ? customer.getProvince() : "") +
(customer.getCity() != null ? customer.getCity() : "") + (customer.getCity() != null ? customer.getCity() : "") +
(customer.getDistrict() != null ? customer.getDistrict() : "") + (customer.getDistrict() != null ? customer.getDistrict() : "");
(customer.getAddress() != null ? customer.getAddress() : "") exportItem.setArea(area);
);
exportItem.setRemark(customer.getRemark()); // 详细地址
exportItem.setAddress(customer.getAddress());
// 创建人 (从BaseEntity获取)
exportItem.setCreateBy(customer.getCreateBy());
// 创建日期 (从BaseEntity获取)
exportItem.setCreateTime(customer.getCreateTime());
return exportItem; return exportItem;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@@ -56,29 +84,54 @@ public class SxCustomerController extends BaseController {
util.exportExcel(response, exportList, "客户管理数据"); util.exportExcel(response, exportList, "客户管理数据");
} }
/**
* 获取客户管理详细信息
*/
@PreAuthorize("@ss.hasPermi('customer:customer:query')") @PreAuthorize("@ss.hasPermi('customer:customer:query')")
@GetMapping("/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable Long id) { public AjaxResult getInfo(@PathVariable("id") Long id) {
return success(sxCustomerService.selectSxCustomerById(id)); return success(sxCustomerService.selectSxCustomerById(id));
} }
/**
* 新增客户管理
*/
@PreAuthorize("@ss.hasPermi('customer:customer:add')") @PreAuthorize("@ss.hasPermi('customer:customer:add')")
@Log(title = "客户管理", businessType = BusinessType.INSERT) @Log(title = "客户管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody SxCustomer sxCustomer) { public AjaxResult add(@RequestBody SxCustomer sxCustomer) {
// 【新增】自动填充当前登录用户的 userId 和 deptId // 自动填充当前登录用户的 userId 和 deptId
sxCustomer.setUserId(getUserId()); sxCustomer.setUserId(getUserId());
sxCustomer.setDeptId(getDeptId()); sxCustomer.setDeptId(getDeptId());
// 自动填充创建人
sxCustomer.setCreateBy(getUsername());
// 【修改点2】自动填充创建时间为当前时间
sxCustomer.setCreateTime(new Date());
return toAjax(sxCustomerService.insertSxCustomer(sxCustomer)); return toAjax(sxCustomerService.insertSxCustomer(sxCustomer));
} }
/**
* 修改客户管理
*/
@PreAuthorize("@ss.hasPermi('customer:customer:edit')") @PreAuthorize("@ss.hasPermi('customer:customer:edit')")
@Log(title = "客户管理", businessType = BusinessType.UPDATE) @Log(title = "客户管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody SxCustomer sxCustomer) { public AjaxResult edit(@RequestBody SxCustomer sxCustomer) {
// 自动填充更新人
sxCustomer.setUpdateBy(getUsername());
// 【修改点3】自动填充更新时间为当前时间
sxCustomer.setUpdateTime(new Date());
return toAjax(sxCustomerService.updateSxCustomer(sxCustomer)); return toAjax(sxCustomerService.updateSxCustomer(sxCustomer));
} }
/**
* 删除客户管理
*/
@PreAuthorize("@ss.hasPermi('customer:customer:remove')") @PreAuthorize("@ss.hasPermi('customer:customer:remove')")
@Log(title = "客户管理", businessType = BusinessType.DELETE) @Log(title = "客户管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")

View File

@@ -122,6 +122,7 @@ public class SxCustomer extends BaseEntity {
@Override @Override
public String toString() { public String toString() {
// 修改:补充 BaseEntity 中的创建人、创建时间等重要字段,便于日志排查
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId()) .append("id", getId())
.append("name", getName()) .append("name", getName())
@@ -133,6 +134,10 @@ public class SxCustomer extends BaseEntity {
.append("remark", getRemark()) .append("remark", getRemark())
.append("userId", getUserId()) .append("userId", getUserId())
.append("deptId", getDeptId()) .append("deptId", getDeptId())
.append("createBy", getCreateBy()) // 补充创建人
.append("createTime", getCreateTime()) // 补充创建时间
.append("updateBy", getUpdateBy()) // 补充更新人
.append("updateTime", getUpdateTime()) // 补充更新时间
.toString(); .toString();
} }
} }

View File

@@ -1,7 +1,11 @@
package com.zhyc.module.sale.domain; package com.zhyc.module.sale.domain;
import com.zhyc.common.annotation.Excel; import com.zhyc.common.annotation.Excel;
import java.util.Date;
/**
* 客户管理导出对象
*/
public class SxCustomerExport { public class SxCustomerExport {
@Excel(name = "客户名称") @Excel(name = "客户名称")
private String name; private String name;
@@ -9,11 +13,23 @@ public class SxCustomerExport {
@Excel(name = "客户电话") @Excel(name = "客户电话")
private String phone; private String phone;
@Excel(name = "客户地址") /** 新增:所在地区 */
private String fullAddress; @Excel(name = "所在地区")
private String area;
@Excel(name = "备注") /** 新增:详细地址 */
private String remark; @Excel(name = "详细地址")
private String address;
/** 新增:创建人 */
@Excel(name = "创建人")
private String createBy;
/** 新增:创建日期 */
@Excel(name = "创建日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date createTime;
// --- 以下是 Getter 和 Setter 方法,必须包含 ---
public String getName() { public String getName() {
return name; return name;
@@ -31,19 +47,35 @@ public class SxCustomerExport {
this.phone = phone; this.phone = phone;
} }
public String getFullAddress() { public String getArea() {
return fullAddress; return area;
} }
public void setFullAddress(String fullAddress) { public void setArea(String area) {
this.fullAddress = fullAddress; this.area = area;
} }
public String getRemark() { public String getAddress() {
return remark; return address;
} }
public void setRemark(String remark) { public void setAddress(String address) {
this.remark = remark; this.address = address;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
} }
} }

View File

@@ -13,10 +13,14 @@
<result property="remark" column="remark"/> <result property="remark" column="remark"/>
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/> <result property="deptId" column="dept_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap> </resultMap>
<sql id="selectSxCustomerVo"> <sql id="selectSxCustomerVo">
SELECT c.id, c.name, c.phone, c.province, c.city, c.district, c.address, c.remark, c.user_id, c.dept_id SELECT c.id, c.name, c.phone, c.province, c.city, c.district, c.address, c.remark, c.user_id, c.dept_id, c.create_by, c.create_time, c.update_by, c.update_time
FROM sx_customer c FROM sx_customer c
</sql> </sql>
@@ -24,6 +28,9 @@
<include refid="selectSxCustomerVo"/> <include refid="selectSxCustomerVo"/>
<where> <where>
<if test="name != null and name != ''"> AND c.name LIKE CONCAT('%', #{name}, '%')</if> <if test="name != null and name != ''"> AND c.name LIKE CONCAT('%', #{name}, '%')</if>
<if test="province != null and province != ''"> AND c.province = #{province}</if>
<if test="city != null and city != ''"> AND c.city = #{city}</if>
<if test="district != null and district != ''"> AND c.district = #{district}</if>
${params.dataScope} ${params.dataScope}
</where> </where>
</select> </select>
@@ -45,6 +52,10 @@
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="userId != null">user_id,</if> <if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if> <if test="deptId != null">dept_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim> </trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=","> <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if> <if test="name != null and name != ''">#{name},</if>
@@ -56,6 +67,10 @@
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="userId != null">#{userId},</if> <if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if> <if test="deptId != null">#{deptId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim> </trim>
</insert> </insert>
@@ -69,6 +84,8 @@
<if test="district != null">district = #{district},</if> <if test="district != null">district = #{district},</if>
<if test="address != null">address = #{address},</if> <if test="address != null">address = #{address},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim> </trim>
WHERE id = #{id} WHERE id = #{id}
</update> </update>