|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.ExcelUtil; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.annotation.OperationLog; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.BaseParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.KeyValVo; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.PageParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.IsptOrderParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.QlyInspect; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.QlyIsptItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.QlyInspectService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.QlyIsptItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Api(tags = "质检") | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = "质检信息") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class QlyInspectController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private QlyInspectService qlyInspectService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private QlyIsptItemService qlyIsptItemService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:list')") | 
|---|
|  |  |  | @PostMapping("/qlyInspect/page") | 
|---|
|  |  |  | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<QlyInspect, BaseParam> pageParam = new PageParam<>(baseParam, QlyInspect.class); | 
|---|
|  |  |  | return R.ok().add(qlyInspectService.page(pageParam, pageParam.buildWrapper(true))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/qlyInspect/all/save") | 
|---|
|  |  |  | @PreAuthorize("'manager:qlyInspect:save'") | 
|---|
|  |  |  | @ApiOperation("单据及明细保存") | 
|---|
|  |  |  | public R allSvae(@RequestBody QlyInspectAndItem params) { | 
|---|
|  |  |  | if (Objects.isNull(params)) { | 
|---|
|  |  |  | return R.error("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(qlyInspectService.allSave(params)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/qlyInspect/reports") | 
|---|
|  |  |  | @ApiOperation("获取可质检单据明细") | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:list')") | 
|---|
|  |  |  | public R listByAsnCode(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | if (Objects.isNull(map)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(qlyInspectService.listByAsn(map)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/qlyInspect/asn/list") | 
|---|
|  |  |  | @ApiOperation("获取待质检单") | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:list')") | 
|---|
|  |  |  | public R getUnInspect(@RequestBody Map<String, String> map) { | 
|---|
|  |  |  | if (Objects.isNull(map)) { | 
|---|
|  |  |  | return R.error("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(qlyInspectService.getUnInspect(map)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/qlyInspect/selected") | 
|---|
|  |  |  | @ApiOperation("选择质检单据") | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:update')") | 
|---|
|  |  |  | public R selectedOrder(@RequestBody IsptOrderParam param) { | 
|---|
|  |  |  | if (Objects.isNull(param)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long loginUserId = getLoginUserId(); | 
|---|
|  |  |  | return qlyInspectService.saveSelected(param, loginUserId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:list')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping("/qlyInspect/save") | 
|---|
|  |  |  | public R save(@RequestBody QlyInspect qlyInspect) { | 
|---|
|  |  |  | qlyInspect.setCreateBy(getLoginUserId()); | 
|---|
|  |  |  | qlyInspect.setCreateTime(new Date()); | 
|---|
|  |  |  | qlyInspect.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | qlyInspect.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!qlyInspectService.save(qlyInspect)) { | 
|---|
|  |  |  | if (!qlyInspectService.qlySave(qlyInspect)) { | 
|---|
|  |  |  | return R.error("Save Fail"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Save Success").add(qlyInspect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:update')") | 
|---|
|  |  |  | @ApiOperation("审核确认") | 
|---|
|  |  |  | @PostMapping("/qlyInspect/verify/complate/{id}") | 
|---|
|  |  |  | public R verifyComplate(@PathVariable Long id) { | 
|---|
|  |  |  | if (Objects.isNull(id)) { | 
|---|
|  |  |  | throw new CoolException("参数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return qlyInspectService.verifyComplate(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('manager:qlyInspect:update')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Delete 质检信息") | 
|---|
|  |  |  | @PostMapping("/qlyInspect/remove/{ids}") | 
|---|
|  |  |  | public R remove(@PathVariable Long[] ids) { | 
|---|
|  |  |  | if (Objects.isNull(ids) || ids.length < 1) { | 
|---|
|  |  |  | return R.error("能数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<QlyInspect> qlyInspects = qlyInspectService.list(new LambdaQueryWrapper<QlyInspect>() | 
|---|
|  |  |  | .in(QlyInspect::getId, ids) | 
|---|
|  |  |  | .gt(QlyInspect::getIsptQty, 0) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (!qlyInspects.isEmpty()) { | 
|---|
|  |  |  | return R.error("有明细单据已在质检中!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!qlyInspectService.removeByIds(Arrays.asList(ids))) { | 
|---|
|  |  |  | return R.error("Delete Fail"); | 
|---|
|  |  |  | return R.error("主单删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!qlyIsptItemService.remove(new LambdaQueryWrapper<QlyIsptItem>().in(QlyIsptItem::getIspectId, ids))) { | 
|---|
|  |  |  | return R.error("明细删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Delete Success").add(ids); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | List<KeyValVo> vos = new ArrayList<>(); | 
|---|
|  |  |  | LambdaQueryWrapper<QlyInspect> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(QlyInspect::getName, condition); | 
|---|
|  |  |  | wrapper.like(QlyInspect::getCode, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | qlyInspectService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
|---|
|  |  |  | item -> vos.add(new KeyValVo(item.getId(), item.getName())) | 
|---|
|  |  |  | item -> vos.add(new KeyValVo(item.getId(), item.getCode())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ExcelUtil.build(ExcelUtil.create(qlyInspectService.list(), QlyInspect.class), response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|