# DrawerCountCurrencyConfigController.java

    package cloud.wconnect.frontoffice.controller.drawercount;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.CurrencyEnum;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.frontoffice.entity.drawercount.DrawerCountCurrencyConfig;
    import cloud.wconnect.frontoffice.pojo.dto.drawercount.DrawerCurrencyConfigDTO;
    import cloud.wconnect.frontoffice.service.drawercount.IDrawerCountCurrencyConfigService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import jakarta.validation.Valid;
    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * Drawer Count功能的币种配置表 前端控制器
     * </p>
     *
     * @author zc
     * @since 2023-08-24
     */
    @RestController
    @RequestMapping("/shift-drawer-count/drawer-count-currency-config")
    public class DrawerCountCurrencyConfigController {

        @Autowired
        private IDrawerCountCurrencyConfigService drawerCountCurrencyConfigService;

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private UpdateLogUtil updateLogUtil;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 查询币种配置
         *
         * @param property 资产标识
         * @return DrawerCurrencyConfigDTO
         * @author zc
         * @date 2023/8/25
         */
        @ApiId(598)
        @GetMapping
        public DrawerCurrencyConfigDTO get(String property) {
            int propertyId = sessionContext.getPropertyId(property);
            DrawerCountCurrencyConfig drawerCountCurrencyConfig = drawerCountCurrencyConfigService.get(propertyId);
            if (Objects.isNull(drawerCountCurrencyConfig)) {
                return new DrawerCurrencyConfigDTO(CurrencyEnum.USD.getId());
            }
            return beanMapper.map(drawerCountCurrencyConfig, DrawerCurrencyConfigDTO.class);
        }

        /**
         * 保存币种配置
         *
         * @param property          资产标识
         * @param currencyConfigDTO 币种配置
         * @return empty map
         * @author zc
         * @date 2023/8/25
         */
        @ApiId(599)
        @PostMapping
        public Map<Object, Object> save(String property, @RequestBody @Valid DrawerCurrencyConfigDTO currencyConfigDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            int loginUserId = sessionContext.getLoginUserId();

            DrawerCountCurrencyConfig drawerCountCurrencyConfig = new DrawerCountCurrencyConfig();
            drawerCountCurrencyConfig.setDrawerCurrency(currencyConfigDTO.getDrawerCurrency());

            DrawerCountCurrencyConfig originConfig = drawerCountCurrencyConfigService.get(propertyId);
            if (Objects.nonNull(originConfig)) {
                drawerCountCurrencyConfig.setId(originConfig.getId());
                drawerCountCurrencyConfig.setUpdateLog(updateLogUtil.append(originConfig.getUpdateLog(), loginUserId));
            } else {
                drawerCountCurrencyConfig.setPropertyId(propertyId);
                drawerCountCurrencyConfig.setUpdateLog(updateLogUtil.get(loginUserId));
            }

            // 保存
            drawerCountCurrencyConfigService.saveOrUpdate(drawerCountCurrencyConfig);
            return Collections.emptyMap();
        }
    }