package com.vincent.rsf.server.manager.controller; 
 | 
  
 | 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
 | 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
 | 
import com.baomidou.mybatisplus.core.metadata.IPage; 
 | 
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.common.utils.FieldsUtils; 
 | 
import com.vincent.rsf.server.manager.controller.params.IsptItemsParams; 
 | 
import com.vincent.rsf.server.manager.entity.QlyIsptItem; 
 | 
import com.vincent.rsf.server.manager.service.QlyIsptItemService; 
 | 
import com.vincent.rsf.server.system.controller.BaseController; 
 | 
import io.swagger.annotations.Api; 
 | 
import io.swagger.annotations.ApiOperation; 
 | 
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 = "质检明细") 
 | 
@RestController 
 | 
public class QlyIsptItemController extends BaseController { 
 | 
  
 | 
    @Autowired 
 | 
    private QlyIsptItemService qlyIsptItemService; 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/page") 
 | 
    public R page(@RequestBody Map<String, Object> map) { 
 | 
        BaseParam baseParam = buildParam(map, BaseParam.class); 
 | 
        PageParam<QlyIsptItem, BaseParam> pageParam = new PageParam<>(baseParam, QlyIsptItem.class); 
 | 
        QueryWrapper<QlyIsptItem> queryWrapper = pageParam.buildWrapper(true); 
 | 
        /**拼接扩展字段*/ 
 | 
        PageParam<QlyIsptItem, BaseParam> page = qlyIsptItemService.page(pageParam, queryWrapper); 
 | 
        List<QlyIsptItem> records = page.getRecords(); 
 | 
        for (QlyIsptItem record : records) { 
 | 
            if (!Objects.isNull(record.getFieldsIndex())) { 
 | 
                Map<String, String> fields = FieldsUtils.getFields(record.getFieldsIndex()); 
 | 
                record.setExtendFields(fields); 
 | 
            } 
 | 
        } 
 | 
        page.setRecords(records); 
 | 
  
 | 
        return R.ok(page); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * @author Ryan 
 | 
     * @date 2025/5/12 
 | 
     * @description: 获取质检信息修改 
 | 
     * @version 1.0 
 | 
     */ 
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/ispts/page") 
 | 
    public R getQlyList(@RequestBody Map<String, Object> map) { 
 | 
        BaseParam baseParam = buildParam(map, BaseParam.class); 
 | 
        PageParam<QlyIsptItem, BaseParam> pageParam = new PageParam<>(baseParam, QlyIsptItem.class); 
 | 
        QueryWrapper<QlyIsptItem> queryWrapper = pageParam.buildWrapper(true); 
 | 
        IPage<QlyIsptItem> page = qlyIsptItemService.pageByWrapper(pageParam, queryWrapper); 
 | 
        List<QlyIsptItem> records = page.getRecords(); 
 | 
        for (QlyIsptItem record : records) { 
 | 
            if (!Objects.isNull(record.getFieldsIndex())) { 
 | 
                Map<String, String> fields = FieldsUtils.getFields(record.getFieldsIndex()); 
 | 
                record.setExtendFields(fields); 
 | 
            } 
 | 
        } 
 | 
        page.setRecords(records); 
 | 
  
 | 
        return R.ok(page); 
 | 
    } 
 | 
  
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/ispt/result/page") 
 | 
    public R getIsptResultList(@RequestBody Map<String, Object> map) { 
 | 
        BaseParam baseParam = buildParam(map, BaseParam.class); 
 | 
        PageParam<QlyIsptItem, BaseParam> pageParam = new PageParam<>(baseParam, QlyIsptItem.class); 
 | 
        QueryWrapper<QlyIsptItem> queryWrapper = pageParam.buildWrapper(true); 
 | 
        IPage<QlyIsptItem> page = qlyIsptItemService.pageByIsptResult(pageParam, queryWrapper); 
 | 
        List<QlyIsptItem> records = page.getRecords(); 
 | 
        for (QlyIsptItem record : records) { 
 | 
            if (!Objects.isNull(record.getFieldsIndex())) { 
 | 
                Map<String, String> fields = FieldsUtils.getFields(record.getFieldsIndex()); 
 | 
                record.setExtendFields(fields); 
 | 
            } 
 | 
        } 
 | 
        page.setRecords(records); 
 | 
  
 | 
        return R.ok(page); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/list") 
 | 
    public R list(@RequestBody Map<String, Object> map) { 
 | 
        return R.ok().add(qlyIsptItemService.list()); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping({"/qlyIsptItem/many/{ids}", "/qlyIsptItems/many/{ids}"}) 
 | 
    public R many(@PathVariable Long[] ids) { 
 | 
        return R.ok().add(qlyIsptItemService.listByIds(Arrays.asList(ids))); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @GetMapping("/qlyIsptItem/{id}") 
 | 
    public R get(@PathVariable("id") Long id) { 
 | 
        return R.ok().add(qlyIsptItemService.getById(id)); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:save')") 
 | 
    @OperationLog("Create 质检信息") 
 | 
    @PostMapping("/qlyIsptItem/save") 
 | 
    public R save(@RequestBody QlyIsptItem qlyIsptItem) { 
 | 
        qlyIsptItem.setCreateBy(getLoginUserId()); 
 | 
        qlyIsptItem.setCreateTime(new Date()); 
 | 
        qlyIsptItem.setUpdateBy(getLoginUserId()); 
 | 
        qlyIsptItem.setUpdateTime(new Date()); 
 | 
        if (!qlyIsptItemService.save(qlyIsptItem)) { 
 | 
            return R.error("Save Fail"); 
 | 
        } 
 | 
        return R.ok("Save Success").add(qlyIsptItem); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:update')") 
 | 
    @OperationLog("Update 质检信息") 
 | 
    @PostMapping("/qlyIsptItem/update") 
 | 
    public R update(@RequestBody QlyIsptItem qlyIsptItem) { 
 | 
        qlyIsptItem.setUpdateBy(getLoginUserId()); 
 | 
        qlyIsptItem.setUpdateTime(new Date()); 
 | 
        if (!qlyIsptItemService.updateById(qlyIsptItem)) { 
 | 
            return R.error("Update Fail"); 
 | 
        } 
 | 
        return R.ok("Update Success").add(qlyIsptItem); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:remove')") 
 | 
    @OperationLog("Delete 质检信息") 
 | 
    @PostMapping("/qlyIsptItem/remove/{ids}") 
 | 
    public R remove(@PathVariable Long[] ids) { 
 | 
        if (!qlyIsptItemService.removeByIds(Arrays.asList(ids))) { 
 | 
            return R.error("Delete Fail"); 
 | 
        } 
 | 
        return R.ok("Delete Success").add(ids); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/query") 
 | 
    public R query(@RequestParam(required = false) String condition) { 
 | 
        List<KeyValVo> vos = new ArrayList<>(); 
 | 
        LambdaQueryWrapper<QlyIsptItem> wrapper = new LambdaQueryWrapper<>(); 
 | 
        if (!Cools.isEmpty(condition)) { 
 | 
            wrapper.like(QlyIsptItem::getId, condition); 
 | 
        } 
 | 
        qlyIsptItemService.page(new Page<>(1, 30), wrapper).getRecords().forEach( 
 | 
                item -> vos.add(new KeyValVo(item.getId(), item.getId())) 
 | 
        ); 
 | 
        return R.ok().add(vos); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:list')") 
 | 
    @PostMapping("/qlyIsptItem/export") 
 | 
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { 
 | 
        ExcelUtil.build(ExcelUtil.create(qlyIsptItemService.list(), QlyIsptItem.class), response); 
 | 
    } 
 | 
  
 | 
    @PreAuthorize("hasAuthority('manager:qlyIsptItem:update')") 
 | 
    @ApiOperation("快速质检") 
 | 
    @PostMapping("/qlyIsptItem/batch/update") 
 | 
    public R batchUpdate(@RequestBody IsptItemsParams params) { 
 | 
        if (Objects.isNull(params)) { 
 | 
            throw new CoolException("参数不能为空!!"); 
 | 
        } 
 | 
        if (qlyIsptItemService.batchUpdate(params, getLoginUserId())) { 
 | 
            return R.ok("修改成功!!"); 
 | 
        } else  { 
 | 
            return R.error("修改失败!!"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |