package com.ruoyi.aftersalesservice.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.aftersalesservice.dto.AfterSalesServiceDto; import com.ruoyi.aftersalesservice.pojo.AfterSalesService; import com.ruoyi.aftersalesservice.service.AfterSalesServiceService; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.equipmentenergyconsumption.pojo.EquipmentEnergyConsumption; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.mapper.SysUserMapper; import com.ruoyi.purchase.dto.VatDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** * @author :yys * @date : 2025/7/30 9:27 */ @RestController @Api(tags = "售后服务") @RequestMapping("/afterSalesService") public class AfterSalesServiceController extends BaseController { @Autowired private AfterSalesServiceService afterSalesServiceService; @Autowired private SysUserMapper sysUserMapper; @GetMapping("/listPage") @ApiOperation("售后服务-分页查询") @Log(title = "售后服务-分页查询", businessType = BusinessType.OTHER) public AjaxResult listPage(Page page, AfterSalesService afterSalesService) { IPage listPage = afterSalesServiceService.listPage(page, afterSalesService); return AjaxResult.success(listPage); } @Log(title = "售后服务-反馈登记", businessType = BusinessType.EXPORT) @PostMapping("/export") @ApiOperation("售后服务-反馈登记") public void export(HttpServletResponse response) { Page page = new Page(-1,-1); AfterSalesService afterSalesService = new AfterSalesService(); IPage listPage = afterSalesServiceService.listPage(page, afterSalesService); List list = new ArrayList<>(); listPage.getRecords().forEach(item -> { AfterSalesServiceDto dto = new AfterSalesServiceDto(); BeanUtils.copyProperties(item, dto); dto.setStatusName(item.getStatus().toString()); list.add(dto); }); ExcelUtil util = new ExcelUtil(AfterSalesServiceDto.class); util.exportExcel(response, list , "反馈登记"); } @Log(title = "售后服务-售后处理", businessType = BusinessType.EXPORT) @PostMapping("/exportTwo") @ApiOperation("售后服务-售后处理") public void exportTwo(HttpServletResponse response) { Page page = new Page(-1,-1); AfterSalesService afterSalesService = new AfterSalesService(); IPage listPage = afterSalesServiceService.listPage(page, afterSalesService); listPage.getRecords().forEach(item -> { item.setStatusName(item.getStatus().toString()); }); ExcelUtil util = new ExcelUtil(AfterSalesService.class); util.exportExcel(response, listPage.getRecords() , "售后处理"); } @PostMapping("/add") @ApiOperation("售后服务-新增") @Log(title = "售后服务-新增", businessType = BusinessType.INSERT) public AjaxResult add(@RequestBody AfterSalesService afterSalesService) { afterSalesService.setStatus(1); SysUser sysUser = sysUserMapper.selectUserById(afterSalesService.getCheckUserId()); if(sysUser == null) throw new RuntimeException("审核人不存在"); afterSalesService.setCheckNickName(sysUser.getNickName()); boolean save = afterSalesServiceService.save(afterSalesService); return save ? AjaxResult.success() : AjaxResult.error(); } @PostMapping("/update") @ApiOperation("售后服务-修改") @Log(title = "售后服务-修改", businessType = BusinessType.UPDATE) public AjaxResult update(@RequestBody AfterSalesService afterSalesService) { boolean update = afterSalesServiceService.updateById(afterSalesService); return update ? AjaxResult.success() : AjaxResult.error(); } @DeleteMapping("/delete") @ApiOperation("售后服务-删除") @Log(title = "售后服务-删除", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestBody List ids) { if (CollectionUtils.isEmpty(ids)) { return AjaxResult.error("请传入要删除的ID"); } boolean delete = afterSalesServiceService.removeByIds(ids); return delete ? AjaxResult.success() : AjaxResult.error(); } @PostMapping("/dispose") @ApiOperation("售后服务-处理") @Log(title = "售后服务-处理", businessType = BusinessType.UPDATE) public AjaxResult dispose(@RequestBody AfterSalesService afterSalesService) { AfterSalesService byId = afterSalesServiceService.getById(afterSalesService.getId()); if(byId == null) throw new RuntimeException("未找到该数据"); if(byId.getStatus().equals(2)) throw new RuntimeException("该数据已处理"); SysUser sysUser = sysUserMapper.selectUserById(afterSalesService.getDisposeUserId()); if(sysUser == null) throw new RuntimeException("处理人不存在"); afterSalesService.setDisposeNickName(sysUser.getNickName()); afterSalesService.setStatus(2); boolean update = afterSalesServiceService.updateById(afterSalesService); return update ? AjaxResult.success() : AjaxResult.error(); } }