|  |  |  | 
|---|
|  |  |  | package com.ruoyi.web.controller.api; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import com.ruoyi.common.basic.PageInfo; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.R; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.entity.SysUser; | 
|---|
|  |  |  | import com.ruoyi.framework.web.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.system.dto.UpdateReminderDto; | 
|---|
|  |  |  | import com.ruoyi.system.model.TErpGoods; | 
|---|
|  |  |  | import com.ruoyi.system.model.TErpMaintenanceReminder; | 
|---|
|  |  |  | import com.ruoyi.system.model.TErpSupplierWarehousingBatch; | 
|---|
|  |  |  | import com.ruoyi.system.query.TErpMaintenanceReminderQuery; | 
|---|
|  |  |  | import com.ruoyi.system.query.TErpProcurementQuery; | 
|---|
|  |  |  | import com.ruoyi.system.service.*; | 
|---|
|  |  |  | import com.ruoyi.system.vo.TErpMaintenanceReminderDetailVo; | 
|---|
|  |  |  | import com.ruoyi.system.vo.TErpMaintenanceReminderListVo; | 
|---|
|  |  |  | import com.ruoyi.system.vo.TErpProcurementVo; | 
|---|
|  |  |  | 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.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.validation.Valid; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/t-erp-maintenance-reminder") | 
|---|
|  |  |  | @Api(tags = "erp保养提醒") | 
|---|
|  |  |  | public class TErpMaintenanceReminderController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final TErpMaintenanceReminderService erpMaintenanceReminderService; | 
|---|
|  |  |  | private final TokenService tokenService; | 
|---|
|  |  |  | private final TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService; | 
|---|
|  |  |  | private final TErpSupplierWarehousingService erpSupplierWarehousingService; | 
|---|
|  |  |  | private final TErpGoodsService erpGoodsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public TErpMaintenanceReminderController(TErpMaintenanceReminderService erpMaintenanceReminderService, TokenService tokenService, | 
|---|
|  |  |  | TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService,TErpSupplierWarehousingService erpSupplierWarehousingService, | 
|---|
|  |  |  | TErpGoodsService erpGoodsService) { | 
|---|
|  |  |  | this.erpMaintenanceReminderService = erpMaintenanceReminderService; | 
|---|
|  |  |  | this.tokenService = tokenService; | 
|---|
|  |  |  | this.erpSupplierWarehousingBatchService = erpSupplierWarehousingBatchService; | 
|---|
|  |  |  | this.erpSupplierWarehousingService = erpSupplierWarehousingService; | 
|---|
|  |  |  | this.erpGoodsService = erpGoodsService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * erp保养提醒分页列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "erp保养提醒分页列表") | 
|---|
|  |  |  | @PostMapping(value = "/pageList") | 
|---|
|  |  |  | public R<PageInfo<TErpMaintenanceReminderListVo>> pageList(@RequestBody TErpMaintenanceReminderQuery query) { | 
|---|
|  |  |  | SysUser user = tokenService.getLoginUser().getUser(); | 
|---|
|  |  |  | return R.ok(erpMaintenanceReminderService.pageList(query,user)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * erp保养提醒详情 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "erp保养提醒详情") | 
|---|
|  |  |  | @GetMapping(value = "/detail/{id}") | 
|---|
|  |  |  | public R<TErpMaintenanceReminderDetailVo> detail(@PathVariable String id) { | 
|---|
|  |  |  | SysUser user = tokenService.getLoginUser().getUser(); | 
|---|
|  |  |  | return R.ok(erpMaintenanceReminderService.detail(id,user)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * erp保养 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "erp保养提醒操作维护") | 
|---|
|  |  |  | @PostMapping(value = "/updateReminder") | 
|---|
|  |  |  | public R<?> updateReminder(@RequestBody @Valid UpdateReminderDto dto) { | 
|---|
|  |  |  | TErpMaintenanceReminder reminder = erpMaintenanceReminderService.getById(dto.getId()); | 
|---|
|  |  |  | reminder.setStatus(dto.getStatus()); | 
|---|
|  |  |  | reminder.setMaintenanceRecord(dto.getHandlerContent()); | 
|---|
|  |  |  | if(dto.getStatus()==2){ | 
|---|
|  |  |  | SysUser user = tokenService.getLoginUser().getUser(); | 
|---|
|  |  |  | reminder.setMaintenancePersonId(user.getUserId().intValue()); | 
|---|
|  |  |  | reminder.setSuccessTime(LocalDateTime.now()); | 
|---|
|  |  |  | erpMaintenanceReminderService.updateById( reminder); | 
|---|
|  |  |  | String warehousingBatchId = reminder.getWarehousingBatchId(); | 
|---|
|  |  |  | TErpSupplierWarehousingBatch byId = erpSupplierWarehousingBatchService.getById(warehousingBatchId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String goodsId = erpSupplierWarehousingService.getById(byId.getWarehousingId()).getGoodsId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder(); | 
|---|
|  |  |  | TErpGoods byId1 = erpGoodsService.getById(goodsId); | 
|---|
|  |  |  | String maintenanceInterval = byId1.getMaintenanceInterval(); | 
|---|
|  |  |  | String maintenanceIntervalUnit = byId1.getMaintenanceIntervalUnit(); | 
|---|
|  |  |  | if(maintenanceIntervalUnit!=null && !"".equals(maintenanceIntervalUnit) && "天".equals(maintenanceIntervalUnit)){ | 
|---|
|  |  |  | Integer day = Integer.valueOf(maintenanceInterval); | 
|---|
|  |  |  | // 当前时间+day天 | 
|---|
|  |  |  | LocalDateTime time1 = LocalDateTime.now().plusDays(day); | 
|---|
|  |  |  | tErpMaintenanceReminder.setMaintenanceTime(time1); | 
|---|
|  |  |  | }else if(maintenanceIntervalUnit!=null && !"".equals(maintenanceIntervalUnit) && "月".equals(maintenanceIntervalUnit)){ | 
|---|
|  |  |  | Integer day = Integer.valueOf(maintenanceInterval); | 
|---|
|  |  |  | // 当前时间+day月 | 
|---|
|  |  |  | LocalDateTime time1 = LocalDateTime.now().plusMonths(day); | 
|---|
|  |  |  | tErpMaintenanceReminder.setMaintenanceTime(time1); | 
|---|
|  |  |  | }else if(maintenanceIntervalUnit!=null && !"".equals(maintenanceIntervalUnit) && "年".equals(maintenanceIntervalUnit)){ | 
|---|
|  |  |  | Integer day = Integer.valueOf(maintenanceInterval); | 
|---|
|  |  |  | // 当前时间+day年 | 
|---|
|  |  |  | LocalDateTime time1 = LocalDateTime.now().plusYears(day); | 
|---|
|  |  |  | tErpMaintenanceReminder.setMaintenanceTime(time1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tErpMaintenanceReminder.setClinicSupplierId(reminder.getClinicSupplierId()); | 
|---|
|  |  |  | tErpMaintenanceReminder.setMaintenanceType(reminder.getMaintenanceType()); | 
|---|
|  |  |  | tErpMaintenanceReminder.setWarehousingBatchId(warehousingBatchId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | erpMaintenanceReminderService.save(tErpMaintenanceReminder); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|