/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.yami.shop.common.util.Json;
import com.yami.shop.distribution.comment.model.DistributionAuditingSet;
import com.yami.shop.common.config.Constant;
import com.yami.shop.distribution.comment.service.DistributionAuditingSetService;
import com.yami.shop.security.platform.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionAuditingSet")
@AllArgsConstructor
public class DistributionAuditingSetController {

    private DistributionAuditingSetService distributionAuditingSetService;


    /**
     * 获取信息(根据店铺)
     */
    @GetMapping("/info")
	@PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:info')")
    public ResponseEntity<DistributionAuditingSet> info() {
        return ResponseEntity.ok(distributionAuditingSetService.getByShopId());
    }


    /**
     * 修改
     */
    @PutMapping
	@PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionAuditingSet distributionAuditingSet) {
        distributionAuditingSet.setAuditingInfoJson(Json.toJsonString(distributionAuditingSet.getAuditingInfo()));
        distributionAuditingSet.setAuditingConditionsJson(Json.toJsonString(distributionAuditingSet.getAuditingConditions()));
        distributionAuditingSet.setUpdateTime(new Date());
        distributionAuditingSet.setModifier(SecurityUtils.getSysUser().getUserId());
        distributionAuditingSetService.updateById(distributionAuditingSet);
        distributionAuditingSetService.removeCacheByShopId(Constant.PLATFORM_SHOP_ID);
        return ResponseEntity.ok().build();
    }

//    /**
//     * 分页获取
//     */
//    @GetMapping("/page")
//	  @PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:page')")
//    public ResponseEntity<IPage<DistributionAuditingSet>> page(DistributionAuditingSet distributionAuditingSet, PageParam<DistributionAuditingSet> page) {
//        IPage<DistributionAuditingSet> distributionAuditingSets = distributionAuditingSetService.page(page, new LambdaQueryWrapper<DistributionAuditingSet>());
//        return ResponseEntity.ok(distributionAuditingSets);
//    }

//    /**
//     * 获取
//     */
//    @GetMapping("/info/{id}")
//	  @PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:info')")
//    public ResponseEntity<DistributionAuditingSet> info(@PathVariable("id") Long id) {
//        DistributionAuditingSet distributionAuditingSet = distributionAuditingSetService.getDistributionAuditingSetInfo(id);
//
//        return ResponseEntity.ok(distributionAuditingSet);
//    }

//    /**
//     * 保存
//     */
//    @PostMapping
//    @PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:save')")
//    public ResponseEntity<Void> save(@RequestBody @Valid DistributionAuditingSet distributionAuditingSet) {
//        distributionAuditingSetService.save(distributionAuditingSet);
//        return ResponseEntity.ok().build();
//    }

//    /**
//     * 删除
//     */
//    @DeleteMapping("/{id}")
//    @PreAuthorize("@pms.hasPermission('distribution:distributionAuditingSet:delete')")
//    public ResponseEntity<Void> delete(@PathVariable Long id) {
//        distributionAuditingSetService.removeById(id);
//        return ResponseEntity.ok().build();
//    }
}
