| | |
| | | import java.util.Map; |
| | | import java.util.HashMap; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.common.utils.LongUtil; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.service.ISysTaskEmergencyService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | @RequestMapping("/system/invoice") |
| | | public class SysInvoiceController extends BaseController |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(SysInvoiceController.class); |
| | | |
| | | @Autowired |
| | | private ISysInvoiceService sysInvoiceService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | |
| | | @Autowired |
| | | private ISysTaskEmergencyService sysTaskEmergencyService; |
| | | |
| | | /** |
| | | * 查询发票申请列表 |
| | |
| | | } |
| | | |
| | | /** |
| | | * App端查看我的某条发票详情(无需后台权限,但只能查看自己的发票) |
| | | */ |
| | | @GetMapping("/myDetail/{invoiceId}") |
| | | public AjaxResult myDetail(@PathVariable("invoiceId") Long invoiceId) |
| | | { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | SysInvoice invoice = sysInvoiceService.selectSysInvoiceByInvoiceId(invoiceId); |
| | | if (invoice == null) { |
| | | return AjaxResult.error("发票不存在"); |
| | | } |
| | | if (!currentUserId.equals(invoice.getApplyUserId())) { |
| | | return AjaxResult.error("无权限查看该发票"); |
| | | } |
| | | return AjaxResult.success(invoice); |
| | | } |
| | | |
| | | /** |
| | | * App端用户编辑自己的发票申请(仅待审核/已驳回可编辑,不可更改关联任务) |
| | | */ |
| | | @Log(title = "发票申请自助修改", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/myEdit") |
| | | public AjaxResult myEdit(@RequestBody SysInvoice sysInvoice) |
| | | { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | if (sysInvoice.getInvoiceId() == null) { |
| | | return AjaxResult.error("发票ID不能为空"); |
| | | } |
| | | SysInvoice exist = sysInvoiceService.selectSysInvoiceByInvoiceId(sysInvoice.getInvoiceId()); |
| | | if (exist == null) { |
| | | return AjaxResult.error("发票不存在"); |
| | | } |
| | | if (!currentUserId.equals(exist.getApplyUserId())) { |
| | | return AjaxResult.error("无权限修改该发票"); |
| | | } |
| | | if (exist.getStatus() != 0 && exist.getStatus() != 2) { |
| | | return AjaxResult.error("只有待审核或已驳回的发票可以修改"); |
| | | } |
| | | Long taskId = exist.getServiceOrderId(); |
| | | Long legacyServiceOrdId = exist.getLegacyServiceOrderId(); |
| | | if(LongUtil.isNotEmpty(taskId) && LongUtil.isEmpty(legacyServiceOrdId)){ |
| | | SysTaskEmergency taskEmergency= sysTaskEmergencyService.selectSysTaskEmergencyByTaskId(taskId); |
| | | if(taskEmergency!=null){ |
| | | legacyServiceOrdId=taskEmergency.getLegacyServiceOrdId(); |
| | | } |
| | | |
| | | } |
| | | // 保持关联任务信息不变,只更新发票内容字段 |
| | | sysInvoice.setServiceOrderId(exist.getServiceOrderId()); |
| | | sysInvoice.setLegacyServiceOrderId(legacyServiceOrdId); |
| | | sysInvoice.setApplyUserId(exist.getApplyUserId()); |
| | | sysInvoice.setApplyTime(exist.getApplyTime()); |
| | | sysInvoice.setStatus(0); // 重新置为待审核 |
| | | int rows = sysInvoiceService.updateSysInvoice(sysInvoice); |
| | | |
| | | if (rows > 0) { |
| | | // 异步同步到旧系统,失败不影响主流程 |
| | | try { |
| | | sysInvoiceService.syncUpdateToLegacySystem(sysInvoice.getInvoiceId()); |
| | | } catch (Exception e) { |
| | | log.warn("发票编辑同步旧系统失败,不影响保存结果: {}", e.getMessage()); |
| | | } |
| | | } |
| | | return toAjax(rows); |
| | | } |
| | | |
| | | /** |
| | | * 获取可申请发票的任务列表 |
| | | * @param searchKeyword 搜索关键词(支持taskCode、serviceCode、legacyServiceOrdNo) |
| | | * @param serviceOrdClass 分公司代码(可选,默认使用用户所属分公司) |