package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.DmpSoftwareSubpackage;
import com.usky.iot.domain.DmpSoftwareUpgrade;
import com.usky.iot.service.DmpSoftwareSubpackageService;
import com.usky.iot.service.DmpSoftwareUpgradeService;
import com.usky.iot.service.vo.DmpSoftwareUpgradeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 软件升级信息表
 *
 * @author ya
 * @since 2022-10-08
 */
@RestController
@RequestMapping("/dmpSoftwareUpgrade")
public class DmpSoftwareUpgradeController {

    @Autowired
    private DmpSoftwareUpgradeService dmpSoftwareUpgradeService;

    /**
     * 新增
     * @param dmpProductInfo
     * @param file
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestPart DmpSoftwareUpgrade dmpProductInfo, @RequestPart MultipartFile file){
        dmpSoftwareUpgradeService.add(dmpProductInfo,file);
        return ApiResult.success();
    }



    /**
     * 分页
     * @param dmpSoftwareUpgradeRequest
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<DmpSoftwareUpgrade>> page(@RequestBody DmpSoftwareUpgradeRequest dmpSoftwareUpgradeRequest)
    {
        return ApiResult.success(dmpSoftwareUpgradeService.page(dmpSoftwareUpgradeRequest));
    }

    @Autowired
    private DmpSoftwareSubpackageService dmpSoftwareSubpackageService;


    @GetMapping("test")
    public void test(){
        DmpSoftwareSubpackage byId = dmpSoftwareSubpackageService.getById(15524);
        byte[] b = byId.getApplyPackage();
        int crc = 0;
        for(int i=0;i<b.length;i++) {
            String str = Integer.toHexString(b[i]&0x00ff);
            if(str.length()==1) {
                str = "0"+str;
            }
//                    System.out.print(b[i]+" ");
//            System.out.print(str+" ");
            crc = (crc + (b[i]&0x00ff))&0xffff;
        }
        System.out.println(crc);

    }
}

