package com.lz.modules.equipment.controller;


import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.equipment.entity.OneCode;
import com.lz.modules.equipment.entity.PrintReq;
import com.lz.modules.equipment.service.OneCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌表
 *
 * @author quyixiao
 * @version 1.0
 * @since 2020年07月29日 16时48分22秒
 */
@RestController
public class EquipmentPrintController {

    @Autowired
    private OneCodeService oneCodeService;


    /**
     * 获取品牌表集合
     *
     * @return 返回页面
     * @throws Exception 异常
     */
    @RequestMapping(value = "/modules/print/equipmentManager")
    public R equipmentBrandManager() throws Exception {
        return R.ok();
    }




    /**
     * 获取品牌表集合
     * @return 返回页面
     * @throws Exception 异常
     */
    @RequestMapping(value = "/modules/print/equipmentPrint")
    public R equipmentPrint(@RequestBody PrintReq req) throws Exception {
        List<String> codes = new ArrayList<>();
        if(StringUtil.isNotBlank(req.getCode())){
            OneCode oneCode = oneCodeService.selectByCode(req.getCode());
            if(oneCode != null){
                return R.error("条码己经存在，请重新输入条码");
            }else{
                codes.add(req.getCode());
                oneCodeService.insertOneCodes(codes);
            }
        }else if(req.getCount()  !=null){
            for (int i = 0; i < req.getCount(); i++){
                String code = "LZ" + StringUtil.getRandomNum(8);
                codes.add(code);
            }
            oneCodeService.insertOneCodes(codes);
        }else{
            R.error("请输入条码内容或者批量打印张数");
        }
        return R.ok("正在打印,请等待");
    }




}
