package com.qianwen.smartman.modules.cps.controller; import java.util.List; import java.util.Map; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.support.Condition; import com.qianwen.core.scanner.modular.annotation.DeleteResource; import com.qianwen.core.scanner.modular.annotation.GetResource; import com.qianwen.core.scanner.modular.annotation.PostResource; import com.qianwen.core.scanner.modular.stereotype.ApiResource; import com.qianwen.core.tenant.annotation.NonDS; import com.qianwen.core.tool.api.R; import com.qianwen.smartman.common.enums.GlobalWcsTypeEnum; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.cps.convert.GlobalWcsConvert; import com.qianwen.smartman.modules.cps.entity.GlobalWcs; import com.qianwen.smartman.modules.cps.service.IGlobalWcsService; import com.qianwen.smartman.modules.cps.vo.GlobalWcsVO; import com.qianwen.smartman.modules.cps.vo.WcsAchievementsUpdateVO; import com.qianwen.smartman.modules.cps.vo.WcsAndAchievementsVO; import com.qianwen.smartman.modules.mdc.entity.WorkstationFeedbackDetail; import com.qianwen.smartman.modules.mdc.enums.FeedbackDetailStatus; import com.qianwen.smartman.modules.mdc.service.IWorkstationFeedbackDetailService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import springfox.documentation.annotations.ApiIgnore; @Api(value = "全局工况", tags = {"全局工况"}) @RestController @ApiResource({"smis/global_wcs"}) @NonDS public class GlobalWcsController { private final IGlobalWcsService globalWcsService; private final IWorkstationFeedbackDetailService feedbackDetailService; public GlobalWcsController(final IGlobalWcsService globalWcsService, final IWorkstationFeedbackDetailService feedbackDetailService) { this.globalWcsService = globalWcsService; this.feedbackDetailService = feedbackDetailService; } @ApiOperationSupport(order = 1) @ApiImplicitParams({@ApiImplicitParam(name = "code", value = "状态码", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "name", value = "名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "type", value = "类型1系统默认,2业务逻辑,4反馈", paramType = "query", dataType = "int")}) @ApiOperation(value = "列表", notes = "传入globalWcs") @GetMapping({"/list"}) public R> list(@RequestParam @ApiIgnore Map globalWcs) { if (!globalWcs.containsKey("type")) { globalWcs.put("type", GlobalWcsTypeEnum.DEFAULT.getType()); } List list = this.globalWcsService.list(Condition.getQueryWrapper(globalWcs, GlobalWcs.class).lambda().orderByAsc(GlobalWcs::getSeq)); return R.data(GlobalWcsConvert.INSTANCE.convert(list)); } @GetResource({"/wcs-achievements"}) @ApiOperation(value = "获取状态和绩效时间", notes = "") public R> getWcsAndAchievements() { return R.data(this.globalWcsService.getWcsAndAchievements()); } @PostResource({"/update-wcs-achievements"}) @ApiOperation(value = "编辑状态和绩效时间", notes = "传入wcsAchievementsUpdateVO") public R updateWcsAndAchievements(@Validated @RequestBody WcsAchievementsUpdateVO wcsAchievementsUpdateVO) { this.globalWcsService.updateWcsAndAchievements(wcsAchievementsUpdateVO); return R.data(wcsAchievementsUpdateVO); } @PostResource({"/add-wcs-achievements"}) @ApiOperation(value = "添加人工反馈状态", notes = "传入FeedBackWcsAchievementsAddDTO") public R addFeedbackAchievements(@Validated @RequestBody WcsAchievementsUpdateVO wcsAchievementsUpdateVO) { return R.status(this.globalWcsService.insertWcsAndAchievements(wcsAchievementsUpdateVO)); } @DeleteResource({"/delete-wcs-achievements/{code}"}) @ApiOperation(value = "删除人工反馈状态", notes = "传入ID") public R delete(@PathVariable String code) { //ExtraLambdaQueryWrapper wra = Lambda.eq(WorkstationFeedbackDetail::getWcs, code); //wra.nested(w -> w.eq(WorkstationFeedbackDetail::getStatus, Integer.valueOf(FeedbackDetailStatus.EFFECTED.getValue()))); boolean exist = this.feedbackDetailService.count(Lambda.eq(WorkstationFeedbackDetail::getWcs, code) .nested(w -> w.eq(WorkstationFeedbackDetail::getStatus, FeedbackDetailStatus.EFFECTED.getValue())) .or().eq(WorkstationFeedbackDetail::getStatus, FeedbackDetailStatus.WAIT_EFFECT.getValue()) .eq(WorkstationFeedbackDetail::getCancel, false)) != 0; if (exist) throw new ServiceException(MessageUtils.message("workstation.wcs.delete.used", new Object[0])); return R.status(this.globalWcsService.removeByCode(code, GlobalWcsTypeEnum.FEEDBACK)); /* boolean exist = this.feedbackDetailService.count(Lambda.eq(WorkstationFeedbackDetail::getWcs, code).nested(w -> { ExtraLambdaQueryWrapper extraLambdaQueryWrapper = w.eq((v0) -> { return v0.getStatus(); }, FeedbackDetailStatus.EFFECTED.getValue()).or()).eq((v0) -> { return v0.getStatus(); }, Integer.valueOf(FeedbackDetailStatus.WAIT_EFFECT.getValue())); }.eq((v0) -> { return v0.getCancel(); }, false)) != 0; if (exist) { throw new ServiceException(MessageUtils.message("workstation.wcs.delete.used", new Object[0])); } return R.status(this.globalWcsService.removeByCode(code, GlobalWcsTypeEnum.FEEDBACK)); */ } @PostResource({"update-wcs-seq"}) @ApiOperation(value = "更新全局工况显示顺序", notes = "按顺序传入wcs的id") public R updateWcsSeq(@RequestBody List codeList) { this.globalWcsService.updateWcsSeq(codeList); return R.status(true); } }