package com.yh.saas.plugin.yiliangyiyun.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.winsea.svc.base.base.entity.CommonCompany;
import com.winsea.svc.base.base.service.ICommonCompanyService;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.plugin.yiliangyiyun.entity.IdentityAuthenticationInfo;
import com.yh.saas.plugin.yiliangyiyun.entity.WeighingManagement;
import com.yh.saas.plugin.yiliangyiyun.service.IWeighingManagementService;
import com.yh.saas.plugin.yiliangyiyun.util.QRCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 检斤管理 前端控制器
 * </p>
 *
 * @author Gdc
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/weighingManagement")
public class WeighingManagementController {

    @Autowired
    private IWeighingManagementService weighingManagementService;
    @Autowired
    private ICommonCompanyService companyService;
    @Autowired
    private QRCodeUtil qrCodeUtil ;
    /**
     * 检斤管理列表
     * @param weighingManagement
     * @return
     */
    @GetMapping("/selectWeighingManagement")
    public Page<WeighingManagement> selectWeighingManagement(WeighingManagement weighingManagement) {
        return weighingManagementService.selectWeighingManagement(weighingManagement);
    }

    /**
     * 毛重检斤
     * @param weighingManagement
     * @return
     */
    @PostMapping("/api/editGrossWeight")
    public String editGrossWeight(@RequestBody WeighingManagement weighingManagement){
        return weighingManagementService.editGrossWeight(weighingManagement);
    }

    /**
     * 皮重检斤
     * @param weighingManagement
     * @return
     */
    @PostMapping("/api/editTare")
    public String editTare(@RequestBody WeighingManagement weighingManagement){
        return weighingManagementService.editTare(weighingManagement);
    }

    /**
     * 出库管理添加皮重检斤
     * @param weighingManagement
     * @return
     */
    @PostMapping("/api/addTare")
    public String addTare(@RequestBody WeighingManagement weighingManagement){
        return weighingManagementService.addTare(weighingManagement);
    }
    /**
     * 出库管理编辑皮重检斤
     * @param weighingManagement
     * @return
     */
    @PostMapping("/api/editTareOut")
    public String editTareOut(@RequestBody WeighingManagement weighingManagement){
        return weighingManagementService.editTareOut(weighingManagement);
    }
    /**
     * 删除检斤管理信息
     * @param weighingManagement
     */
    @PostMapping("/api/deleteWeightcheck")
    public void deleteWeightcheck(@RequestBody WeighingManagement weighingManagement){
        weighingManagementService.deleteWeightcheck(weighingManagement.getId());
    }
    /**
     * 查看检斤信息
     *  @param id
     * @return
     */
    @GetMapping("/getWeighingManagement")
    public WeighingManagement getWeighingManagement(@RequestParam String id) {
        return weighingManagementService.getWeighingManagement(id);
    }

    /**
     * 获取二维码
     * @param weighingManagement
     * @return
     */
    @GetMapping("/generateQRCodeImage")
    public String generateQRCodeImage(WeighingManagement weighingManagement) {
        weighingManagement.setCompId(AuthSecurityUtils.getCurrentUserInfo().getCompId());
        CommonCompany commonCompany = companyService.selectById(weighingManagement.getCompId());
        return qrCodeUtil.generateQRCodeImage(weighingManagement.getPrintString(),800,800,"company",weighingManagement.getCompId());
    }

    /**
     * 扫描二维码
     * @param weighingManagement
     * @return
     */
    @GetMapping("/getQRcode")
    public WeighingManagement getQRcode(WeighingManagement weighingManagement) {
        return weighingManagementService.getQRcode(weighingManagement);
    }

}

