package com.pj.project.tb_business; import java.util.Date; import java.util.List; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.pj.constants.UserTypeEnum; import com.pj.project.tb_business_item.TbBusinessItem; import com.pj.project.tb_business_item.TbBusinessItemService; import com.pj.project.tb_notices.TbNoticesService; import com.pj.project.tb_pass_record.TbPassRecord; import com.pj.project.tb_pass_record.TbPassRecordService; import com.pj.utils.so.SoMap; import org.aspectj.weaver.loadtime.Aj; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import com.pj.utils.sg.*; import com.pj.project4sp.SP; import com.pj.current.satoken.StpUserUtil; import cn.dev33.satoken.annotation.SaCheckPermission; import javax.annotation.Resource; /** * Controller: tb_business -- 入境登记 * * @author qzy */ @RestController @RequestMapping("/TbBusiness/") public class TbBusinessController { /** * 底层 Service 对象 */ @Autowired TbBusinessService tbBusinessService; @Resource private TbBusinessItemService tbBusinessItemService; @Resource private TbPassRecordService tbPassRecordService; @Resource private TbNoticesService tbNoticesService; @RequestMapping(value = "getMsg") public AjaxJson getMsg(){ return AjaxJson.getSuccessData(BusinessMessageManager.get(StpUserUtil.getCustomerId())); } /** * 增 */ @RequestMapping("add") @SaCheckPermission(TbBusiness.PERMISSION_CODE) @Transactional(rollbackFor = Exception.class) public AjaxJson add(TbBusiness t) { return tbBusinessService.addOrUpdate(t); } /** * 删 */ @RequestMapping("delete") @SaCheckPermission(TbBusiness.PERMISSION_INPUT) @Transactional(rollbackFor = Exception.class) public AjaxJson delete(String id) { TbBusiness db= tbBusinessService.getById(id); if (db!=null){ tbBusinessService.storeMsg(db.getCustomerId(),"业务订单【"+db.getNo()+"】已删除。"+ DateUtil.now()+"。"); } tbBusinessService.removeById(id); tbBusinessItemService.removeByBusinessId(id); tbPassRecordService.removeByBusinessId(id); return AjaxJson.getSuccess(); } /** * 删 - 根据id列表 */ @RequestMapping("deleteByIds") @SaCheckPermission(TbBusiness.PERMISSION_CODE) @Transactional(rollbackFor = Exception.class) public AjaxJson deleteByIds() { List ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); ids.forEach(id -> { tbBusinessItemService.removeByBusinessId(id + ""); }); int line = SP.publicMapper.deleteByIds(TbBusiness.TABLE_NAME, ids); return AjaxJson.getByLine(line); } /** * 改 */ @RequestMapping("update") @SaCheckPermission(TbBusiness.PERMISSION_CODE) public AjaxJson update(TbBusiness t) { tbBusinessService.addOrUpdate(t); return AjaxJson.getSuccess(); } /** * 确认业务 */ @RequestMapping("confirm") @Transactional(rollbackFor = Exception.class) public AjaxJson confirm() { if (!StpUtil.hasPermissionAnd(TbBusiness.PERMISSION_CONFIRM) && ! StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无确认业务权限"); } SoMap so = SoMap.getRequestSoMap(); List ids = so.getListByComma("ids", String.class); tbBusinessService.confirm(ids); return AjaxJson.getSuccess(); } /** * 确认业务 */ @RequestMapping("adminConfirmPay") @Transactional(rollbackFor = Exception.class) public AjaxJson adminConfirmPay() { if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无确认支付权限"); } SoMap so = SoMap.getRequestSoMap(); List ids = so.getListByComma("ids", String.class); String ticket = so.getString("payTicket"); tbBusinessService.adminConfirmPay(ids, ticket); return AjaxJson.getSuccess(); } /** * 手动入场确认 see adminSetIn */ @RequestMapping("adminConfirmIn") @Transactional(rollbackFor = Exception.class) @Deprecated public AjaxJson adminConfirmIn() { if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无确认入场权限"); } SoMap so = SoMap.getRequestSoMap(); String id = so.getString("id"); String inChannel = so.getString("inChannel"); tbBusinessService.adminConfirmIn(id, inChannel); return AjaxJson.getSuccess(); } /** * 查 - 根据id */ @RequestMapping("getById") public AjaxJson getById(String id) { TbBusiness t = tbBusinessService.getById(id); List items = tbBusinessItemService.findByBusinessId(id); t.setItems(items); return AjaxJson.getSuccessData(t); } /** * 查集合 - 根据条件(参数为空时代表忽略指定条件) */ @RequestMapping("getList") public AjaxJson getList() { SoMap so = SoMap.getRequestSoMap(); String currentCustomerId = StpUserUtil.getCustomerId(); if (!currentCustomerId.equals(UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { so.put("customerId", currentCustomerId); } List list = tbBusinessService.getList(so.startPage()); return AjaxJson.getPageData(so.getDataCount(), list); } /** * 改 */ @RequestMapping("pay") public AjaxJson pay() { if (!StpUtil.hasPermissionAnd("tb-business-pay") && ! StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无支付权限"); } SoMap so = SoMap.getRequestSoMap(); String id = so.getString("id"); String payTicket = so.getString("payTicket"); tbBusinessService.pay(id, payTicket); return AjaxJson.getSuccess(); } @RequestMapping("adminSetIn") public AjaxJson adminSetIn() { if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无入场权限"); } SoMap so = SoMap.getRequestSoMap(); String id = so.getString("id"); Date inTime = so.getDateTime("realInTime"); Date chinaCarInTime = so.getDateTime("chinaCarInTime"); TbBusiness tbBusiness = tbBusinessService.getById(id); tbBusiness.setChinaCarInTime(chinaCarInTime).setRealInTime(inTime).setAdminConfirmIn(1); tbBusinessService.updateById(tbBusiness); //更新境外车入场记录 tbPassRecordService.addOrUpdate(tbBusiness.getId(), tbBusiness.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getCardNo(), 2, tbBusiness.getRealInTime(), null, tbBusiness.getCountryName()); //更新中国车入场记录 tbPassRecordService.addOrUpdate(tbBusiness.getId(), tbBusiness.getCustomerId(), tbBusiness.getCustomerName(), tbBusiness.getChinaCarNo(), 2, tbBusiness.getChinaCarInTime(), null, "中国车"); //发送消息 String text = "您的车辆已入场,业务单号["+ tbBusiness.getNo() + "]"; tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text); return AjaxJson.getSuccess(); } @RequestMapping("adminOut") public AjaxJson adminOut(){ if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) { return AjaxJson.getError("无离场权限"); } SoMap so = SoMap.getRequestSoMap(); String id = so.getString("id"); TbBusiness business= tbBusinessService.getById(id); Date outTime=so.getDateTime("outDayTime"); if (business.getRealInTime().getTime()>outTime.getTime()) { return AjaxJson.getError("离场时间须大于出场时间"); } business.setOutDayTime(outTime); tbBusinessService. calculationPartMoney("越南车",business); tbBusinessService.updateById(business); Date chinaCarOutTime=so.getDateTime("chinaCarOutTime"); if (chinaCarOutTime.getTime()